DFHJS2LS - generating Json structure from cobol copybook

652 Views Asked by At

I have my output structure in COBOL - from which I try to generate to a JSON structure through DFHJS2LS - IBM tools. All the fields change to be required - this giving trouble when generating classes in .Net as all the fields are not present.

Question: How and where (in COBOL or DFHJS2LS) to define fields as optional in order to get them generated properly avoiding null pointer exception.

1

There are 1 best solutions below

10
cschneid On

According to the documentation you can define your COBOL data items with...

data description OCCURS n TIMES

...and use mapping level 4.1 or higher and specify TRUNCATE-NULL-ARRAYS = ENABLED. There is a reference to "structured arrays" which I take to mean you would need to do something like...

05  Something Occurs 1 Times.
    10  Something-Real PIC X(8).

...so you get...

"type":"array"
"maxItems":1
"minItems":0
"items":{ ... }

You could also specify mapping level 4.0 or higher and use...

data description OCCURS n TO m TIMES DEPENDING ON t

...to obtain...

   "field-name":{
               "type":"array",
               "maxItems":m
               "minItems":n
               "items":{ ... }
              }`

Mapping level is specified by...

//INPUT.SYSUT1 DD *
[...other control statements...]
MAPPING-LEVEL=4.3
[...other control statements...]