01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING".
01 NAME2 PIC X(13).
now I want to display the value of NAME1 in reverse order
i.e value should be displayed as "GNIMMARGORP LOBOC"
HOW can I do that ??? please let me know if any one knows
it.
Answers were Sorted based on User's Feedback
Answer / mr2981
to reverse the string use REVERSE function
01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING".
01 NAME2 PIC X(13).
MOVE FUNCTION REVERSE(NAME1) TO NAME2.
| Is This Answer Correct ? | 34 Yes | 3 No |
Answer / elizabeth
Using reference modification each character can be
extracted and placed in the next string in any order
| Is This Answer Correct ? | 11 Yes | 0 No |
Answer / rajani
working-storage section.
01 name1 pic x(17) value 'cobol programming'.
01 name2 pic x(17).
01 i pic 99.
01 j pic 99 value 1.
procedure division.
perform para varying i from 17 by -1 until i<1.
display name2.
stop run
para.
move name1(i:1) to name2(j:1).
add 1 to j.
| Is This Answer Correct ? | 11 Yes | 1 No |
Answer / jagan
This should convert the string in reverse order without any
built-in functions . And one more thing is COBOL PROGRAMMING
is actually 17 characters.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NAME-1 PIC X(17) 'COBOL PROGRAMMING'
01 NAME-2
05 NAME-21 PIC X(1) OCCURS 17 TIMES.
01 I PIC X(2)
01 J PIC X(2)
PROCEDURE DIVISON.
MAIN-PARA.
MOVE 0 TO J.
PERFORM READ-NAME VARYING I FROM 17 BY -1 UNTIL I > 0.
STOP RUN.
READ-NAME
ADD 1 TO J.
MOVE NAME-1(I) TO NAME-21(J).
END-READ-NAME.
Correct me in case any problem with above code.
| Is This Answer Correct ? | 7 Yes | 4 No |
Answer / sairanga
procedure division.
move name1(17:1) to name2(1:1).
move name1(16:1) to name2(2:1).
move name1(15:1) to name2(3:1).
.
.
.
move name1(2:1) to name2(16:1).
move name1(1:1) to name2(17:1).
display name2.
stop run.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / sunil
Hi,
Please try this code it should work.
IDENTIFICATION DIVISION.
PROGRAM-ID. MID.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR1 PIC X(17) VALUE IS 'COBOL PROGRAMMING'.
01 STR2 PIC X(1).
01 STR3 PIC X(17) VALUE SPACE.
01 STRLEN PIC 9(2).
PROCEDURE DIVISION.
INSPECT STR1 TALLYING STRLEN FOR CHARACTERS.
DISPLAY STRLEN.
PERFORM UNTIL STRLEN < 1
MOVE STR1(STRLEN:1) TO STR2
DISPLAY STR2
STRING
STR3 DELIMITED BY SPACE
STR2 DELIMITED BY SPACE
INTO STR3
COMPUTE STRLEN STRLEN - 1
DISPLAY STR3
END-PERFORM.
DISPLAY STR3.
STOP RUN.
Thanks,
Sunil
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ankur kar
In order to reverse the String the only way is by declaring
the string as an array and then sequentially arrage the
array based on the asending/desending order of the array
and then display the sequential result accordingly.
Otherwise there is no command in COBOL that will allow the
string to be displayed in the reverse order.
| Is This Answer Correct ? | 3 Yes | 4 No |
Answer / devraj pradhan
as per my knowledge this problem can be solve by STRING AND
UNSTRING COMMAND as in that there is REPLACING option is
there by which any string can be replace in reverse order
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / satya
As per my knowledge we can solve this problem with use of
STRING AND UNSTRING commands,first UNSTRING the give string
and add all the characters according to our choice by using
STRING COMMAND.
| Is This Answer Correct ? | 1 Yes | 6 No |
Answer / rajul
just define
01 name2 picX(13) right justified.
and then use move stmt
move name1 to name2.
| Is This Answer Correct ? | 2 Yes | 13 No |
How many bytes will be allocated for the following record description entries? 01 REC-A. 05 A PIC S9(4). 05 B PIC XXXBXXX. 05 C PIC ____9.99. 05 D PIC S9(5) COMP-3. 05 E PIC 9(3) COMP.
16 Answers IBM, TCS,
how to check whether the open command of a sequential file is successful? or not?
what are the isolation levels and where we use it in the db2 program
01 var1 pic x(10) 01 var2 redefines var1 pic 9(10). then in procedure division move 'abcde' to var1 then waht is the value of var1 and var2
How many bytes do a s9 (7) comp-3 field occupy?
How do you define a variable of COMP-1? COMP-2?
I have a File that has duplicate records. I need only those records that occur more than thrice.?
What is the difference between working storage copybook and linkage section copybook?
where do u use low-value and high value in cobol
I have a files containing both duplicate and non-duplicate records.The file is already sorted by a key.I want to determine those records that are duplicate and records that are non-duplicate.If duplicate the record is move to a duplicate file and if non-duplicate that will be move to valid file.thank you
diffrence between z(2) and z9(2)
i want to enter the name 'pandu' into ur table how?