Technical Articles
How to check the maximum length of a function import parameter in SEGW based OData services – The Old Way
Some days ago I had a problem with an OData service, more specifically due to a Function Import.
The Function Import has 2 input parameters
- Article (MATNR)
- Serial Number (GERNR).
The developer that coded the Function Import decided to use directly IT_PARAMETERS and then run some conversion routines to ensure we have the right format.
Side Note: We all know that we should use methods get_parameters or get_converter_parameters from io_tech_request_context. If you want to deeply understand how gateway manages conversions, you must read this blog series from Thomas Nitschke.
Anyway, the problem is not due to conversions but in the maximum length of the parameters.
Article and Serial have maximum length of 18 characters but there is no impediment of sending an Article or Serial with more then 18 characters.
In this scenario, I was expecting that the Gateway Foundation framework handles the length violation as it already does for EntitySets, but this is not the case for Function Imports.
Since in this particular case, an alpha routine is being called for Article (CONVERSION_EXIT_MATN1_INPUT), if the Article has more then 18 characters the service terminates in a dump.
In order to avoid the dump, we then need to implement some check/control on the Data Provider Extension class.
The purpose of this blog is to share my solution for this particular problem. Here it is:
(serialdetail is the complex structure used in the Return Type Kind of the Function Import)
"UC Quickfix for Function Import parameter length control
data article type zcl_zui5srs_mpc=>serialdetail-matnr.
describe field article length data(article_length) in character mode.
if strlen( ls_parameter-value ) > article_length.
raise exception type /iwbep/cx_mgw_busi_exception
exporting
textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited
http_status_code = /iwbep/cx_mgw_busi_exception=>gcs_http_status_codes-precondition_failed
message_unlimited = |{ 'Material Number has more then 18 characters'(001) }|.
endif.
This piece of code is implemented in the /iwbep/if_mgw_appl_srv_runtime~execute_action redefinition on the Data Provider Extension Class of the service.
After some exchanges with Andre Fischer, I have learned that from SAP_GWFND 752 and higher, we have a new mechanism to control Function Import lengths directly in the service model.
You can find a dedicated blog from Andre Fischer with the new way of doing this one.
Thanks for the summary of your analysis and the reference to the other blog posts. Great.