on ‎2022 Feb 01 4:50 PM
Currently I'm implementing an unmanaged CREATE behaviour, but the error handling is too generic at the moment..
TRY
...
DATA(request) = client_proxy->create_resource_for_entity_set( 'A_SALESORDERITEM' )->create_request_for_create( ).
APPEND 'SALESORDER' TO so_item_properties.
APPEND 'MATERIAL' TO so_item_properties.
APPEND 'REQUESTEDQUANTITY' TO so_item_properties.
APPEND 'REQUESTEDQUANTITYUNIT' TO so_item_properties.
...
request->set_business_data(
is_business_data = items
it_provided_property = so_item_properties
).
...
CATCH /iwbep/cx_gateway.
APPEND VALUE #(
symsg-msgty = 'E'
symsg-msgid = '/N4C02/CM_HTTP_COMM'
symsg-msgno = '006'
severity = if_abap_behv_message=>severity-error
cid = sales_order_item_out-cid
) TO messages.
APPEND VALUE #(
%cid = sales_order_item_out-cid
%create = if_abap_behv=>mk-on
) TO failed-salesorderitem.
...
ENDTRY.
The above merely throws a generic error for all gateway errors which is reported in the Fiori Elements app.
How do I specifically handle each and every Gateway exception caught in iwbep/cx_gateway ?
E.g. the Gateway is current throwing an exception of
No language-specific unit defined in language EN for internal unit T
... This is for entering a non-existent Quantity unit of T.
The issue is the end-user doesn't see this.... All they get is the generic 'Gateway Exception' error.
I know I can catch this info using something like...
CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).
However, I have a number of issues with what is being return in lx_gateway above.
Firstly, accessing it is problematic as it's an object with attached methods to retrieve data (e.g. get_text( ) ).
Secondly, the data format looks to depend on the error, here are some scenarios I've tested.
1) Everything correct apart from an invalid RequestedQuantityUnit.
500 HTTP status
MSGID BM
MSGNO 302
MSGV1 pce
MSGV2 EN
MSGV3
MSGV4
2) Everything correct apart from a blank Material.
400 HTTP status
Unlike the above error, no message properties are returned, but we do have an
HTTP_ERROR_BODY property.
{"error":{"code":"V1/320","message":{"lang":"en","value":"No item category available (Table T184 OR TEXT )"},"innererror":{"application":{"component_id":"SD-SLS-SO","service_namespace":"/SAP/","service_id":"API_SALES_ORDER_SRV","service_version":"0001"},"transactionid":"64205A9E09A00030E0061F9CEDB7A798","timestamp":"","Error_Resolution":{"SAP_Transaction":"","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"},"longtext_url":"/sap/opu/odata/iwbep/message_text;o=BACKEND/","errordetails":[{"ContentID":"","code":"/IWBEP/CX_MGW_BUSI_EXCEPTION","message":"No item category available (Table T184 OR TEXT )","longtext_url":"/sap/opu/odata/iwbep/message_text;o=BACKEND/","propertyref":"","severity":"error","transition":false,"target":""}]}}}
3) No properties entered.
Although they are set to Mandatory in the Behaviour Definition, /iwbep/cx_gateway IS NOT CAUGHT.
I've tried to include as much detail as possible but just to clarify, the 2 issues are:
a) I need a consistent way of trapping all exceptions, so I can populate the messages table, which sets up the returned message(s) back to the UI.
b) I need to be able to catch all Mandatory fields that haven't been populated.
Thank you in advance.
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
You have to fill the reported response parameter.
TYPES: BEGIN OF ty_longtext,
msgv1(50),
msgv2(50),
msgv3(50),
msgv4(50),
END OF ty_longtext.
DATA: ls_longtext TYPE ty_longtext.
APPEND VALUE #( %tky = keys[ 1 ]-%tky )
TO failed-rapgeneratorbo.
APPEND VALUE #( %tky = keys[ 1 ]-%tky
%msg = new_message(
id = '/DMO/CM_RAP_GEN_MSG'
number = 064
severity = if_abap_behv_message=>severity-error
v1 = |{ ls_longtext-msgv1 }|
v2 = |{ ls_longtext-msgv2 }|
)
)
TO reported-rapgeneratorbo.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andre.
I know about the reported response, but the issue is how is the exception caught and populated in the first place?
In your example, that too is hard-coded with a specific ID, number, severity etc, but how can I populate this with the specific exception from the API?
E.g. I'm using API_SALES_ORDER_SRV/A_SalesOrderItem and implemented the CREATE using....
request->set_business_data(
is_business_data = items
it_provided_property = so_item_properties
).
Thanks andre.fischer
Here's my solution with a couple of changes.
Thanks for your help!
TYPES: BEGIN OF ty_longtext,
msgv1(50),
msgv2(50),
msgv3(50),
msgv4(50),
END OF ty_longtext.
DATA: ls_longtext TYPE ty_longtext.
...
CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).
IF lx_gateway->http_status_code = 500.
ls_longtext = lx_gateway->get_text( ).
ELSE.
ls_longtext = Lx_gateway->get_longtext( ).
ENDIF.
APPEND VALUE #(
%msg = new_message(
id = '00'
number = 001
severity = if_abap_behv_message=>severity-error
v1 = ls_longtext-msgv1
v2 = ls_longtext-msgv2
v3 = ls_longtext-msgv3
v4 = ls_longtext-msgv4
)
) TO reported-salesorderitem.
APPEND VALUE #(
%create = if_abap_behv=>mk-on
) TO failed-salesorderitem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.