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

Have you code any new programs in COBOL ? What is the functionality of the programs?

2 Answers   Patni, Xansa,


how you will define variables length in cobol.

3 Answers   Temenos,


TYPES OF SORTINGS. which is more prefarable.

2 Answers   Syntel, TCS,


Define static linking and dynamic linking.

0 Answers  


What is the difference between subscript and index?

1 Answers  






can we print comp 3 stmts how ?

3 Answers   Accenture, TCS,


01 xxx pic 9(4). 01 yyy pic 9(6). move 123456 into yyy. move yyy to xxx. display yyy. what would be the value of yyy

13 Answers   HSBC,


State the various causes of s0c1, s0c5 and s0c7.

0 Answers  


What is a SSRANGE and NOSSRANGE?

0 Answers  


Can we access the a[0] in the array ?

6 Answers   DCL, IBM,


wht is the diff b/w if and evaluate stmts ?

2 Answers   DELL,


Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing this?

6 Answers   T systems,


Categories