1.

How do we remove the spaces at end of every record in an output file that is of variable length?

Answer»

Spaces that are PRESENT at the end of the record are called trailing spaces. COBOL does not provide the functionality to remove such trailing spaces. But it can be achieved by using the RECORD-LENGTH field as FOLLOWS:
Consider a scenario where we have a file of variable length and the maximum possible record length is 4000. To remove trailing space from EVERY record, then we can alter the record length value to RECORD-LENGTH. This ensures that the records are trimmed which are beyond actual record length. Assuming that a variable-length file has a maximum record length of 4000.

  • Move the original record length value to RECORD-LENGTH. This process ENABLES the trimming of the entire record that is beyond the length.
  • In case the data is populated only up to 3000 bytes - meaning there are 1000 trailing spaces. Then move the record length value to RECORD-LENGTH.
  • By doing this, the records would be trimmed off and 1000 bytes would be freed.


Discussion

No Comment Found