2011 Nov 23 5:42 AM
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
2011 Nov 23 6:07 AM
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.
2011 Nov 23 3:11 PM
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
2011 Nov 29 7:01 PM
Hi Rob,
Its currently working fine with the current code and didn't see any issues so far.
2011 Nov 29 7:03 PM
I said it's problematic.
It may work for a while and then stop working.
Rob
2011 Nov 29 7:05 PM
And I thought you were asking the question because the code is not working.
Rob
2011 Nov 29 7:18 PM
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.
2011 Nov 30 5:21 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |