My question is how to use the field “length of†included in a record to extract the ensuing “length of†bytes.
We have an input file (FB) with the following “copyâ€:
01 to 0020 fixed structure
21 to 1000 variable structures as:
- Field Code: packed decimal: 3 bytes
- Data Length: binary: 2 bytes
- Data: depending on Data length bytes
The input fields are not in an specific order, and probably some of them will not appear.
I.e.
Field X’00001C’ means “Nameâ€, max length 20 bytes, not always filled (first record, 4 bytes, second record 10 bytes).
Field X’00002C’ means “Surnameâ€, max length 20 bytes, not always filled (first record, 7 bytes, second record 15 bytes).
****** ***************************** Top of Data ******************************
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000 01223984 NAME SURNAME
FFFFFFFFFFFFFFFFFFFF00300FFFFFFFF00100DCDC00200EEDDCDC444444444444444444
2011112570050000000000C080122398400C00514500C072495145000000000000000000
------------------------------------------------------------------------------
000002 20111125700500000000 LARGE SURNAME LARGE NAME
FFFFFFFFFFFFFFFFFFFF00200DCDCC4EEDDCDC00100DCDCC4DCDC4444444444444444444
2011112570050000000000C0D319750249514500C0A31975051450000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000 01223984 NAME SURNAME
FFFFFFFFFFFFFFFFFFFF00300FFFFFFFF00100DCDC00200EEDDCDC444444444444444444
2011112570050000000000C080122398400C00514500C072495145000000000000000000
------------------------------------------------------------------------------
000002 20111125700500000000 LARGE SURNAME LARGE NAME
FFFFFFFFFFFFFFFFFFFF00200DCDCC4EEDDCDC00100DCDCC4DCDC4444444444444444444
2011112570050000000000C0D319750249514500C0A31975051450000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
We need to create an output file with Fixed part and only “nameâ€, â€surname†fields, and full length.
****** ***************************** Top of Data ******************************
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000NAME SURNAME
FFFFFFFFFFFFFFFFFFFFDCDC4444444444444444EEDDCDC4444444444444444444444444
201111257005000000005145000000000000000024951450000000000000000000000000
------------------------------------------------------------------------------
000002 20111125700500000000LARGE NAME LARGE SURNAME
FFFFFFFFFFFFFFFFFFFFDCDCC4DCDC4444444444DCDCC4EEDDCDC4444444444444444444
201111257005000000003197505145000000000031975024951450000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000NAME SURNAME
FFFFFFFFFFFFFFFFFFFFDCDC4444444444444444EEDDCDC4444444444444444444444444
201111257005000000005145000000000000000024951450000000000000000000000000
------------------------------------------------------------------------------
000002 20111125700500000000LARGE NAME LARGE SURNAME
FFFFFFFFFFFFFFFFFFFFDCDCC4DCDC4444444444DCDCC4EEDDCDC4444444444444444444
201111257005000000003197505145000000000031975024951450000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
I tried to use PARSE to find out the fields I’m interested in, but using FIXLEN as a fixed length of 20 bytes, my output creates “rubbish†bytes just extracting 20 bytes from end of “Field codeâ€,
****** ***************************** Top of Data ******************************
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000 NAME SURNAME SURNAME 012239
FFFFFFFFFFFFFFFFFFFF00DCDC00200EEDDCDC0000EEDDCDC00300FFFFFF444444444444
2011112570050000000004514500C0724951450007249514500C07012239000000000000
------------------------------------------------------------------------------
000002 20111125700500000000 LARGE NAME LARGE SURNAME
FFFFFFFFFFFFFFFFFFFF00DCDCC4DCDC4444444400DCDCC4EEDDCDC00100444444444444
201111257005000000000A3197505145000000000D319750249514500C0A000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 20111125700500000000 NAME SURNAME SURNAME 012239
FFFFFFFFFFFFFFFFFFFF00DCDC00200EEDDCDC0000EEDDCDC00300FFFFFF444444444444
2011112570050000000004514500C0724951450007249514500C07012239000000000000
------------------------------------------------------------------------------
000002 20111125700500000000 LARGE NAME LARGE SURNAME
FFFFFFFFFFFFFFFFFFFF00DCDCC4DCDC4444444400DCDCC4EEDDCDC00100444444444444
201111257005000000000A3197505145000000000D319750249514500C0A000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************
Thank you in advance
Domingo Fernández.