DSM Template Services Manual

Display-Text Procedures
DSM Template Services Manual427187-004
2-25
Procedures That Convert Variable-Length Tokens
Organizational Principles
Sometimes the value of a token consists of a variable number of fixed-length values.
To define such a token:
1. Define a DDL DEF that describes the fixed-length element.
2. Define a token type with OCCURS VARYING that refers to the DEF in Step 1 and
use this token type when defining the main token.
3. Use a template-language FORMAT statement to associate a custom-formatting
procedure with the DEF in Step 1.
4. Write the custom-formatting procedure to convert one occurrence of the fixed-
length element. The SPI_BUFFER_FORMATNEXT_ procedure calls your custom-
formatting procedure as many times as necessary, each time pointing to a different
occurrence of the fixed-length element in the token.
Example 2-4 shows such a composite structure.
The value maxnum is the maximum number of elements in any one ABC-TKN-MAIN
token. At execution time, when the value of the ABC-TKN-MAIN token is set, the len
field can be set to the actual length.
Example 2-4. Variable Number of Fixed-Length Values
CONSTANT abc-tnm-main VALUE IS 8.
!
! The fixed-length structure
!
DEFINITION abc-ddl-flen.
02 fld-1 TYPE zspi-ddl-int.
END
!
! The multi-element structure
!
DEFINITION abc-ddl-main.
02 len TYPE zspi-ddl-int.
02 elem TYPE abc-ddl-flen OCCURS maxnum TIMES.
END
TOKEN-TYPE abc-typ-main VALUE IS zspi-tdt-struct
DEF IS abc-ddl-main
OCCURS VARYING.
TOKEN-CODE abc-tkn-main VALUE IS abc-tnm-main
TOKEN-TYPE IS abc-typ-main
SSID abc-val-external-ssid
HEADING "Main".