cancel
Showing results for 
Search instead for 
Did you mean: 

Header Response in Batch Processing

Former Member
0 Kudos

Hello,

My Scenario:

Multiple records update is required from the front end. This is achieved via Batch Processing. Upon processing of each record, an update message for each record should be sent back to UI5.


Requirement:

Need to send back the status message to UI for each single record.


Actual Process followed:

Lets say I have 3 records for updating, the sequence of methods called are as below:

1. Change Set BEGIN.

2. Update Entity (Called 3 times)

3. Change Set END.


In Begin method is just redefined and has no code.

In Update entity I am collecting all the individual record in an global internal table of same class.

In End method, calling an RFC to update all 3 records at a time. This RFC returns 3 messages indicating success or failure which needs to sent to UI.


Hence I thought to send these messages by concatenating into single message and send via Header response in method Change Set END as follows:

  1. data:  ls_header               TYPE ihttpnvp. 
  2. ls_header-name = 'my-custom-message'
  3. ls_header-value = 'my_message'
  4. /iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

Problem:

I am not getting any header response with name my-custom-message.

Kindly suggest me to send the messages to UI5 with any corrections to above procedure or an alternative procedure.

Note: The header response with above method is only working from method Update Entity and I don't want to call the RFC for each single entity.

Regards,

Satish D R

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi

In some of the methods you call set_header?(create_entity get_entity...)

former_member185414
Active Contributor
0 Kudos

Hello Satish,

One question - Do you want a All or None behavior or partial success is also acceptable. In case you need all/none behavior then obviously you cannot call the RFC in every Update method and what you have designed is fine.

One alternative way which we did was that append two additional columns - status code and message in the structure where you are storing the values from the UI for every update record and populate these structures and pass them back to UI. Now UI has the data at the row level and can choose to display a cumulative or individual status for every record.

BR.

Former Member
0 Kudos

Hi Ankit,

Partial success is also accepted.

Ex:

Out of 5 records, 4 is successfully changed and 1 is failed.

The RFC will give me 5 messages for each record. This has to be sent back to UI from END method. So how can this be done. I tries via Header Response, but I am not getting any messages in the header response.

Regards,

Satish D R

former_member185414
Active Contributor
0 Kudos

Hello Satish,

I think you meant 1 message for each record and not 5 for each record. You can add messages to the message container and read the same in UI.

" Loop at the records and check if any records failed

" If a single record failed, instantiate the message container.

*-- Create the business exception object to initialize message container

             IF lref_busi_exception IS NOT  BOUND.

               CREATE OBJECT lref_busi_exception.

*-- Obtain message container

               IF mo_msg_container IS INITIAL.

                 CALL METHOD lref_busi_exception->get_msg_container

                   RECEIVING

                     ro_message_container = mo_msg_container.

               ENDIF.

             ENDIF.


*-- Pass the data to identify the record which errored out to message container

             lv_msg_v1 = <data>.

             CALL METHOD mo_msg_container->add_message

               EXPORTING

                 iv_msg_type   = 'E'

                 iv_msg_id     = <Msg Class>

                 iv_msg_number = <Msg No>

                 iv_msg_v1     = lv_msg_v1.

             CLEAR lv_msg_v1.

" Close If condition where you would have checked for error/failed record

" Endloop.


Finally do as below -

*-- Finally raise exception in case of errors

         IF mo_msg_container IS BOUND.

           CREATE OBJECT lref_exception

             EXPORTING

               message_container = mo_msg_container.

           RAISE EXCEPTION lref_exception.



Let me know in case you need further clarification.

HTH.

BR.

Former Member
0 Kudos

Hi Ankit,

Thanks for your help. We have UI5 as the front end. Can you give an idea on how to read these messages so that I am convince the UI5 team.

Your input is appreciated.

Regards,

Satish D R

former_member185414
Active Contributor
0 Kudos

Hello Satish,

I have limited front end development experience so I cannot help on UI coding right now. Instead I found out below thread.-

BR.

Former Member
0 Kudos

Hi Ankit,

I tried your solution and the response contains only 1 message but I have added 2 messages in the message container. Is it possible to show multiple messages? Below is my code:

DATA:

    ls_message  TYPE bapiret2,

    lt_messages TYPE bapirettab.

  CALL FUNCTION 'ZDRAFM_DOCUMENTS_RELEASE' DESTINATION lv_destination

    EXPORTING

      iv_user_id         = gv_user_id

      iv_doc_type        = gv_doc_type

      iv_appr_rej        = gv_app_rej

      iv_device_id       = gv_device_id

      iv_ismobile        = gv_ismobile

      it_credit_blocked  = gt_credit_blk_ord

      it_discount_orders = gt_discount_ord

      it_damaged_orders  = gt_damaged_ord

      it_material_return = gt_mrv_ord

    IMPORTING

      et_return          = lt_messages.

  DATA:

    lref_busi_exception TYPE REF TO /iwbep/cx_mgw_busi_exception,

    lref_msg_container  TYPE REF TO /iwbep/if_message_container.

  CREATE OBJECT lref_busi_exception.

  CALL METHOD lref_busi_exception->get_msg_container

    RECEIVING

      ro_message_container = lref_msg_container.

  LOOP AT lt_messages INTO ls_message.

    CALL METHOD lref_msg_container->add_message

      EXPORTING

        iv_msg_type   = ls_message-type

        iv_msg_id     = ls_message-id

        iv_msg_number = ls_message-number

        iv_msg_text   = ls_message-message.

  ENDLOOP.

  IF lref_busi_exception IS BOUND.

    RAISE EXCEPTION lref_busi_exception.

  ENDIF.


Below is the response seen in the browser. (Single message is displayed).

Your input will be really helpful.

Regards,

Satish D R

former_member185414
Active Contributor
0 Kudos

Hello Satish,

I am able to successfully add multiple messages in the container. Screenshots are -

In Networks tab -

In Console tab -

BR.

Former Member
0 Kudos

Hi Ankit,

Can you share you complete code here

Regards,

Satish D R

former_member185414
Active Contributor
0 Kudos

Hi Satish,

Backend code is below -

METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_end.

     DATA :

           lv_msg_v1 TYPE symsgv ,

           ls_failed_evaluator TYPE <type>,

           lref_busi_exception TYPE REF TO /iwbep/cx_mgw_busi_exception.

*-- Check if any one evaluator failed in assignment

     IF mt_failed_evaluator IS NOT INITIAL.

*-- Create the exception object

       CREATE OBJECT lref_busi_exception.

*-- Populate the data in message container

       IF mo_msg_container IS INITIAL.

         CALL METHOD lref_busi_exception->get_msg_container

           RECEIVING

             ro_message_container = mo_msg_container.

       ENDIF.

       LOOP AT mt_failed_evaluator INTO ls_failed_evaluator.

*-- Collect the evaluator email ids based on operation flag.

*-- All Delete failures go with 78 message

         IF ls_failed_evaluator-operation_flag EQ zif_cdp_assessment_constants=>gc_delete.

           lv_msg_v1 = ls_failed_evaluator-email_addr.

*-- Add all the email id to the message container

           CALL METHOD mo_msg_container->add_message

             EXPORTING

               iv_msg_type   = zif_cdp_assessment_constants=>gc_msgty_error

               iv_msg_id     = zif_cdp_assessment_constants=>gc_msgid

               iv_msg_number = zif_cdp_assessment_constants=>gc_msgno_078_msg_cnt

               iv_msg_v1     = lv_msg_v1.

         ENDIF.

         CLEAR ls_failed_evaluator.

       ENDLOOP.

       RAISE EXCEPTION lref_busi_exception.

     ENDIF.

     COMMIT WORK.

   ENDMETHOD.


BR

Former Member
0 Kudos

Hi Ankit,

Still i am not getting multiple messages. Can you let me know what is the type of variable mo_msg_container in your code.

Regards,

Satish D R

former_member185414
Active Contributor
0 Kudos

Hello Satish,

It's /IWBEP/IF_MESSAGE_CONTAINER.

Snapshot -

BR