Anda di halaman 1dari 5

Add line items automatically in VA01

Add a line item automatically when a user clicks on save to sales order in VA01

 Limitations:
 Expectations:
 Approach Followed:
 Code:
 Execution Snapshots:
 Advantages:
 Use Cases:

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.

o The only required input should be material number and quantity.

o Item number ( VBAP-POSNR ) should be auto determined.
o Item category and other item details should be read from master data / configuration tables.
o Schedule line data to be determined as for a normal manually added item.
o Pricing should be determined automatically.
o Any code written in user exits should be triggered for this item as well.

Approach Followed:

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).
Execution Snapshots:
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.


 The item addition can be done on the basis of certain conditions and multiple items can be
added by placing this code in a loop.
 Since all standard performs are called to fill the data , even the different user-exits for item
will be triggered if implemented for the item.
 By adding a check for call_bapi equal to ‘X’ and TRTYP eq ‘H’ , this code can be executed
from Create Sales Order BAPI also.
 Item number is determined automatically.
 Item category , item substitution, scheduling , availability check and pricing is done by
standard performs.
 If the requirement is to add items just as the user enters the header details, that can be done
with minimum code changes.

Use Cases:
This can be used in certain business scenarios like:

 Suppose based on the customer some free items need to be added to sales order. In such
case the item ( material ) and customer combination can be stored in a custom table. It can
be then read from and populated automatically.

 It can also be used if some default material has to be added to all sales orders being


 The above code can also be written in user


 Sometime the requirement can be to delete a line item internally using code.Below is the
code for this

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).


Help Taken from below SCN posts:

Re: New line in SD order

Re: Adding default line items on VA01/VA21 based on Incoterms


Sensitive data has been blurred in the snapshots.

Feel free to provide feedback and valuable comments.

 ~ Tanmay