how we can reverse the string in the cobol for example
satheesh can be reveresed as hseehtas

Answers were Sorted based on User's Feedback



how we can reverse the string in the cobol for example satheesh can be reveresed as hseehtas..

Answer / g venkatesh

data division.
01 ws-input pic x(8).
01 ws-output pic x(8).
01 i pic 9.
01 j pic 9.
procedure division.
move 1 to i.
perform varying j from 8 by -1 until j =0
move ws-input(i:1) to ws-output(j:1)
add 1 to i
end-perform
display ws-output.
stop run.

Is This Answer Correct ?    51 Yes 7 No

how we can reverse the string in the cobol for example satheesh can be reveresed as hseehtas..

Answer / adarsh

This can be achieved using
1. FUNCTION REVERSE - RECOMMENDED
2. REFERENCE MODIFICATION
.

1. MOVE FUNCTION REVERSE(WS-NAME-INPT) TO
WS-NAME-RVRS.

2. MOVE WS-NAME-INPT(1:1) TO WS-NAME-RVRS(8:1)
MOVE WS-NAME-INPT(2:1) TO WS-NAME-RVRS(7:1)
MOVE WS-NAME-INPT(3:1) TO WS-NAME-RVRS(6:1)
MOVE WS-NAME-INPT(4:1) TO WS-NAME-RVRS(5:1)
MOVE WS-NAME-INPT(5:1) TO WS-NAME-RVRS(4:1)
MOVE WS-NAME-INPT(6:1) TO WS-NAME-RVRS(3:1)
MOVE WS-NAME-INPT(7:1) TO WS-NAME-RVRS(2:1)
MOVE WS-NAME-INPT(8:1) TO WS-NAME-RVRS(1:1).

Is This Answer Correct ?    19 Yes 6 No

how we can reverse the string in the cobol for example satheesh can be reveresed as hseehtas..

Answer / paul

DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 9.
01 J PIC 9.
01 ST1 PIC X(5).
01 ST2 PIC X(5).
PROCEDURE DIVISION.
MOVE 1 TO I.
MOVE 'KOTI' TO ST1.
PARA-A.
PERFORM PARA-B VARYING J FROM 5 BY -1 UNTIL J = 0.
DISPLAY 'STRING REVERSE' ST2.
STOP RUN.
PARA-B.
MOVE ST1(I:1) TO ST2(J:1).
ADD 1 TO I.

Is This Answer Correct ?    5 Yes 1 No

Post New Answer

More COBOL Interview Questions

Program A calls program B. Will the working storage variables declared in program B be initialized every time it is called by program A or will the values be retained until the end of program A?

7 Answers  


01 MOVE 10 TO N 05 PERFOM PARA1 TIMES STOP RUN WAT WILL HAPPEN?? WILL IT RUN INFINITELY OR AN ERROR WIL BE THER BECAUSE NO OF TIMES IS NOT GIVEN??

1 Answers  


can we use the two 01 level in file discription ?

6 Answers  


I have a Main Program which is calling Sub-Program which is a DB2 pgm. What will happen if I am not closing the cursor used in the Sub-program? Please advise..

3 Answers   iGate,


What are the different data types available in COBOL?

4 Answers  






sample code for read a 2nd record from last in flatfile how can do?

4 Answers   iNautix,


using redefine can you redefine lower variable size to higher variable size?

3 Answers   Patni,


When can the USING phrase be included in the call statement ?

2 Answers  


At the minimum, which division of COBOL is enough to be coded?

3 Answers   CTS,


How do you define a table/array in COBOL?

5 Answers   Hexaware,


How To Separate The Numerics From An Alphanumric Data Item Which Contains Both Alphabates And Numerics ?

4 Answers  


If we use GO BACK instead of STOP RUN in cobol?

2 Answers   Temenos,


Categories