Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Roll back on Custom table Update

Former Member
0 Likes
6,788

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

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

7 REPLIES 7
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,545

check this


CHECK s_vbeln[] IS NOT INITIAL.
DELETE pt_input WHERE vbeln NOT IN s_vbeln.
SORT pt_input BY vbeln.
LOOP AT pt_input ASSIGNING <lfs_input>.
  AT END OF vbeln.
    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.
      "perform enqueue
      IF sy-subrc EQ 0.
        DELETE FROM z_data_buffer WHERE vbeln = <lfs_input>-vbeln.
        IF sy-subrc NE 0.
          ROLLBACK WORK.
         " perform dequeue
        ELSE.
          MODIFY z_data_buffer FROM TABLE lt_backlog.
          IF sy-subrc NE 0.
            ROLLBACK WORK.
             " perform dequeue
          ELSE.
            COMMIT WORK.
             " perform dequeue
          ENDIF.
        ENDIF.
       REFRESH lt_log.
      ENDIF.
    ENDIF.
  ENDAT.
ENDLOOP.

Read only

Former Member
0 Likes
1,545

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

In addition to Keshav's points, LOOP AT ...WHERE./AT END OF is problematic.

Rob

Read only

0 Likes
1,545

Hi Rob,

Its currently working fine with the current code and didn't see any issues so far.

Read only

0 Likes
1,545

I said it's problematic.

It may work for a while and then stop working.

Rob

Read only

0 Likes
1,545

And I thought you were asking the question because the code is not working.

Rob

Read only

0 Likes
1,545

HI Rob,

I was checki ng if there is a better way of doing it and also making sure that it is good.

So far no issues and will also look at your suggestion. Appreciate your feedback.

Read only

0 Likes
1,545

Check the extended syntax check message for "using control breaks in a loop with where". Also there is no need of a control break in your code as you are only using vbeln in your code. Just delete the adjacent duplicates and loop it.

Kesav