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

String manipulation in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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: 3156
Location: Tucson AZ

PostPosted: Thu Dec 07, 2006 8:02 pm
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: 127
Location: kerala,india

PostPosted: Fri Dec 08, 2006 11:05 am
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: 2481
Location: @my desk

PostPosted: Fri Dec 08, 2006 11:47 am
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 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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top