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

How can we reverse a string wthout using STRING function


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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: 1448
Location: Chicago, IL

PostPosted: Sat Nov 25, 2006 12:12 pm
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: 127
Location: kerala,india

PostPosted: Sat Nov 25, 2006 2:42 pm
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
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 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 3
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