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


Please Help Members By Posting Answers For Below Questions

There are 5 fields and 1000 records in a file. Unload it into an array. Write the syntax for declaration and how will you unload it.

932


What is the utilization of copybook in cobol?

657


What are the different rules to perform a Search?

615


Are you comfortable in cobol or jcl?

643


What is inspect in cobol ?

801






What is the local-storage section?

681


How to find out the closest prime number of an input number? I believe it has something to do with SEARCH and COBOL Linear Array.

3715


What are the different rules for performing sort operation?

760


How to get the last record in vsam file in cluster? And how can you get the ksds file records into cobol program?

708


What is the compute verb? How is it used?

659


How to remove the spaces at the end of each record in the output file of variable length, via cobol program?

673


here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1 PIC X(8) VALUE IS 'A1B2C3D4' but i need to have A2,A3 as ABCD & 1234 repectively...... A2 = ABCD A3 = 1234 Can you please explain me what are the different ways to do it?

6827


What is the difference between external and global variables in COBOL?

813


What is the problem of ordered sequential files access?

697


What is the difference between PIC 9.99 and PIC9v99?

781