06-16-2006 10:46 AM
Hi guys ,
when v want to upload PO data using BAPI FM
wat r the Strutures to be passed
Is it necessary 2 pass Xstructures
if So? why ? can any one have sample Code
Regards
Anil kumar
06-16-2006 10:55 AM
Hi,
Check the sample code..
report zpo_test .
*DATA DECLARATION
constants : c_x value 'X'.
*Structures to hold PO header data
data : header like bapimepoheader ,
headerx like bapimepoheaderx .
*Structures to hold PO account data
data : account like bapimepoaccount occurs 0 with header line ,
accountx like bapimepoaccountx occurs 0 with header line .
*Internal Tables to hold PO ITEM DATA
data : item like bapimepoitem occurs 0 with header line,
itemx like bapimepoitemx occurs 0 with header line,
*Internal table to hold messages from BAPI call
return like bapiret2 occurs 0 with header line,
*Internal table to hold messages from BAPI call
pocontractlimits like bapiesucc occurs 0 with header line.
data : w_header(40) value 'PO Header',
purchaseorder like bapimepoheader-po_number,
delivery_date like bapimeposchedule-delivery_date.
data : ws_langu like sy-langu.
*text-001 = 'PO Header' - define as text element
selection-screen begin of block b1 with frame title text-001.
parameters : company like header-comp_code default '122' ,
doctyp like header-doc_type default 'NB' ,
cdate like header-creat_date default sy-datum ,
vendor like header-vendor default '2000000012' ,
pur_org like header-purch_org default 'PU01' ,
pur_grp like header-pur_group default '005' .
*sociedad like HEADER-COMP_CODE default '122' ,
*vendedor like HEADER-SALES_PERS default 'sale person'.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters : item_num like item-po_item default '00010',
material like item-material default '12000000' ,
tipo_imp like item-acctasscat default 'K' ,
*pos_doc like ITEM-ITEM_CAT default 'F' ,
shorttxt like item-short_text default 'PRUEBA BAPI' ,
grup_art like item-matl_group default '817230000' ,
plant like item-plant default '3001' ,
mpe like item-trackingno default '9999' ,
*contrato like ITEM-AGREEMENT default '4904000003' ,
*quantity like ITEM-QUANTITY default 1 .
po_unit like item-po_unit default 'EA'.
selection-screen end of block b2.
* Par?mnetros de imputaci?n
selection-screen begin of block b3 with frame title text-004.
parameters : centro like account-costcenter default '1220813150',
cuenta like account-gl_account default '6631400' ,
num_pos like account-po_item default '10' ,
serial like account-serial_no default '01' ,
ind_imp like account-tax_code default 'I2' .
selection-screen end of block b3.
*&---------------------------------------------------------------------*
start-of-selection.
*&---------------------------------------------------------------------*
*DATA POPULATION
*&---------------------------------------------------------------------*
ws_langu = sy-langu. "Language variable
*POPULATE HEADER DATA FOR PO
*HEADER-COMP_CODE = sociedad .
header-doc_type = doctyp .
header-vendor = vendor .
header-creat_date = cdate .
header-created_by = 'TD17191' .
header-purch_org = pur_org .
header-pur_group = pur_grp .
header-comp_code = company .
header-langu = ws_langu .
*HEADER-SALES_PERS = vendedor .
*HEADER-CURRENCY = 'DOP' .
*HEADER-ITEM_INTVL = 10 .
*HEADER-PMNTTRMS = 'N30' .
*HEADER-EXCH_RATE = 1 .
*&---------------------------------------------------------------------*
*POPULATE HEADER FLAG.
*&---------------------------------------------------------------------*
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-vendor = c_x.
headerx-creat_date = c_x.
headerx-created_by = c_x.
headerx-purch_org = c_x.
headerx-pur_group = c_x.
headerx-langu = c_x.
*HEADERX-sales_pers = c_x.
*HEADERX-CURRENCY = c_x.
*HEADER-ITEM_INTVL = c_x.
*HEADER-PMNTTRMS = c_x.
*HEADER-EXCH_RATE = c_x.
*HEADER-EXCH_RATE = c_x.
*&---------------------------------------------------------------------*
*POPULATE ITEM DATA.
*&---------------------------------------------------------------------*
item-po_item = item_num.
item-quantity = '1'.
*ITEM-MATERIAL = material .
item-short_text = 'prueba bapi_po_create1'.
*ITEM-TAX_CODE = ''.
item-acctasscat = 'K' .
*ITEM-ITEM_CAT = 'D' .
item-matl_group = '817230000' .
item-plant = '3001' .
item-trackingno = '99999'.
item-preq_name = 'test'.
*ITEM-AGREEMENT = '' .
*ITEM-AGMT_ITEM = ''.
item-quantity = '1' .
item-po_unit = 'EA'.
*ITEM-ORDERPR_UN = 'EA'.
item-conv_num1 = '1'.
item-conv_den1 = '1'.
item-net_price = '1000000' .
item-price_unit = '1'.
item-gr_pr_time = '0'.
item-prnt_price = 'X'.
item-unlimited_dlv = 'X'.
item-gr_ind = 'X' .
item-ir_ind = 'X' .
item-gr_basediv = 'X'.
*ITEM-PCKG_NO = '' .
append item. clear item.
*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG TABLE
*&---------------------------------------------------------------------*
itemx-po_item = item_num.
itemx-po_itemx = c_x.
*ITEMX-MATERIAL = C_X.
itemx-short_text = c_x.
itemx-quantity = c_x.
*ITEMX-TAX_CODE = C_X.
itemx-acctasscat = c_x.
*ITEMX-ITEM_CAT = c_x.
itemx-matl_group = c_x.
itemx-plant = c_x.
itemx-trackingno = c_x.
itemx-preq_name = c_x.
*ITEMX-AGREEMENT = C_X.
*ITEMX-AGMT_ITEM = c_x.
itemx-stge_loc = c_x.
itemx-quantity = c_x.
itemx-po_unit = c_x.
*ITEMX-ORDERPR_UN = C_X.
itemx-conv_num1 = c_x.
itemx-conv_den1 = c_x.
itemx-net_price = c_x.
itemx-price_unit = c_x.
itemx-gr_pr_time = c_x.
itemx-prnt_price = c_x.
itemx-unlimited_dlv = c_x.
itemx-gr_ind = c_x .
itemx-ir_ind = c_x .
itemx-gr_basediv = c_x .
append itemx. clear itemx.
*&---------------------------------------------------------------------*
*POPULATE ACCOUNT DATA.
*&---------------------------------------------------------------------*
account-po_item = item_num.
account-serial_no = serial .
account-creat_date = sy-datum .
account-costcenter = centro .
account-gl_account = cuenta .
account-gr_rcpt = 'tester'.
append account. clear account.
*&---------------------------------------------------------------------*
*POPULATE ACCOUNT FLAG TABLE.
*&---------------------------------------------------------------------*
accountx-po_item = item_num .
accountx-po_itemx = c_x .
accountx-serial_no = serial .
accountx-serial_nox = c_x .
accountx-creat_date = c_x .
accountx-costcenter = c_x .
accountx-gl_account = c_x .
account-gr_rcpt = c_x.
append accountx. clear accountx.
*&---------------------------------------------------------------------*
*BAPI CALL
*&---------------------------------------------------------------------*
call function 'DIALOG_SET_NO_DIALOG'.
call function 'BAPI_PO_CREATE1'
exporting
poheader = header
poheaderx = headerx
importing
exppurchaseorder = purchaseorder
tables
return = return
poitem = item
poitemx = itemx
poaccount = account
poaccountx = accountx.
*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
* IMPORTING
* RETURN =
.
end-of-selection.
*&---------------------------------------------------------------------*
*Output the messages returned from BAPI call
*&---------------------------------------------------------------------*
loop at return.
write / return-message.
endloop.
Regards
vijay
06-16-2006 10:54 AM
Yes we have to pass the X structures as well the structure with data. The X structures indicate which fields you are intending to send the data.
Regards,
Ravi
06-16-2006 10:55 AM
Hi,
Check the sample code..
report zpo_test .
*DATA DECLARATION
constants : c_x value 'X'.
*Structures to hold PO header data
data : header like bapimepoheader ,
headerx like bapimepoheaderx .
*Structures to hold PO account data
data : account like bapimepoaccount occurs 0 with header line ,
accountx like bapimepoaccountx occurs 0 with header line .
*Internal Tables to hold PO ITEM DATA
data : item like bapimepoitem occurs 0 with header line,
itemx like bapimepoitemx occurs 0 with header line,
*Internal table to hold messages from BAPI call
return like bapiret2 occurs 0 with header line,
*Internal table to hold messages from BAPI call
pocontractlimits like bapiesucc occurs 0 with header line.
data : w_header(40) value 'PO Header',
purchaseorder like bapimepoheader-po_number,
delivery_date like bapimeposchedule-delivery_date.
data : ws_langu like sy-langu.
*text-001 = 'PO Header' - define as text element
selection-screen begin of block b1 with frame title text-001.
parameters : company like header-comp_code default '122' ,
doctyp like header-doc_type default 'NB' ,
cdate like header-creat_date default sy-datum ,
vendor like header-vendor default '2000000012' ,
pur_org like header-purch_org default 'PU01' ,
pur_grp like header-pur_group default '005' .
*sociedad like HEADER-COMP_CODE default '122' ,
*vendedor like HEADER-SALES_PERS default 'sale person'.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters : item_num like item-po_item default '00010',
material like item-material default '12000000' ,
tipo_imp like item-acctasscat default 'K' ,
*pos_doc like ITEM-ITEM_CAT default 'F' ,
shorttxt like item-short_text default 'PRUEBA BAPI' ,
grup_art like item-matl_group default '817230000' ,
plant like item-plant default '3001' ,
mpe like item-trackingno default '9999' ,
*contrato like ITEM-AGREEMENT default '4904000003' ,
*quantity like ITEM-QUANTITY default 1 .
po_unit like item-po_unit default 'EA'.
selection-screen end of block b2.
* Par?mnetros de imputaci?n
selection-screen begin of block b3 with frame title text-004.
parameters : centro like account-costcenter default '1220813150',
cuenta like account-gl_account default '6631400' ,
num_pos like account-po_item default '10' ,
serial like account-serial_no default '01' ,
ind_imp like account-tax_code default 'I2' .
selection-screen end of block b3.
*&---------------------------------------------------------------------*
start-of-selection.
*&---------------------------------------------------------------------*
*DATA POPULATION
*&---------------------------------------------------------------------*
ws_langu = sy-langu. "Language variable
*POPULATE HEADER DATA FOR PO
*HEADER-COMP_CODE = sociedad .
header-doc_type = doctyp .
header-vendor = vendor .
header-creat_date = cdate .
header-created_by = 'TD17191' .
header-purch_org = pur_org .
header-pur_group = pur_grp .
header-comp_code = company .
header-langu = ws_langu .
*HEADER-SALES_PERS = vendedor .
*HEADER-CURRENCY = 'DOP' .
*HEADER-ITEM_INTVL = 10 .
*HEADER-PMNTTRMS = 'N30' .
*HEADER-EXCH_RATE = 1 .
*&---------------------------------------------------------------------*
*POPULATE HEADER FLAG.
*&---------------------------------------------------------------------*
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-vendor = c_x.
headerx-creat_date = c_x.
headerx-created_by = c_x.
headerx-purch_org = c_x.
headerx-pur_group = c_x.
headerx-langu = c_x.
*HEADERX-sales_pers = c_x.
*HEADERX-CURRENCY = c_x.
*HEADER-ITEM_INTVL = c_x.
*HEADER-PMNTTRMS = c_x.
*HEADER-EXCH_RATE = c_x.
*HEADER-EXCH_RATE = c_x.
*&---------------------------------------------------------------------*
*POPULATE ITEM DATA.
*&---------------------------------------------------------------------*
item-po_item = item_num.
item-quantity = '1'.
*ITEM-MATERIAL = material .
item-short_text = 'prueba bapi_po_create1'.
*ITEM-TAX_CODE = ''.
item-acctasscat = 'K' .
*ITEM-ITEM_CAT = 'D' .
item-matl_group = '817230000' .
item-plant = '3001' .
item-trackingno = '99999'.
item-preq_name = 'test'.
*ITEM-AGREEMENT = '' .
*ITEM-AGMT_ITEM = ''.
item-quantity = '1' .
item-po_unit = 'EA'.
*ITEM-ORDERPR_UN = 'EA'.
item-conv_num1 = '1'.
item-conv_den1 = '1'.
item-net_price = '1000000' .
item-price_unit = '1'.
item-gr_pr_time = '0'.
item-prnt_price = 'X'.
item-unlimited_dlv = 'X'.
item-gr_ind = 'X' .
item-ir_ind = 'X' .
item-gr_basediv = 'X'.
*ITEM-PCKG_NO = '' .
append item. clear item.
*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG TABLE
*&---------------------------------------------------------------------*
itemx-po_item = item_num.
itemx-po_itemx = c_x.
*ITEMX-MATERIAL = C_X.
itemx-short_text = c_x.
itemx-quantity = c_x.
*ITEMX-TAX_CODE = C_X.
itemx-acctasscat = c_x.
*ITEMX-ITEM_CAT = c_x.
itemx-matl_group = c_x.
itemx-plant = c_x.
itemx-trackingno = c_x.
itemx-preq_name = c_x.
*ITEMX-AGREEMENT = C_X.
*ITEMX-AGMT_ITEM = c_x.
itemx-stge_loc = c_x.
itemx-quantity = c_x.
itemx-po_unit = c_x.
*ITEMX-ORDERPR_UN = C_X.
itemx-conv_num1 = c_x.
itemx-conv_den1 = c_x.
itemx-net_price = c_x.
itemx-price_unit = c_x.
itemx-gr_pr_time = c_x.
itemx-prnt_price = c_x.
itemx-unlimited_dlv = c_x.
itemx-gr_ind = c_x .
itemx-ir_ind = c_x .
itemx-gr_basediv = c_x .
append itemx. clear itemx.
*&---------------------------------------------------------------------*
*POPULATE ACCOUNT DATA.
*&---------------------------------------------------------------------*
account-po_item = item_num.
account-serial_no = serial .
account-creat_date = sy-datum .
account-costcenter = centro .
account-gl_account = cuenta .
account-gr_rcpt = 'tester'.
append account. clear account.
*&---------------------------------------------------------------------*
*POPULATE ACCOUNT FLAG TABLE.
*&---------------------------------------------------------------------*
accountx-po_item = item_num .
accountx-po_itemx = c_x .
accountx-serial_no = serial .
accountx-serial_nox = c_x .
accountx-creat_date = c_x .
accountx-costcenter = c_x .
accountx-gl_account = c_x .
account-gr_rcpt = c_x.
append accountx. clear accountx.
*&---------------------------------------------------------------------*
*BAPI CALL
*&---------------------------------------------------------------------*
call function 'DIALOG_SET_NO_DIALOG'.
call function 'BAPI_PO_CREATE1'
exporting
poheader = header
poheaderx = headerx
importing
exppurchaseorder = purchaseorder
tables
return = return
poitem = item
poitemx = itemx
poaccount = account
poaccountx = accountx.
*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
* IMPORTING
* RETURN =
.
end-of-selection.
*&---------------------------------------------------------------------*
*Output the messages returned from BAPI call
*&---------------------------------------------------------------------*
loop at return.
write / return-message.
endloop.
Regards
vijay
07-22-2009 4:26 AM
06-16-2006 10:55 AM
06-16-2006 11:01 AM
Have a look at the Function MOdule's documentation.
It has a nice example also:
<b>Example
Example of population of BAPI interface in the Function Builder
Parameter: POHEADER
COMP_CODE = 1000
DOC_TYPE = NB
ITEM_INTVL = 00001
VENDOR = 0000001000
PMNTTRMS = 0001
PURCH_ORG = 1000
PUR_GROUP = 001
CURRENCY = EUR
Parameter: POHEADERX
COMP_CODE = X
DOC_TYPE = X
ITEM_INTVL = X
VENDOR = X
PMNTTRMS = X
PURCH_ORG = X
PUR_GROUP = X
Parameter: POITEM
PO_ITEM = 00001
MATERIAL = 100-100
PLANT = 1000
STGE_LOC = 0001
QUANTITY = 15.000
TAX_CODE = V0
ITEM_CAT = 0
ACCTASSCAT = K
Parameter: POITEMX
PO_ITEM = 00001
MATERIAL = X
PLANT = X
STGE_LOC = X
QUANTITY = X
TAX_CODE = X
ITEM_CAT = X
ACCTASSCAT = X
Parameter: POSCHEDULE
PO_ITEM = 00001
SCHED_LINE = 0001
DELIVERY_DATE = 02.12.2002
QUANTITY = 6.000
PO_ITEM = 00001
SCHED_LINE = 0002
DELIVERY_DATE = 03.12.2002
QUANTITY = 5.000
PO_ITEM = 00001
SCHED_LINE = 0003
DELIVERY_DATE = 04.12.2002
QUANTITY = 4.000
Parameter: POSCHEDULEX
PO_ITEM = 00001
SCHED_LINE = 0001
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0002
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0003
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
Parameter: POACCOUNT
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = 15.000
GL_ACCOUNT = 0000400000
COSTCENTER = 0000001000
CO_AREA = 1000
Parameter: POACCOUNTX
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = X
GL_ACCOUNT = X
COSTCENTER = X
CO_AREA = X
Parameter: POCOND
ITM_NUMBER = 000001
COND_ST_NO = 001
COND_TYPE = PB00
COND_VALUE = 79.900000000
CURRENCY = EUR
CURRENCY_ISO = EUR
COND_UNIT = KG
COND_P_UNT = 1
CHANGE_ID = U
Parameter: POCONDX
ITM_NUMBER = 000001
COND_ST_NO = 000
ITM_NUMBERX = X
COND_TYPE = X
COND_VALUE = X
CURRENCY = X
CHANGE_ID = X
Parameter: POPARTNER
PARTNERDESC = OA
LANGU = EN
BUSPARTNO = 0000001100
PARTNERDESC = GS
LANGU = EN
BUSPARTNO = 0000001200
PARTNERDESC = PI
LANGU = EN
BUSPARTNO = 0000001000</b>
Regards,
Ravi
06-16-2006 11:03 AM
09-25-2007 4:08 PM
&----
*& Report ZP_TEST_POBAPI
*&
&----
*&
*&
&----
REPORT zp_test_pobapi.
*- BAPI related declarations
DATA : g_pohdr TYPE bapimepoheader,
g_pohdrx TYPE bapimepoheaderx,
gt_poitem TYPE TABLE OF bapimepoitem,
gt_poitemx TYPE TABLE OF bapimepoitemx,
gt_posched TYPE TABLE OF bapimeposchedule,
gt_poschedx TYPE TABLE OF bapimeposchedulx,
gt_poacct TYPE TABLE OF bapimepoaccount,
lt_poacct TYPE bapimepoaccount,
gt_poacctx TYPE TABLE OF bapimepoaccountx,
lt_poacctx TYPE bapimepoaccountx,
gt_poservice TYPE TABLE OF bapiesllc,
gt_posrvacc TYPE TABLE OF bapiesklc,
gt_return TYPE TABLE OF bapiret2,
centro like bapimepoaccount-costcenter VALUE '1000',
cuenta like bapimepoaccount-gl_account VALUE '112655' ,
num_pos like bapimepoaccount-po_item VALUE '10' ,
serial like bapimepoaccount-serial_no VALUE '01' ,
ind_imp like bapimepoaccount-tax_code VALUE 'I2' ..
PERFORM prepare_header.
PERFORM prepare_items.
PERFORM prepare_schedule.
lt_poacct-po_item = '0010'.
lt_poacct-serial_no = serial .
lt_poacct-creat_date = sy-datum .
lt_poacct-costcenter = centro .
lt_poacct-gl_account = cuenta .
lt_poacct-gr_rcpt = 'tester'.
APPEND lt_poacct to gt_poacct.
append gt_poacct. clear gt_poacct.
&----
*POPULATE gt_poacct FLAG TABLE.
&----
lt_poacctx-po_item = '0010' .
lt_poacctx-po_itemx = 'X' .
lt_poacctx-serial_no = serial .
lt_poacctx-serial_nox = 'X' .
lt_poacctx-creat_date = 'X' .
lt_poacctx-costcenter = 'X' .
lt_poacctx-gl_account = 'X' .
lt_poacct-gr_rcpt = 'X'.
append lt_poacctx to gt_poacctx.
PERFORM create_po.
&----
*& Form prepare_header
&----
Set up header structure
----
FORM prepare_header.
g_pohdr-comp_code = '1000'.
g_pohdrx-comp_code = 'X'.
set up doc type
g_pohdr-doc_type = 'NB'.
g_pohdrx-doc_type = 'X'.
g_pohdr-vendor = '0000010123'.
g_pohdrx-vendor = 'X'.
g_pohdr-langu = sy-langu.
g_pohdrx-langu = 'X'.
g_pohdr-purch_org = 'BA01'.
g_pohdr-purch_org = '1000'.
g_pohdrx-purch_org = 'X'.
g_pohdr-pur_group = '001'.
g_pohdrx-pur_group = 'X'.
g_pohdr-currency = 'EUR'.
g_pohdrx-currency = 'X'.
ENDFORM. " prepare_header
&----
*& Form prepare_items
&----
Set up item values
----
FORM prepare_items.
DATA : ls_poitem TYPE bapimepoitem,
ls_poitemx TYPE bapimepoitemx.
ls_poitem-po_item = '00010'.
ls_poitemx-po_item = '00010'.
ls_poitemx-po_itemx = 'X'.
ls_poitem-material = 'PARAG03'.
ls_poitemx-material = 'X'.
ls_poitem-short_text = 'PAR'.
ls_poitemx-short_text = 'X'.
ls_poitem-vend_mat = 'xyz'.
ls_poitemx-vend_mat = 'X'.
ls_poitem-quantity = '100'.
ls_poitemx-quantity = 'X'.
ls_poitem-po_unit = 'EA'.
ls_poitemx-po_unit = 'X'.
ls_poitem-po_unit_iso = 'EA'.
ls_poitemx-po_unit_iso = 'X'.
ls_poitem-net_price = '6'.
ls_poitemx-net_price = 'X'.
ls_poitem-price_unit = '1'.
ls_poitemx-price_unit = 'X'.
ls_poitem-item_cat = 'D'.
ls_poitemx-item_cat = 'X'.
ls_poitem-plant = '1000'.
ls_poitemx-plant = 'X'.
ls_poitem-acctasscat = 'K'.
ls_poitemx-acctasscat = 'X'.
ls_poitem-acctasscat = <fs_req>-knttp.
ls_poitemx-acctasscat = 'X'.
*
ls_poitem-distrib = <fs_req>-vrtkz.
ls_poitemx-distrib = 'X'.
*
ls_poitem-part_inv = <fs_req>-twrkz.
ls_poitemx-part_inv = 'X'.
*
ls_poitem-gr_ind = <fs_req>-wepos.
ls_poitemx-gr_ind = 'X'.
*
ls_poitem-gr_non_val = <fs_req>-weunb.
ls_poitemx-gr_non_val = 'X'.
*
ls_poitem-ir_ind = <fs_req>-repos.
ls_poitemx-ir_ind = 'X'.
ls_poitem-agreement = <fs_req>-konnr.
ls_poitemx-agreement = 'X'.
*
ls_poitem-agmt_item = <fs_req>-ktpnr.
ls_poitemx-agmt_item = 'X'.
*
ls_poitem-preq_no = <fs_req>-banfn.
ls_poitemx-preq_no = 'X'.
*
ls_poitem-preq_item = <fs_req>-bnfpo.
ls_poitemx-preq_item = 'X'.
*
ls_poitem-preq_name = <fs_req>-afnam.
ls_poitemx-preq_name = 'X'.
*
ls_poitem-pckg_no = <fs_req>-packno.
ls_poitemx-pckg_no = 'X'.
APPEND : ls_poitem TO gt_poitem,
ls_poitemx TO gt_poitemx.
ENDFORM. " prepare_items
&----
*& Form prepare_schedule
&----
Schedule data
----
FORM prepare_schedule.
DATA : ls_posched TYPE bapimeposchedule,
ls_poschedx TYPE bapimeposchedulx.
ls_poschedx-po_item = '00010'.
ls_posched-po_item = '00010'.
ls_poschedx-po_itemx = 'X'.
ls_posched-delivery_date = '10.10.2007'.
ls_poschedx-delivery_date = 'X'.
ls_posched-quantity = '100'.
ls_poschedx-quantity = 'X'.
ls_posched-preq_no = <fs_req>-banfn.
ls_poschedx-preq_no = 'X'.
*
ls_posched-preq_item = <fs_req>-bnfpo.
ls_poschedx-preq_item = 'X'.
APPEND : ls_posched TO gt_posched,
ls_poschedx TO gt_poschedx.
ENDFORM. " prepare_schedule
&----
*& Form create_po
&----
Create PO with ref to the req
----
FORM create_po.
DATA : lt_return TYPE TABLE OF bapiret2,
l_ponum TYPE banfn.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = g_pohdr
poheaderx = g_pohdrx
testrun = 'X'
IMPORTING
exppurchaseorder = l_ponum
TABLES
return = lt_return
poitem = gt_poitem
poitemx = gt_poitemx
poschedule = gt_posched
poschedulex = gt_poschedx
poaccount = gt_poacct
poaccountx = gt_poacctx
poservices = gt_poservice
posrvaccessvalues = gt_posrvacc.
APPEND LINES OF lt_return TO gt_return.
IF NOT l_ponum IS INITIAL.
MESSAGE s398(00) WITH 'Purchase document ' l_ponum
' successfully created'.
ENDIF.
ENDFORM. " create_po