09-25-2008 8:08 AM
Hi SAP Technical Guru,
i am new to module pool programming.
i designed custom screen which is like TA me21n means it has one tabstrip and tablecontrol.
for header details(fields) at tab strip, and item detials(fields) at table control i used.
now i have to capture screen fields into FM bapi_po_create1 and update the database tables.
please suggest me how to create Purchase Order through BAPI FM.
regards,
09-25-2008 9:17 AM
>now i have to capture screen fields
if you crate the screen fields referring to the structure/table/variables defined in the program then you don't need to capture any information, directly read/use the structures and fill the parameters of the BAPI.
Call the BAPI.
09-25-2008 9:28 AM
hi vijay babu,
thanks for your valuble answer,but how can call BAPI and where can i call bapi.
if you have any progrmme regarding this pls send.
regards,
09-25-2008 2:54 PM
here is the sample code
*tables for passing podata to bapi
DATA : gt_header TYPE STANDARD TABLE OF bapimepoheader,
gt_headerx TYPE STANDARD TABLE OF bapimepoheaderx,
gt_item TYPE STANDARD TABLE OF bapimepoitem,
gt_itemx TYPE STANDARD TABLE OF bapimepoitemx,
gt_account TYPE STANDARD TABLE OF bapimepoaccount,
gt_accountx TYPE STANDARD TABLE OF bapimepoaccountx,
*tables used for passing custom field data to bapi
gt_custom TYPE STANDARD TABLE OF bapiparex,
gt_custdata_in TYPE STANDARD TABLE OF bapi_te_mepoaccounting,
gt_custdata_ix TYPE STANDARD TABLE OF bapi_te_mepoaccountingx,
*tables used for cathing messages returned by bapi
gt_return TYPE STANDARD TABLE OF bapiret2,
gt_return1 TYPE STANDARD TABLE OF bapiret2,
*Work area declaration for passing custom field data to bapi
w_custom LIKE LINE OF gt_custom,
w_custdata_in LIKE LINE OF gt_custdata_in,
w_custdata_ix LIKE LINE OF gt_custdata_ix,
*Work area declaration for passing podata to bapi
w_header LIKE LINE OF gt_header,
w_headerx LIKE LINE OF gt_headerx,
w_item LIKE LINE OF gt_item,
w_itemx LIKE LINE OF gt_itemx,
w_account LIKE LINE OF gt_account,
w_accountx LIKE LINE OF gt_accountx,
*work area declaration for cathing messages returned by bapi
w_return LIKE LINE OF gt_return,
w_return1 LIKE LINE OF gt_return1.
*----------------------------------------------------------------------*
*populating po dat into internal tables
w_header-comp_code = 'PH02'.
w_header-doc_type = 'TEST'.
w_header-vendor = '0000600019'.
w_header-purch_org = 'PH02'.
w_header-pur_group = '901'.
w_headerx-comp_code = 'X'.
w_headerx-doc_type = 'X'.
w_headerx-vendor = 'X'.
w_headerx-purch_org = 'X'.
w_headerx-pur_group = 'X'.
w_item-po_item = '00001'.
w_item-short_text = 'test po'.
w_item-po_unit = 'CM'.
w_item-matl_group = '01'.
w_item-po_unit = 'EA'.
w_item-plant = 'PH02'.
w_item-quantity = '1.000'.
w_item-net_price = '10.00'.
w_item-item_cat = '0'.
w_item-acctasscat = 'K'.
APPEND w_item TO gt_item.
w_itemx-po_item = '00001'.
w_itemx-short_text = 'X'.
w_itemx-matl_group = 'X'.
w_itemx-po_unit = 'X'.
w_itemx-plant = 'X'.
w_itemx-stge_loc = 'X'.
w_itemx-quantity = 'X'.
w_itemx-tax_code = 'X'.
w_itemx-net_price = 'X'.
w_itemx-item_cat = 'X'.
w_itemx-acctasscat = 'X'.
APPEND w_itemx TO gt_itemx.
w_account-po_item = '00001'.
w_account-serial_no = '01'.
w_account-quantity = '1.000'.
w_account-gl_account = '0000199999'.
w_account-costcenter = '0000400011'.
APPEND w_account TO gt_account.
w_accountx-po_item = '00001'.
w_accountx-serial_no = '01'.
w_accountx-quantity = 'X'.
w_accountx-gl_account = 'X'.
w_accountx-costcenter = 'X'.
APPEND w_accountx TO gt_accountx.
w_custdata_in-po_item = '00001'.
w_custdata_in-serial_no = '01'.
w_custdata_in-zzttry = '1000'.
w_custom-structure = 'BAPI_TE_MEPOACCOUNTING'.
MOVE w_custdata_in TO w_custom-valuepart1.
APPEND w_custom TO gt_custom.
w_custdata_ix-zzttry = 'X'.
w_custdata_ix-po_item = '00001'.
w_custdata_ix-serial_no = '01'.
w_custom-structure = 'BAPI_TE_MEPOACCOUNTINGX'.
MOVE w_custdata_ix TO w_custom-valuepart1.
APPEND w_custom TO gt_custom.
*----------------------------------------------------------------------*
*bapi to create po oreders
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = w_header
poheaderx = w_headerx
TABLES
return = gt_return
poitem = gt_item
poitemx = gt_itemx
poaccount = gt_account
poaccountx = gt_accountx
extensionin = gt_custom.
*bapi for po data commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = ' '
IMPORTING
return = w_return1.
*----------------------------------------------------------------------*
*clearing tables & work area
REFRESH:gt_account,gt_item,gt_itemx,gt_accountx.
CLEAR:w_header,w_headerx.
*----------------------------------------------------------------------*
*displaying message returned by bapi
LOOP AT gt_return INTO w_return.
WRITE: w_return-type , w_return-id , w_return-number , w_return-message .
ENDLOOP.
09-25-2008 3:15 PM
It depends on your design, It can be called when you press save Button.
inside the PAI module, in the user_command module you can call the bapi.
case ok_code.
when 'SAVE'.
call the bapi here..
endcase.
09-26-2008 10:44 AM
hi vijay,
i called the BAPI at save button module under PAI event.
i am getting error like invalid field format (screen error).
how to over come this problem.
regards,
09-26-2008 10:55 AM
I think it is coming from the Qty fields. check it once. you mention the reference fields etc in the screen attributes. Try to create the screen fields Referring to Dictionary and then change them later.