Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Parsing a record using cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
JOJO

New User


Joined: 06 Dec 2007
Posts: 4
Location: Jacksonville

PostPosted: Wed May 07, 2008 1:47 am    Post subject: Parsing a record using cobol
Reply with quote

Hi,

I am trying to parse an input file using cobol. My input file has the records I need to parse in the field IN-DBC-TEXT. Basically, I need to capture words which come after 'FROM', '.FROM' or 'JOIN'. I tried using a loop to take in the first delimited word in an array and move the rest into another field.

I think there is something wrong with moving the rest of the records to WS-DBC-REST. Could someone please help me with getting the desired output?

I-DBC-FILE has lrecl of 25296 and is a fixed block.

ExampleS of input field value in IN-DBC-TEXT:

CHANGE FROM NAME1 TO NAME2;
NAME3 JOIN NAME4 CONTROL;
CHARGE NAME5 .FROM NAME6;

And the desired output should be:

NAME1
NAME4
NAME6

Here is the main part of the code.

P200-READ-IN-FILE-RECORDS.

READ I-DBC-FILE
AT END
MOVE 'Y' TO WS-EOF
GO TO P200-EXIT.
DISPLAY IN-DBC-TBL

ADD 1 TO NUMIN.
SET INDX TO 1.
MOVE 'N' TO TBL-IND.
MOVE IN-DBC-DB TO OUT-DBC-DB
MOVE IN-DBC-TBL TO OUT-DBC-TBL
MOVE IN-DBC-TEXT TO WS-TEXT

PERFORM P250-UNSTRING THRU P250-EXIT
VARYING INDX FROM 1 BY 1
UNTIL WS-DBC-REST EQUAL TO SPACES.

P250-UNSTRING.

EVALUATE TBL-IND
WHEN 'Y'
MOVE WS-DBC-PARSE TO OUT-VW-TBL
PERFORM P350-WRITE THRU P350-WRITE-EXIT
END-EVALUATE.

UNSTRING WS-TEXT DELIMITED BY SPACE
INTO IND-WORD (INDX)
WS-DBC-REST
DISPLAY 'WS-DBC-REST ' WS-DBC-REST
MOVE WS-DBC-REST TO WS-TEXT

MOVE IND-WORD (INDX) TO WS-DBC-PARSE.
DISPLAY 'WS-DBC-PARSE' WS-DBC-PARSE
DISPLAY 'TBL-IND' TBL-IND
EVALUATE WS-DBC-PARSE
WHEN 'FROM'
WHEN '.FROM'
WHEN 'JOIN'
MOVE 'Y' TO TBL-IND
WHEN OTHER
MOVE 'N' TO TBL-IND
END-EVALUATE.

P250-EXIT.
EXIT.
Back to top
View user's profile Send private message
References
PostPosted: Wed May 07, 2008 1:47 am    Post subject: Re: Parsing a record using cobol Reply with quote

dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 5943
Location: 221 B Baker St

PostPosted: Wed May 07, 2008 6:52 am    Post subject:
Reply with quote

Hello,

First, i believe you do not need to test ".FROM". The test for "FROM" will suffice.

You mention that the input has lrecl of 25296. Could "FROM" and/or "JOIN" exist in the record more than 1 time?

If this was my requirement, i'd probably just loop thru the input using reference modification. When i got a it, i'd unstring from that point to get the next "word". If a search word can only exist once per record, i'd only continue the loop until i found a hit. If multiples are possible, i'd continue until i was finished with the record.

I expect the code would run more efficiently if as the loop processed, the code made sure there was still more data to be parsed.
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 95
Location: Bangalore

PostPosted: Wed May 07, 2008 7:41 am    Post subject:
Reply with quote

as dick scherrer mentioned, reference modification will be a good idea in this case.
i would like to find the position of the value "FROM " in the record and then get the next characters until i find a space (i.e. the next word).
and similarly for the "JOIN " as well.

however, if the "FROM " and "JOIN " are present in the same record, then we need to do some further codings...
Back to top
View user's profile Send private message
JOJO

New User


Joined: 06 Dec 2007
Posts: 4
Location: Jacksonville

PostPosted: Wed May 07, 2008 8:33 am    Post subject: Reply to: Parsing a record using cobol
Reply with quote

Thanks for your responses..

The input file used can contain more than 1 'FROM' or 'JOIN' keywords and sometimes both 'FROM' and 'JOIN'.

I would like to look into the option of using reference modification. Is there any link which has the details with examples of reference modification? I could go thru it and use it..
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 5943
Location: 221 B Baker St

PostPosted: Thu May 08, 2008 4:46 am    Post subject:
Reply with quote

Hello KP,

If you use the "SEARCH" at the top of the page, use reference modification as your keywords, and click the "Search for all terms" radio-button, you will get many "hits". Look thru them and there are several with code in the topic.

You could also look in the COBOL manual by using the "IBM Manuals" link at the top of the page. There is both a Language Reference and Programmers Guide for the most used versions of the mainframe compiler.

I'd suggest you create a small test case to become familiar with reference modification. When you have something written and have any questions, post what is not clear here and someone will be able to help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1