Transforming XML text to COBOL data items
About this task
Because XML data is neither fixed length nor fixed format, you need to use special techniques when you move XML data to a COBOL data item.
For alphanumeric items, decide whether the XML
data should go at the left (default) end, or at the right end, of
the COBOL data item. If the data should go at the right end, specify
the JUSTIFIED RIGHT
clause in the definition of
the item.
Give special consideration to numeric XML values,
particularly decorated
monetary values such as '$1,234.00'
or '$1234'. These two strings might mean the same thing in XML, but
need quite different definitions if used as
COBOL sending fields.
Use one of the following techniques when you move XML data to COBOL data items:
- If
the format is reasonably regular, code a
MOVE
to an alphanumeric item that you redefine appropriately as a numeric-edited item. Then do the final move to a numeric (operational) item by moving from, and thus de-editing, the numeric-edited item. (A regular format would have the same number of digits after the decimal point, a comma separator for values greater than 999, and so on.) - For simplicity
and vastly increased flexibility, use the following
intrinsic functions for alphanumeric XML data:
NUMVAL
to extract and decode simple numeric values from XML data that represents plain numbersNUMVAL-C
to extract and decode numeric values from XML data that represents monetary quantities
However, using these functions is at the expense of performance.