cancel
Showing results for 
Search instead for 
Did you mean: 

Create entity using Batch Request in sapui5

former_member225463
Participant
0 Kudos

Hello Experts,

I need one help regarding batch processing.

I have to create two entries using the button Create in one call which i am trying with the help of Batch OData calls.

I have implemented by create method of the DPC_EXT Class. Now once the call happens from the frontend, how the backend will get called means which method and what kind of code we have to write to handle the batch call.

Please find out the call which i am doing from the UI :

var oButton = new sap.ui.commons.Button({

  id : 'B-Create',

  text : 'Batch Call',

  width : '10em',

  press : function(){

  userEntry1 = { 

  Bname : 'Ned', 

  Address : 'Flanders', 

  City : 'Raipur', 

  State: 'Chatisgarh', 

       }, 

       userEntry2 = { 

  Bname : 'Chief', 

         Address : 'Wiggum', 

         City : 'Delhi', 

         State: 'Delhi', 

       }; 

     //create an array of batch changes and save 

     var batchChanges = []; 

     batchChanges.push(oModel.createBatchOperation("userdetails", "POST", contactEntry1) ); 

     batchChanges.push(oModel.createBatchOperation("userdetails", "POST", contactEntry2) ); 

     oModel.addBatchChangeOperations(batchChanges); 

     //submit changes and refresh the table and display message 

     oModel.submitBatch(function(data) { 

      

function(err) { 

       alert("Success "); 

     }

     }, function(err) { 

       alert("Error occurred "); 

     }); 

   }, 

Note : userdetails is my entity set name , and the create method of DPC_EXT Class has already being redefined and working perfectly.

Kindly help me the steps and the codes which i have to write.

Best Regards,

Vikash

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

your code is ok, do you see a request in Dev tools / Network?

former_member225463
Participant
0 Kudos

Hi Maskin,

I have written the frontend code, in the backend what we need to write did any method has to be redefined for capturing the batch request?

I don't know the backend part .can you please help.

Regards,

Vikash

former_member182372
Active Contributor
0 Kudos

no, GW should handle batch requests transparent

again, your code looks fine, do you have any issues? do you see request coming out to GW?

Ryan-Crosby
Active Contributor
0 Kudos

Hi Vikash,

I think you might need to write the code for the CHANGESET_BEGIN and CHANGESET_END methods of your DPC_EXT class.

Regards,

Ryan Crosby

former_member225463
Participant
0 Kudos

HI Ryan,

Thanks for the reply.Can you please provide me a sample code what needs to be write in the CHANGESET_BEGIN and CHANGESET_END methods of the DPC_EXT class.

Regards,

Vikash

former_member225463
Participant
0 Kudos

Hello Maskin,

Please find out the error screen shot which i am facing.

Regards,

Vikash

Ryan-Crosby
Active Contributor
0 Kudos

Hi Vikash,

I have only worked with the operations in one proof of concept scenario in the past so I will try to explain my scenario as best I can - maybe that along with seeing some of the code will give you some insight and ideas into how to achieve your requirement.  The first thing I would note is that I was doing update of deliveries with regards to handling units so I was setting up the batch mode to do several creates and deletes on a single delivery in one shot.  In the changeset begin I merely set some flags and prep some tables to collect up the data.  Then for the corresponding create and delete methods I record the operations that need to be performed and lastly in the changeset end I execute the one RFC call to the back end system that does all of the delivery updating in one shot.  See below for the code snippets:


METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_begin.

* Initialize tables
   CLEAR: gt_batch_items, gt_batch_pickhus, gt_batch_packhus.
   REFRESH: gt_batch_items, gt_batch_pickhus, gt_batch_packhus.

* Mark for batch processing
   gv_batch = gc_x.

ENDMETHOD.


METHOD pickhus_delete_entity.

   DATA: ls_entity TYPE zcl_zpacking_mpc=>ts_pickhu.

* Restrict to batch mode only
   restrict_operation( message = 'Perform Pick HU deletion in batch mode' ).

* Copy key fields to structure and append
   copy_keys( EXPORTING lt_key_tab    = it_key_tab
              CHANGING  ls_entity     = ls_entity ).
   APPEND ls_entity TO gt_batch_pickhus.

ENDMETHOD.


METHOD packhus_create_entity.

* Restrict to batch mode only
   restrict_operation( message = 'Perform Pack HU creation in batch mode' ).

* Save update to be processed at end of change set
   io_data_provider->read_entry_data( IMPORTING es_data = er_entity ).

* Copy key fields to structure and append
   copy_keys( EXPORTING lt_key_tab    = it_key_tab
              CHANGING  ls_entity     = er_entity ).
   APPEND er_entity TO gt_batch_packhus.

ENDMETHOD.


METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_end.

   TYPES: BEGIN OF tt_exidv,
            exidv TYPE exidv,
          END OF tt_exidv.

   DATA: lv_dest    TYPE          rfcdest,
         ls_exidv   TYPE          tt_exidv,
         lv_subrc   TYPE          sy-subrc,
         lt_packhus TYPE TABLE OF tt_exidv,
         lt_pickhus TYPE TABLE OF tt_exidv,
         ls_packhu  TYPE          zcl_zpacking_mpc=>ts_packhu,
         ls_pickhu  TYPE          zcl_zpacking_mpc=>ts_pickhu,
         ls_item    TYPE          zcl_zpacking_mpc=>ts_item,
         lr_exidv   TYPE RANGE OF exidv,
         wa_exidv   LIKE LINE OF  lr_exidv,
         ls_message TYPE          bapi_msg.

   CONSTANTS: lc_e(1TYPE c VALUE 'E',
              lc_eq(2) TYPE c VALUE 'EQ'.

* Initialize for processing
   CLEAR: lv_dest, ls_exidv, lv_subrc, lt_packhus,
          lt_pickhus, ls_packhu, ls_pickhu, ls_item,
          lr_exidv, ls_exidv, ls_message.
   REFRESH: lt_packhus, lt_pickhus, lr_exidv.

* Get RFC destination
   lv_dest = me->get_destination( ).

* Internalize pack HU numbers
   wa_exidv-sign   = lc_e.
   wa_exidv-option = lc_eq.
   LOOP AT gt_batch_packhus INTO ls_packhu.
     ls_exidv-exidv = wa_exidv-low = ls_packhu-hu.
     APPEND ls_exidv TO lt_packhus.
     APPEND wa_exidv TO lr_exidv.
   ENDLOOP.

* Internalize pick HU numbers
   LOOP AT gt_batch_pickhus INTO ls_pickhu.
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
         input  = ls_pickhu-hu
       IMPORTING
         output = ls_exidv-exidv.
     APPEND ls_exidv TO lt_pickhus.
   ENDLOOP.

* Reset HU to internal number
   LOOP AT gt_batch_items INTO ls_item WHERE hu IN lr_exidv.
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
         input  = ls_item-hu
       IMPORTING
         output = ls_item-hu.
     MODIFY gt_batch_items FROM ls_item INDEX sy-tabix.
   ENDLOOP.

* Call RFC to update delivery packing
   CALL FUNCTION 'ZLE_UPDATE_PACKING' DESTINATION lv_dest
     IMPORTING
       message     = ls_message
       return_code = lv_subrc
     TABLES
       items       = gt_batch_items
       create_hus  = lt_packhus
       delete_hus  = lt_pickhus.

   IF lv_subrc IS NOT INITIAL.
*   Return error to calling application
     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
       EXPORTING
         textid  = /iwbep/cx_mgw_busi_exception=>business_error
         message = ls_message.
   ENDIF.

ENDMETHOD.

Regards,

Ryan Crosby

former_member225463
Participant
0 Kudos

Hi Ryan,

I have found one blog where you no nned to write so much of code in changeset begin and change set end.

Just write your logic in the create, update as usual and write the code in changeset begin and change set end. as EXIT and COMMIT WORK respectively.

Its working for me.

Best Regards,

Vikash

Ryan-Crosby
Active Contributor
0 Kudos

Hi Vikash,

Ok, that must have been your other message where you explained - I wasn't sure which came first.  My example was a bit different as I tried to explain however because I was bundling all of the separate transactions into one LUW on the back end - hence all of the extra code within the methods.  Glad that it is working for you now

Regards,

Ryan Crosby

Answers (1)

Answers (1)

former_member225463
Participant
0 Kudos

Hi All,

Got the Solution for the Batch Creation. We have to write the following code in

/IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN :

method /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN.

   EXIT.

   endmethod.


and in /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_END


METHOD /iwbep/if_mgw_core_srv_runtime~changeset_end.

     COMMIT WORK.

   ENDMETHOD.


Thanks for the inputs and help.


Regards,

Vikash