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 we reverse a string wthout using STRING function

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
nimje.mangesh

New User


Joined: 25 Jun 2006
Posts: 2

PostPosted: Sat Nov 25, 2006 4:35 am    Post subject: How can we reverse a string wthout using STRING function
Reply with quote

This is the question asked in an interview. Please try to give complete logic with code.
Back to top
View user's profile Send private message

mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Nov 25, 2006 4:42 am    Post subject:
Reply with quote

Have no idea of what you mean. Can you explain further?
Back to top
View user's profile Send private message
nimje.mangesh

New User


Joined: 25 Jun 2006
Posts: 2

PostPosted: Sat Nov 25, 2006 4:54 am    Post subject:
Reply with quote

it means that if we have string named " MANGESH"
I have to print it as "HSEGNAM" without using string reverse function
given in cobol .we have to do it by using other operator
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Sat Nov 25, 2006 12:12 pm    Post subject: Re: How can we reverse d string wthout using string fn in co
Reply with quote

There would be many ways... This is what I thought at first... Pls excuse me of syntax errors....
Code:
01 WS-STRING   PIC X(10) VALUE 'MANGESH'.
01 WS-REV-STR   PIC X(10) VALUE SPACES.
01 WS-OUT-STR   PIC X(10) VALUE SPACES.
01 L      PIC 99 VALUE 01.
01 M      PIC 99.

MOVE <<total string length>> TO M.       /*(10 in this case)

PERFORM PROCESSING-PARA 10 TIMES.
INSPECT WS-REV-STR TALLYING WS-COUNT FOR LEADING SPACES.
MOVE WS-REV-STR(WS-COUNT +1:10- WS-COUNT) TO WS-OUT-STR.

PROCESSING-PARA.
   MOVE WS-STRING(L:1) TO WS-REV-STR(M:1).
   ADD 1 TO L.
   SUBSTRACT 1 FROM M.
   EXIT.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Sat Nov 25, 2006 2:42 pm    Post subject:
Reply with quote

We can use cobol aggregate function FUNCTION REVERSE for this work done
here is a sample code

Code:
IDENTIFICATION DIVISION.               
PROGRAM-ID. SAMP.                       
DATA DIVISION.                         
WORKING-STORAGE SECTION.               
01 VAR2 PIC X(4).                       
01 VAR1 PIC X(4).                       
PROCEDURE DIVISION.                     
MAIN.                                   
    MOVE 'ABCD' TO VAR2.               
    MOVE FUNCTION REVERSE(VAR2) TO VAR1.
    DISPLAY VAR1.                       
    DISPLAY VAR2.                       
    STOP RUN.                           
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Nov 28, 2006 6:14 am    Post subject:
Reply with quote

This might work. Not saying it's the best way, just another way.
Code:
 
01  ws-var pic  x(010)  value 'ABCDEF'.
01  ws-var-tbl  redefines ws-var.
    05  ws-var-char occurs 10 pic  x.

01  ws-var-rev. 
    05  ws-rev-char occurs 10 pic  x.


preform varying sub from 1 by 1 until sub > 10
    move ws-var-char(sub) to ws-rev-char(11 - sub)
end-perform

display '>' ws-var-rev '<'


ps - Glad you changed the problem stmt - now it makes sense.
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. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
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 Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am


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