#EXPORT

#EXPORT( symbol, data );

symbolThe name of a previously declared template variable.
dataThe name of a field, RECORD structure, or dataset.

The #EXPORT statement produces XML text from the specified data and places it in the symbol. This allows the LOADXML(symbol,name) form to instantiate an XML scope on the information from the data to process.

The XML output is generated with the following format:

  <Data>
    <Field label="<label-of-field>"
           name="<name-of-field>"
           position="<n>"
           rawtype="<n>"
           size="<n>"
           type="<ecl-type-without-size>" />
    ...
  </Data>

IFBLOCKs are simply expanded out in the XML. Nested RECORD types have an isRecord attribute that is set to 1, and are followed by the fields they contain, and then a Field tag with no name and the isEnd attribute set to 1. This representation is used rather than nested objects so it can be processed by a #FOR statement. Child dataset types are also expanded out in a similar way, and have an isDataset attribute set to 1 on the field.

Example:

NamesRecord := RECORD
  STRING10 first;
  STRING20 last;
END;
r := RECORD
  UNSIGNED4 dg_parentid;
  STRING10 dg_firstname;
  STRING dg_lastname;
  UNSIGNED1 dg_prange;
  IFBLOCK(SELF.dg_prange % 2 = 0)
    STRING20 extrafield;
  END;
  NamesRecord namerec;
  DATASET(NamesRecord) childNames;
END;
  
ds := DATASET('~RTTEST::OUT::ds', r, thor);
  
#DECLARE(out);
#EXPORT(out, r);
OUTPUT(%'out'%);
  /* produces this result:
  <Data>
    <Field label="DG_ParentID"
        name="DG_ParentID"
        position="0"
        rawtype="262401"
        size="4"
        type="unsigned integer"/>
    <Field label="DG_firstname"
        name="DG_firstname"
        position="1"
        rawtype="655364"
        size="10"
        type="string"/>
    <Field label="DG_lastname"
        name="DG_lastname"
        position="2"
        rawtype="-983036"
        size="-15"
        type="string"/>
    <Field label="DG_Prange"
        name="DG_Prange"
        position="3"
        rawtype="65793"
        size="1"
        type="unsigned integer"/>
    <Field label="ExtraField"
        name="ExtraField"
        position="4"
        rawtype="1310724"
        size="20"
        type="string"/>
    <Field isRecord="1"
        label="namerec"
        name="namerec"
        position="5"
        rawtype="13"
        size="30"
        type="namesRecord"/>
    <Field label="first"
        name="first"
        position="6"
        rawtype="655364"
        size="10"
        type="string"/>
    <Field label="last"
        name="last"
        position="7"
        rawtype="1310724"
        size="20"
        type="string"/>
    <Field isEnd="1" name="namerec"/>
    <Field isDataset="1"
        label="childNames"
        name="childNames"
        position="8"
        rawtype="-983020"
        size="30"
        type="table of &lt;unnamed&gt;"/>
    <Field label="first"
        name="first"
        position="9"
        rawtype="655364"
        size="10"
        type="string"/>
    <Field label="last"
        name="last"
        position="10"
        rawtype="1310724"
        size="20"
        type="string"/>
    <Field isEnd="1" name="childNames"/>
  </Data>
  */
  
  //which you can then process ;ike this:
LOADXML(%'out'%, 'Fred');
#FOR (Fred)
  #FOR (Field)
    #IF (%'{@isEnd}'% <> '')
      OUTPUT('END');
    #ELSE
      OUTPUT(%'{@type}'%
      #IF (%'{@size}'% <> '-15' AND
           %'{@isRecord}'%='' AND
           %'{@isDataset}'%='')
           + %'{@size}'%
      #END
        + ' ' + %'{@label}'% + ';');
    #END
  #END
#END
OUTPUT('Done');

See Also: LOADXML, #EXPORTXML, #DECLARE