cancel
Showing results for 
Search instead for 
Did you mean: 

Message-Handling with ODATA Batch

moritz_zwerger
Explorer
0 Kudos

Hi all,

I'm working with ODATA for a while now and finally tried to get the batch mode running.

Everything works fine so far, but I'm struggling with the message handling.

I'd like to hand back messages from backend to frontend, either if the (update) request was successful or failed.

I redefined the changeset_begin method and set

cv_defer_mode = abap_true.

to jump into the changeset_process method.

In the changeset_process method I added the following code:

  METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_process.
    DATA:
      ls_changeset_request     TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request,
      ls_changeset_req_parent  TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request,
      lo_create_context        TYPE REF TO /iwbep/if_mgw_req_entity_c,
      lv_entity_type           TYPE string,
      ls_changeset_response    TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response,
      ls_changeset_resp_parent TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response,
      ls_tbl_bndl              TYPE zcl_zfvr_ui5_mpc=>ts_tbl_bndl, 
      lt_tbl_bndl              TYPE zcl_zfvr_ui5_mpc=>tt_tbl_bndl,
      lv_error_entity          TYPE string.

    FIELD-SYMBOLS:
      <ls_header>              TYPE zcl_zfvr_ui5_mpc=>ts_tbl_bndl. 

    LOOP AT it_changeset_request INTO ls_changeset_request.
      lo_create_context ?= ls_changeset_request-request_context.
      lv_entity_type = lo_create_context->get_entity_type_name( ).
*--------------------------------------------------------------------*
      "! CREATE
      CASE ls_changeset_request-operation_type.
        WHEN /iwbep/if_mgw_appl_types=>gcs_operation_type-create_entity.
* create (HTTP POST)
          CASE lv_entity_type.
            WHEN 'TBL_BNDL'.
              ls_changeset_request-entry_provider->read_entry_data( IMPORTING es_data = ls_tbl_bndl ).
          ENDCASE.        
   ENDCASE.
 ENDLOOP.

DATA ls_messages LIKE LINE OF lt_messages. DATA lt_messages TYPE bapiret2_t.
 ls_messages-type = 'E'.
 ls_messages-id = '1'.
 ls_messages-message = 'custom message'.
 ls_messages-log_no = ''.
 ls_messages-log_msg_no = ''.
 ls_messages-message_v1 = 'E_Var1'.
 ls_messages-message_v2 = 'E_Var2'.
 ls_messages-message_v3 = 'E_Var3'.
 ls_messages-message_v4 = 'E_Var4'.
 ls_messages-parameter = ''.
 ls_messages-row = ''.DATA lo_container TYPE REF TO /iwbep/if_message_container.
 lo_container = me->mo_context->get_message_container( ).lo_container->add_message(
   iv_msg_type = ls_messgaes-type
   iv_msg_id = ls_messgaes-id
   iv_msg_number = ls_messgaes-number
   iv_msg_text = ls-messages-mesage
   iv_is_leading_message = abap_true
   iv_add_to_response_header = abap_true).

 ENDMETHOD.

I tried to get the messages in the UI5-frontend via

oModel.update("/TBL_BNDLSet('1')", Object , {groupId: "editGroup"});
oModel.submitChanges({
	groupId: "editGroup",
	success: function(data, response){
console.log(response.headers["sap-messages"]);
}
});

While not using batch, espacially not using the changeset_process method but using the TBL_BNDLSET_UPDATE_ENTITY Method this worked fine.

But with batch processing, I can't find any custom messages in the response.

I tried to raise exceptions and finde those messages, but couldn't find them either.

The weired thing is, the debugger does not even jump into the changeset_end method (which is redefined).

How does the message handling with batch works? Any ideas or suggestions?

The reason why I want to use the changeset_process method is, because I want to push mutliple entries to the backend and process them in the database at once.

Many thanks and best regards

Moritz

Accepted Solutions (0)

Answers (2)

Answers (2)

haemma83
Active Participant
0 Kudos

Hi. Got the same issue. I got a Batch Processing and a afterwards a "Submit Changes" on the frontend. But I do not receive any Response or I don't know how to debug it in this case:

			oModel.submitChanges({
				groupId: "group1",
				success: jQuery.proxy(function (oData, oResponse) {
					if(oData){
						
					}
				
				}, this),
				error: function (oError) {
					if (oError) {
				
						this.parseMsg(oError);
				
					}
				
				}


			});

petergilberg
Participant
0 Kudos

Hi,

if you're using batch requests you'll have to process all responses and look for errors:

this.getView().getModel("oDataModel").attachBatchRequestCompleted(
	function (oEvent) {		
		var oParams = oEvent.getParameters();		
		oParams.requests.forEach(function (request) {			
			if(!request.success) {
				console.log(JSON.parse(request.response.responseText).error.message.value);
			}			
		});
	}, this);

Maybe someone knows a nicer way to do this, but by attaching this eventhandler, you have some general logic in place.

Best regards!

Ryan-Crosby
Active Contributor
0 Kudos

Hi Moritz,

I haven't had the reason to pass back multiple messages myself but I found a similar example in our system with the following suggesting that you would pass messages when a failure occurs with code like this:

RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            textid            = /iwbep/cx_mgw_busi_exception=>business_error
            message_container = lo_message_container.

Regards,

Ryan Crosby