Without further settings, ABAP fieldnames are mapped to uppercase JSON fieldnames, but a JSON request (incoming data) could also use lowercase fieldnames.
If this mapping is not sufficient, an other mapping cound be adjusted following the next steps.
The actual mapping is performed in class /EPO1/CL_FIELD_NAME_MAPPING, method MAP.
Using transaktion SM30 to adjust the mapping (using the EPO service id as key).
Field | Description |
---|---|
Service | EPO service for incoming services (=provided webservices), EPO service ID for outgoing services (=consumed webservices) |
Message direction | Direction of a message; 'I' = inbound (request for an incoming call or response of an outgoing call) 'O' = outbound (response from an incoming call or request of an outgoing call) |
ABAP fieldname | Name of an ABAP structure field |
Ext. fieldname | Name of an external JSON field |
It is possible to specify a default mapping method, using an empty ABAP fieldname - write one of these keywords into the external fieldname
This default mapping works in both directions and is applied to all fields, where no explicit mapping is defined.
Transaction /EPO1/EXC, open the menu items
Processing FM
/EPO1/GFMC_JSON_PROCESSINGFM
this function module will read the settings regarding the field mapping; other function modules might not be able to use and interpret these information
Field Mapping
check this checkbox to enable the field mapping; the service name of the operation is the first key field in the table /EPO1/FIELD_MAP
During the data processing (both directions: request and response), the mapping is done with the method /EPO1/CL_FIELD_NAME_MAPPING=>MAP, which reads the table /EPO1/FIELD_MAP.
For outbound calls there are 2 classes in the EPO Connector, which handle principially all tasks involved with calling any JSON REST API.
If the programmer wants to create the JSON request and to interpret the response JSON individually the methods which are included in class /EPO1/CL_JSON_BASE_OUT can be used separately.
ABAP to JSON:
Use function module /EPO1/EXC_ABAP_TO_JSON (all json format options 0,1,2,t,tb,tbi, recommended are 0 or 2 for JavaScript Apps) or method /EPO1/CL_TOOLS=>ABAP_TO_JSON (JSON creation with json format options t=transformation, tb=transformation, line breaks and tbi=transformation, line breaks and intent)
JSON to ABAP:
Use method /EPO1/CL_TOOLS=>JSON_TO_ABAP for filling ABAP variables from a JSON string.
Both methods can be called, passing the EPO service ID to I_SERVICE_ID and the transformation /EPO1/EXC_JSON_FIELD_MAPPING to I_TRANSFORMATION. This transformation uses the static method /EPO1/CL_FIELD_NAME_MAPPING=>MAP for the mapping, which reads the table /EPO1/FIELD_MAP.
Convert an ABAP structure to JSON, using the direction 'O' (outbound):
Parameter | Description |
---|---|
I_ABAP | ABAP structure |
I_STRIP_INITIAL | Remove empty elements/structures/tables |
I_DESCRIBE | Describe conversion instead of converting |
I_TABLE_FORMAT | JSON format 0, 1, 2 or t, tb, tbi. See DDIC domain /EPO1/RESPONSE_FORMAT. |
I_SERVICE_ID | The service ID is passed to the transformation (in order to select the mapping information) |
ES_CALLSTATUS | Error messages |
E_JSON | JSON as string |
E_JSON_X | JSON as xstring |
Convert an ABAP structure to JSON, using the direction 'O' (outbound):
Parameter | Description |
---|---|
I_ANY | ABAP structure |
I_LINE_BREAK | 'X' in order to add line breaks |
I_INTENT | 'X' in order to add intents (additional to the line break) |
I_STRIP_INITIAL | Remove empty elements/structures/tables |
I_TRANSFORMATION | Convert the JSON-XML, using this transformation (use /EPO1/EXC_JSON_FIELD_MAPPING) |
I_SERVICE_ID | The service ID is passed to the transformation (in order to select the mapping information) |
ES_CALLSTATUS | Error messages |
E_JSON | JSON as string |
E_JSON_X | JSON as xstring |
Convert a JSON response (string or xstring) into an ABAP structure, using the direction 'I' (inbound):
Parameter | Description |
---|---|
I_JSON | JSON as string |
I_JSON_X | JSON as xstring |
I_TRANSFORMATION | Convert the JSON-XML, using this transformation (use /EPO1/EXC_JSON_FIELD_MAPPING) |
I_SERVICE_ID | The service ID is passed to the transformation (in order to select the mapping information) |
E_ANY | ABAP structure |
ES_CALLSTATUS | Error messages |
If required, the mapping table could also be passed to the mapping class, without the need for customizing. This could be useful, if there is a always simple mapping which is not expected to be changed.
Note: the static mapping cannot be used to handle the mapping of incoming request.
Use the class-method SET_STATIC_MAPPING in order to populate the mapping table.
If an existing combination of IV_FIELDNAME_ABAP / IV_SERVICE_ID / IV_DIRECTION is used, the value of IV_FIELDNAME_EXTERNAL will overwrite the existing data.
Example - for the 'static mapping' service
" define the [camelCase] - mapping
/epo1/cl_field_name_mapping=>set_static_mapping(
iv_fieldname_abap = ''
iv_fieldname_external = /epo1/cl_field_name_mapping=>c_camel_case_lower ).
" define the mapping of a long JSON name (which cannot be mapped directly to an ABAP field)
/epo1/cl_field_name_mapping=>set_static_mapping(
iv_fieldname_abap = 'REGISTRERINGSDATO_ENHETSREG'
iv_fieldname_external = 'registreringsdatoEnhetsregisteret' ).
...
" convert JSON to ABAP, using the defined mapping (with the dummy-servicename C_STATIC_MAPPING)
lv_service = /epo1/cl_field_name_mapping=>c_static_mapping.
/epo1/cl_tools=>json_to_abap(
EXPORTING
i_json_x = i_response
i_transformation = '/EPO1/EXC_JSON_FIELD_MAPPING'
i_service = lv_service
IMPORTING
e_any = e_response_s
es_callstatus = ls_callstatus ).
Example - for using a real EPO service
" set the field mapping (static, without the need for customizing table /EPO1/FIELD_MAP)
" for incoming and outgoing messages
/epo1/cl_field_name_mapping=>set_static_mapping(
iv_fieldname_abap = ''
iv_fieldname_external = '[camelCase]'
iv_service_id = iv_service_id_outbound ).
...