Add a line item automatically when a user clicks on save to sales order in VA01
There is a long list of user-exits present in SD module that facilitate customization to the standard process. However, no User exits , Customer Exits or BADI's have been provided which can add an item automatically to Sales Order.
To add an item manually in a SO the only input required from the user is the material number and quantity. Rest all the information is determined automatically by the standard code.The automatic addition of item should take care of below points.
We will be using USEREXIT_MOVE_FIELD_TO_VBAK to write our code. This userexit is present in include MV45AFZZ of program SAPMV45A.
This user exit is used to transfer some fields to the sales order header.However , we will write our code in this exit to add an item during save.
*--Check if the user has pressed SAVE button
IF sy-ucomm EQ 'SICH'.
*--Read table XVBAP to check if the material is not already added
READ TABLE xvbap INTO ls_xvbap WITH KEY matnr = 000000000000240000
updkz = 'I'.
IF sy-subrc NE 0.
CLEAR: vbap.
*--Initialize workareas for VBAP and VBEP
PERFORM vbap_unterlegen(sapfv45p).
PERFORM vbep_unterlegen(sapfv45e).
*--Populate material number and quantity
vbap-matnr = ‘000000000000240000’.
rv45a-kwmeng = 1000.
*--Call standard performs to populate material details.
*--Perform for material validations and details
PERFORM vbap-matnr_pruefen(sapfv45p) USING charx sy-subrc.
*--Perform for item category determination. This will take care of substitution items if any for this material.
PERFORM vbap-pstyv_pruefen(sapfv45p).
*--Perform for filling VBAP with default values from configuration and master tables
PERFORM vbap_fuellen(sapfv45p).
PERFORM vbap-matnr_null_pruefen(sapfv45p).
PERFORM vbep-wmeng_setzen(sapfv45e).
*--Perform to check sales unit
PERFORM vbap-vrkme_pruefen(sapfv45p) USING charx
CHANGING sy-subrc sy-msgid sy-msgty sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*--Perform to update VBAP values
PERFORM vbap_bearbeiten(sapfv45p).
*--Perform for filling VBEP with default values. This will take care of schedule lines of the item
PERFORM vbep_fuellen(sapfv45e).
*--Perform to check quantity
PERFORM vbep-wmeng_pruefen(sapfv45e) USING charx
CHANGING sy-subrc sy-msgid sy-msgty sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*--Perform to update VBEP values
PERFORM vbep_bearbeiten(sapfv45e).
*--Perform to fill conditions and pricing data
PERFORM vbap_bearbeiten_ende(sapfv45p).
ENDIF.
ENDIF.
Go to VA01 to create a sales order. Enter sold to party and other details. Add 1 item manually.
Click on save, item 240000 should be item as next item ( POSNR 20 ).
Check the SO in VA03. Here the item 20 is added successfully.
Check line item schedule line data:
Check Pricing data:
Thus , we see in this way a line item can be added automatically in the sales order.
This can be used in certain business scenarios like:
EDIT:
Suppose we want to delete the item number 20.
ivbap-selkz = 'X'.
MODIFY ivbap TRANSPORTING selkz WHERE posnr = '0020'.
IF sy-subrc EQ 0.
PERFORM xvbap_loeschen_loop(sapfv45p).
ENDIF.
Help Taken from below SCN posts:
Re: Adding default line items on VA01/VA21 based on Incoterms
Note:
Sensitive data has been blurred in the snapshots.
Feel free to provide feedback and valuable comments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |