2010 Mar 27 11:11 AM
Hi,
I have a requirement where we need to add new line item when ever the net weight is less than 50 KG.
Effected Transaction will be VA01, VA02.
Currently I have implemented the logic in below subroutine:
Perform userexit_save_document_prepare.
Using this perform new item is getting added to the document but the Pricing is not determined for the newly added item.
Please suggest, if you have came across such situation or scenario.
Thanks in advance.
Kind Regards.
2010 Mar 28 6:21 AM
Hi Wasim,
You will need to add the pricing line also in your user exit logic as SAP will not generate the pricing line automatically.
To do that use the exit USEREXIT_NEW_PRICING_VBAP in include MV45AFZB and look at adding a new line to xkomv.
Regards,
Neil.
2010 Mar 28 6:21 AM
Hi Wasim,
You will need to add the pricing line also in your user exit logic as SAP will not generate the pricing line automatically.
To do that use the exit USEREXIT_NEW_PRICING_VBAP in include MV45AFZB and look at adding a new line to xkomv.
Regards,
Neil.
2010 Mar 28 10:33 AM
Hi Neil,
Thanks for the reply.
If possible can you please let me know, what important values we need to fill in the structure xkomv and also do we need to fill KOMP.
I have tried deleting the line automatically depending upon condition by updating the field XVBAP-UPDKZ = 'D'.
But still it is not working and throwing dump message via SAP mail.
If u have some sample code or any idea.
Please share.
Thanks.
Regards.
2010 Mar 29 6:17 AM
hi Wasim,
try filling the following fields in XKOMV :
KPOSN (next available item number)- check tabke KONPfor next available item number for that sales order/condition number
STUNR (seq no. from 1...99)
ZAEHK (00,01,02 ..)
KSCHL -(condition type)
KAWRT - value
WAERS- currency
KMEIN- cond_unit eq 'EA'.
KPEIN - per (1).
It should work without filling in KOMP.
Regards,
Neil.
2010 Mar 29 7:59 AM
In addition to these fields you have to fill values to following fields also
knumv - Extract from vbak-knumv,
updkz - 'I' to insert records
Vinod
2010 Mar 31 2:59 PM
Hi Neil & Vinod,
Thanks for the response and your input. Finally I am able to complete the developement and got the OK approval from the client.
Below I am adding code for reference.
In Userexit: SAVE_DOCUMENT_PREPARE
This include is implemented to check the sales order line items.
Whenever during creation or change of Sales order line item
If Netweight is less than 50 KG then create a new line item
If Netweight is more than 50 KG then created line item must be removed
CONSTANTS
CONSTANTS:
kc_va01 TYPE sy-tcode VALUE 'VA01',
kc_va02 TYPE sy-tcode VALUE 'VA02',
kc_zva01 TYPE sy-tcode VALUE 'ZVA01_STRECKE',
kc_vc01n TYPE sy-tcode VALUE 'VC01N',
kc_kdkg1 TYPE kna1-kdkg1 VALUE '01',
kc_matnr TYPE mara-matnr VALUE '000004014517999999',
kc_ntgew TYPE vbap-ntgew VALUE '50.000',
kc_kg TYPE vbap-gewei VALUE 'KG',
kc_qty TYPE vbap-kwmeng VALUE '1.000',
kc_vrkme TYPE vbap-vrkme VALUE 'VAR',
kc_we TYPE knvp-parvw VALUE 'WE',
kc_de TYPE mlan-aland VALUE 'DE',
kc_x TYPE char01 VALUE 'X'.
Data field
DATA:
zc_auart TYPE vbak-auart,
zc_kunnr TYPE kna1-kunnr,
zn_ntsum TYPE vbap-ntgew,
zn_ntgew TYPE vbap-ntgew,
zc_gewei TYPE vbap-gewei,
zc_posnr TYPE vbap-posnr,
zc_taxm1 TYPE mlan-taxm1,
zc_spart TYPE mara-spart,
zc_flag TYPE char01,
zc_err TYPE char01.
Work area
DATA:
wa_bapi_head TYPE bapisdhead,
wa_bapi_item_in TYPE bapiitemin,
wa_bapi_item_out TYPE bapiitemex,
wa_bapi_partner TYPE bapipartnr,
wa_bapi_bapicond TYPE bapicond,
wa_return TYPE bapireturn.
Internal tables
DATA:
it_bapi_item_in TYPE STANDARD TABLE OF bapiitemin,
it_bapi_partner TYPE STANDARD TABLE OF bapipartnr,
it_bapi_item_out TYPE STANDARD TABLE OF bapiitemex,
it_bapi_item_cond TYPE STANDARD TABLE OF bapicond,
it_bapi_return TYPE STANDARD TABLE OF bapiret2.
This part of code should work only for the following transaction
CHECK sy-tcode EQ kc_va01
OR sy-tcode EQ kc_va02
OR sy-tcode EQ kc_zva01
OR sy-tcode EQ kc_vc01n.
If said Doc type is found in table then dont proceed further
SELECT SINGLE auart
INTO zc_auart
FROM zsd_excl_auart
WHERE auart EQ vbak-auart
AND del_flag EQ space.
CHECK sy-subrc NE 0.
If Customer Condition Group1 equals to 01 then dont proceed further
SELECT SINGLE kunnr
INTO zc_kunnr
FROM kna1
WHERE kunnr EQ vbak-kunnr
AND kdkg1 EQ kc_kdkg1.
CHECK sy-subrc NE 0.
Now sum the netweight of each line items
LOOP AT xvbap.
** Get position number
zc_posnr = xvbap-posnr + 10.
** If record is marked for deletion then ignore
IF xvbap-updkz EQ updkz_delete
OR xvbap-updkz EQ updkz_mark_del.
CONTINUE.
ENDIF.
check if material already exist
IF xvbap-matnr = kc_matnr.
zc_flag = kc_x.
CONTINUE.
ENDIF.
Check conversion unit
IF xvbap-gewei EQ kc_kg.
zn_ntgew = xvbap-ntgew.
ELSE.
Perform unit conversion (Kept for future use)
zn_ntgew = xvbap-ntgew.
ENDIF.
sum the total net weight
ADD zn_ntgew TO zn_ntsum.
ENDLOOP.
Check condition
If net weight is less than 51 KG then add new line
IF zn_ntsum LE kc_ntgew
AND zc_flag IS INITIAL.
*** Get Division
SELECT SINGLE spart
FROM mara
INTO zc_spart
WHERE matnr EQ kc_matnr.
IF sy-subrc EQ 0.
*** Get tax code
SELECT SINGLE taxm1
FROM mlan
INTO zc_taxm1
WHERE matnr EQ kc_matnr
AND aland EQ kc_de.
IF sy-subrc EQ 0.
ENDIF.
ENDIF.
*** Header
MOVE:
vbak-auart TO wa_bapi_head-doc_type,
vbak-vkorg TO wa_bapi_head-sales_org,
vbak-vtweg TO wa_bapi_head-distr_chan,
vbak-spart TO wa_bapi_head-division.
*** Item
MOVE:
zc_posnr TO wa_bapi_item_in-itm_number,
kc_matnr TO wa_bapi_item_in-material,
kc_qty TO wa_bapi_item_in-req_qty,
kc_vrkme TO wa_bapi_item_in-sales_unit.
APPEND wa_bapi_item_in TO it_bapi_item_in.
*** Partner
MOVE:
kc_we TO wa_bapi_partner-partn_role,
vbak-kunnr TO wa_bapi_partner-partn_numb.
APPEND wa_bapi_partner TO it_bapi_partner.
*** Call BAPI to retrieve Material and Condition information
CALL FUNCTION 'BAPI_SALESORDER_SIMULATE'
DESTINATION 'NONE'
EXPORTING
order_header_in = wa_bapi_head
IMPORTING
return = wa_return
TABLES
order_items_in = it_bapi_item_in[]
order_partners = it_bapi_partner[]
order_items_out = it_bapi_item_out[]
order_condition_ex = it_bapi_item_cond[]
messagetable = it_bapi_return[].
*** No need to check return table
*** It is kept for future use
*** Fill item table
CLEAR xvbap.
LOOP AT it_bapi_item_out
INTO wa_bapi_item_out.
xvbap-updkz = updkz_new.
xvbap-vbeln = vbak-vbeln.
xvbap-posnr = zc_posnr.
xvbap-matnr = kc_matnr.
xvbap-matwa = xvbap-matnr.
xvbap-pmatn = xvbap-matnr.
xvbap-matkl = wa_bapi_item_out-matl_group.
xvbap-arktx = wa_bapi_item_out-short_text.
xvbap-pstyv = wa_bapi_item_out-item_categ.
xvbap-prodh = wa_bapi_item_out-prod_hier.
xvbap-spart = zc_spart.
xvbap-vstel = wa_bapi_item_out-ship_point.
xvbap-werks = wa_bapi_item_out-plant.
xvbap-kwmeng = wa_bapi_item_out-qty_req_dt.
xvbap-vrkme = wa_bapi_item_out-sales_unit.
xvbap-netwr = wa_bapi_item_out-net_value.
xvbap-waerk = wa_bapi_item_out-currency.
xvbap-wklnd = kc_de.
xvbap-taxm1 = zc_taxm1.
xvbap-sktof = kc_x.
APPEND xvbap TO xvbap.
ENDLOOP. "LOOP AT it_bapi_item_out
*** Fill condition table
LOOP AT it_bapi_item_cond
INTO wa_bapi_bapicond.
CLEAR xkomv.
xkomv-updkz = updkz_new.
xkomv-knumv = vbak-knumv.
xkomv-kposn = xvbap-posnr.
xkomv-stunr = wa_bapi_bapicond-cond_st_no.
xkomv-zaehk = wa_bapi_bapicond-cond_count.
xkomv-kschl = wa_bapi_bapicond-cond_type.
xkomv-kntyp = wa_bapi_bapicond-condtype.
xkomv-kumza = wa_bapi_bapicond-numconvert.
xkomv-kumne = wa_bapi_bapicond-denominato.
xkomv-kmein = wa_bapi_bapicond-cond_unit.
xkomv-waers = wa_bapi_bapicond-currency.
APPEND xkomv TO xkomv.
ENDLOOP. "LOOP AT it_bapi_item_cond
ENDIF. "IF zn_ntsum LE kc_ntgew
If net weight is greater than 50 KG then remove auto created line item
IF zn_ntsum GT kc_ntgew
AND zc_flag EQ kc_x.
*** Check entry in table VBAP
CLEAR xvbap.
READ TABLE xvbap INTO xvbap
WITH KEY matnr = kc_matnr.
IF sy-subrc EQ 0.
xvbap-updkz = updkz_delete.
MODIFY xvbap
TRANSPORTING updkz
WHERE matnr = kc_matnr.
CLEAR yvbap.
READ TABLE yvbap INTO yvbap
WITH KEY matnr = xvbap-matnr.
IF sy-subrc EQ 0.
yvbap-updkz = updkz_delete.
MODIFY yvbap
TRANSPORTING updkz
WHERE matnr = kc_matnr.
ELSE.
APPEND xvbap TO yvbap.
ENDIF.
DELETE xkomv
WHERE kposn = xvbap-posnr.
ENDIF.
ENDIF. "IF zn_ntsum GT kc_ntgew