Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How can i reverse a string declared as alphabets

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How can i reverse a string declared as alphabets
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: 1188
Location: Bangalore,India

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

Hi Arun,

Please make a search befor posting

http://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    Post subject: Re: how to reverse string
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: 2360
Location: Israel

PostPosted: Mon Nov 27, 2006 3:03 pm    Post subject:
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: 95
Location: India

PostPosted: Mon Nov 27, 2006 3:12 pm    Post subject: Re: how to reverse string
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    Post subject: Re: How can i reverse a string declared as alphabets
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Find a string in PS file opened in br... mukkas CLIST & REXX 2 Sat Feb 24, 2018 2:15 pm
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us