|
Do
your customers ever have a need to request a simple query where they
supply the name of the field they want to see at execution time?
Here is a simple way to access and extract the data from the record.
Set up a simple data dictionary containing the field name, field offset
in the record (where the first byte in the record is offset zero) and
field type (small integer, integer, double integer, character, etc.).
This could be an internal table in WORKING-STORAGE, a DB2 table or a
VSAM KSDS file.
Define a work area like this that redefines your record area:
01 RECORD-WORK-AREA
REDEFINES xxxxxxxxxxxxxxxxxxx.
03 FILLER OCCURS 0 TO nn1 TIMES DEPENDING ON RECORD-OFFSET
SET SET SET PIC X(1).
03 FIELD-CHARACTER PIC X(nn2).
03 FILLER REDEFINES FIELD-CHARACTER.
05 FIELD-SMALL-INTEGER PIC S9(4) COMP.
05 FILLER PIC X(nn3).
03 FILLER REDEFINES FIELD-CHARACTER.
05 FIELD-INTEGER PIC S9(9) COMP.
05
FILLER PIC X(nn4).
03 FILLER REDEFINES FIELD-CHARACTER.
05 FIELD-DOUBLE-INTEGER PIC S9(18) COMP.
05 FILLER PIC X(nn5).
Define RECORD-OFFSET somewhere in WORKING-STORAGE as a PIC S9(9) COMP
field.
Do
a lookup in your data dictionary for the field name supplied by the
customer. Move the associated field offset to RECORD-OFFSET. Then,
depending on the field-type, you can move the appropriate field from the
RECORD-WORK-AREA to wherever you what to use it.
Notes:
xxxxxxxxxxxxxxxxxxxxxxxx is the name of your record area that we are
redefining.
nn1 is the maximum size of your record.
nn2 is the size of the largest character field in your record.
nn3 is nn2 – 2.
nn4 is nn2 – 4.
nn5 is nn2 – 8. |