IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How can i reverse a string declared as alphabets


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arunpvarier

New User


Joined: 07 Nov 2006
Posts: 16
Location: banglore

PostPosted: Mon Nov 27, 2006 2:47 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Nov 27, 2006 3:01 pm
Reply with quote

Hi Arun,

Please make a search befor posting

www.ibmmainframes.com/viewtopic.php?t=15857&highlight=reverse
Back to top
View user's profile Send private message
SSR
Warnings : 1

New User


Joined: 26 Feb 2006
Posts: 38

PostPosted: Mon Nov 27, 2006 3:02 pm
Reply with quote

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
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Mon Nov 27, 2006 3:03 pm
Reply with quote

You can use the intrinsic function REVERSE.

O.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Mon Nov 27, 2006 3:12 pm
Reply with quote

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
View user's profile Send private message
muthukannan

New User


Joined: 03 Aug 2006
Posts: 42
Location: Chennai

PostPosted: Mon Nov 27, 2006 5:12 pm
Reply with quote

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.

icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top