cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a API in BADI implementation in HANA Cloud Public edition

Ravi_Solanki
Explorer
0 Kudos
186

Hi Experts,

We need to check if we can call Supplier confirmation API in a BADI implementation. We need to read the supplier confirmation data in the implemented BADI while Workflow triggers.

If possible, Kindly provide the sample code if any.

SAP S/4HANA Cloud Public Edition 

Accepted Solutions (0)

Answers (2)

Answers (2)

Pradeep_Reddy
Participant
0 Kudos

Can you use the view : I_SupplierInvoiceAPI01 in BADI and it is a released view.

Jeremy_Deo
Participant
0 Kudos

Hello dear user,

In SAP S/4HANA Cloud Public Edition, calling an external API within a BADI implementation involves using the SAP Business Technology Platform (BTP) services, specifically the SAP Cloud SDK and HTTP client libraries. Here's how you can achieve this:

1. Choose the Right BADI

Identify the correct BADI using SAP Extensibility Explorer or SAP Help Portal.

Ensure the BADI allows external API calls (some are restricted in the public cloud).

2. Implement the BADI Using Custom Logic

SAP S/4HANA Cloud Public Edition supports custom logic via ABAP for Cloud Development. Follow these steps:

Step 1: Create the BADI Implementation

  1. Open SAP Fiori App → "Custom Logic".
  2. Find the required BADI (e.g., BADI_SALESORDER_CHANGE).
  3. Click Create Implementation.

Step 2: Use ABAP HTTP Client to Call the API

Since direct HTTP calls (e.g., cl_http_client) are restricted in S/4HANA Cloud Public Edition, use the SAP ABAP Environment HTTP Client:

TRY.

    DATA(lo_http_client) = cl_web_http_client=>create_by_url( 'https://api.example.com/data' ).

 

    " Set HTTP Method

    lo_http_client->request->set_method( if_web_http_request=>co_method_get ).

 

    " Set Headers (if required)

    lo_http_client->request->set_header( 'Content-Type', 'application/json' ).

    lo_http_client->request->set_header( 'Authorization', 'Bearer your_token_here' ).

 

    " Send Request

    lo_http_client->send( ).

 

    " Get Response

    DATA(lv_response) = lo_http_client->response->get_text( ).

 

    " Process Response

    WRITE: / 'API Response:', lv_response.

 

  CATCH cx_web_http_client_error INTO DATA(lo_error).

    WRITE: / 'HTTP Error:', lo_error->get_text( ).

ENDTRY.

3. Read Supplier Confirmation Data in ABAP

Within the BADI method, use ABAP logic to fetch supplier confirmation details. Example:

 

METHOD if_ex_mm_pur_confirmation_badi~post.

  

  DATA: lt_confirmations TYPE TABLE OF mm_pur_confirmation,

        ls_confirmation TYPE mm_pur_confirmation.

 

  " Read supplier confirmations

  lt_confirmations = io_confirmation->get_confirmations( ).

 

  " Loop through confirmations

  LOOP AT lt_confirmations INTO ls_confirmation.

    WRITE: / 'Supplier:', ls_confirmation-supplier,

           / 'PO:', ls_confirmation-purchase_order,

           / 'Confirmed Qty:', ls_confirmation-confirmed_quantity,

           / 'Delivery Date:', ls_confirmation-confirmed_delivery_date.

  ENDLOOP.

 

ENDMETHOD.

4. Deploy and Test

Save and Activate the BADI.

Test using Business Process Testing (BPT) in SAP Fiori.

 

I hope those elements will help you answering your question.

Best regards,

Jeremy

Ravi_Solanki
Explorer
0 Kudos
Thanks Jeremy for your reply. I have tried above suggestions but seems like these are not allowed in Public cloud.