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
 

 

String manipulation in COBOL

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

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Thu Dec 07, 2006 2:18 pm    Post subject: String manipulation in COBOL
Reply with quote

Hi everyone,

I have fields

01 ws-name pic x(15)

01 ws-date pic x(10)

I am using

STRING 'ACCOUNT NAME:' DELIMITED BY SIZE

WS-NAME DELIMITED BY SPACE

WS-DATE DELIMITED BY SIZE INTO WS-DISPLAY

and output is displayed as


ACCOUNT NAME: MMISCHELLE/20040506


As per the reqirement should be displayed as


ACCOUNT NAME: M MISCHLLE/20040506


Can anyone help me in formatting this.

Waiting for reply.

Thank you
Back to top
View user's profile Send private message

sankar_MF

New User


Joined: 19 Sep 2006
Posts: 29

PostPosted: Thu Dec 07, 2006 3:37 pm    Post subject:
Reply with quote

Hi,

Please use the string command as follows, you will get the required output.

STRING 'ACCOUNT NAME:'DELIMITED BY SIZE
WS-NAME(1:1) ' ' DELIMITED BY SIZE
WS-NAME(2:14) DELIMITED BY SPACE
WS-DATE DELIMITED BY SIZE INTO WS-DISPLAY


Thanks
Sankar
Back to top
View user's profile Send private message
adarsh444

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Thu Dec 07, 2006 7:58 pm    Post subject: Re: String manipulation in COBOL
Reply with quote

Hi

But that will work only for the sample data i have given.

ACCOUNT NAME: M MISCHLLE/20040506

I have lots of names(WS-NAME) embedded with spaces in between.
I want to handle all the cases.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Thu Dec 07, 2006 8:02 pm    Post subject:
Reply with quote

Please give more examples of WS-NAME
Back to top
View user's profile Send private message
cobolunni

Active User


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

PostPosted: Fri Dec 08, 2006 11:05 am    Post subject:
Reply with quote

Considering M and MISCHLLE as first name and last name, I think this code will work

Code:
ID DIVISION.                                                   
PROGRAM-ID. SAMP.                                             
DATA DIVISION.                                                 
WORKING-STORAGE SECTION.                                       
01 WS-NAME PIC X(15).                                         
01 WS-DATE PIC X(10).                                         
01 WS-FNAME PIC X(15).                                         
01 WS-LNAME PIC X(15).                                         
01 WS-DISPLAY PIC X(60).                                       
PROCEDURE DIVISION.                                           
MAIN.                                                         
    MOVE 'ALEX THOMAS' TO WS-NAME.                             
    MOVE '20040506' TO WS-DATE.                               
    UNSTRING WS-NAME DELIMITED BY ' ' INTO WS-FNAME WS-LNAME. 
    STRING 'ACCOUNT NAME : ' DELIMITED BY SIZE WS-FNAME       
    DELIMITED BY SPACE ' ' DELIMITED BY SIZE WS-LNAME DELIMITED
    BY SPACE '/' DELIMITED BY SIZE WS-DATE DELIMITED BY SIZE   
    INTO WS-DISPLAY.                                           
    DISPLAY WS-DISPLAY.                                       
    STOP RUN.                                                 


will give result as
Code:
ACCOUNT NAME : ALEX THOMAS/20040506
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Fri Dec 08, 2006 11:47 am    Post subject:
Reply with quote

Hi Adarsh,

Try this code.

Code:
WORKING-STORAGE SECTION.                     
77  NAME-IN   PIC X(15) VALUE 'ARUN RAJ S'. 
77  DATE-IN   PIC X(10) VALUE '20061201'.   
77  RES         PIC X(25).                     
PROCEDURE DIVISION.                         
MAIN.                                       
    STRING NAME-IN DELIMITED BY  '  ' ------>DOUBLE SPACE       
                      '/'     DELIMITED BY SIZE         
                DATE-IN DELIMITED BY SIZE INTO RES
    DISPLAY '(' RES ')'                     
    STOP RUN.                               


Please let me know if it is working as per your requirement.

Thanks
Arun
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 RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm


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