Basic provides facilities for converting between variable length data structures and fixed length data structures.
For example, block converts a dynamic array into a fixed length record, automatically handling issues such as adding leading zeros or trailing spaces. It also allows the user to convert decimal or hexadecimal numbers into binary fields within the fixed length data structure. unblock is the converse of block and creates variable length structures from fixed length data structures.
block and unblock may also be used with great effect to handle foreign tapes created with more than one record per tape block, or when importing or exporting formatted data to/from UNIX or DOS.
block and unblock statements use a pre-defined structure to control the way in which they operate. This structure must be created as a dynamic array, with one attribute per field within the structure. Each attribute specifies the starting position of the field within the fixed length record, its length, and its type, separated by commas.
If working with an 80 byte card image and the user wishes to make attribute 5 of the dynamic array replace a customer name stored in bytes 51 through 70 of the card image (or visa versa), attribute 5 of the structure would be:
51,20,L
Define the field as type L so that trailing spaces are automatically trimmed if unblocking the card image to a dynamic array and automatically appended if blocking the dynamic array to the card image.
If using an R type, this trims or inserts leading zeros as appropriate.
Type B is used only when working with binary numbers in the fixed length record. It converts between a binary number there and a normal numeric character string in the dynamic array.
Type X is similar to type B, but works with binary numbers in the fixed length record, and hexadecimal character strings in the dynamic array. If no type code is specified, the data is moved without conversion.
If the structure has errors in it, such as referencing byte 0 of the fixed length record, moving zero bytes, or trying to extract data from beyond the end of the fixed length record, the block and unblock commands which use the structure set system(0) to a value other than zero.
A good way of testing a structure is to take the original data, block it, and immediately unblock it using the same structure, verifying that the original data is recovered. Then do the same again first unblocking then blocking. Both tests should regenerate the original data, or at least, the user should be able to explain all differences.
block fixed from dynamic using structure
fixed | Fixed length structure that is being created. |
dynamic | Contains the data being used to create it. |
structure | Contains the template controlling where the data from dynamic are placed within fixed and what conversions (if any) are performed on it during this process. |
If the command works correctly, system(0) is set to 0. If the command works incorrectly during this process (almost always because of a bad structure), system(0) specifies the type of error.
unblock dynamic from fixed using structure
dynamic | The dynamic array that is being created. |
fixed | Contains the fixed length data being used to create it. |
structure | Contains the template controlling where the data from fixed are placed within dynamic and what conversions (if any) are performed on it during this process. |
If the command works correctly, system(0) is set to 0. If the command works incorrectly during this process (almost always because of a bad structure), system(0) specifies the type of error.