Read the flat file. Use COBOL to extract specific rows

I have a flat file:

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 need to read a file with COBOLand write lines with a line salto a temp file.

Is a unstringgood option? Please suggest me an approach to solving this problem.

Thanks in advance.

+3
source share
3 answers

Yes, notring is probably the best choice. Keep in mind that modern SORT mainframe utilities usually have built-in data choices. If the COBOL requirement is really preferred, you can find a convenient route.

+3
source

INSPECT? ...

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

COUNTER - |SAL|, INPUT-RECORD.

+3

Unstring is a great option. Since each field is bounded by a vertical stripe, this is a natural correspondence.

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 for a step-by-step field by field, until you reach the end.

For instance:

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
+1
source

All Articles