BLOCK/UNBLOCK Statement

mvBASIC 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.

Description

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.

Examples

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.

Format of BLOCK

BLOCK fixed FROM dynamic USING structure

Parameter(s)

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.

Format of UNBLOCK

UNBLOCK dynamic FROM fixed USING structure

Parameter(s)

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.

See Also

Statement and Function Reference