Sample: Specifying values for arrays and strings

A sample is provided to show how a generated copybook looks like when the schema in a Swagger file uses the data type of array and string. This sample also shows how to specify values for the array and string fields in the copybook.

zosConnect-2.0 Applies to zosConnect-2.0.

Started task Applies to z/OS Connect Servers run by using a z/OS started task procedure.

A Swagger file sample

Assume a Swagger file in JSON format:


{
  "swagger": "2.0",
  "info": {
    "version": "0.0.1",
    "title": "Sample Swagger file to explain how to populate data to array and string in program."
  },
  "paths": {
    "/": {
      "get": {
        "produces": [ "application/json" ],
        "description": "operation with array and optional string parameters",
        "responses": {
          "200": {
            "description": "successful operation",
            "schema": { "$ref": "#/definitions/sampleArray" }
          }
        }
      }
    }
  },
  "definitions": {
     "sampleArray": {
         "required":["myarray"],
          "properties": {
              "myarray":{
                  "type": "array",
                  "maxItems": 10,
                  "items": {
                      "type": "object",
                      "properties": {
                        "optionalString": {
                          "type": "string"
                        }
                      }
                  }
              }
          }    
    }
  }
}

In the definition of sampleArray, an array that is named myarray is defined. In this array, an object with one optional string parameter that is named optionalString is defined.

Fields in the generated copybook

Based on the Swagger file above, the following lines are generated in the copybook:


06 RespBody.

               09 myarray2-num                  PIC S9(9) COMP-5 SYNC.

               09 myarray OCCURS 10.

                 12 optionalString-num            PIC S9(9) COMP-5 SYNC.

                 12 optionalString.
                   15 optionalString2-length        PIC S9999 COMP-5 SYNC.
                   15 optionalString2               PIC X(255).
                 12 filler                        PIC X(3).
The myarray field represents an array. The size of the array is specified in the myarray2-num field. The maximum size is 10, which is indicated by the clause of OCCURS 10.
Tip: You can find the minimum size of the array in the comments of the copybook.

The optionalString field represents an element of the array. If an element is empty, which means no value needs to be set to the optionalString field, you must set optionalString-num as 0; otherwise, set optionalString-num as 1.

The optionalString2 field represents a variable-length array of characters of binary data. This field is used to specify the value of an array element. The optionalString2-length field is used to specify the length of the value of optionalString2.

Example: specifying values for the array and string fields

Assume the following array data to be populated into the generated copybook:

[[ {"MY"},{"HELLO"},{} ]]

You can specify values for the array and string fields as follows:


MOVE 3 TO myarray2-num.

MOVE 1 TO optionalString-num IN myarray(1).
MOVE '2' TO optionalString2-length IN myarray(1).
MOVE 'MY' TO optionalString2 IN myarray(1).

MOVE 1 TO optionalString-num IN myarray(2).
MOVE '5' TO optionalString2-length IN myarray(2).
MOVE 'HELLO' TO optionalString2 IN myarray(2).

MOVE 0 TO optionalString-num IN myarray(3).