Skip to Content
Product Information
Author's profile photo Clark Huang

[Feature]Side-by-side extensiblity to custom the product and customer material mapping logic(ABAP)

Background

Some suppliers may have special logic in product and customer material mapping logic between buyer and supplier. Someone create own mapping table in S/4HANA. Someone need to remove the specify characters both in transmission from buyer and outbound delivery customer material from supplier.

This blog would introduce how to make use of the side-by-side extensibility offered by SAP Self-Billing CockpitSAP Self-Billing Cockpit allows you to implement your custom business logic by using RESTful APIs.You can create your RESTful APIs on BTP or SAP S/4HANA.

Solution

Self-Billing would send you the request as below with transmitted material and reference material.

{ 
  "transmittedMaterialData": [ 
    { 
      "transmittedProduct": "TG80%%01", 
      "transmittedCustomerMaterial": "8001" 
    } 
  ], 
  "referenceMaterialData": [ 
    { 
      "delivery": "D01", 
      "soldToParty": "S01", 
      "referenceProduct": "TG8001", 
      "referenceCustomerMaterial": "80--01" 
    } 
  ] 
} 

You can implement the mapping logic and return the response as below.

[ 
  { 
    "delivery": "D01", 
    "soldToParty": "S01", 
    "transmittedProduct": "TG80%%01", 
    "transmittedCustomerMaterialNumber": "8001", 
    "referenceProduct": "TG8001", 
    "referenceCustomerMaterialNumber": "80--01" 
  } 
] 

Details structure in admin guide.

Create one Restful API in S/4HANA system 

 

Create request and response structures and tables for restful API import parameters in t-code “SE11”.

Create one structure type “ZTRANSMITTEDMATERIALDATA”

Create one table type “ZTRANSMITTEDMATERIALDATAS”

Create one structure type “ZREFERENCEMATERIALDATA”

Create one table type “ZREFERENCEMATERIALDATAS”

Create one structure type “ZMATERIALMAPPINGAPIREQUEST” wihch include those two request table

Create one structure type “ZMappedMaterial” for the response body

Create one table type “ZMappedMaterials” for the response body

Create one structure “” type for the response body

 

2. About the restful API, we need to create two class in t-code “SE24” as below.

One request handle class “ZCL_SBC_REQ_HANDLER” which inherit from CL_REST_HTTP_HANDLER

This class would be maintain in the SICF service node later on to handle the restful API.

Overwrite the method “Get_ROOT_HANDLER”, add the route logic. iv_template “/sbcMaterialMapping” is the restful API URL patch. iv_handler_class is the handler class of this restful API.

  METHOD if_rest_application~get_root_handler.

    io_router->attach(
      EXPORTING
        iv_template      =    '/sbcMaterialMapping'              " Unified Name for Resources
        iv_handler_class =    'ZCL_SBC_MATERIAL_MAP_PROVIDER'              " Object Type Name
    ).

    ro_root_handler = io_router.

  ENDMETHOD.

 

Then you need to create the handler class “ZCL_SBC_MATERIAL_MAP_PROVIDER” which inherit from CL_REST_RESOURCE.

Overwrite the POST method as Self-Billing cockpit would call this restful API by POST

Example code:

In this example, we would remove the special character in both transmitted and reference material. Then do the material mapping.

  method IF_REST_RESOURCE~POST.

    DATA(lo_entity) = mo_request->get_entity( ).
    DATA(lv_data) = lo_entity->get_string_data( ).
    DATA : ls_sbcreq TYPE ZMATERIALMAPPINGAPIREQUEST.
    DATA : ls_json TYPE string.
    DATA resp TYPE ZMATERIALMAPPINGAPIRESPONSE.

    /ui2/cl_json=>deserialize(
      EXPORTING
        json             =         lv_data         " JSON string
      CHANGING
        data             =         ls_sbcreq         " Data to serialize
    ).

    LOOP AT ls_sbcreq-transmittedMaterialData ASSIGNING FIELD-SYMBOL(<tran>).
      DATA : tranProduct TYPE string.
      DATA : tranCustomerMaterial TYPE string.
      tranProduct = <tran>-transmittedProduct.
      tranCustomerMaterial = <tran>-transmittedCustomerMaterial.
      replace all occurrences of PCRE '[^\w]' in tranProduct with ''.
      replace all occurrences of PCRE '[^\w]' in tranCustomerMaterial with ''.
      LOOP AT ls_sbcreq-referenceMaterialData ASSIGNING FIELD-SYMBOL(<ref>).
        DATA : refProduct TYPE string.
        DATA : refCustomerMaterial TYPE string.
        refProduct = <ref>-referenceProduct.
        refCustomerMaterial = <ref>-referenceCustomerMaterial.
        replace all occurrences of PCRE '[^\w]' in refProduct with ''.
        replace all occurrences of PCRE '[^\w]' in refCustomerMaterial with ''.
        IF ( tranProduct = refProduct and tranCustomerMaterial = refCustomerMaterial )
          or ( tranProduct = refProduct and ( tranCustomerMaterial = '' or refCustomerMaterial = '' ) )
          or ( tranCustomerMaterial = refCustomerMaterial and ( tranProduct = '' or refProduct = '' ) ).
          INSERT VALUE #( TRANSMITTEDPRODUCT = <tran>-transmittedProduct
                transmittedCustomerMaterial = <tran>-transmittedCustomerMaterial
                delivery = <ref>-delivery
                soldToParty = <ref>-soldToParty
                referenceProduct = <ref>-referenceProduct
                referenceCustomerMaterial = <ref>-referenceCustomerMaterial
                ) INTO TABLE resp-MAPPEDMATERIALS.
        ENDIF.
      ENDLOOP.

    ENDLOOP.

        /ui2/cl_json=>serialize(
      EXPORTING
        data             =        resp       " Data to serialize
      RECEIVING
        r_json           =        ls_json          " JSON string
    ).

    mo_response->create_entity( )->set_string_data( iv_data = ls_json ).
  endmethod.

 

Create one service node for restful API in t-code SICF

Logon Data maintain the client, user and password. Later on, we would maintain this user and password in BTP destination.

In the handler list, maintain the handle class “ZCL_SBC_REQ_HANDLER” created before with the URL patch and router

 

Save and active the service

 

In case the restful API development done. You can use POSTMAN to test the API authroization and function firstly.

Example request body: There are both special characters in transmitted and reference data.

{
    "transmittedMaterialData": [
        {
            "transmittedProduct": "",
            "transmittedCustomerMaterial": "TG80  03"
        },
        {
            "transmittedProduct": "TG80%%05",
            "transmittedCustomerMaterial": "8005"
        }
    ],
    "referenceMaterialData": [
        {
            "delivery": "80002264",
            "soldToParty": "24100001",
            "referenceProduct": "TG8003",
            "referenceCustomerMaterial": "TG80**03"
        },
        {
            "delivery": "80002265",
            "soldToParty": "24100001",
            "referenceProduct": "TG8005",
            "referenceCustomerMaterial": "80--05"
        }
    ]
}

Expected response

Restful API would return the mapped material as below. Then Self-Billing cockpit would use this mapped result for following processing.

{
    "MAPPEDMATERIALS": [
        {
            "TRANSMITTEDPRODUCT": "",
            "TRANSMITTEDCUSTOMERMATERIAL": "TG80  03",
            "DELIVERY": "80002264",
            "SOLDTOPARTY": "24100001",
            "REFERENCEPRODUCT": "TG8003",
            "REFERENCECUSTOMERMATERIAL": "TG80**03"
        },
        {
            "TRANSMITTEDPRODUCT": "TG80%%05",
            "TRANSMITTEDCUSTOMERMATERIAL": "8005",
            "DELIVERY": "80002265",
            "SOLDTOPARTY": "24100001",
            "REFERENCEPRODUCT": "TG8005",
            "REFERENCECUSTOMERMATERIAL": "80--05"
        }
    ]
}

 

How to get the restful API URL patch?

  1. Domain: SICF->Go to-> ICM Monitor-> Services

Use the one domain with HTTPS

2. The service node we created before “ZSBC”

3. The restful API URL patch in the handler class “/sbctestclark”

URL = Domain + Service node + URL patch

 

Create the destination on SAP BTP.

  1. Log on to the SAP BTP Cockpit (Cloud Foundry environment) with your registered subaccount.

  2. Choose Connectivity Destination  New Destination to create a new destination for aligning transmission data.

  3. In the Destination Configuration wizard, configure the destination as follows:

    • For self-billing with automatic posting:

      Destination Property

      Value

      Name

      SELFB_DEST_SBWAP_MATERIAL_MAPPING

      Type

      HTTP

      Description

      Destination for product mapping extensions for self-billing with automatic posting

      URL

      <The URL path of the RESTful API created in the previous step>

      Proxy Type

      • For the RESTful API created in SAP S/4HANA, choose OnPremise.

      • For the RESTful API created on SAP BTP, choose Internet.

      Authentication

      Basic Authentication

      User

      <User with the authorization of the RESTful API created in the previous step)

      Password

      <Password of the user>

    • For self-billing with invoice creation:

      Destination Property

      Value

      Name

      SELFB_DEST_SBINV_MATERIAL_MAPPING

      Type

      HTTP

      Description

      Destination for product mapping extensions for self-billing with invoice creation

      URL

      <The URL path of the RESTful API created in the previous step>

      Proxy Type

      • For the RESTful API created in SAP S/4HANA, choose OnPremise.

      • For the RESTful API created on SAP BTP, choose Internet.

      Authentication

      Basic Authentication

      User

      <User with the authorization of the RESTful API created in the previous step>

      Password

      <Password of the user>

       

     

Test in Self-Billing Cockpit

Self-Billing Cockpit now have the possiblity to mapped the customer material with special characters

 

Additional Information

 

Blog Post Series for SAP Self-Billing Cockpit

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.