How to display string in the reverse order using occurs
clause?
Answer Posted / nk
01 MY-STRING PIC X(9) VALUE 'ABCDEFGHI'.
01 FILLER REDEFINES MY-STRING.
05 CHAR OCCURS 9 TIMES. (could use INDEXED BY here)
01 OUT-STRING PIC X(9).
01 IDX-IN PIC 9.
01 IDX-OUT PIC 9.
MOVE 9 TO IDX-IN.
PERFORM MOVE-A-CHAR (could also do an inline PERFORM)
VARYING IDX-OUT FROM 1 BY 1
UNTIL IDX-OUT > 9.
MOVE-A-CHAR.
MOVE CHAR(IDX-IN) TO OUT-STRING(IDX-OUT).
SUBTRACT 1 FROM IDX-IN.
MOVE-A-CHAR-EXIT.
EXIT.
| Is This Answer Correct ? | 1 Yes | 3 No |
Post New Answer View All Answers
Which Search verb is equivalent to PERFORM…VARYING?
i made it to stage 3 of an interview process wednessday they will quiz my knowledge again face to face for an analyst role recruiter said it will be based on Business requirements system is cobol and good ideas what they might ask etc
How many sections are there in data division in COBOL?
What is perform what is varying?
Define cobol?
How to remove 2 duplicate records and copy only one using job control language?
What are the different rules to perform a Search?
Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
What are the pertinent COBOL commands?
What is the difference between PIC 9.99 and PIC9v99?
What is an in line perform? When would you use it? Anything else you wish to say about it.
What are the different rules for performing sort operation?
Which is not true about evaluate statement
What the difference is between continue and next sentence?
In COBOL, what is the different between index and subscript?