4 Data Variables and Data handling
Unlike the PACK USING and UNPACK USING statements, the XPACK and XUNPACK statements include the variable name in the packed string and use a variable length string format.
As the data is transferred to the destination string, it is converted into string format and stored along with the variable name and array index.
The XPACK and XUNPACK statements can operate on a STRUCT. STRUCT is treated as a list of variables.
The XPACK statement packs each member variable in a buffer. The XUNPACK statement unpacks to a user defined type if it is passed as an argument to XUNPACK and the member variable matches the name in the buffer.
Pack destination string variable from variable list specified by the string expression. The string expression contains a list of variable names separated by a comma.
For example:
List$="A,A$,B,B$,A$(1),Array$(*)"
Pack destination string variable from variable list as defined by the referenced remote list(s).
For example:
XPACK Dest$ USING REMOTE LISTS Label1,Label2 Label1: IN DATA SET LIST A,A$ Label2: IN DATA SET LIST ...
Pack destination string variable from variable list.
For example:
XPACK Dest$ FROM A,A$,B,B$,A$(*)
XUNPACK Buf$
Unpack buffer variable into variables as named in the buffer.
For example:
A$="Test" B=123 XPACK Buf$ FROM A$,B A$="" B=0 XUNPACK Buf$This recovers the initial values of A$ and B.
For example:
XPACK Buf$ FROM A$,B,C List$="A$,B" XUNPACK Buf$ USING List$This should unpack the variables A$ and B only.
For example:
XPACK Buf$ FROM A$,B,C XUNPACK Buf$ FROM A$,BThis unpacks the variables A$ and B only.
For example:
XPACK Buf$ FROM A$,B,C XUNPACK Buf$ USING REMOTE LISTS Label Label: IN DATA SET LIST A$,B
The following rules apply:
Type | Name | ~ | Idx | ~ | Len | ~ | Value | ... | $ |
numeric
X
string
$
End-of-list
Simple = 47 XPACK Buf$ FROM SimpleResults in the following buffer:
"NSimple~0~2~47$"Equivalent Eloquence code:
Buf$="N"&"Simple~"&"0~"&VAL$(LEN(VAL$(Simple))) &"~"&VAL$(Simple)&"$"
Simple$ = "String" XPACK Buf$ FROM Simple$Results in the following buffer:
"XSimple~0~6~String$"Equivalent Eloquence code:
Buf$="X"&"Simple~"&"0~"&VAL$(LEN(Simple$))&"~"&Simple$&"$"
A$(1)="TEST" XPACK Buf$ USING "A$(1)"Results in the following buffer:
"XA~1~4~TEST$"
DIM A$(0:3) A$(0)="000" A$(1)="111" A$(2)="222" A$(3)="333" XPACK Buf$ FROM A$(*)Results in the following buffer:
"XA~1~3~000XA~2~3~111XA~3~3~222XA~4~3~333$"
DIM Type$[1],Var_name$[15],Value$[80],Variable$[22] INTEGER P,Idx,Len LOOP Type$=Buf$[1,1] ! Type EXIT IF Type$="$" Buf$=Buf$[2] P=POS(Buf$,"~") ! locate separator Var_name$=Buf$[1;P-1] ! Variable name Buf$=Buf$[P+1] P=POS(Buf$,"~") ! locate separator Idx=VAL$(Buf$[1,P-1]) ! Array index Buf$=Buf$[P+1] P=POS(Buf$[P],"~") ! Separator Len=VAL(Buf$[1,P-1]) ! Value length Buf$=Buf$[P+1] Value$=Buf$[1;Len] ! Value Buf$=Buf$[Len+1] IF Idx THEN Variable$=Var_name$&"("&VAL$(Idx)&")" ELSE Variable$=Var_name$ END IF IF Type$="X" THEN COMMAND Variable$&"$=Value$" ELSE COMMAND Variable$&"="&Value$ END IF END LOOP