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 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
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
No new posts change string before sertan string anatol DFSORT/ICETOOL 8 Tue Aug 15, 2017 5:43 pm

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