DEV Community

taimenwillems
taimenwillems

Posted on

How to make an XML element optional in a Cobol provider webservice (DFHLS2WS), based on a Cobol structure

To make an XML element optional in a Cobol provider webservice (DFHLS2WS), based on a Cobol structure (not from an XSD), you can modify the Cobol structure to include the OCCURS DEPENDING ON clause.

Suppose you have a Cobol structure that looks like this:

01 MyStructure.
   05 ElementA PIC X(10).
   05 ElementB PIC X(20).
Enter fullscreen mode Exit fullscreen mode

And you want to make "ElementB" optional in the resulting XML structure. Then you can modify the COBOL structure by moving "ElementB" to a separate level that can be made optional, for example:

01 MyStructure.
   05 ElementA PIC X(10).
   05 ElementB PIC X(20) OCCURS 0 TO 1 DEPENDING ON ElementB-Present.
   05 ElementB-Present PIC 9(1) VALUE 1.
Enter fullscreen mode Exit fullscreen mode

This way, "ElementB" is optional in the resulting XML structure, and its presence or absence depends on the value of "ElementB-Present". If "ElementB-Present" has the value "1", then "ElementB" is included in the XML structure; when "0", it is not included.

You can then use the modified Cobol structure to define and generate the webservice using the DFHLS2WS utility. Use the Cobol structure as input for the utility to generate the appropriate XML structure.

Top comments (0)