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
 

 

Extracting word by word from a text using cobol program

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

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Wed May 07, 2008 1:13 pm    Post subject: Extracting word by word from a text using cobol program
Reply with quote

Hi,

I have a requirement of extracting words from a given text using cobol. I tried using UNSTRING option but not getting the desired output. Can someone help me out with this?

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

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed May 07, 2008 1:15 pm    Post subject:
Reply with quote

not getting the desired output? what does your input look like and what are your expectations?
Back to top
View user's profile Send private message
aaleya

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Wed May 07, 2008 1:35 pm    Post subject: Reply to: Extracting word by word from a text using cobol pr
Reply with quote

Actually say i have a text 'abc bcd cde def '. Now my requirement is to extract word by word from the text. We can say first moving abc to one field and rest to another field. We can use space as a delimiter. When i tried parsing this using UNSTRING, its moving abc to one field and bcd to another field. But my requirement is move abc to one field A(can be a array) and rest to another field B. This field B can be my input to UNSTRING again so next time it moves bcd to field A and rest to field B. This process will continue untill it encounters spaces. Could you please help me with this?

Thanks!
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed May 07, 2008 3:03 pm    Post subject:
Reply with quote

Use INSPECT here

Code:


77 COUNTR PIC 9 VALUE ZERO.
01 WS-TEXT PI X(20).
01 WS-A PIC X(3).
01 WS-B PIC X(17).

MOVE 'abc bcd cde def ' TO WS-TEXT

PERFORM UNTIL WS-TEXT = SPACES

INSPECT WS-TEXT TALLYING COUNTR FOR LEADING SPACE

MOVE WS-TEXT(1:COUNTR) TO WS-A
MOVE WS-TEXT(COUNTR+2 : LENGTH OF WS-TEXT - COUNTR+1) TO WS-B
MOVE 0 TO COUNTR
MOVE WS-B TO WS-TEXT

END-PERFORM

Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed May 07, 2008 4:15 pm    Post subject:
Reply with quote

or
Code:

01  WORK-AREA.
    05  ALPHA-FIELD              PIC X(20) VALUE '999 901 ALB'.
    05  WORK1                    PIC X(5)  VALUE SPACES.
    05  WORK2                    PIC X(20) VALUE SPACES.


DISPLAY 'ALPHA-FIELD '  ALPHA-FIELD
DISPLAY 'WORK1       '  WORK1

PERFORM UNTIL ALPHA-FIELD = SPACES
    INSPECT ALPHA-FIELD
            REPLACING FIRST SPACE BY '#'
    UNSTRING ALPHA-FIELD
            DELIMITED BY '#'
        INTO WORK1
             ALPHA-FIELD
    END-UNSTRING
    DISPLAY 'ALPHA-FIELD '  ALPHA-FIELD
    DISPLAY 'WORK1       '  WORK1
    MOVE SPACES             TO WORK1
END-PERFORM

GOBACK.


Code:

ALPHA-FIELD 999 901 ALB
WORK1

ALPHA-FIELD 901 ALB
WORK1       999
ALPHA-FIELD ALB
WORK1       901
ALPHA-FIELD
WORK1       ALB
Back to top
View user's profile Send private message
aaleya

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Thu May 08, 2008 8:47 am    Post subject: Reply to: Extracting word by word from a text using cobol pr
Reply with quote

Thank you so much!!!!
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
No new posts I can not compile my program PL1 V3.R... Miguel Fernandez PL/I & Assembler 13 Tue Dec 06, 2016 8:30 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm


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