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
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 |
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 |
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 |
i Want All cobol ERROR codes?
SUPPOSE I HAVE 60 CHARACTERS STING. IN THAT I WANT FIND OUT HOW MANY TIMES 'A'(ASSUME)WILL REPEATED AND I HAVE TO PASS 'E' IN PLACE OF 'A'ALONG THAT STRING.
whats the disadvantage of search all over search?
I have a field with data type X(10). I want to perform arithmetic operation on this field? I tried doing it by moving the value into a numeric field. but it didn't work out. I am getting a S0C7 abend. Pls let me know if there is any way of getting this done?
i have mainprogram and subgram...if i compile mainprogram without stop run..what will u get in compilation time?
How do you reference the following file formats from cobol programs?
which is better comp or comp-3 in terms of memory utilization?
WHAT IS SOC3?HOW IT CAN BE RESOLVED?
how can we get current dat and time thru cobol pgm
HOW TO MOVE REDEFINES CLAUSE FROM INPUT TO OUTPUT ?
What is Static,Dynamic linking ?
How to Write the RESTART Logic Using COBOL?
4 Answers GalaxE, L&T, Syntel, TCS,