Skip to Content
0
Former Member
Nov 23, 2011 at 05:42 AM

Roll back on Custom table Update

5223 Views

Please suggest if the below update and Rollback on the custom table is accurate. We ran into some issues with missing data

when the earier codewas deleting all the sales orders in custom table and then updating sales order.

Background of the program:

I have a custom report in which i capture changes done to a sales order based on standard change log tables CDHDR.

Changes can be of 2 types:

1) Change to the existing Sales order item

2) Creation of new line items within a sales order

Program flow

1) Capture the Sales Orders changes in an internal table and from step 2 process one sales order at a time.

2) Delete a Sales order from custom table for which new changes are found

3) Check the Lock on this Sales Order. (This has 3 scenarios)

a)If no Lock exists on the sales order, then update the buffer table. Result: Buffer table is updated successfully.

b)If no Lock exists on the sales order, then update the buffer table. Result: If for some reason the update fails,

Rollback the Deletion.

c)If Lock exists on the sales order, then Roll back the deletion.

Code

CHECK  s_vbeln[] IS NOT INITIAL.   " All the Sales orders are captured in S_VBELN.

  LOOP AT s_vbeln.

    LOOP AT pt_input ASSIGNING <lfs_input> WHERE vbeln = s_vbeln-low.

      AT END OF vbeln.

        DELETE FROM z_data_buffer WHERE vbeln = s_vbeln-low.

*************************This Section of Code gathers all the data for the sales order ito internal table [lt_log] *********
*************************The custom table z_data_buffer is updated from this internal table [lt_log]**********************

         READ TABLE lt_log_details INTO lx_log_details
               WITH KEY vbeln = <lfs_input>-vbeln TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
            LOOP AT lt_log_details INTO lx_log_details
                                FROM sy-tabix.
            IF lx_log_details-vbeln = <lfs_input>-vbeln.
              APPEND lx_log_details TO lt_log.
            ELSE.
              EXIT.
            ENDIF.
          ENDLOOP.
*********************************************************************************************************************************************


*** Locks the Sales order in custom table z_data_buffer
        CALL FUNCTION 'ENQUEUE_EZ_VBELN3'
          EXPORTING
            mode_z_data_buffer = 'E'
            mandt                 = sy-mandt
            vbeln                 = <lfs_input>-vbeln
          EXCEPTIONS
            foreign_lock          = 1
            system_failure        = 2
            OTHERS                = 3.

        IF sy-subrc <> 0.
*--Roll back the Deletion Done.
             ROLLBACK WORK.
         ELSE.
                 MODIFY z_data_buffer FROM TABLE lt_backlog.      
                    IF sy-subrc <>  0.
                         ROLLBACK WORK.
                    ENDIF.
        ENDIF.

        CALL FUNCTION 'DEQUEUE_EZ_VBELN3'
          EXPORTING
            mode_ztps_data_buffer = 'E'
            mandt                 = sy-mandt
            vbeln                 = <lfs_input>-vbeln.

        REFRESH lt_log.
      ENDAT.
    ENDLOOP.

  ENDLOOP.

<Added Code tags>

Edited by: Suhas Saha on Nov 23, 2011 12:03 PM