10-17-2011 12:19 PM
Hi Experts,
Is there a way to add a default line items (material list) on the Quotation/Sales Order creation based on the Incoterms, I was able to do that but I have to hardcode some data since I don't know where to get it. Here are my code:
check vbkd-inco1 is not initial.
select
makt~matnr
makt~maktx
zmilssd01~etenr
into corresponding fields of table it_mara
from zmilssd01
inner join makt on maktmatnr eq zmilssd01matnr
where spart eq vbak-spart
and inco1 eq vbkd-inco1.
if zzinco1 ne vbkd-inco1.
refresh: xvbap, ivbap, xvbep, ivbep.
clear: xvbap, ivbap, xvbep, ivbep.
endif.
clear p_ctr.
sort it_mara by etenr.
if it_mara[] is not initial and xvbap[] is initial..
loop at it_mara.
clear vbap.
add 1 to p_ctr.
vbap-mandt = vbak-mandt.
vbap-vbeln = vbak-vbeln.
HARD-CODED PART *************************************
vbap-matkl = 'FFS'.
vbap-pstyv = 'AGX'.
vbap-zieme = 'AU'.
vbap-umziz = 1.
vbap-umzin = 1.
vbap-meins = 'AU'.
vbap-spart = 'SE'.
vbap-gsber = 'C9S3'.
vbap-netwr = 0.
vbap-waerk = 'MYR'.
vbap-antlf = 9.
vbap-vrkme = 'AU'.
vbap-gewei = 'KG'.
vbap-erlre = 'B'.
vbap-werks = 'C902'.
vbap-vstel = 'FFS1'.
vbap-erdat = sy-datum.
vbap-ernam = sy-uname.
vbap-erzet = sy-uzeit.
vbap-umvkz = 1.
vbap-umvkn = 1.
HARD-CODED PART *************************************
p_posnr = p_ctr * 10.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_posnr
importing
output = vbap-posnr.
vbap-matnr = it_mara-matnr.
vbap-matwa = it_mara-matnr.
vbap-arktx = it_mara-maktx.
move vbap to xvbap.
xvbap-updkz = 'I'.
append xvbap.
ivbap-posnr = vbap-posnr.
ivbap-tabix = p_ctr.
append ivbap.
endloop.
zzinco1 = vbkd-inco1.
endif.
I just want to know where to get the data of the hardcoded part given only the material number (just like on the VA21/VA01 item screen where you only need to input material number and the XVAP/IVBAP table was auto populated.)
By the way, I used exit of MV45AFZZ form userexit_move_field_to_vbak to input my code.
Thanks,
Eric
10-18-2011 3:14 AM
Hi Roderick
I just want to know where to get the data of the hardcoded part given only the material number (just like on the VA21/VA01 item screen where you only need to input material number and the XVAP/IVBAP table was auto populated
I did not get this. It looks like you are getting materials from custom table depending on incoterms. Here do you want to add line items in va01?. If that is a requirement you have to use standard includes in your custom report.
Regards,
Madhu.
10-18-2011 3:14 AM
Hi Roderick
I just want to know where to get the data of the hardcoded part given only the material number (just like on the VA21/VA01 item screen where you only need to input material number and the XVAP/IVBAP table was auto populated
I did not get this. It looks like you are getting materials from custom table depending on incoterms. Here do you want to add line items in va01?. If that is a requirement you have to use standard includes in your custom report.
Regards,
Madhu.
10-18-2011 3:31 AM
Hi Madhu,
Sorry for the confusion but yes the material is coming from a custom table based on incoterms. What I want is for those material to be added to VA01 line items.
As of now I copied the material to XVBAP and IVBAP then add some required hardcoded data (copied from the data if I manually input the material in VA01 line item).
Anyway, can you provide me the includes that you are talking to include those material from the custom table to VA01 line item.
Many thanks,
Eric
10-18-2011 4:05 AM
Thanks for the help, I already figured out the solution:
DATA: li_material TYPE STANDARD TABLE OF zmilssd01,
lwa_material TYPE zmilssd01.
REFRESH li_material. CLEAR lwa_material.
SELECT * FROM zmilssd01 INTO TABLE li_material
WHERE spart EQ vbak-spart
AND inco1 EQ vbkd-inco1.
IF sy-subrc IS INITIAL.
SORT li_material BY etenr.
LOOP AT li_material INTO lwa_material.
PERFORM vbap_unterlegen(sapfv45p).
PERFORM vbep_unterlegen(sapfv45e).
vbap-matnr = lwa_material-matnr. "Material number to be inserted
vbap-posnr = lwa_material-etenr * 10.
vbap-zmeng = '1.000'. "Target Quantity
READ TABLE XVBAP with key matnr = lwa_material-matnr
posnr = vbap-posnr.
if sy-subrc is INITIAL.
CONTINUE.
ENDIF.
PERFORM vbap-matnr_pruefen(sapfv45p) USING charx sy-subrc.
PERFORM vbap-pstyv_pruefen(sapfv45p).
PERFORM vbap_fuellen(sapfv45p).
PERFORM vbap-matnr_null_pruefen(sapfv45p).
PERFORM vbep-wmeng_setzen(sapfv45e).
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 vbap-vrkme_pruefen(sapfv45p)
USING charx
CHANGING sy-subrc sy-msgid sy-msgty sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
PERFORM vbap_bearbeiten(sapfv45p).
PERFORM vbep_fuellen(sapfv45e).
PERFORM vbep-wmeng_pruefen(sapfv45e)
USING charx
chary
CHANGING sy-subrc sy-msgid sy-msgty sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
PERFORM vbep_bearbeiten(sapfv45e).
ENDLOOP.
PERFORM vbap_bearbeiten_ende(sapfv45p).
ENDIF.
Thanks a lot!
10-18-2011 4:19 AM
Hi Rick,
Little late reply. These are routines you have to handle.I tried this for sales order.All the best.
Regards,
Madhu.
10-18-2011 10:55 AM
Hi Mudhu,
Is there any other way to do it? My code is ok, it can populate the line item automatically but the incoterms is set to default if I change it. Therefore I can't change the incoterms.
I think it has something to do with this routine: perform vbap_unterlegen(sapfv45p).
Thanks,
Eric
10-19-2011 7:28 AM
10-19-2011 11:50 AM
Hi Madhu,
My problem is after my code in the user exit (please see below) was executed the table VBKD is refresh (or set to default):
if sy-tcode eq 'VA21'.
check vbkd-inco1 is not initial.
select * from zmilssd01 into table it_mara
where spart eq vbak-spart
and inco1 eq vbkd-inco1.
if zzinco1 ne vbkd-inco1.
refresh: xvbap, ivbap, xvbep, ivbep, ivbep1.
clear: xvbap, ivbap, xvbep, ivbep, ivbep1.
endif.
clear lv_tabix.
sort it_mara by etenr.
if it_mara[] is not initial.
check xvbap[] is initial.
loop at it_mara into wa_mara.
add 1 to lv_tabix.
clear: vbap.
perform vbap_unterlegen(sapfv45p).
perform vbep_unterlegen(sapfv45e).
vbap-matnr = wa_mara-matnr.
lv_posnr = lv_tabix * 10.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_posnr
importing
output = vbap-posnr.
perform vbap-matnr_pruefen(sapfv45p) using charx sy-subrc.
perform vbap-pstyv_pruefen(sapfv45p).
perform vbap_fuellen(sapfv45p).
perform vbap-matnr_null_pruefen(sapfv45p).
perform vbep-wmeng_setzen(sapfv45e).
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 vbap_bearbeiten(sapfv45p).
perform vbep_fuellen(sapfv45e).
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 vbep_bearbeiten(sapfv45e).
endloop.
perform vbap_bearbeiten_ende(sapfv45p).
endif.
zzinco1 = vbkd-inco1.
endif.
This is I think because of the routine that being called after the user exit:
perform userexit_move_field_to_vbak(sapmv45a).
perform vbkd_fuellen.
The routine perform vbkd_fuellen reset the VBKD.
Is there another way or code that you can provide to get the same result?
Many thanks,
Eric