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

reverse of string using string function only


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

New User


Joined: 07 Dec 2006
Posts: 5
Location: chennai

PostPosted: Mon Dec 11, 2006 12:36 pm
Reply with quote

Hi all,


Can anybody plz tell me how to reverse a string using string function in cobol

if u explain me with code it will be better.

thanx in advance,
Back to top
View user's profile Send private message
neelesht

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Mon Dec 11, 2006 12:41 pm
Reply with quote

Hi Cynderilla,

there is a reverse function in COBOL to reverse a string
FUNCTION REVERSE(STRING)

Please correct me if I am wrong.

Neelesh
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Dec 11, 2006 1:26 pm
Reply with quote

Hi Cynderilla,
topic is discussed, u can get more information from below link

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

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Dec 11, 2006 1:38 pm
Reply with quote

Hi

Code:
MOVE FUNCTION REVERSE('your string') TO RES.


The variable RES will have your reversed string.

Thanks
Arun

[/code]
Back to top
View user's profile Send private message
cynderilla

New User


Joined: 07 Dec 2006
Posts: 5
Location: chennai

PostPosted: Mon Dec 11, 2006 5:22 pm
Reply with quote

Hi All,


thank's for u r responses

but wat i really need is reverse of a string for example

"abcdef" to "fedcba".

using String Verb in cobol i want to reverse it ,only STRING verb
n nothing other than that.

if it is possible plzz help me.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Dec 11, 2006 6:00 pm
Reply with quote

Going a byte at a time and starting from the tail end using reference modification.

If its length is known and small, hardcode a single string statement with all of the one byte string elements.

If its length is unknown or long, use a perform loop with a single string statement and a single string element and keep track with the string pointer.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 11, 2006 9:14 pm
Reply with quote

Hello,

To do what i believe you want, please try the following:

01 REVERSE-WORK.
05 RW-IN PIC XXXX.
05 RW-OUT PIC XXXX.

MOVE 'QWER' TO RW-IN.
DISPLAY RW-IN.
STRING RW-IN(4:1),
RW-IN(3:1),
RW-IN(2:1),
RW-IN(1:1) DELIMITED BY '\'
INTO RW-OUT.
DISPLAY RW-OUT.

The "input" and "output" displays.
QWER
REWQ

If your field(s) are very long or variable in length. . . . .

Is there some business reason to NOT use the reverse function?
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 Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
Search our Forums:

Back to Top