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
 
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: 2287
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
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm

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