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

db2 variable decimal(15,2) what is the equalent size of cobol variable

2 Answers   Syntel,


How to use the same cobol program in Batch and CICS onlines ? Please expalin with an example. Thanks in advance.

1 Answers  


I try to use some column names in my cobol progorm but these column not in db2 table ..when do i get error ..while bind time or runtime?

2 Answers  


How to find whether a Flat file is empty or not without Reading a file in COBOL Program. (not using JCL)

9 Answers   Bank Of America,


What is the difference between a binary search and a sequential search? What are the pertinent cobol commands?

0 Answers  






i have 10 names in an array and my name is one of them also array is not in sorted order i need to display my name using index how will i do this

0 Answers  


wirte a pgm in using files in which we hav 10 ,20,30 40...100 records in inputfile and i want them to be send to outputfile in reverse order. PLZ HELP ME OUT .........THIS IS A RECENT QUESTION IN IGATE..

5 Answers   iGate,


Why occurs can not be used in 01 level ?

2 Answers   TCS,


what is rediffine clause?in what situation it can use?give me real time example?

1 Answers   IBM,


How much salary you are expecting? If they ask in an interview, what we have to tell?

6 Answers   Tech Mahindra, Wipro,


In CICS/VSAM every file that is accessed should be defined in FCT. we have CICS READ, WRITE, BROWSE commands for VSAM files. How does it work with DB2 tables. It know it has to do with the plan. Please expain with examples.

1 Answers  


Can we dynamically increase the size of occurs clause? i.e In case I an not sure of the size of array and want to increase the size at run time.If yes , how?

1 Answers  


Categories