DEV Community

taimenwillems
taimenwillems

Posted on

How to create a flexible number of xml-elements in a cobol provider webservice (DFHLS2WS), starting from a cobol-structure.

If you have a COBOL structure that corresponds to the XML elements of your provider webservice and you want to create an element that can occur from 1 to 1000 times, you can modify the COBOL structure to include a repeating group. This can be done using the "OCCURS" clause in COBOL.

Suppose you have a COBOL structure that looks like this:

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

And you want "ElementB" to be able to repeat 1 to 1000 times in the resulting XML structure. Then you can modify the COBOL structure by moving "ElementB" to a repeating group with the 'OCCURS x TO y TIMES' clause, for example:

01 MyStructure.
   05 ElementA PIC X(10).
   05 ElementB OCCURS 1 TO 1000 TIMES
      PIC 9(5).
Enter fullscreen mode Exit fullscreen mode

This way, you can repeat "ElementB" 1 to 1000 times in the resulting XML structure, depending on how many times it occurs in the input.

Then, you can use the modified COBOL structure to define and generate the webservice using the DFHLS2WS utility. You can use the modified COBOL structure as input for the utility to generate the appropriate XML structure.

Top comments (0)