Can we reverse the string in cobol ? See the following problem : 77 NAME PIC X(10) VALUE 'MANOJ', 77 SRNAME PIC X(10).I want JONAM in SRNAME.

Showing Answers 1 - 20 of 20 Answers

MANOJ

  • Jul 25th, 2006
 

Hi,

 we can reverse the string using cobol prog like this :

 IDENTIFICATION DIVISION.                          
 PROGRAM-ID. MID.                                  
 ENVIRONMENT DIVISION.                             
 DATA DIVISION.                                    
 WORKING-STORAGE SECTION.                          
 01 STR1 PIC X(7) VALUE IS 'MANOJ'.              
 01 STR2 PIC X(1).                                 
 01 STR3 PIC X(7) VALUE SPACE.                     
*01 STR4 PIC X(7).                                 
 01 STRLEN PIC 9(1).                               
 01 CTR1 PIC 9(1) VALUE IS 1.                      
 PROCEDURE DIVISION.                               
     INSPECT STR1 TALLYING STRLEN FOR CHARACTERS.  
     DISPLAY STRLEN.                               
     PERFORM UNTIL STRLEN < 1                      

        MOVE STR1(STRLEN:1) TO STR2   
    DISPLAY STR2                  
    STRING                        
      STR3 DELIMITED BY SPACE     
      STR2 DELIMITED BY SPACE     
      INTO STR3                     
      COMPUTE STRLEN = STRLEN - 1   
      DISPLAY STR3                  
      END-PERFORM.                    
     DISPLAY STR3.                 
     STOP RUN.                    

  Thanking you.

manoj   

  Was this answer useful?  Yes

rahul

  • Sep 8th, 2006
 

hello

Is there any other method?

regards,

rahul

  Was this answer useful?  Yes

rahul

  • Sep 8th, 2006
 

hello

Suppose I have 1000 records in one PS file . My requirement is taking first 2 records.

In each record contain 6 fields eg.

NAME,ADDRESS-1,ADDRESS-2,CITY,SATATE,ZIPCODE

My requirement is write record vertically 1st record and 2ed record  is beside of  first record

         Input PS

Rahulhyderabada.pdvcddgfgdsjfgdgf

Rohandsagfdhfkhdkshfhdhsfkdskkfkh

            Output PS

Rahul                 Rohan

Hyderab             dsagf

.pdvcdd             fkhdksh

Jfgdgf               hsdfdfd

Sdvffjds            dvfdsjfvds

 

Regards,

rahul

Mark

  • Oct 23rd, 2006
 

You can also define table of PIC(X) elements that occurs depending on the string length.

  Was this answer useful?  Yes

abdul muneer

  • Feb 17th, 2012
 

Yes we can reverse a string by using move reference modification concept
eg:01 name pic x(4).
01 rname pic x(4).
move name(1:1) to rname(4:1).
move name(2:1) to rname(3:1).
move name(3:1) to rname(2:1).
move name(4:1) to rname(1:1).

  Was this answer useful?  Yes

Nik

  • May 14th, 2012
 

Have you tried doing this -

Code
  1. MOVE FUNCTION REVERSE(WS-A) TO WS-B

  Was this answer useful?  Yes

RAMESH

  • Jul 3rd, 2012
 

by using reference modification......

IDENTIFICATION DIVISION.
PROGRAM-ID. REVSTRN.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR1 PIC X(5) VALUE IS MANOJ.
01 STR2 PIC X(5).
01 I PIC 9(1).
01 J PIC 9(1) VALUE 5.
01 K PIC 9(1) VALUE 5.

PROCEDURE DIVISION.
DISPLAY " STRING:", STR1.
PERFORM VARYING I FROM 1 BY 1 UNTIL I > K
MOVE STR1(I: 1) TO STR2(J: 1)
COMPUTE J = J - 1.
END-PERFORM.
DISPLAY " REV STRNG:", STR2.
STOPRUN.

RESULT:
STRING: MANOJ
REV STRNG: JONAM

  Was this answer useful?  Yes

Rishi Sharma

  • May 22nd, 2014
 

Yes it can be done by following code:

Code
  1.  MOVE FUNCTION REVERSE(WS-String) TO WS-Reversed-String

  Was this answer useful?  Yes

sashi

  • Nov 19th, 2014
 

i have one ps file it contain 2 headers ans 2 tiles each header contain some records now my requirement is i want 2 header contain some records copy to out put file is this possible could u please suggest me.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions