Skip to main content

Problem:

When examining a variable length sequential file in a hex editor, extra bytes with a value of x"00" have been inserted at the end of records.  When accessing the file from a COBOL program these extra bytes do not appear in the data.  Is this a problem?

Resolution:

These additional bytes are padding and are inserted by the file handler to ensure that the next record starts at an address which is an exact multiple of the data alignment value for the file type.  They are not the result of corruption and are perfectly normal.

Variable length record sequential files consist of a 128 byte header record and then a number of data records, each of which is preceeded by a 2 or 4 byte record header.

Example output from od -xAd:

0000000  307e 0000 0000 0000 3037 3130 3136 3131

0000016  3235 3535 3438 3037 3130 3136 3131 3235

0000032  3535 3438 003e 0001 0000 0000 0000 0000

0000048  0100 0000 0000 0000 0050 0000 0002 0000

0000064  0000 0000 0000 0000 0000 0000 0000 0100

0000080  0000 0000 0000 0000 0000 0000 0000 0000

0000096  0000 0000 0000 0000 0000 0000 586c 3978

0000112  0000 0000 0000 0000 0000 0000 0000 0000

0000128  4050 4141 4141 4141 4141 4141 4141 4141

0000144  4141 4141 4141 4141 4141 4141 4141 4141

*

0000208  4141 0000 401e 4242 4242 4242 4242 4242

0000224  4242 4242 4242 4242 4242 4242 4242 4242

0000240  4242 4242

0000244

In the above example at offset 128 you can see the first data record starts with a two byte record header containing x"4050" which denotes that this is a normal data record (4) and has a length of 80 bytes (050).  80 2 is not evenly divisible by 4, therefore two padding bytes are required. These padding bytes appear at offset 210 as x"0000".

The next record starts at offset 212, is a normal data record and has a length of 30 bytes (x"401e").  30 2 is evenly divisible by 4 so no padding bytes are required for this record.

N.B. The record header is only two bytes in the example as the maximum record lenght is less than 4096 bytes.  For record lengths greater than this a four byte header would be used.

For further information refer to the following Server Express documentation:

1. File Handling Reference > File Structures > Files with Headers > Variable format record sequential files.

2. File Handling Reference > File Structures > Files with Headers > Standard record header.

The documentation on the standard record header states that the padding character is normally spaces.  This is wrong and the padding character is actually null, i.e. x"00" as per the example above.

Old KB# 2263

#ServerExpress
#RMCOBOL
#AcuCobol
#COBOL
#netexpress