Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1187
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
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us