开发者

Read a flat file. Use COBOL to retrieve specific rows

开发者 https://www.devze.com 2023-03-12 08:43 出处:网络
I have a flat file like this: 1|sal|manager|2007/01/01|2007/12/31 2|sal|manager|2008/01/01|2008/12/31 3|per|abc|manager

I have a flat file like this:

1|sal|manager|2007/01/01|2007/12/31
2|sal|manager|2008/01/01|2008/12/31
3|per|abc|manager
4|sal|manager|2007/01/01|2007/12/31
5|per|xyz|ceo

I have to read the file using COBOL, and write the rows that has the string sal into a temp file.

Is unstri开发者_开发问答ng a good option? Please suggest me an approach to solve this problem.

Thanks in advance.


Have you considered using INSPECT? The following would work for you too...

MOVE ZERO TO COUNTER  
INSPECT INPUT-RECORD TALLYING COUNTER FOR ALL '|SAL|'  
IF COUNTER > ZERO  
   write to temp file  
END-IF   

COUNTER is some numeric working storage variable to receive a count of the number on non-overlapping occurences of the string |SAL| found in INPUT-RECORD.


Yes, unstring is probably your best bet. Keep in mind that modern mainframe SORT utilities usually have data selection capabilities built in. If the COBOL requirement is really just a preference being expressed, you might find the utility route easier.


Unstring is an excellent option. Since each field is delimited by a vertical bar, it is a natural fit.

If you have a fixed number of fields, you can do it all at once. If you have a variable number of fields, you can use the "pointer" option to step field by field until you get to the end.

For example:

Move +1 to my-ptr
Move input-record to remaining-str
Perform until remaining-str = spaces
   Unstring remaining-str
      delimited by '|'
      into
         next-field
         remaining-str
      pointer my-ptr
   End-Unstring
   ... do something with next-field ...
End-Perform
0

精彩评论

暂无评论...
验证码 换一张
取 消