Restrict/Stop User From Deleting Line Items Of Sales Order Through Transaction (T-Code) VA02.




Requirement is to Restrict / Stop User From Deleting Line Items Of Sales Order Through Transaction (T-Code) VA02. Say, user has created a sales order with say 2 line items via VA01 transaction.





Save it. A new sales order gets created. In our case the sales order number is 3679.


Now what user wants is he/she should not be able to delete both the line items from the sales order however if he/she wants to add a third line item or wants to delete a new line item which was not a part of sales order while creating he/she should be allowed to do so.


So to achieve this requirement we will have to do an enhancement in Include Program MV45AFZB. Here you will find a user exit, USEREXIT_CHECK_XVBAP_FOR_DELET - This is the user exit where we will have to do the enhancement.


SAMPLE CODE:


DATA: v_lines TYPE i,
             wa_ivbap LIKE LINE OF ivbap,
             wa_xvbap LIKE LINE OF xvbap,
             v_vbeln TYPE vbeln.

IF sy-tcode = 'VA02' OR sy-tcode = 'VA42'.
        IF sy-ucomm EQ 'YES'.

             READ TABLE xvbap INTO wa_xvbap INDEX 1.

             LOOP AT ivbap[] INTO wa_ivbap WHERE selkz = 'X'.

                      v_lines = sy-tabix.

                      SELECT SINGLE vbeln INTO v_vbeln FROM vbap
                                      WHERE vbeln = wa_xvbap-vbeln
                                           AND posnr = wa_ivbap-posnr.

                               IF sy-subrc EQ 0.
                                      CLEAR wa_ivbap-selkz.
                                      MODIFY ivbap FROM wa_ivbap TRANSPORTING selkz.
                                      us_exit = charx.
                               ELSE.
                                      EXIT.
                               ENDIF.

             ENDLOOP.

        ENDIF.
ENDIF.



This code will restrict the user to delete line items from the sales order in transaction VA02. But in case if there is a requirement where the user wants to delete the sales order completely, the above code will create issue.


In the above screenshot you can see there are two ways of deleting.
  • Delete the complete Sales Order (In the above figure the top Delete highlighted).
  • Select the line item and delete it By using a delete icon given just below the Line Items table Control.


The above code will get executed for both the cases. However when the user goes to delete the complete sales order, it won't allow him/her to do so. So what we will have to do is change the code to differentiate between both the DELETE options.


FCODE is a variable to differentiate between the two options. In debugging you can find the difference.

  • Fcode for the 1st Option is 'LOES'. (i.e. When user wants to delete the complete sales order).
  • FCODE for the 2nd option is 'POLO'.


So we will have to Enhance/Revise the code as below to achieve the requirement:


REVISED CODE:


DATA: v_lines TYPE i,
             wa_ivbap LIKE LINE OF ivbap,
             wa_xvbap LIKE LINE OF xvbap,
             v_vbeln TYPE vbeln.

IF sy-tcode = 'VA02' OR sy-tcode = 'VA42'.
        IF sy-ucomm EQ 'YES' AND fcode = 'POLO'.

             READ TABLE xvbap INTO wa_xvbap INDEX 1.

             LOOP AT ivbap[] INTO wa_ivbap WHERE selkz = 'X'.

                      v_lines = sy-tabix.

                      SELECT SINGLE vbeln INTO v_vbeln FROM vbap
                                      WHERE vbeln = wa_xvbap-vbeln
                                           AND posnr = wa_ivbap-posnr.

                               IF sy-subrc EQ 0.
                                      CLEAR wa_ivbap-selkz.
                                      MODIFY ivbap FROM wa_ivbap TRANSPORTING selkz.
                                      us_exit = charx.
                               ELSE.
                                      EXIT.
                               ENDIF.

             ENDLOOP.

        ENDIF.
ENDIF.



So now user will be restricted to delete line items from the sales order in transaction VA02 but simultaneously if he/she wants to delete the complete sales order he/she will be able to do so.


Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.