on 2025 Mar 26 10:35 AM
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.
Request clarification before answering.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
12 | |
9 | |
8 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.