Monday, 5 April 2021

SAP Multichannel Foundation for Utilities and Public Sector(MCF) enhancement using BAdI Implementation

The purpose of this article is to explain the developers how standard MCF service(ERP_ISU_UMC) can be utilized to incorporate the custom requirements.

SAP NetWeaver Gateway Service model extensibility can be achieved on different levels :

1. OData entity structure extension(Using append structure to add custom fields)

2. OData entity logic extension(for example , adding additional validations)

3. Addition of new OData entities

So now let’s move to our example.

Scenario : Fetch few additional custom fields from Account Contacts and customize the logic(Point 1 and 2)

Step 1: Go to SEGW and open project ERP_ISU_UMC, Right Click and Select ‘Copy Project’

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 2: Enter the custom Project name , Change the Package and click Ok.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 3: To include the additional fields in entity AccountContact

◉ Identify the structure being used for that particular entity

In this case , structure ISUS_UMC_CONTACT is used for Entity AccountContact.

Enhance the above structure using .Append

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 4: After enhancing the structure with .Append, select the Entity AccountContact and click Import->Properties, to fetch the additional fields from the append structure.

Select all the required fields and click on Next and Finish .

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 5 :Then generate the service, using the Generate Runtime Objects Button.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Rename the classes as per naming convention and click ok. Note : Keep the ‘Overwrite Base/Extended Services’ check box unchecked.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 6 : Open the ZCL_ZICCSERP_ISU_UMC_DPC_EXT Class and redefine the method ‘GET_SERVICE_IMPL’ with the code shown below.

  METHOD get_service_impl.
    DATA: lr_badi TYPE REF TO  isu_umc_odata.
    IF mv_no_commit = abap_true.  "batch processing is active
      mo_context->set_parameter( EXPORTING iv_name = 'CHANGESET_ACTIVE' iv_value = abap_true ).
    ENDIF.
    mo_context->set_parameter( iv_name = 'DPC' iv_value = me ).
    mo_context->set_parameter( iv_name = 'RECDET' iv_value = mr_request_details ).

    GET BADI lr_badi
      FILTERS
        entity_name  = iv_entity_name
        service_name = iv_service_name.
    CALL BADI lr_badi->get_instance
      EXPORTING
        ir_context      = mo_context
      CHANGING
        cr_service_impl = rr_result.

  ENDMETHOD.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 7 : Now to write our custom logic we must enhance BAdI : ISU_UMC_ODATA.

In this E.g. we are enhancing the logic for AccountContact Entity.

Below are the steps to enhance the BAdI

Step 7.1 : Create a Custom Class(ZLCS_ICC_ERPISU_UMC_ACCOUNTCONTACT’ with ‘CL_FKK_UMC_ODATA_ACCCONTACT’ as superclass and mark it as Final

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 7.2 : Go to SE19 , enter the standard BAdI name(ISU_UMC_ODATA) and click Create Implementation

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 7.3 : Give your Custom implementation name and click on OK.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 7.4 : On the Next Screen, add details as shown.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 7.5 : Mark this custom implementation as ‘Default Implementation’ , add Filter values and Activate.

Note : Filter Values are the Entity and EntitySet names for which the enhancement should be triggered.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 8 : Then go back to your Custom Class ZLCS_ICC_ERPISU_UMC_ACCOUNTCONTACT and redefine the required methods(GET/GETENTITYSET/CREATE etc )to write the custom logic.

In this example we have redefined the GET and CREATE Methods.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Step 9 : After activating all our custom developments , Next step is to Register/Maintain Service and then test the service.

◉ Maintain Service

Go to Transaction /N/IWFND/MAINT_SERVICE and click add services.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

On the Next screen , Provide the service name along with the system Alias name and click on Get Services.

After the Service name appears on the Select Backend Services section , Select the service, and click on Add Selected Services.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

◉ Once the service is registered, we can now test in using the transaction /N/IWFND/GW_CLIENT

Let’s start with fetching Contact details for a particular Partner and then creating a new Contact note for a Partner. Below are the details for the same.

To Fetch Contact Note Details for Particular Partner

Note : Since we do not have field Partner in the our AccountContact Entity we can make use of the existing Association between Accounts and AccountContact for our requirement.

URI : sap/opu/odata/sap/ZICCSERP_ISU_UMC_SRV/Accounts(AccountID=’0000000000′)/AccountContacts

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

After Execution , below is the response

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Note: Since PartnerID field is not present in the Entity, we are making use of the existing association between Entity Accounts and AccountContacts to fetch Contact Note details for a particular Partner ID.

To Create Contact Note for a Partner

URI : /sap/opu/odata/sap/ZICCSERP_ISU_UMC_SRV/AccountContacts

Request Body(json Format) :

{

"AccountContactID" : " ",

"AccountID" : "0000000000",

"ContactClassID" : "0001",

"ContactActionID" : "0001",

"ContactPriorityID" : "",

"ContactDate" : "\/Date(1615939200000)\/",

"Note" : "Test12347867\r\nTest5686987\r\nTest56789\r\nTest56789\r\nTest56789\r\nTest56789\r\nTest56789",

"ContactTypeID" : "4",

"IncomingFlag" : true ,

"ContactTime" : "PT11H25M05S",

"CreatedBy" : "XXXXX"

}

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

After Execution ,we can see a new Contact Note is created .

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Note:

1 major issue faced during Get or Post is shown in the screenshot below

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

The above error can be resolved in 2 ways

1. First way is to maintain the Partner IDs in your User profile .

To do so follow the below mentioned steps:

Go To Tcode SU01 ->Select Go to from toolbar ->References and maintain the below values. Key should have your Partner Values.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

2. Second way is to comment out the CHECK_USER_AUTHORISATION method present in your redefined methods of your enhancement class ZCLS_ICC_ERPISU_UMC_ACCCONTACT.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Now our next concern would be how to find the right superclass for our custom class.

Its simple, Super Class for your Custom Class can be found from the standard implementations

E.g. In our Case we were implementing Custom Logic for AccountContact
So the standard Enhancement for the above entity is ‘ISU_UMC_ODATA_ACCOUNTCONTACT’(Can be found by checking the implementation for BAdI ISU_UMC_ODATA).

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Open the above Implementation and check for its implementing class

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Open the Implementing Class to check its Superclass.

ABAP Development, NW ABAP Gateway (OData), SAP ABAP Tutorial and Material, SAP ABAP Career, SAP ABAP Learning, SAP ABAP Preparation, SAP ABAP Guides

Incase you are creating a new Entity, the superclass in that case should be CL_ISU_UMC_ODATA_ABSTRACT.

No comments:

Post a Comment