View previous topic :: View next topic
|
Author |
Message |
arunpvarier
New User
Joined: 07 Nov 2006 Posts: 16 Location: banglore
|
|
|
|
how can i reverse a string declared as alphabets
w-s section.
01 S1 pic A(5) value "ABCDE".
02 S2 pic a(5).
In procedure division i want to reverse S1 and to store in S2. ie is S2 the content should be"EDCBA". how can i code this? |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
Back to top |
|
|
SSR Warnings : 1 New User
Joined: 26 Feb 2006 Posts: 38
|
|
|
|
Hi,
You can use an array.
1. Unstring the values in to an array using occurs clause and
Unstring command.
2. Read the array from the last value to first and store it to the required
variable.
Thanks
SSR. |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
You can use the intrinsic function REVERSE.
O. |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
Hi Arun
Hope the following code will also work.
MOVE 1 TO J
PERFORM VARYING I FROM 5 BY -1 UNTIL I < 1
MOVE TEXT(I : 1) TO RESULT(J : 1)
ADD 1 TO J
END-PERFORM |
|
Back to top |
|
|
muthukannan
New User
Joined: 03 Aug 2006 Posts: 42 Location: Chennai
|
|
|
|
Here is the pgm u needed....
IDENTIFICATION DIVISION.
PROGRAM-ID REVSTR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR PIC X(3) VALUE 'ABC'.
01 STR1 PIC X(3) VALUE SPACES.
PROCEDURE DIVISION.
A000-MAIN-PARA.
MOVE FUNCTION REVERSE(STR) TO STR1.
DISPLAY 'STR' STR.
DISPLAY 'STR1' STR1.
STOP RUN.
|
|
Back to top |
|
|
|