Skip to Content
Technical Articles

How to check the maximum length of a function import parameter in SEGW based OData services

A few days ago Sérgio Fraga asked how to use the Function Import Parameter Length Check that is available in SAP_GWFND 752 and higher in a lower release Question to conversion blog post.

Since there are currently no plans to downport the feature to 750 Sérgio Fraga plans to post his implementation as a blog post.

The above mentioned feature is a so called model feature. Model features can be set for the OData model of an SEGW based SAP Gateway service and they can influence the behavior of your OData Service.

The first tricky thing is to find that parameter since it is actually named USE_STRICT_FUNCTION_PARAM_CHK due to the restrictions in ABAP to use that long object names. (we will fix this typo in the documenation ;-))

When the model feature USE_STRICT_FUNCTION_PARAM_CHK is being enabled for the model of an OData service in the model provider extension class the SAP Gateway framework will check whether the length of a parameter exceeds the max-length used when defining the parameter.

So when you define a max-length for function import parameter as 10 in SEGW and when you execute the function import URI request with parameter value greater than 10 it will result in error.

How can this feature be enabled?

Model features are being enabled in the DEFINE method of your model provider extension class. To get a quick result I decided to redefine the sample service /IWBWEP/GWSAMPLE_BASIC.

 

Here I redefined the DEFINE( ) method of the model provider extension class and added the following coding.

  METHOD define.
    super->define(  ).
    DATA model_feature TYPE /iwbep/if_mgw_appl_types=>ty_s_model_features.
    model_feature-use_strict_function_param_chk  = abap_true.
    model->set_model_features( model_feature ).
  ENDMETHOD.

When checking the type /iwbep/if_mgw_appl_types=>ty_s_model_features you can find other model features as well.

You can test this behavior in the SAP Gateway client (transaction /n/iwfnd/gw_client).

Using the uri and choosing the http method POST

/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrder_Confirm?SalesOrderID='0500000000_too_long'

fails with the error message Malformed URI literal syntax.

{
  "error" : {
    "code" : "005056A509B11EE1B9A8DBD9EA7BB778",
    "message" : {
      "lang" : "de",
      "value" : "Malformed URI literal syntax"
    },
    "innererror" : {
      "transactionid" : "2CC63F1F947000D0E005F9B1B27A30E8",
      "timestamp" : "20201103074652.3120690",
      "Error_Resolution" : {
        "SAP_Transaction" : "For backend administrators: use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details",
        "SAP_Note" : "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"
      }
    }
  }
}

Whereas using the following uri

/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrder_Confirm?SalesOrderID='0500000012'&$format=json

works (provided that your sales order in the EPM demo data has the status ‘N’) and you get the following response:

{
  "d" : {
    "__metadata" : {
      "id" : "https://hostname:port/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrderSet('0500000012')",
      "uri" : "https://hostname:port/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrderSet('0500000012')",
      "type" : "GWSAMPLE_BASIC.SalesOrder"
    },
    "SalesOrderID" : "0500000012",
    "Note" : "EPM DG: SO ID 0500000012 Deliver as fast as possible",
    "NoteLanguage" : "EN",
    "CustomerID" : "0100000005",
    "CustomerName" : "TECUM",
    "CurrencyCode" : "EUR",
    "GrossAmount" : "24704.40",
    "NetAmount" : "20760.00",
    "TaxAmount" : "3944.40",
    "LifecycleStatus" : "P",
    "LifecycleStatusDescription" : "In Bearbeitung",
    "BillingStatus" : "",
    "BillingStatusDescription" : "Initial",
    "DeliveryStatus" : "",
    "DeliveryStatusDescription" : "Initial",
    "CreatedAt" : "\/Date(1593122400000)\/",
    "ChangedAt" : "\/Date(1604389733043)\/",
    "ToBusinessPartner" : {
      "__deferred" : {
        "uri" : "https://hostname:port/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrderSet('0500000012')/ToBusinessPartner"
      }
    },
    "ToLineItems" : {
      "__deferred" : {
        "uri" : "https://hostname:port/sap/opu/odata/SAP/Z_REDEF_GWSAMPLE_SRV/SalesOrderSet('0500000012')/ToLineItems"
      }
    }
  }
}

 

 

 

 

/
3 Comments
You must be Logged on to comment or reply to a post.
  • Thank you for the clarification Andre Fischer .

    Can you just explain me why for Function Import parameters we have this special behavior?

    I mean, for EntitySets we don’t need to do this, it comes by default with GW, or does it mean in SAP_GWFND 7.52 and higher we would have to control this for both Function Imports and EntitySets?

    And..I have an S/4 onPrem with SAP_GWFND 7.53 Sandbox but I don’t see the component USE_STRICT_FUNCTION_PARAM_CHK in type TY_S_MODEL_FEATURES.

    Am I missing something?

    Thank you

    /
    • With regards to your question why we need a special behavior for function imports.

      This special behavior is necessary since the SAP Gateway framework must not break existing implementations.

      So it can be added to a newly created service by you. But if we (SAP) would add this behavior as a default from a framework perspective this could cause problems with existing implementations since in this case function imports would raise error messages that so far have worked without any problem.

      Best regards,

      Andre