Skip to content

MDRYAJLR4 Copybook

Jump to MDRST/MDRFRAME copybook

RPG Prototypes for YAJL with mdr_ prefix

mdr_beginArray

if called without parameter or with blank parameter, it starts non-labeled array, otherwise, it starts labeled array (means beginning square bracket with the prefix label) returns: Yajl generation status

dcl-pr mdr_beginArray int(10) extproc('YAJL_BEGINARRAY');
  label varchar(65535) const options(*varsize:*nopass);
end-pr;

mdr_endArray

ends the array by adding closing square bracket returns: Yajl generation status

dcl-pr mdr_endArray int(10) extproc('YAJL_ENDARRAY')
end-pr;

mdr_beginObject

if called without parameter or with blank parameter, it starts non-labeled object, otherwise, it starts labeled object (means beginning curly bracket with prefix label) returns: Yajl generation status

dcl-pr mdr_beginObject int(10) extproc('YAJL_BEGINOBJ');
  label varchar(65535) const options(*varsize:*nopass);
end-pr;

mdr_endObject

ends the object by adding closing curly bracket returns: Yajl generation status

dcl-pr mdr_endObject int(10) extproc('YAJL_ENDOBJ')
end-pr;

mdr_addNull

adds JSON entry in the ouptut with the supplied name entry and value as null returns: Yajl generation status

dcl-pr mdr_addNull int(10) extproc('YAJL_ADDNULL');
  value varchar(65535) const options(*varsize:*nopass);
end-pr;

mdr_addChar

adds name and value pair when both parameters supplied. When only one parameter is supplied, it adds the value in double quotes to the string array returns: Yajl generation status

dcl-pr mdr_addChar int(10) extproc('YAJL_ADDCHAR');
  label varchar(65535) const options(*varsize);
  value varchar(65535) const options(*varsize:*nopass:*omit);
end-pr;

mdr_addNum

Add a numeric value to the JSON data stream if one parameter: value(input) = number to add to JSON stream (in string form) if two parameters: value1 (input) = key of property to add to object value2 (input) = number to set as property value (in string form) // returns: yajl_gen_status_ok (i.e 0) upon success, or generator status code upon failure.

dcl-pr mdr_addNum int(10) extproc('YAJL_ADDNUM');
  label varchar(65535) const options(*varsize);
  value varchar(65535) const options(*varsize:*nopass:*omit);
end-pr;

mdr_addBool

adds name and value(true/false depending on whether the indicator is On or off) when both parameters supplied. When only one parameter is supplied, it is expected to be either On or off and thereby, it adds true/false value to the boolean array. returns: Yajl generation status

dcl-pr mdr_addBool int(10) extproc('YAJL_ADDBOOL');
  label varchar(65535) const options(*varsize);
  Value ind const options(*nopass);
end-pr;

mdr_startJson

allocates the required memory for subsequent use of beginobject, addchar etc functions to build JSON Parameters: beautify : On would add line breaks and indentation for readability Off would generate compact JSON escSolidus: On would escape the solidus (aka forward slash) characters. : default is Off // returns: yajl_gen_status_ok (i.e. 0) if successful yajl_gen_open_fail (i.e. 1000001) upon failure

dcl-pr mdr_startJson int(10) Extproc('YAJL_GENOPEN');
  beautify ind const;
  escSolidus ind const options(*nopass);
end-pr;

mdr_endJson

closes the JSON generation channel and deallocates memory. subsequent addchar, getJson etc cannot be used

dcl-pr mdr_endJson Extproc('YAJL_GENCLOSE')
end-pr;

mdr_getJson

Copies JSON generator buffer to the caller's variable or buffer. ccsid = (input) CCSID to convert data to. 0=job CCSID. bufptr = (input) Pointer to variable or buffer to copy the data to. bufSize = (input) Size of the jsonBuf buffer (in bytes) rtnLen = (output) length of data placed in buffer returns: YAJL generator status.

dcl-pr mdr_getJson int(10) Extproc('YAJL_COPYBUF');
  ccsid  int(10) value;
  bufptr pointer value;
  bufsize int(10) value;
  rtnlen int(10);
end-pr;

mdr_getJsonPtr

returns a pointer to JSON internal buffer where JSON data is stored. rtnptr = (output) pointer to YAJL's generator buffer rtnlen = (output) length of returned buffer in bytes returns: YAJL generator status.

dcl-pr mdr_getJsonPtr int(10) Extproc('YAJL_GETBUF');
  bufptr pointer;
  bufsize uns(10);
end-pr;

mdr_getJsonStr

returns the current JSON buffer to an RPG variable of max 2000000 size. Receiving variable must be a varchar. Not optimized and can impact performance. Use mdr_getJson for larger size or better performance

dcl-pr mdr_getJsonStr varucs2(2000000) extproc('YAJL_COPYBUFSTR')
end-pr;

MDR_addTimestamp

Adds an ISO 8601 timestamp in: YYYY-MM-DDTHH:MM:SS.sss format to the JSON document. // @param (input) name = key name if within an object, or omit @param (input) val = standard RPG timestamp field @param (input/opt) tz = time zone to use, examples are: 'Z' = UTC '+0500' = 5 hours east of UTC '-0600' = 6 hours west of UTC ' ' = local time 'UTC' (default) Convert to UTC and report as a UTC timestamp // @param (input) datesep = date separator (default: -) @param (input) timesep = time separator (default: :) @param (input) tzsep = timezone sep (default: none) // @return returns yajl_gen_status_ok upon success, or generator status code upon failure.

dcl-pr MDR_addTimestamp extproc('YAJL_ADDTIMESTAMP');
  name           Varchar(65535) CONST OPTIONS(*VARSIZE:*OMIT);
  val            Timestamp  CONST;
  tz             Varchar(6)  CONST OPTIONS(*OMIT:*NOPASS);
  datesep        Varchar(1)  CONST OPTIONS(*OMIT:*NOPASS);
  timesep        Varchar(1)  CONST OPTIONS(*OMIT:*NOPASS);
  tzsep          Varchar(1)  CONST OPTIONS(*OMIT:*NOPASS);
end-pr;

!!! note: Below are all the non YAJL procedures added in MDRYAJLR4 module by Midrange Dynamics

mdr_getEntry

returns the value at the specified key node. e.g. for the node "city":"Paris", it will return "Paris". The node must be of string type, otherwise, it will return blank

dcl-pr mdr_getEntry varchar(1024) extproc('YAJL_GETSTRKEY');
  bgnNode pointer value;
  entry varchar(50) const;
end-pr;

mdr_GetNumKey

returns the numeric value in string form at the specified key node. for the node "orderno":57689, it will return '57689'. The node must be of numeric type. Otherwise, it returns blank

dcl-pr mdr_GetNumKey varchar(50) extproc('YAJL_GETNUMSTR');
  node pointer value;
end-pr;