Created
March 25, 2017 22:10
-
-
Save jasper07/a5ee6bd74c80d3a5af81fd96bdc0649e to your computer and use it in GitHub Desktop.
Example of ABAP DPC_EXT code for mapping bapi warning to UI5 field without an Exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
METHOD myentityset_update_entity. | |
io_data_provider->read_entry_data( IMPORTING es_data = er_entity ). | |
*--- get the context path from the request uri | |
DATA(lt_headers) = /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( )->get_request_header( ). | |
DATA(lv_request_uri) = lt_headers[ name = '~request_uri' ]-value. | |
DATA(lv_context_path) = match( val = lv_request_uri regex = `/([^\/]+)\/?$` ). | |
DATA(lv_message_target) = lv_context_path && |/Field1|. "/MyEntity('Key')/Field1 | |
DATA lt_msg_types TYPE TABLE OF char1. | |
*--- determine which messages to show | |
IF er_entity-show_warning = abap_true. | |
APPEND /iwbep/if_message_container=>gcs_message_type-warning TO lt_msg_types. | |
ENDIF. | |
IF er_entity-show_info EQ abap_true. | |
APPEND /iwbep/if_message_container=>gcs_message_type-info TO lt_msg_types. | |
ENDIF. | |
IF er_entity-show_success EQ abap_true. | |
APPEND /iwbep/if_message_container=>gcs_message_type-success TO lt_msg_types. | |
ENDIF. | |
IF er_entity-show_error EQ abap_true. | |
APPEND /iwbep/if_message_container=>gcs_message_type-error TO lt_msg_types. | |
ENDIF. | |
DATA lt_return TYPE STANDARD TABLE OF bapiret2. | |
LOOP AT lt_msg_types ASSIGNING FIELD-SYMBOL(<fs_msg_type>). | |
" create bapi message | |
APPEND INITIAL LINE TO lt_return ASSIGNING FIELD-SYMBOL(<fs_return>). | |
MESSAGE ID '00' TYPE <fs_msg_type> NUMBER 001 | |
INTO <fs_return>-message | |
WITH |message { sy-tabix } type { <fs_msg_type> } value { er_entity-field1 }|. | |
CALL FUNCTION 'BALW_BAPIRETURN_GET2' | |
EXPORTING | |
type = sy-msgty | |
cl = sy-msgid | |
number = sy-msgno | |
par1 = sy-msgv1 | |
IMPORTING | |
return = <fs_return>. | |
*--- only link Errors and Warning to the target field | |
<fs_return>-field = COND #( WHEN <fs_msg_type> = /iwbep/if_message_container=>gcs_message_type-warning THEN lv_message_target | |
WHEN <fs_msg_type> = /iwbep/if_message_container=>gcs_message_type-error THEN lv_message_target | |
ELSE || ). | |
ENDLOOP. | |
LOOP AT lt_return ASSIGNING <fs_return>. | |
" add message from bapi structure | |
mo_context->get_message_container( )->add_message_from_bapi( | |
EXPORTING is_bapi_message = <fs_return> | |
iv_entity_type = iv_entity_set_name | |
it_key_tab = VALUE /iwbep/t_mgw_name_value_pair( ( name = 'KEY1' value = er_entity-key1 ) ) | |
iv_add_to_response_header = boolc( er_entity-throw_exception = abap_false ) | |
iv_message_target = CONV string( <fs_return>-field ) ). | |
ENDLOOP. | |
IF er_entity-throw_exception = abap_true. | |
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception | |
EXPORTING | |
message_container = mo_context->get_message_container( ). | |
ENDIF. | |
MODIFY zodata_warning FROM er_entity. | |
ENDMETHOD. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment