How-To Enable Input Conversion for OData Function Parameters
2025-02-15
Contents
Some ABAP values have curious in-memory (and in-database) representations which are meant to be hidden from the user. The standard SAP user interface does this automatically, but the behavior of these values in external interfaces varies.
For example, address numbers, ie. the keys of address entries, use conversion exit ALPHA. This means that address number 1 would be represented as 0000000001 in-memory and in-database.
Address number domain
RFC Function Modules / Web Services
RFC function modules, and therefore also web services, do not convert values automatically. This makes sense, since an RFC call coming from another ABAP system expects all values to already be in the correct in-memory form, ie. the RFC call looks pretty much like normal function module call.
FUNCTIONzweb_service.*"----------------------------------------------------------------------*"*"Local Interface:*" IMPORTING*" VALUE(IM_NAME1) TYPE AD_NAME1*" EXPORTING*" VALUE(EX_ADDRESS_NUMBER) TYPE AD_ADDRNUM*" VALUE(EX_NAME1) TYPE AD_NAME1*"----------------------------------------------------------------------SELECTSINGLEaddrnumberFROMadrcINTO@ex_address_numberWHEREname1=@im_name1.IFsy-subrc=0.ex_name1=im_name1.ENDIF.ENDFUNCTION.
Address number includes prefixing zeroes
While understandable, this behavior is a poor fit in a world where integration to ABAP systems are increasingly implemented using different flavors of HTTP, rather than the proprietary ABAP RFC protocol. It forces actual RFC functions and RFC functions used for defining web services to be implemented separately: the web service functions need to manually convert values for output in order to not expose the in-memory representation to the caller. This means that the only guard against exposing ABAP’s internal weirdness is the programmer.
FUNCTIONzweb_service.*"----------------------------------------------------------------------*"*"Local Interface:*" IMPORTING*" VALUE(IM_NAME1) TYPE AD_NAME1*" EXPORTING*" VALUE(EX_ADDRESS_NUMBER) TYPE AD_ADDRNUM*" VALUE(EX_NAME1) TYPE AD_NAME1*"----------------------------------------------------------------------SELECTSINGLEaddrnumberFROMadrcINTO@ex_address_numberWHEREname1=@im_name1.IFsy-subrc=0.ex_name1=im_name1.CALL FUNCTION'CONVERSION_EXIT_ALPHA_OUTPUT'EXPORTINGinput=ex_address_numberIMPORTINGoutput=ex_address_number.ENDIF.ENDFUNCTION.
Address number is returned without the prefixing zeroes
OData
The more modern OData protocol improves the situation considerably: when an OData entity is defined by referring to data elements, the OData framework performs input and output conversions automatically.
OData entity structure
OData entity in SEGW transaction
Any values returned by the OData framework are automatically converted for output, which means that address numbers will not contain the extra prefixing zeroes:
METHODaddresses_get_entityset.DATA(lt_select_option)=io_tech_request_context->get_filter()->get_filter_select_options().DATAlr_address_numberTYPE RANGE OFad_addrnum.io_tech_request_context->get_filter()->convert_select_option(EXPORTINGis_select_option=VALUE#(lt_select_option[property='ADDRESS_NUMBER']OPTIONAL)IMPORTINGet_select_option=lr_address_number).DATAlr_name1TYPE RANGE OFad_name1.io_tech_request_context->get_filter()->convert_select_option(EXPORTINGis_select_option=VALUE#(lt_select_option[property='NAME1']OPTIONAL)IMPORTINGet_select_option=lr_name1).SELECTaddrnumberASaddress_number,name1FROMadrcINTOCORRESPONDING FIELDS OFTABLE@et_entitysetWHEREaddrnumberIN@lr_address_numberANDname1IN@lr_name1.ENDMETHOD.
OData converts address numbers automatically
Conversions are likewise automatically handled in entity keys (since a direct SELECT could not work if ls_key-address_number was not in the same format as the values in the database):
You have to manually add the conversion exit to the parameter definition by redefining the define method in the model provider extension (*_MPC_EXT) class: