cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

S/4HANA Cloud CBO logic: Read BP Attachment, Base64, and store as 500-char chunks?

sanjaynaiksap
Explorer
0 Kudos
269

System: SAP S/4HANA Cloud, public edition and Private Edition
Extensibility: Key-User Custom Business Object (CBO) 

Preparation step: A PDF is attached to the Business Partner with filename

Desired behavior (in CBO logic)

  1. Read the BP attachment

  2. Encode binary to Base64.

  3. Split into 500-character parts.

  4. Save those parts into CBO(multiple rows/items).

Questions for the community

  1. Is there a released (whitelisted) API that CBO key-user logic can call to read a Business Partner attachment by filename or attachment ID?

  2. Are HTTP/OData calls allowed from CBO logic for this purpose?
  3. If direct read from CBO logic is not supported, what is the recommended pattern?

my call fails before the HTTP request is sent (BLE circuit-breaker “fail-fast”).
Call is from CBO logic using CL_BLE_HTTP_CLIENT.

DATA: lv_comm_scenario type string,
            lv_outbound_service type string,
            lv_csrf type string,
           lv_body type string,
           lv_content_length type string.

DATA: lv_filename TYPE string VALUE 'lv_upload_id.pdf'.
lv_comm_scenario = 'YY1_CCS_SMI_INTERNAL'.
lv_outbound_service = 'YY1_OUTB_ADD_ATTACHMENT_REST'.
DATA(lo_client) = cl_ble_http_client=>create( communication_scenario = lv_comm_scenario outbound_service = lv_outbound_service ).
DATA(lo_req1) = cl_ble_http_request=>create( ). lo_req1->set_method( if_ble_http_request=>co_method-get ).
DATA(lv_filter) = |$filter=BusinessObjectTypeName eq 'BUSINESSPARTNER' and LinkedSAPObjectKey eq '9980000154'|.
lo_req1->set_resource_extension( |/AttachmentFolder?{ lv_filter }&$expand=to_Doc&$top=1| ).
TRY.
DATA(lo_res1) = lo_client->send( lo_req1->set_header_parameter( name = 'Accept' value = 'application/json' ) ).
CATCH cx_ble_http_exception INTO DATA(lx).
"-> log/raise lx->get_text( ) "config or DNS/SSL problems show up here RETURN. ENDTRY.

Thanks in advance!

Accepted Solutions (0)

Answers (1)

Answers (1)

Chuma
Active Contributor
0 Kudos

Hello @sanjaynaiksap 

Thank you for reaching out.

CBO logic calls API_CV_ATTACHMENT_SRV, reads and Base64-encodes the file in 500-character chunks, aligned with SAP capabilities. Use BUT000 + leading zeros, call via CL_BLE_HTTP_CLIENT with a comm arrangement, and convert with XCO. SAP Help Portal3648499 - How to use API_CV_ATTACHMENT_SRV to download attachments for enterprise pro...

Let me know if you need further information

With kind regards

Chuma

sanjaynaiksap
Explorer
0 Kudos
Hi Chuma,
sanjaynaiksap
Explorer
0 Kudos
Thanks a lot for the guidance! I tried wiring this exactly as suggested, but my call fails before the HTTP request is sent (BLE circuit-breaker “fail-fast”). Call is from CBO logic using CL_BLE_HTTP_CLIENT.DATA: lv_comm_scenario type string, lv_outbound_service type string, lv_csrf type string, lv_body type string, lv_content_length type string, lv_xml type string, lv_startDate type d, lv_endDate type d. DATA: lv_filename TYPE string VALUE 'lv_upload_id.pdf'. lv_comm_scenario = 'YY1_CCS_SMI_INTERNAL'. lv_outbound_service = 'YY1_OUTB_ADD_ATTACHMENT_REST'. * Fetch CSRF Token for Attachment Service DATA(lo_client) = cl_ble_http_client=>create( communication_scenario = lv_comm_scenario outbound_service = lv_outbound_service ). " Build request to /AttachmentFolder to locate the document keys DATA(lo_req1) = cl_ble_http_request=>create( ). lo_req1->set_method( if_ble_http_request=>co_method-get ). DATA(lv_filter) = |$filter=BusinessObjectTypeName eq 'BUSINESSPARTNER' and LinkedSAPObjectKey eq '9980000154'|. lo_req1->set_resource_extension( |/AttachmentFolder?{ lv_filter }&$expand=to_Doc&$top=1| ). TRY. DATA(lo_res1) = lo_client->send( lo_req1->set_header_parameter( name = 'Accept' value = 'application/json' ) ). CATCH cx_ble_http_exception INTO DATA(lx). "-> log/raise lx->get_text( ) "config or DNS/SSL problems show up here RETURN. ENDTRY.