You will run the program a number of times, using different declarations of the JSON GENERATE statement - the declarations are in the J100-SIMPLE-GENERATE, J200-GENERATE-EXCEPTION, and J300-COMPLEX-GENERATE paragraphs.
The program currently runs the following JSON GENERATE statement:
JSON GENERATE JSON-DOC FROM COBOL-STRUCTURE COUNT IN C1
The results displayed in the right-hand pane.
We'll now update the program to enhance the JSON GENERATE statement to include some exception handling.
The program now runs the following JSON GENERATE statement:
JSON GENERATE JSON-DOC FROM COBOL-STRUCTURE COUNT IN C1 ON EXCEPTION EXHIBIT NAMED JSON-CODE EXHIBIT NAMED JSON-STATUS GO TO J999-EXIT END-JSON
This does not affect the generated JSON, but gives a more contemporary control over JSON GENERATE, by handling any potential exceptions within the JSON statement, instead of using a conditional statement following JSON GENERATE as shown in the J100 paragraph.
The last declaration to run, J300, demonstrates the use of the NAME and SUPPRESS clauses. The NAME clause is used to re-map the '_reference' field in COBOL (the proceeding hyphen is due to a reserved words constraint) to 'reference' in JSON. The SUPPRESS clause is used to omit certain COBOL fields from the JSON output.
The program now runs the following JSON GENERATE statement:
JSON GENERATE JSON-DOC FROM COBOL-STRUCTURE COUNT IN C1 NAME OF _reference OF COBOL-STRUCTURE IS 'reference' SUPPRESS salary OF COBOL-STRUCTURE typ OF COBOL-STRUCTURE ON EXCEPTION EXHIBIT NAMED JSON-CODE EXHIBIT NAMED JSON-STATUS GO TO J999-EXIT END-JSON