When a Mainframe EBCDIC copybook consists of multiple records, you need to separate them out into a general structure, with each record type going to a new file for clarity and ease of loading/processing.

Mainframe EBCDIC copybook filter design pattern

With TextPipe (download), the steps are

  1. Use a pattern match to identify each record type we have in the file – using the record header
  2. Pass this record header with its associated data to a subfilter
  3. The subfilter handles just that record type, and puts each record type in a new file.

In our file, each record starts with a 3 byte field which we will ignore, followed by a 5 letter record type id, #REC#, #TRAA, #TRAD etc. There is also a field following this record id, but we don't need it, and the value might not always be 'N'. Note: Often, the record type field's VALUES are not included in the copybook, but has to be read from the comments or documentation. In these cases the record type field usually has a constant name like REC-ID.

Sample Mainframe Cooybook

05 T-REC.
10 T-REC-LEN PIC S9(4) COMP VALUE 68.
10 T-REC-ID PIC X(5) VALUE '#REC#'.
10 T-REC-STAT PIC X VALUE 'N'.
...


05 T-TRAA.
10 T-TRAA-LEN PIC S9(4) COMP VALUE 69.
10 T-TRAA-ID PIC X(5) VALUE '#TRAA'.
10 T-TRAA-STAT PIC X VALUE 'N'.
...

05 T-TRAC.
10 T-TRAC-LEN PIC S9(4) COMP VALUE 68.
10 T-TRAC-ID PIC X(5) VALUE '#TRAC'.
10 T-TRAC-STAT PIC X VALUE 'N'.
...

05 T-TRAD.
10 T-TRAD-LEN PIC S9(4) COMP VALUE 199.
10 T-TRAD-ID PIC X(5) VALUE '#TRAD'.
10 T-TRAD-STAT PIC X VALUE 'N'.
...

Records

The general TextPipe pattern for each record type within the file looks like this:

   

Let's dig into this.

The first step is an EasyPattern (a user-friendly type of pattern match). It looks for

  1. The start of the text, followed by
  2. Any 3 characters (the PIC S9(4) COMP field we are ignoring), followed by
  3. the EBCDIC characters #TRTS. (Remembering that PC's use ASCII, we need to specify the literal is EBCDIC), followed by
  4. 65 other characters – the rest of the record

When something matches this pattern, it must be a record of type #TRTS, and it gets passed unchanged to the subfilter:

  1. The Mainframe Copybook filter applies just the copybook segment that relates to the #TRTS record
  2. The result goes to the file TRTS-records.txt on your desktop
  3. The text is then prevented from continuing in the filter – it stops dead here.

Pro Tip: We can easily copy this structure by selecting the top filter, and choosing the [x2] button in the footer.

Working out the copybook size

When we paste each copybook fragment into a mainframe copybook filter, we can click the [Show Parse Tree] button to find out the record length. e.g.

-01 COPYBOOK 1-73 Length:73
05 T-TRAA 1-73 Length:73
10 T-TRAA-LEN S9(4) COMP-3. 1-3 Length:3
10 T-TRAA-ID X(5). 4-8 Length:5
10 T-TRAA-STAT X(1). 9 Length:1
10 T-TRAA-COMPL X(1). 10 Length:1
10 T-TRAA-COM S9(4) COMP-3. 11-13 Length:3
10 T-TRAA-DATA 14-73 Length:60

Once we know the length is 73, we just subtract 8 from it, (the first 3 characters followed by the 5 character record type = 8) to find out the remaining characters we need, in this case, 65:

[ TextStart, 3 chars, EBCDIC('#TRAA'), 65 chars ]

We also have to grab the record type TRAA from the copybook and put it into the pattern match, and also into the output filename.

%USERPROFILE%\Desktop\TRAA-Records.txt

Then we move onto the next record type.

Master record match

Once we have setup all the record types, we need to gather ALL the record patterns into one MASTER pattern match at the top of the list.

   

The master copybook pattern match looks like this:

[
TextStart,
3 chars,
EBCDIC('#'),
(EBCDIC('TRTS'), 65 chars)
or
(EBCDIC('TRAA'), 65 chars)
or

..one line for each record type..

(EBCDIC('TRTS'), 29 chars)

]

Ready to Rock 'n' Roll!

Then you're ready to drag and drop your mainframe file into TextPipe and click [Go] or press [F9]!

Errors?

If the error log reports that there were extra bytes in the file that could not be matched, this indicates that

May the force be with you!

Buy Now Buy Download