3

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 unstring a good option? Please suggest me an approach to solve this problem.

Thanks in advance.

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
williamtell
  • 301
  • 5
  • 17

3 Answers3

3

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.

cschneid
  • 10,237
  • 1
  • 28
  • 39
3

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.

NealB
  • 16,670
  • 2
  • 39
  • 60
  • Inspect is easier here, you only want to know if the text |sal| is present in the record. With unstring you need code to process all parts that were found. – Kwebble Jun 16 '11 at 09:07
1

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
Joe Zitzelberger
  • 4,238
  • 2
  • 28
  • 42