2008 Aug 15 8:42 PM
Hi All,
I am trying to create the Purchase order based on the user selection and it is creating fine with one line item. But if I have same vendor with 2 or more line items, the PO is having only one line item. The following is the code I have. Can someone please help me where I am doing wrong.
Thanks,
Veni.
LOOP AT gt2_zcoop INTO gs_zcoop1.
IF gs_zcoop1-coopind = 'K'.
AT NEW kunnr.
MOVE 'Y' TO lv_flg.
ENDAT.
IF lv_flg EQ 'Y'.
PERFORM pheaderdata.
CLEAR lv_flg.
ENDIF.
PERFORM pitemdata.
APPEND gs_zcoop1 TO gt3_zcoop.
CLEAR gs_zcoop1.
AT END OF kunnr.
PERFORM call_pofunction.
PERFORM update_po_gt_zcoop.
it_cmpo-znum = po_number.
APPEND it_cmpo.
PERFORM errorcheckandcommit.
CLEAR chbox.
REFRESH pitem.
REFRESH pitemx.
REFRESH plt_schedules_in.
REFRESH plt_schedules_inx.
REFRESH poaccount.
REFRESH poaccountx.
REFRESH potextheader.
REFRESH potextitem.
lv_npoitem = 10.
ENDAT.
ENDIF.
ENDLOOP.
FORM pheaderdata.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_zcoop1-kunnr
IMPORTING
output = lv_nvendor.
header data
pheader-comp_code = '1100'.
pheader-doc_type = 'SE'.
pheader-vendor = lv_nvendor.
pheader-purch_org = 'P000'.
pheader-pur_group = '006'.
pheader-our_ref = gs_zcoop1-coopref.
pheaderx-comp_code = 'X'.
pheaderx-doc_type = 'X'.
pheaderx-vendor = 'X'.
pheaderx-purch_org = 'X'.
pheaderx-pur_group = 'X'.
pheaderx-our_ref = 'X'.
CLEAR lv_nvendor.
ENDFORM. " pheaderdata
&----
*& Form pitemdata
&----
text
----
--> p1 text
<-- p2 text
----
FORM pitemdata.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_poitem
IMPORTING
output = lv_npoitem.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_aaord
IMPORTING
output = lv_naaord.
pitem-po_item = lv_npoitem.
pitem-short_text = gs_zcoop1-prdct.
pitem-matl_group = '200200001'.
pitem-quantity = gs_zcoop1-iamount.
pitem-po_unit = 'EA'.
pitem-net_price = '1.00'.
pitem-acctasscat = 'F'.
pitem-plant = 'SOAH'.
pitem-gr_basediv = 'X'.
APPEND pitem.
pitemx-po_item = lv_npoitem.
pitemx-po_itemx = 'X'.
pitemx-short_text = 'X'.
pitemx-matl_group = 'X'.
pitemx-quantity = 'X'.
pitemx-po_unit = 'X'.
pitemx-net_price = 'X'.
pitemx-acctasscat = 'X'.
pitemx-plant = 'X'.
pitemx-gr_basediv = 'X'.
APPEND pitemx.
*Fill schedule lines
plt_schedules_in-po_item = lv_npoitem.
plt_schedules_in-sched_line = '0001'.
plt_schedules_in-delivery_date = '03/20/2008'.
plt_schedules_in-quantity = gs_zcoop1-iamount.
APPEND plt_schedules_in.
*Fill schedule line flags
plt_schedules_inx-po_item = lv_npoitem.
plt_schedules_inx-sched_line = '0001'.
plt_schedules_inx-po_itemx = 'X'.
plt_schedules_inx-sched_linex = 'X'.
plt_schedules_inx-delivery_date = 'X'.
plt_schedules_inx-quantity = 'X'.
APPEND plt_schedules_inx.
poaccount-po_item = lv_npoitem.
poaccount-serial_no = '01'.
poaccount-quantity = gs_zcoop1-iamount.
poaccount-gl_account = '0000603000'.
poaccount-orderid = lv_naaord.
APPEND poaccount.
poaccountx-po_item = lv_npoitem.
poaccountx-po_itemx = 'X'.
poaccountx-serial_no = '01'.
poaccountx-serial_nox = 'X'.
poaccountx-quantity = 'X'.
poaccountx-gl_account = 'X'.
poaccountx-orderid = 'X'.
APPEND poaccountx.
potextheader-po_item = lv_npoitem.
potextheader-text_line = gs_zcoop1-reason.
APPEND potextheader.
potextitem-po_item = lv_npoitem.
potextitem-text_line = 'Item Text'.
APPEND potextitem.
lv_npoitem = lv_npoitem + 10.
ENDFORM. " pheaderdata
&----
*& Form call_pofunction
&----
text
----
--> p1 text
<-- p2 text
----
FORM call_pofunction.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = pheader
poheaderx = pheaderx
IMPORTING
exppurchaseorder = po_number
TABLES
return = return1
poitem = pitem
poitemx = pitemx
poschedule = plt_schedules_in
poschedulex = plt_schedules_inx
poaccount = poaccount
poaccountx = poaccountx
potextheader = potextheader
potextitem = potextitem.
ENDFORM. " call_pofunction
Hi All,
I am trying to create the Purchase order based on the user selection and it is creating fine with one line item. But if I have same vendor with 2 or more line items, the PO is having only one line item. The following is the code I have. Can someone please help me where I am doing wrong.
Thanks,
Veni.
LOOP AT gt2_zcoop INTO gs_zcoop1.
IF gs_zcoop1-coopind = 'K'.
AT NEW kunnr.
MOVE 'Y' TO lv_flg.
ENDAT.
IF lv_flg EQ 'Y'.
PERFORM pheaderdata.
CLEAR lv_flg.
ENDIF.
PERFORM pitemdata.
APPEND gs_zcoop1 TO gt3_zcoop.
CLEAR gs_zcoop1.
AT END OF kunnr.
PERFORM call_pofunction.
PERFORM update_po_gt_zcoop.
it_cmpo-znum = po_number.
APPEND it_cmpo.
PERFORM errorcheckandcommit.
CLEAR chbox.
REFRESH pitem.
REFRESH pitemx.
REFRESH plt_schedules_in.
REFRESH plt_schedules_inx.
REFRESH poaccount.
REFRESH poaccountx.
REFRESH potextheader.
REFRESH potextitem.
lv_npoitem = 10.
ENDAT.
ENDIF.
ENDLOOP.
FORM pheaderdata.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_zcoop1-kunnr
IMPORTING
output = lv_nvendor.
header data
pheader-comp_code = '1100'.
pheader-doc_type = 'SE'.
pheader-vendor = lv_nvendor.
pheader-purch_org = 'P000'.
pheader-pur_group = '006'.
pheader-our_ref = gs_zcoop1-coopref.
pheaderx-comp_code = 'X'.
pheaderx-doc_type = 'X'.
pheaderx-vendor = 'X'.
pheaderx-purch_org = 'X'.
pheaderx-pur_group = 'X'.
pheaderx-our_ref = 'X'.
CLEAR lv_nvendor.
ENDFORM. " pheaderdata
&----
*& Form pitemdata
&----
text
----
--> p1 text
<-- p2 text
----
FORM pitemdata.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_poitem
IMPORTING
output = lv_npoitem.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_aaord
IMPORTING
output = lv_naaord.
pitem-po_item = lv_npoitem.
pitem-short_text = gs_zcoop1-prdct.
pitem-matl_group = '200200001'.
pitem-quantity = gs_zcoop1-iamount.
pitem-po_unit = 'EA'.
pitem-net_price = '1.00'.
pitem-acctasscat = 'F'.
pitem-plant = 'SOAH'.
pitem-gr_basediv = 'X'.
APPEND pitem.
pitemx-po_item = lv_npoitem.
pitemx-po_itemx = 'X'.
pitemx-short_text = 'X'.
pitemx-matl_group = 'X'.
pitemx-quantity = 'X'.
pitemx-po_unit = 'X'.
pitemx-net_price = 'X'.
pitemx-acctasscat = 'X'.
pitemx-plant = 'X'.
pitemx-gr_basediv = 'X'.
APPEND pitemx.
*Fill schedule lines
plt_schedules_in-po_item = lv_npoitem.
plt_schedules_in-sched_line = '0001'.
plt_schedules_in-delivery_date = '03/20/2008'.
plt_schedules_in-quantity = gs_zcoop1-iamount.
APPEND plt_schedules_in.
*Fill schedule line flags
plt_schedules_inx-po_item = lv_npoitem.
plt_schedules_inx-sched_line = '0001'.
plt_schedules_inx-po_itemx = 'X'.
plt_schedules_inx-sched_linex = 'X'.
plt_schedules_inx-delivery_date = 'X'.
plt_schedules_inx-quantity = 'X'.
APPEND plt_schedules_inx.
poaccount-po_item = lv_npoitem.
poaccount-serial_no = '01'.
poaccount-quantity = gs_zcoop1-iamount.
poaccount-gl_account = '0000603000'.
poaccount-orderid = lv_naaord.
APPEND poaccount.
poaccountx-po_item = lv_npoitem.
poaccountx-po_itemx = 'X'.
poaccountx-serial_no = '01'.
poaccountx-serial_nox = 'X'.
poaccountx-quantity = 'X'.
poaccountx-gl_account = 'X'.
poaccountx-orderid = 'X'.
APPEND poaccountx.
potextheader-po_item = lv_npoitem.
potextheader-text_line = gs_zcoop1-reason.
APPEND potextheader.
potextitem-po_item = lv_npoitem.
potextitem-text_line = 'Item Text'.
APPEND potextitem.
lv_npoitem = lv_npoitem + 10.
ENDFORM. " pheaderdata
&----
*& Form call_pofunction
&----
text
----
--> p1 text
<-- p2 text
----
FORM call_pofunction.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = pheader
poheaderx = pheaderx
IMPORTING
exppurchaseorder = po_number
TABLES
return = return1
poitem = pitem
poitemx = pitemx
poschedule = plt_schedules_in
poschedulex = plt_schedules_inx
poaccount = poaccount
poaccountx = poaccountx
potextheader = potextheader
potextitem = potextitem.
ENDFORM. " call_pofunction
2008 Aug 15 10:45 PM
Hi,
Can any one please help me with it. I debuged it and it is going to the PERFORM pitemdata twice. But in ME23n Po only one item is comming - the second one with item no as 10. There is no item 20.
I have transaction commit also.
thanks,
Veni.
2008 Aug 17 8:18 AM
Hi Vani,
Check your At new statement. You are specifying like this.
At new Kunnr
kunnr is customer field not vendor. check it thoroughly.
Regards,
Santosh Kumar M.
2008 Aug 17 8:20 AM
Go with "Lifnr"
At new lifnr.
<set the flag>.
end at.
if v_flag = 'X'
perform sub_header.
endif.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |