If you process files with structured records, you need to extract parts of it and maybe convert it and assign it rex variables. Creating records must work in the opposite direction. For Extracting variables out of a record a series of SUBSTR functions is used, to push variables into a record we use OVERLAYs.
I created a tiny script which might be useful.
The structure is defined in a compound variable (Stem) and has an entry for each data item:
structure.1="Name Char 10"
structure.2="IDNo Bin 2"
structure.3="Telephone NUM 8"
structure.4="Address VAR *"
structure.0=4
first the variable name is defined, followed by the type and length, the offset in the record is calculated internally. Currently there are the following types: CHAR string of certain length NUM numeric string (as CHAR) but it will be "right" justified BIN binary number, the numeric value is translated into its binary representation and vice versa. VAR Character string with variable length, therefore you don't need the length DEC packed fields (for our hosties) will be packed and unpacked
The definition will be passed to the STRUCTURE procedure in DEFINE mode. The necessary statements to push the variables in a record and fetch it from a record will be created. Later on these statements will be used as "Interpret" Macros.
Check out the following example to understand the method:
structure.1="Name Char 10"
structure.2="IDNo Bin 2"
structure.3="Telephone NUM 8"
structure.4="Address VAR *"
structure.0=4
structure('DEFINE',structure.)
SAY "1. Structure defined"
NAME="John Smith"
idno="2178"
telephone=442518234
ADDRESS="Leicester Court Road 2356"
SAY "2. Variables set"
record=structure('PUT',structure.)
SAY "3. compose record from Variables"
DROP NAME idno telephone ADDRESS
SAY "4. Variables dropped, as we fetch them back from record"
SAY "5. Fetch Variables from record"
structure('GET',structure.,record)
SAY 'Name : 'NAME
SAY 'IDNo : 'idno
SAY 'Telephone: 'telephone
SAY 'Address : 'ADDRESS
SAY "6. Variables created using structure definition from record"
EXIT
If you read an process a file you need the STRUCTURE(GET,...) method. To write records STRUCTURE(PUT,...). Reading and writing records is not part of the functions, and must be performed with appropriate commands. The structure procedures are attached! |