SDF command strings can be converted to structure or list type S variables according to very specific rules. Conversely, the conversion of structure or list type S variables into SDF strings is equally possible.
To convert an SDF command string into an S variable the operand *STRING-TO-
VARIABLE(...) should be set in the SET-VARIABLE command (see "SET-VARIABLE Assign value to variable "), to effect the reverse conversion use the predefined function VARIABLE-TO-STRING( ) (see "VARIABLE-TO-STRING( ) Convert variable ").
Note
It is not possible to specify positional operands for the conversion in SET-VARIABLE. Doing so results in an error message.
Conversion rules
Converting SDF command strings to S variables
Operands are converted to structure elements.
Simple operand values are converted to simple structure element values.
SDF lists are converted into list variables.
The lists are converted regardless of the SDF data types.
The following applies by default (VALUE-TYPE = *STD): If an integer value is found in the input string, then “integer” is stored as the data type for the variable. If the value TRUE or FALSE is found (in capital or small letters), then “boolean” is stored as the data type for the variable. In all other cases, “string” is stored as the data type for the variable. When VALUE-TYPE = *STRING is specified, “string” stored as the data type for the variable regardless of its value.Command/statement names are converted to element values with the reserved name SYSOPER.
Values which initiate a structure are converted to element values with the reserved name SYSSTRUC.
Operands in SDF structures are converted to second-level structure element names. These elements are appended to the element name which results from the conversion of the operand, and which in turn identifies the structure.
Converting S variables to SDF command strings
The conversion of S variables of type string to character strings is similar to & replacement. Integer values are automatically converted to strings, Boolean values are converted to the string value ‘TRUE‘ or ‘FALSE‘ as applicable.
Thus, an S variable must be initialized as follows if its value after conversion from an S variable to an SDF string is to be a value of type C-string:
/SET-VARIABLE DATA.OPER = 'C''mychain'''
This has the effect that the string value 'C''mychain'''is saved in the variable DATA.OPER, and on conversion is transformed into the following SDF syntax:
OPER = C'mychain'
This results in the value “C'mychain'” being specified with the SDF data type <C-string> in accordance with the OPER operand.
Summary:
SDF syntax string | Complex S variables (name DATA) |
OPER = value | DATA.OPER = 'value' |
operation oper1 = val1 | DATA.SYSOPER = 'operation' |
oper = struc (oper1 = val1) | DATA.OPER.SYSSTRUC = 'struc' |
oper = (val1,val2,val3) | DATA.OPER#1 = 'val1' |
Exceptions
Only the external form of SDF strings will be parsed according to these rules. The basic data items processed are the characters strings. Neither the semantic information nor the internal SDF syntax descriptors are converted and stored as S variables: e.g. if OPER = A (OP1=VAL1) is stored in an S variable, this gives no indication whether A is a keyword, a name or a filename.
Restrictions on the string input
The SDF string FROM=(file,*LIB(LIB=lib,EL=elem)) cannot be converted to an S variable, because SDF-P does not support any form of heterogeneous list.
Examples (showing the restrictions)
Example 1
FROM=(file,*LIB(LIB=lib,EL=elem)) is converted to:
A.FROM#1.SYSSTRUC = 'file' A.FROM#2.SYSSTRUC = '*LIB' A.FROM#2.LIB = 'lib' A.FROM#2.EL = 'elem'
Such complex variables are possible for dynamic structure lists. However, the first element of the list must be converted as a SYSSTRUC element, which conflicts with the actual structure of the SDF string. A.FROM#1 = 'file' is impossible.
Example 2
OP = (a,b,c) is converted to:
A.OP#1 = 'a' A.OP#2 = 'b' A.OP#3 = 'c'
On the other hand, OP = (a,b,c(OPR=d)) is converted to:
A.OP#1.SYSSTRUC = 'a' A.OP#2.SYSSTRUC = 'b' A.OP#3.SYSSTRUC = 'c' A.OP#3.OPR = 'd'
Note
The conversion of an individual value depends on the structure of the input string, and may therefore be rejected (except for VALUE-TYPE= *STRING).
Example 3
The SDF strings FCB-TYPE=ISAM and FCB-TYPE=ISAM(KEY-POS=5,KEY-LEN=8) result in two different structures in SDF-P:
DATA.FCB-TYPE = 'ISAM'
and
DATA.FCB-TYPE.SYSSTRUC = 'ISAM' DATA.FCB-TYPE.KEY-LEN = 8 DATA.FCB-TYPE.KEY-POS = 5
Hence, in S procedures the two variable structures can be sorted by means of the predefined function VARIABLE-ATTRIBUTE(..., ATTRIBUTE=*TYPE). For example, for VARIABLE-ATTRIBUTE('DATA.FCB-TYPE', ATTRIBUTE=*TYPE) this gives the results:
'*STRUCTURE', if the operand value is a structure.
in any other case, '*ANY' or '*STRING'
Example 4
The strings OPER=A(OP1=X,OP2=Y) and OPER=B(OP1=X,OP2=Y) create the same structure elements, but OP1 means something fundamentally different in the two cases:
DATA.OPER.SYSSTRUC = 'A' DATA.OPER.OP1 = 'X' DATA.OPER.OP2 = 'Y' DATA.OPER.SYSSTRUC = 'B' DATA.OPER.OP1 = 'X' DATA.OPER.OP2 = 'Y'