Cobol Programs to implement endpoint
Copybooks:
working-storage
wsjson.cpy - contains variables used by endpoints, to format json, and for CRUD functions
procedure division
json.cpy - contains routines to format json, and also to handle file errors (similar to allerr.cpy but returning the file error to the calling program in json).
In Program:
set GRAPHICAL-SCREEN-SW = “Y” even though we aren’t using graphical screens; this suppresses the character based displays that still exist in some programs
set AUTOMATED-RUN = “Y” - this tells any called programs not to try to display messages to a non-existent window
use WSJSON.CPY in working storage, and JSON.CPY in the procedure division
routine PRINT-RECORD builds one record and exports it to json; it calls paragraph GENERATE-RECORD-JSON, which is where you put the specific fields to be returned and format them, if necessary
if you are returning two types of data, as with get_po, where we return the header data for the PO and then an array of the lines, we do the header data in a separate paragraph, and use GENERATE-RECORD-JSON to generate the repeating data in the array.
You need to put the “[“ and “]” characters to indicate the beginning and end of array data manually
paragraphs ADD-RECORD and ADD-NUMERIC-RECORD are used to add data to the output string
paragraphs ADD-LAST-RECORD is used for the final output in a json string