2025 Apr 05 4:39 PM - edited 2025 Apr 05 4:48 PM
Dear All
Please support that how to read messages returned by Business Object Interface programmatically.
We can read the response through debugging, but how to read same using ABAP.
In below code
REPORTED DATA(reported)
OR
is having %MSG having the error message but final structure is only available at runtime.
MODIFY ENTITY I_ProductionOrderTP
CREATE FIELDS (
product
productionplant
productionversion
productionordertype
orderplannedtotalqty
productionunit
basicschedulingtype
)
AUTO FILL CID WITH VALUE #(
(
%data-product = 'FG228'
%data-productionplant = '1010'
%data-productionversion = '0001'
%data-productionordertype = 'YBM1'
%data-orderplannedtotalqty = 5
%data-productionunit = 'ST'
%data-basicschedulingtype = '4'
)
)
FAILED DATA(failed)
REPORTED DATA(reported)
MAPPED DATA(mapped).
IF failed IS INITIAL.
COMMIT ENTITIES BEGIN
RESPONSES
FAILED DATA(failed_commit)
REPORTED DATA(reported_commit).
IF sy-subrc = 0 AND failed_commit IS INITIAL.
CONVERT KEY OF i_productionordertp
FROM TEMPORARY VALUE #( %pid = mapped-productionorder[ 1 ]-%pid
%tmp = mapped-productionorder[ 1 ]-%key )
TO FINAL(ls_finalkey).
ENDIF.
COMMIT ENTITIES END.
" Number of created Order: ls_finalkey-productionorder
ELSE.
ROLLBACK ENTITIES.
ENDIF.
Request clarification before answering.
Hello @adnanmaqbool
Thank you for your questions and for sharing the screenshot.
It was very helpful. Here’s an easy method to read RAP EML messages in S/4HANA Cloud ABAP Environment and map them to your items.
1) Interaction-phase messages (RE
DATA lt_texts TYPE STANDARD TABLE OF string.
LOOP AT reported-productionorder INTO DATA(ls_rep). "entity-specific table
LOOP AT ls_rep-%msg INTO DATA(lo_msg). "if_abap_behv_message
APPEND lo_msg->get_text( ) TO lt_texts. "plain text
ENDLOOP.
ENDLOOP.
2) Save/commit messages (REPORTED in COMMIT ENTITIES)
COMMIT ENTITIES BEGIN
RESPONSES
FAILED DATA(failed_commit)
REPORTED DATA(reported_commit).
"...
COMMIT ENTITIES END.
LOOP AT reported_commit-productionorder INTO DATA(ls_rep_c).
LOOP AT ls_rep_c-%msg INTO DATA(lo_msg_c).
APPEND lo_msg_c->get_text( ) TO lt_texts.
ENDLOOP.
ENDLOOP.
3) Which rows failed (FAILED)
IF failed-productionorder IS NOT INITIAL.
LOOP AT failed-productionorder INTO DATA(ls_failed).
" correlate via ls_failed-%cid / %key to your input
ENDLOOP.
ENDIF.
IF failed-productionorder IS NOT INITIAL.
LOOP AT failed-productionorder INTO DATA(ls_failed).
" correlate via ls_failed-%cid / %key to your input
ENDLOOP.
ENDIF.
IF failed-productionorder IS NOT INITIAL.
LOOP AT failed-productionorder INTO DATA(ls_failed).
" correlate via ls_failed-%cid / %key to your input
ENDLOOP.
ENDIF.
4) Optional: get T100 ID/number (if available)
TRY.
DATA(lo_t100) = CAST if_t100_message( lo_msg ).
DATA(lv_id) = lo_t100->t100key-msgid.
DATA(lv_no) = lo_t100->t100key-msgno.
CATCH cx_sy_move_cast_error.
ENDTRY.
5) Map created keys (MAPPED → final key)
IF mapped-productionorder IS NOT INITIAL.
DATA(ls_finalkey) = VALUE i_productionordertp_key( ).
CONVERT KEY OF i_productionordertp
FROM TEMPORARY VALUE #(
%pid = mapped-productionorder[ 1 ]-%pid
%tmp = mapped-productionorder[ 1 ]-%key )
TO FINAL(ls_finalkey).
"ls_finalkey-productionorder = created number
ENDIF.
Notes
• %msg exists per reported row; at compile time you access reported-<entity> (no RTTI needed).
• Capture both phases: before COMMIT ENTITIES and inside it.
• Use %cid/%key to tie messages to your input rows.
If you want, I can wrap this into a tiny reusable utility example zcl_eml_msg=>collect( reported )) that returns a bapiret2 table
You can check below SAP Useful References(GenAI Assist support)
With kind regards
Chuma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 22 | |
| 16 | |
| 13 | |
| 6 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.