DEV Community

taimenwillems
taimenwillems

Posted on

1

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay