Defining service fields
Service fields are used in service interfaces to map, transform, and modify the data used between a IBM® z/OS® Connect API and the underlying z/OS application that the API utilizes. Customizing service fields allows you to provide metadata and optimize payloads for service interfaces.
Before you begin
If the service interface file is not already opened in the service interface editor, in Project Explorer, go to the service-interfaces/ folder for your project and double-click the service interface file (.si file).
From the service interface editor, you can edit service fields by using the Edit Field wizard. Access the Edit Field wizard for a given service field by right-clicking a service field, and selecting Edit field. You can also access the Edit Field wizard by selecting a service field, and then clicking the Edit field button in the Service interface editor.
The options of the Edit Field wizard change according to the data type of the service field being edited.
To learn about commonly used Edit Field wizard options, see Overview of the Edit Field wizard. To learn about other capabilities of the Edit Field wizard, see the sections following this overview.
When re-importing data structures, ensure that the definitions for service fields remain preserved. Errors caused by re-importing data structures are indicated by a symbol in the service interface editor, or in the problems view of the API toolkit.
Overview of the Edit Field wizard
- Interface rename allows you to specify a different name to be used for the IBM z/OS Connect service.
- Override data type allows you to specify a new data type at the service level to perform conditional mediation between application and API data.
-
Use Default value type to specify the datatype that is used for a default value.
- Default value is a datatype-specific value that is used by the service during runtime whenever there is no appropriate service field value specified by an API request or response.
- Code page conversion can be toggled on to convert service response code to CHAR data type.
- Business description metadata can be provided to clearly indicate the purpose of the service field as it relates to a service.
- Response service interfaces cannot contain default values in fields. If a default value is specified for a response service interface, a message will be issued in the Problems view to assist problem resolution.
- The default value can be overridden if a value is assigned in the API editor during API creation. If a value is specified in the payload at run time, the runtime value will always override the value that was specified at development time. To prevent the assigned default value from being overridden at run time, set the field to be omitted from the interface.
- The Code page conversion check box is only visible when the Data type field has a value of CHAR. To convert the code page for the CHAR type, select the Code page conversion check box; otherwise, clear it.
Defining array counters
Array counters can be used to optimize the request and response JSON for services which utilize arrays. For request interfaces, an array counter is automatically set to the number of array entries received in the request JSON for the respective array. For response interfaces, an array counter indicates the number of array entries to include in the response JSON from the respective array.
Array counters are defined by specifying a numeric service field to be used as a counter for fixed-length or variable-length arrays.
The following conditions must be met for a service field to be used as an array counter.
-
Defining array counters requires installation of the minimum IBM z/OS Connect server and API toolkit versions that support the array counters capability. To learn more about IBM z/OS Connect version requirements for capabilities, see Capabilities compatibility.
- Only integer service fields can be used for array counters.
- The array counter service field must reside in the same data structure as the array it counts for.
- The array counter cannot be an OCCURS DEPENDING ON or a REFER object.
- Array counters cannot be used to count more than one array.
- The array counter must be located before the array it counts for in the service data structure.
- If the array that is using an array counter has a parent array in the service data structure, then the array counter must also have the same immediate parent array.
- If the array has a parent REDEFINES, the array counter must also have the same immediate parent REDEFINES.
Service fields that do not meet this criteria will not be listed for selection when editing an array in the service interface editor.
- Counted by indicates a numeric field that specifies the number of
sequential entries used in the array. This count always starts from the first entry of the
array.
To change a counted array back to a non-counted array, select the empty line provided at the top of the drop-down list for the Counted by field.
- Minimum items defines the minimum number of expected array entries. This
minimum is expressed as
minItems
in the JSON schema that corresponds to the service interface.
- Counters specify the number of sequential array entries in use by a service, starting with and including the first entry.
- When setting a counter for an array, the minimum expected number of array entries can be
customized. This minimum is reflected in the generated JSON schema (minItems).
- To enforce the minimum number of array occurrences for API requests and responses, you must enable the Enforce minimum array occurrence options in your service project. To learn how to enforce minimum array occurrences, see Service-level data conversion customization.
The following example of a service interface demonstrates where an array counter,
F_COMMENT_CNT
, can be used to define the number of F_COMMENT
array
entries within a service interface. Also included in this example is a fixed-length array,
F_ROUTINGCODE
, which is counted by F_ROUTINGCODE_CNT
.
Defining Boolean fields
Service fields can be exposed in JSON payloads as type Boolean to create more easily consumable APIs. Boolean service fields allow for the definition of specific request and response conditions to process true or false values for a given service field, while leaving the underlying COBOL or PL/I application field values unchanged.
To expose a given service field as Boolean, select the Boolean option in the Override data type property of the Edit Field wizard.
The following conditions must be met for a service field to be overridden as type Boolean:
- Overriding service fields as type Boolean requires installation of the minimum IBM z/OS Connect server and API toolkit versions that support the boolean override capability. To learn more about IBM z/OS Connect version requirements for capabilities, see Capabilities compatibility.
- The application data type for the service field is Char.
- If the application data type for the service field is not Char:
- The service field's application data type must not be Float or Double.
- For decimal service field data types, decimal scale must be set to 0 so that fields can be read as integers.
- PL/I data types that are
VARYING
cannot be overridden as Boolean service fields.
Service fields that do not meet this criteria will not display the option to be overridden to Boolean in the service interface editor.
- Under the Request tab:
- The True value type and False value type field
properties determine how service request JSON values are transformed into application data. True and
false request values can be defined with the following options:
- Single values use a precise value to determine if a service field value is true or false. Single values must be of the same datatype as the Original data type, unless hex values are used.
- High values are byte values consisting of all 0xFF .
- Low values are byte values consisting of all 0x00.
- The True value type and False value type field
properties determine how service request JSON values are transformed into application data. True and
false request values can be defined with the following options:
- Under the Response tab:
- The True value type and False value type field
properties define how service field values are determined as true for an API response. In addition
to single values, high values, and low values options, true and false response
values can be defined with the following additional options:
- Range of values uses a specified lower and upper bound value to determine if a service field value is true or false. Value ranges are inclusive and must be of the same datatype as the Original data type, unless hex values are used.
- Multiple values consist of a delimited set of values which determine if a service field value is true or false. You can choose the delimiter that is used between values.
- The True value type and False value type field
properties define how service field values are determined as true for an API response. In addition
to single values, high values, and low values options, true and false response
values can be defined with the following additional options:
Once a service field has been overridden as type Boolean, it will be marked in the Data Type column of the service interface editor as Boolean, in parenthesis. Also, when looking at service fields using the API field mapping editor, fields that are overridden as type Boolean will be listed as Boolean fields.
- For the JSON request and response payload, the only valid values are
true
andfalse
, without single or double quotes. Any values other thantrue
andfalse
cannot be used. - If a service response value does not match either of the specified true or false conditions, an
API response of
null
is issued instead.
The following example demonstrates how a service field that is overridden as type Boolean
appears in the service interface editor. In this example, the F_AVAILABLE
service
field is overridden to express a CHAR value as a Boolean data type in the resulting API request and
response JSON.
Defining Date fields
Service fields can be exposed and consumed in JSON payloads as date string patterns in order to create effective APIs that utilize validated dates. Date service fields allow for the exposing of host dates as OpenAPI™ 2.0 compliant dates, while leaving the underlying COBOL or PL/I application field values unchanged.
To override a given service field as a Date, select the Date option in the Override data type property of the Edit Field wizard.
-
Overriding service fields as dates requires installation of the minimum IBM z/OS Connect server and API toolkit versions that support the date override capability. To learn more about IBM z/OS Connect version requirements for capabilities, see Capabilities compatibility.
- CICS CHAR containers cannot be redefined as a Date service field.
- In the Host date pattern field of the Edit Field wizard, you can begin to type the date pattern of an underlying application field. By pressing Ctrl + Space, content assist will suggest matching date components that are applicable to your pattern.
- Alternatively, you can click the insert... button next to the Host date pattern field. A dialogue box will open containing all available date components. Select a component and click OK to insert the date component at the current cursor position in the Host date pattern field.
- Top-level data structures cannot be overridden as characters by using the Redefine as CHAR field function of the service interface editor.
- The Redefine as CHAR field function only applies to STRUCT type
application fields which meet the following conditions:
- The STRUCT is not already a redefining field.
- The STRUCT does not contain redefining fields, also known as nested redefines.
- The STRUCT does not contain ARRAY fields.
- All numeric fields in the STRUCT are zoned decimal with "sign is separate" is signed.
- All fields in the STRUCT have the same encoding. For example, all SBCS, all Unicode, or all DBCS.
- The following additional properties apply to service fields that are overridden as CHAR fields.
- The redefining field created by the Redefine as CHAR field function is considered a "User defined field", and can be later removed by using the Remove user defined field context menu action.
- The redefining field created by the Redefine as CHAR field function will
be preserved during data structure re-import if the following conditions are met:
- The redefined STRUCT still exists in the re-imported data structure.
- The redefined STRUCT still satisfies the requirements for the Redefine as CHAR field function.
- Some examples featured in this section use the Redefine as CHAR field function. This capability is only required to enable the definition of STRUCTs as character groups, and is not required to override existing numeric and character fields as dates.
- For requests, the host date pattern is used to convert a JSON date value to a host date value. For responses, the host date pattern is used to convert a host date value to a JSON date value.
- Default JSON data types can be overridden where necessary by using the data transformation function of the z/OS Connect EE API toolkit. To learn more, see COBOL to JSON schema mapping and PL/I to JSON schema mapping.
- For requests, an invalid JSON date value will result in an HTTP response code 400 that includes either message GMOMW0024E or GMOMW0025E. For responses, an invalid host date value will cause the field to be omitted from the JSON, and message GMOMW0026E will be issued by the IBM z/OS Connect server.
- Services that are updated to utilize date fields must be re-imported into APIs that use those services. When re-importing services that utilize date fields, the impact analysis view will specify which API's are affected and how.
The following table contains a list of accepted host date patterns:
Component name | Component syntax | Description |
---|---|---|
Day of Month | dd | Two digit day of Month. |
Day of Year | DDD | Three digit ordinal Day. |
Month of Year | MM | Two digit month of Year. |
Year | yyyy | Four digit Year. |
Year of Century | YY | Two digit Year. This component must be followed by a Century component. |
Century | CC | Two digit century. This component must be preceded by a Year of Century component. |
Literal ('') | 'value' | Single quotes that contain a literal consisting of one or more characters. Characters in a
quoted literal are not parsed as date pattern components. Example: ‘abcMM’ |
Hex literal (%'') | %'hex value' | A literal consisting of one or more hex-encoded bytes. Hex literals are not supported for
numeric fields. Example: %’CAFE’ |
Literal escape (\) | \character | An escaped literal consisting of one character. Example: \' |
The following table contains all COBOL fields that are acceptable for a Date override. Only the following COBOL field types may be used for a Date override:
Field type | Example declarations | Example Host Date patterns |
---|---|---|
PIC [S]9(n) USAGE COMP |
05 YYYYDDD PIC [S]9(7) COMP 05 YYYYMMDD PIC [S]9(8) COMP |
yyyyDDD yyyyMMdd |
PIC [S]9(n) USAGE COMP-3 |
05 YYYYDDD PIC [S]9(7) COMP-3 05 DDMMYYYY PIC [S]9(8) COMP-3 |
yyyyDDD ddMMyyyy |
PIC [S]9(n) USAGE DISPLAY |
05 YYYYDDD PIC [S]9(7) DISPLAY 05 MMDDYYCC PIC [S]9(8) DISPLAY |
yyyyDDD MMddYYCC |
PIC X(n) USAGE DISPLAY |
05 MMDDYYYY PIC X(8) DISPLAY 05 MM-DD-YYYY PIC X(10) DISPLAY 05 MM-DD-YYYY PIC 99/99/9999 DISPLAY |
MMddyyyy MM/dd/yyyy MM/dd/yyyy |
PIC N(n) USAGE NATIONAL |
05 YYYYMMDD PIC N(8) NATIONAL 05 YYYY-MM-DD PIC N(11) NATIONAL 05 YYYY-MM-DD PIC 99/99/9999 NATIONAL |
MMddyyyy yyyy年MM月dd日 yyyy/MM/dd |
PIC X(n) USAGE DISPLAY-1 |
05 YYYYMMDD PIC X(10) DISPLAY-1 05 YYYY-MM-DD PIC X(20) DISPLAY-1 |
MMddyyyy yyyy年MM月dd日 |
PIC 9(n) USAGE NATIONAL |
05 YYYYDDD PIC 9(7) NATIONAL 05 YYCCMMDD PIC 9(8) NATIONAL |
yyyyDDD YYCCmmdd |
PIC S9(n) USAGE NATIONAL SIGN [LEADING|TRAILING] SEPARATE |
05 YYYYDDD PIC S9(7) NATIONAL SIGN LEADING SEPARATE 05 YYCCMMDD PIC S9(8) NATIONAL SIGN TRAILING SEPARATE |
yyyyDDD YYCCmmdd |
The following table contains all PL/I fields that are acceptable for a Date override. Only the following PL/I field types may be used for a Date override:
Field type | Example declarations | Example Host Date patterns |
---|---|---|
FIXED DECIMAL(n,0) |
05 YYYYDDD FIXED DECIMAL(7) 05 YYYYMMDD FIXED DECIMAL(8) |
yyyyDDD yyyyMMdd |
PICTURE '(n)9' |
05 YYYYDDD PICTURE '(7)9' 05 DDMMYYYY PICTURE '(8)9' |
yyyyDDD ddMMyyyy |
PICTURE 'S(n)9' or '(n)9S' |
05 YYCCDDD PICTURE 'S(7)9' 05 YYCCMMDD PICTURE '(8)9S' |
YYCCDDD YYCCMMdd |
CHAR(n) NONVARYING |
05 MMDDYYYY CHAR(8) NONVARYING 05 MM_DD_YYYY CHAR(10) NONVARYING 05 YYYY_MM_DD CHAR(20) NONVARYING |
MMddyyyy MM/dd/yyyy yyyy年MM月dd日 |
WCHAR(n) NONVARYING |
05 YYYYMMDD WCHAR(8) NONVARYING 05 YYYY_MM_DD WCHAR(11) NONVARYING |
MMddyyyy yyyy年MM月dd日 |
Numeric date override example
04 F-YYYYDDD-COMP PIC 9(07) COMP.
The following override is applied to the service field:
"F_YYYYDDD_COMP" : {
"type" : "string",
"format" : "date"
}
The
following value is provided in the response JSON at
runtime:"F_YYYYDDD_COMP" : "2020-02-29"
For the request, the service
takes the JSON date value of "2020-02-29"
and converts it to a host date value of
2020060
using the pattern yyyyDDD. For the response, the host date value
of 2020060
is converted to a JSON date value of "2020-02-29"
using
the same pattern, yyyyDDD.
Character date override example
04 F-DD-MM-YYYY-SBCS PIC X(10) DISPLAY.
The following override is applied to the service field:
"F_DD_MM_YYYY_SBCS" : {
"type" : "string",
"format" : "date"
}
The
following value is provided in the response JSON at
runtime:"F_DD_MM_YYYY_SBCS" : "2020-02-29"
For the request, the service
takes a JSON date value of "2020-02-29"
and converts it to a host date value of
29/02/2020
using the pattern dd/MM/yyyy. For the response, the host date
value of 29/02/2020
is converted to a JSON date value of
"2020-02-29"
using the same pattern, dd/MM/yyyy.
Group date override example
04 F-DD-MM-YYYY-DETAIL-SBCS.
04 F-MM PIC 9(02) DISPLAY.
04 FILLER PIC X(01) VALUE '/'.
04 F-DD PIC 9(02) DISPLAY.
04 FILLER PIC X(01) VALUE '/'.
04 F-YYYY PIC 0(04) DISPLAY.
The STRUCT is overridden as a character field group in the service interface editor by right-clicking the STRUCT and selecting the Redefine as CHAR field function.
The following override is applied to the service field group:
"detailSBCS_MM/dd/yyyy" : {
"type" : "string",
"format" : "date"
}
The
following value is provided in the response JSON at
runtime:"detailSBCS_MM/dd/yyyy" : "2020-02-29"
For the request, the
service takes the JSON date value of "2020-02-29"
and converts it to a host date
value of 02/29/2020
using the pattern MM/dd/yyyy. For the response, the
host date value of 02/29/2020
is converted to a JSON payload of
"2020-02-29"
using the same pattern, MM/dd/yyyy.