2006 Dec 22 1:20 PM
help me to create purchase order through bapi.
2006 Dec 22 1:26 PM
Hi ,
Try this,
REPORT ZTEST_BAPI .
*- 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,
gt_poacctx TYPE TABLE OF bapimepoaccountx,
gt_poservice TYPE TABLE OF bapiesllc,
gt_posrvacc TYPE TABLE OF bapiesklc,
gt_return TYPE TABLE OF bapiret2.
perform prepare_header.
PERFORM prepare_items.
PERFORM prepare_schedule.
perform create_po.
*&---------------------------------------------------------------------*
*& Form prepare_header
*&---------------------------------------------------------------------*
* Set up header structure
*----------------------------------------------------------------------*
FORM prepare_header.
g_pohdr-comp_code = '2000'.
g_pohdrx-comp_code = 'X'.
* set up doc type
g_pohdr-doc_type = 'NB'.
g_pohdrx-doc_type = 'X'.
g_pohdr-vendor = '0008000330'.
g_pohdrx-vendor = 'X'.
g_pohdr-langu = sy-langu.
g_pohdrx-langu = 'X'.
g_pohdr-purch_org = 'BA01'.
g_pohdrx-purch_org = 'X'.
g_pohdr-pur_group = '800'.
g_pohdrx-pur_group = 'X'.
g_pohdr-currency = 'USD'.
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-short_text = 'ABSORBER,SHOCK:PALLETIZER'.
ls_poitemx-short_text = 'X'.
ls_poitem-material = '000000000001070062'.
ls_poitemx-material = '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.32'.
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 = '1575'.
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/31/2005'.
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
Regards,
Raghav
2006 Dec 22 1:26 PM
Hi ,
Try this,
REPORT ZTEST_BAPI .
*- 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,
gt_poacctx TYPE TABLE OF bapimepoaccountx,
gt_poservice TYPE TABLE OF bapiesllc,
gt_posrvacc TYPE TABLE OF bapiesklc,
gt_return TYPE TABLE OF bapiret2.
perform prepare_header.
PERFORM prepare_items.
PERFORM prepare_schedule.
perform create_po.
*&---------------------------------------------------------------------*
*& Form prepare_header
*&---------------------------------------------------------------------*
* Set up header structure
*----------------------------------------------------------------------*
FORM prepare_header.
g_pohdr-comp_code = '2000'.
g_pohdrx-comp_code = 'X'.
* set up doc type
g_pohdr-doc_type = 'NB'.
g_pohdrx-doc_type = 'X'.
g_pohdr-vendor = '0008000330'.
g_pohdrx-vendor = 'X'.
g_pohdr-langu = sy-langu.
g_pohdrx-langu = 'X'.
g_pohdr-purch_org = 'BA01'.
g_pohdrx-purch_org = 'X'.
g_pohdr-pur_group = '800'.
g_pohdrx-pur_group = 'X'.
g_pohdr-currency = 'USD'.
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-short_text = 'ABSORBER,SHOCK:PALLETIZER'.
ls_poitemx-short_text = 'X'.
ls_poitem-material = '000000000001070062'.
ls_poitemx-material = '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.32'.
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 = '1575'.
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/31/2005'.
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
Regards,
Raghav
2006 Dec 22 1:28 PM
There is BAPI for creation of Purchase Order which is 'BAPI_PO_CREATE1'
or else U can write a BDC for the same.
Message was edited by:
Ramesh Babu Chirumamilla
2006 Dec 22 1:30 PM
Hi,
REPORT z_po_create NO STANDARD PAGE HEADING
MESSAGE-ID z0lo_scm
LINE-SIZE 132
LINE-COUNT 65 .
TABLES : ekko,
ekpo.
*----
D A T A D E C L A R A T I O N S
*----
*--Type declaration to store data read from table EKKO.
TYPES : BEGIN OF t_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bsart TYPE ekko-bsart,
aedat TYPE ekko-aedat,
ernam TYPE ekko-ernam,
lifnr TYPE ekko-lifnr,
ekorg TYPE ekko-ekorg,
ekgrp TYPE ekko-ekgrp,
spras TYPE ekko-spras,
werks TYPE ekpo-werks,
END OF t_ekko.
*--Type declaration to store data read from table EKPO.
TYPES : BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
knttp TYPE ekpo-knttp,
matkl TYPE ekpo-matkl,
bednr TYPE ekpo-bednr,
afnam TYPE ekpo-afnam,
meins TYPE ekpo-meins,
bpumz TYPE ekpo-bpumz,
bpumn TYPE ekpo-bpumn,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
webaz TYPE ekpo-webaz,
END OF t_ekpo.
*--Type declaration to store data read from table LFA1.
TYPES : BEGIN OF t_lfa1,
lifnr TYPE lfa1-lifnr,
land1 TYPE lfa1-land1,
END OF t_lfa1.
TYPES : BEGIN OF t_head_item,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bsart TYPE ekko-bsart,
aedat TYPE ekko-aedat,
ernam TYPE ekko-ernam,
lifnr TYPE ekko-lifnr,
ekorg TYPE ekko-ekorg,
ekgrp TYPE ekko-ekgrp,
spras TYPE ekko-spras,
pincr TYPE ekko-pincr,
zterm TYPE ekko-zterm,
waers TYPE ekko-waers,
inco1 TYPE ekko-inco1,
inco2 TYPE ekko-inco2,
bedat TYPE ekko-bedat,
ebelp TYPE ekpo-ebelp,
txz01 TYPE ekpo-txz01,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
knttp TYPE ekpo-knttp,
matkl TYPE ekpo-matkl,
bednr TYPE ekpo-bednr,
afnam TYPE ekpo-afnam,
meins TYPE ekpo-meins,
bpumz TYPE ekpo-bpumz,
bpumn TYPE ekpo-bpumn,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
webaz TYPE ekpo-webaz,
mwskz TYPE ekpo-mwskz,
adrnr TYPE ekpo-adrnr,
END OF t_head_item.
*--Type declaration to store data read from table EKPO.
TYPES : BEGIN OF t_sucess,
ebeln TYPE ekko-ebeln,
END OF t_sucess.
TYPES : BEGIN OF t_ekko_ekpo,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
inco1 TYPE ekko-inco1,
inco2 TYPE ekko-inco2,
zterm TYPE ekko-zterm,
waers TYPE ekko-waers,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
netpr TYPE ekpo-netpr, " Net price
peinh TYPE ekpo-peinh, " price per unit
mwskz TYPE ekpo-mwskz, " Tax Code
knttp TYPE ekpo-knttp, " Account ass cata
bednr TYPE ekpo-bednr,
END OF t_ekko_ekpo.
*--Type declaration to store data for error log.
TYPES: BEGIN OF t_err_log,
ebeln TYPE ebeln, " Purchase order no.
type(4) TYPE c, " Message Type
number(5) TYPE c, " Message Number
message(100) TYPE c, " Message Desp
END OF t_err_log.
*--Type declaration to store data for success log.
TYPES :BEGIN OF t_succ_log,
ebeln TYPE ebeln, " Purchase order no.
type(4) TYPE c, " Message Type
number(5) TYPE c, " Message Number
message(100) TYPE c, " Message Desp
END OF t_succ_log.
*--
DATA : BEGIN OF it_contracts_tmp OCCURS 0,
ebeln LIKE ekko-ebeln,
END OF it_contracts_tmp.
TYPES : BEGIN OF t_mul_cont,
ebeln LIKE ekko-ebeln,
matnr LIKE ekpo-matnr,
END OF t_mul_cont.
TYPES : BEGIN OF t_delivery_address,
addrnumber LIKE adrc-addrnumber,
name1 LIKE adrc-name1,
name2 LIKE adrc-name2,
street LIKE adrc-street,
house_num1 LIKE adrc-house_num1,
city1 LIKE adrc-city1,
city2 LIKE adrc-city2,
post_code1 LIKE adrc-post_code1,
country LIKE adrc-country,
region LIKE adrc-region,
END OF t_delivery_address.
TYPES : BEGIN OF t_plant_adrnr,
werks LIKE t001w-werks,
adrnr LIKE t001w-adrnr,
END OF t_plant_adrnr.
*-- Variables declarations.
DATA : v_ebeln TYPE ekko-ebeln, "PO Number
v_bsart TYPE ekko-bsart,
v_ekorg TYPE ekko-ekorg, "Purchasing Organization
v_ekgrp TYPE ekko-ekgrp, "Purchasing group
v_lifnr TYPE ekko-lifnr, "Vendor Number
v_werks TYPE ekpo-werks, "Plant
v_matnr TYPE ekpo-matnr, "Material Number
v_infnr TYPE ekpo-infnr, "Agreement
v_succ_po TYPE ekko-ebeln,
v_bukrs TYPE ekko-ebeln,
v_werks1 TYPE ekpo-werks, "Plant
v_ekorg1 TYPE ekko-ekorg, "Purchasing Organization
v_ekgrp1 TYPE ekko-ekgrp, "Purchasing group
v_bsart1 TYPE ekko-bsart,
v_konnr TYPE ekpo-konnr,
v_title TYPE sytitle. " Title
*-- Constants declarations.
CONSTANTS: c_bstyp TYPE ekpo-bstyp VALUE 'K',
c_bstyp1 TYPE ekpo-bstyp VALUE 'F',
c_x VALUE 'X'.
*----
D A T A D E C L A R A T I O N S FOR BAPI
*----
**-BAPI structure for Purchase Order Header Data
DATA : x_poheader TYPE bapimepoheader,
**-BAPI structure for Purchase Order Header Data (Change Toolbar)
x_poheaderx TYPE bapimepoheaderx,
**-BAPI structure for Purchase Order Item Data
x_poitem TYPE bapimepoitem,
**-BAPI structure for Purchase Order Item Data (Change Toolbar)
x_poitemx TYPE bapimepoitemx,
**-BAPI structure for messages
x_return TYPE bapiret2,
**-Structure for the error log
x_err_log TYPE t_err_log,
**-Structure for sucess log
x_succ_log TYPE t_err_log,
**-Delivery address
x_deliveryaddr TYPE bapimepoaddrdelivery,
**-BAPI structure for Purchase Order Export/Import: Item Data
x_poexpimpitem TYPE bapieipo,
**-BAPI structure for PO Export/Import: Item Data (Change Toolbar)
x_poexpimpitemx TYPE bapieipox.
**-BAPI internal table containing purchase order item
DATA : it_poitem TYPE STANDARD TABLE OF bapimepoitem,
**-BAPI internal table containing PO item data (Change Toolbar)
it_poitemx TYPE STANDARD TABLE OF bapimepoitemx,
**-BAPI Return table containing messages
it_return TYPE STANDARD TABLE OF bapiret2,
it_deliveryaddr TYPE STANDARD TABLE OF bapimepoaddrdelivery,
**-BAPI structure for Purchase Order Export/Import: Item Data
it_poexpimpitem TYPE STANDARD TABLE OF bapieipo,
**-BAPI structure for PO Export/Import: Item Data(change tool)
it_poexpimpitemx TYPE STANDARD TABLE OF bapieipox.
*----
I N T E R N A L T A B L E D E C L E R A T I O N S
*----
DATA: it_ekko_dest TYPE STANDARD TABLE OF t_ekko WITH HEADER LINE,
**-Internal table for fetching PO's
it_head_item TYPE STANDARD TABLE OF t_head_item WITH HEADER LINE,
**-Internal table for fetching Contract number
it_ekko_ekpo TYPE STANDARD TABLE OF t_ekko_ekpo WITH HEADER LINE,
**-Internal table for fetching created PO's
it_sucess TYPE STANDARD TABLE OF t_sucess WITH HEADER LINE,
**-Internal table for PO's which doesnot have contracts
it_contract TYPE STANDARD TABLE OF t_sucess WITH HEADER LINE,
**-internal table for fetching vendor details
it_lfa1 TYPE STANDARD TABLE OF t_lfa1 WITH HEADER LINE,
**-internal table for fetching Delivery address details
it_delivery_address TYPE STANDARD TABLE OF
t_delivery_address WITH HEADER LINE,
**-internal table for fetching Plant details
it_plant_adrnr TYPE STANDARD TABLE OF t_plant_adrnr WITH HEADER LINE,
**-Internal table containing error messages for PO Create
it_err_log TYPE STANDARD TABLE OF t_err_log,
**-Internal table containing error messages for PO Change
it_err_chg_log TYPE STANDARD TABLE OF t_err_log,
**-Internal table containing sucess messages for po create
it_succ_log TYPE STANDARD TABLE OF t_succ_log,
**-Internal table containing success messages for PO change
it_succ_chg_log TYPE STANDARD TABLE OF t_succ_log,
**-Internal table containing Multiple contract numbers
it_po_matnr_mul_cont TYPE STANDARD TABLE OF t_mul_cont WITH HEADER LINE.
internal table for bdcdata
DATA : bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
----
I N C L U D E P R O G R A M
----
INCLUDE zzuti_std_header_footer.
*----
S E L E C T I O N S C R E E N
*----
*-- Selection criteria
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_ebeln FOR ekko-ebeln, "PO Number
s_bsart FOR ekko-bsart DEFAULT 'ZHBV', "PO Type
s_aedat FOR ekko-aedat DEFAULT sy-datum, "Creation Date
s_ekorg FOR ekko-ekorg, "Purchasing Organization
s_ekgrp FOR ekko-ekgrp, "Purchasing group
s_lifnr FOR ekko-lifnr, "Vendor Number
s_werks FOR ekpo-werks, "Plant
s_matnr FOR ekpo-matnr, "Material Number
s_infnr FOR ekpo-infnr, "Agreement
s_konnr FOR ekpo-konnr. "Outline Agreement
PARAMETERS : cb_test AS CHECKBOX. "BAPI Test run
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS :p_bukrs LIKE ekko-bukrs OBLIGATORY DEFAULT '9040', "Company Code
p_werks LIKE ekpo-werks OBLIGATORY DEFAULT '7040', "Plant
p_ekorg LIKE ekko-ekorg OBLIGATORY DEFAULT '9040', "Purchasing Organization
p_ekgrp LIKE ekko-ekgrp OBLIGATORY DEFAULT '031', "Purchasing group
p_bsart1 LIKE ekko-bsart OBLIGATORY DEFAULT 'ZHIH'. "PO Type
SELECTION-SCREEN END OF BLOCK b2.
----
A T S E L E C T I O N - S C R E E N
----
AT SELECTION-SCREEN.
*-- Validating the Selection Screen inputs.
PERFORM validate_user_input.
----
S T A R T - O F - S E L E C T I O N
----
START-OF-SELECTION.
*-- Getting data from table EKKO.
PERFORM get_purchase_order.
*-- Getting data from table EKKO
PERFORM get_po_created.
*-- Getting data from table EKKO & EKPO
PERFORM get_contract_num.
*-- Getting data from ADRC table
PERFORM get_delivery_address.
*-- Creating the PO.
PERFORM create_po.
----
E N D - O F - S E L E C T I O N
----
END-OF-SELECTION.
*-- Display list_heading.
PERFORM list_heading.
**---Display PO sucess log
IF NOT it_succ_log[] IS INITIAL.
PERFORM f_display_succ_po_log.
ENDIF.
**---Display PO error log
IF NOT it_err_log[] IS INITIAL.
PERFORM f_display_err_po_log.
ENDIF.
*-- Display PO which are already created
IF NOT it_sucess[] IS INITIAL.
PERFORM display_createdpo_rept.
ENDIF.
*-- Display PO which has multiple contracts
IF NOT it_po_matnr_mul_cont[] IS INITIAL.
PERFORM po_matnr_mul_contr.
ENDIF.
*-- Display PO which doesnt have contract numbers
IF NOT it_contract[] IS INITIAL.
PERFORM display_contract_rept.
ENDIF.
**---Display PO Changes sucess log
IF NOT it_succ_chg_log[] IS INITIAL.
PERFORM display_succ_chg_rept.
ENDIF.
**---Display PO Changes error log
IF NOT it_err_chg_log[] IS INITIAL.
PERFORM display_err_chg_rept.
ENDIF.
*-- Clearing the variables and internal tables.
PERFORM clear_variables.
----
TOP OF PAGE
----
TOP-OF-PAGE.
*-- standard top of page
PERFORM std_top_of_page CHANGING v_title.
&----
*& Form VALIDATE_USER_INPUT
&----
Form to validate user inputs at Selection Screen.
----
FORM validate_user_input .
*-- Validating Purchasing Document Number
IF NOT s_ebeln[] IS INITIAL.
SELECT ebeln
INTO v_ebeln
FROM ekko
UP TO 1 ROWS
WHERE ebeln IN s_ebeln.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Document Number'(004).
ENDIF.
ENDIF.
*-- Validating Purchasing Document Type
IF NOT s_bsart[] IS INITIAL.
SELECT bsart
INTO v_bsart
FROM t161
UP TO 1 ROWS
WHERE bsart IN s_bsart.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Document Type'(005).
ENDIF.
ENDIF.
*-- Validating Purchasing org
IF NOT s_ekorg[] IS INITIAL.
SELECT ekorg
INTO v_ekorg
FROM t024e
UP TO 1 ROWS
WHERE ekorg IN s_ekorg.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Organization'(006).
ENDIF.
ENDIF.
*-- Validating Purchasing group
IF NOT s_ekgrp[] IS INITIAL.
SELECT ekgrp
INTO v_ekgrp
FROM t024
UP TO 1 ROWS
WHERE ekgrp IN s_ekgrp.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Group'(007).
ENDIF.
ENDIF.
*-- Validating Vendor's account number
IF NOT s_lifnr[] IS INITIAL.
SELECT lifnr
INTO v_lifnr
FROM lfa1
UP TO 1 ROWS
WHERE lifnr IN s_lifnr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Vendor account number'(008).
ENDIF.
ENDIF.
*-- Validating Plant
IF NOT s_werks[] IS INITIAL.
SELECT werks
INTO v_werks
FROM t001w
UP TO 1 ROWS
WHERE werks IN s_werks.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Plant'(009).
ENDIF.
ENDIF.
*-- Validating Material
IF NOT s_matnr[] IS INITIAL.
SELECT matnr
INTO v_matnr
FROM mara
UP TO 1 ROWS
WHERE matnr IN s_matnr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Material Number'(010).
ENDIF.
ENDIF.
*-- Validating info record(Agreement)
IF NOT s_infnr[] IS INITIAL.
SELECT infnr
INTO v_infnr
FROM eina
UP TO 1 ROWS
WHERE infnr IN s_infnr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid purchasing info record'(011).
ENDIF.
ENDIF.
*-- Validating Purchase aggreement
IF NOT s_konnr[] IS INITIAL.
SELECT ebeln
INTO v_konnr
FROM ekko
UP TO 1 ROWS
WHERE ebeln IN s_konnr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid purchasing purchase agreement'(023).
ENDIF.
ENDIF.
*-- Validating Destination company code
IF NOT p_bukrs IS INITIAL.
SELECT SINGLE bukrs
INTO v_bukrs FROM t001
WHERE bukrs = p_bukrs.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Company Code'(012).
ENDIF.
ENDIF.
*-- Validating Destination Plant
IF NOT p_werks IS INITIAL.
SELECT SINGLE werks
INTO v_werks1 FROM t001w
WHERE werks = p_werks.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Plant'(009).
ENDIF.
ENDIF.
*-- Validating Destination Purchasing Organization
IF NOT p_ekorg IS INITIAL.
SELECT SINGLE ekorg
INTO v_ekorg1 FROM t024e
WHERE ekorg = p_ekorg.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Organization'(006).
ENDIF.
ENDIF.
*-- Validating Purchasing group
IF NOT p_ekgrp IS INITIAL.
SELECT SINGLE ekgrp
INTO v_ekgrp1 FROM t024
WHERE ekgrp = p_ekgrp.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Group'(007).
ENDIF.
ENDIF.
*-- Validating Purchasing Document Type
IF NOT p_bsart1 IS INITIAL.
SELECT SINGLE bsart
INTO v_bsart1 FROM t161
WHERE bsart = p_bsart1.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Invalid Purchasing Document Type'(005).
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_USER_INPUT
&----
*& Form GET_PURCHASE_ORDER
&----
Form to fetch data required from table EKKO & EKPO into internal table.
----
FORM get_purchase_order.
REFRESH it_head_item.
*-- Getting data from table EKKO & EKPO.
SELECT a~ebeln
a~bukrs
a~bsart
a~aedat
a~ernam
a~lifnr
a~ekorg
a~ekgrp
a~spras
a~pincr
a~zterm
a~waers
a~inco1
a~inco2
a~bedat
b~ebelp
b~txz01
b~matnr
b~werks
b~lgort
b~menge
b~knttp
b~matkl
b~bednr
b~afnam
b~meins
b~bpumz
b~bpumn
b~netpr
b~peinh
b~webaz
b~mwskz
b~adrnr
INTO TABLE it_head_item
FROM ekko AS a
INNER JOIN ekpo AS b
ON a~ebeln = b~ebeln
WHERE a~ebeln IN s_ebeln
AND a~bsart IN s_bsart
AND a~aedat IN s_aedat
AND a~ekgrp IN s_ekgrp
AND a~ekorg IN s_ekorg
AND a~lifnr IN s_lifnr
AND a~loekz <> c_x
AND b~werks IN s_werks
AND b~matnr IN s_matnr
AND b~infnr IN s_infnr
AND b~konnr IN s_konnr
AND b~loekz <> c_x.
IF sy-subrc = 0.
*-- Create PO with same number as ZHBV PO
*-- with the letter I in front
SORT it_head_item BY ebeln.
LOOP AT it_head_item.
it_head_item-ebeln+0(1) = 'I'.
MODIFY it_head_item INDEX sy-tabix.
ENDLOOP.
ELSE.
MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).
STOP.
ENDIF.
ENDFORM. " GET_PURCHASE_ORDER
&----
*& Form GET_PO_CREATED
&----
Form to fetch data required from table EKKO into internal table.
Delete those records which are already created
----
FORM get_po_created .
*--fetch data from table EKKO into internal table
*--Where Docu type = 'ZHIH'
IF NOT it_head_item[] IS INITIAL.
SELECT a~ebeln
a~bukrs
a~bsart
a~aedat
a~ernam
a~lifnr
a~ekorg
a~ekgrp
a~spras
b~werks
INTO TABLE it_ekko_dest
FROM ekko AS a
INNER JOIN ekpo AS b
ON aebeln = bebeln
FOR ALL ENTRIES IN it_head_item
WHERE a~ebeln = it_head_item-ebeln
AND a~bsart = p_bsart1
AND a~bukrs = p_bukrs
AND b~werks = p_werks
AND b~bstyp = c_bstyp1
AND a~ekorg = p_ekorg
AND a~ekgrp = p_ekgrp.
IF sy-subrc = 0.
SORT it_ekko_dest BY ebeln.
ENDIF.
ENDIF.
*--Move all the PO numbers into sucess internal table
*--if the PO was already created
LOOP AT it_ekko_dest.
MOVE it_ekko_dest-ebeln TO it_sucess-ebeln.
APPEND it_sucess.
CLEAR it_sucess.
DELETE it_head_item WHERE ebeln = it_ekko_dest-ebeln.
ENDLOOP.
CLEAR it_head_item.
IF it_head_item[] IS INITIAL.
MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).
STOP.
ENDIF.
ENDFORM. " GET_PO_CREATED
&----
*& Form GET_CONTRACT_NUM
&----
text
----
FORM get_contract_num .
*--Select the data to get contract number
IF NOT it_head_item[] IS INITIAL.
SELECT a~ebeln "contract numbers
a~lifnr
a~inco1
a~inco2
a~zterm
a~waers
b~ebelp
b~matnr
b~netpr
b~peinh
b~mwskz
b~knttp
b~bednr
INTO TABLE it_ekko_ekpo
FROM ekko AS a
INNER JOIN ekpo AS b
ON a~ebeln = b~ebeln
FOR ALL ENTRIES IN it_head_item
WHERE b~matnr = it_head_item-matnr
AND a~bukrs = p_bukrs " Company code
AND a~ekorg = p_ekorg " Purchase org
AND a~loekz <> c_x " Deletion indicator for header data
AND a~kdatb <= sy-datum " Validity period start
AND a~kdate >= sy-datum " Validity period end
AND b~loekz <> c_x " Deletion indicator for item data
AND b~bstyp = c_bstyp. " Purch. doc. category
IF sy-subrc = 0.
SORT it_ekko_ekpo BY matnr.
ENDIF.
LOOP AT it_head_item.
READ TABLE it_ekko_ekpo WITH KEY matnr = it_head_item-matnr
BINARY SEARCH.
IF sy-subrc <> 0.
*-- move the data to the internal table
*-- which doesnt have contract number
it_contract-ebeln = it_head_item-ebeln.
APPEND it_contract.
CLEAR it_contract.
*-- Deleting the record
*-- which doesnt have any contract number
DELETE it_head_item WHERE ebeln = it_head_item-ebeln.
ENDIF.
ENDLOOP.
CLEAR it_head_item.
ENDIF.
IF it_head_item[] IS INITIAL.
MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).
STOP.
ENDIF.
*-- Get the vendor country details.
IF NOT it_ekko_ekpo[] IS INITIAL.
SELECT lifnr
land1
INTO TABLE it_lfa1
FROM lfa1
FOR ALL ENTRIES IN it_ekko_ekpo
WHERE lifnr = it_ekko_ekpo-lifnr.
IF sy-subrc = 0.
SORT it_lfa1 BY lifnr.
ENDIF.
ENDIF.
ENDFORM. " GET_CONTRACT_NUM
&----
*& Form GET_DELIVERY_ADDRESS
&----
Delivery address details
----
FORM get_delivery_address .
*-- Get the Plant details.
SELECT werks adrnr
INTO TABLE it_plant_adrnr
FROM t001w.
*-- Get the delivery address details.
IF NOT it_head_item[] IS INITIAL.
SELECT addrnumber
name1
name2
street
house_num1
city1
city2
post_code1
country
region
INTO TABLE it_delivery_address
FROM adrc
FOR ALL ENTRIES IN it_head_item
WHERE addrnumber = it_head_item-adrnr.
IF sy-subrc = 0.
SORT it_delivery_address BY addrnumber.
ENDIF.
ENDIF.
*-- Get the Plant address details.
IF NOT it_plant_adrnr[] IS INITIAL.
SELECT addrnumber
name1
name2
street
house_num1
city1
city2
post_code1
country
region
APPENDING TABLE it_delivery_address
FROM adrc
FOR ALL ENTRIES IN it_plant_adrnr
WHERE addrnumber = it_plant_adrnr-adrnr.
IF sy-subrc = 0.
SORT it_delivery_address BY addrnumber.
ENDIF.
ENDIF.
ENDFORM. " GET_DELIVERY_ADDRESS
&----
*& Form CREATE_PO
&----
CREATE PURCHASE ORDER
----
FORM create_po .
DATA : fg_matnr_multi_contracts TYPE c,
l_contracts TYPE i.
SORT it_head_item BY ebeln.
LOOP AT it_head_item.
AT NEW ebeln.
REFRESH : it_poitemx,it_poitem,it_deliveryaddr,it_return , it_contracts_tmp.
CLEAR: x_poheader,x_poheaderx,x_poitem,x_poitemx,x_deliveryaddr,x_return,
x_err_log,x_succ_log, it_contracts_tmp,it_poitemx,it_poitem,
it_deliveryaddr,it_return.
READ TABLE it_head_item WITH KEY ebeln = it_head_item-ebeln.
**-Populate PO Header structure
x_poheader-po_number = it_head_item-ebeln. " PO no.
x_poheader-comp_code = p_bukrs. " Company code
x_poheader-doc_type = p_bsart1. " Document type
x_poheader-creat_date = it_head_item-aedat. " Date created
x_poheader-created_by = it_head_item-ernam. " Created by
x_poheader-langu = sy-langu. " Language key
x_poheader-langu_iso = sy-langu. " Language key iso
x_poheader-purch_org = p_ekorg. " Purchasing org.
x_poheader-pur_group = p_ekgrp. " Purch. Group
x_poheader-doc_date = it_head_item-bedat. " Doc date
**-Populate PO Header 'X' structure
x_poheaderx-po_number = c_x.
x_poheaderx-comp_code = c_x.
x_poheaderx-doc_type = c_x.
x_poheaderx-creat_date = c_x.
x_poheaderx-created_by = c_x.
x_poheaderx-vendor = c_x.
x_poheaderx-langu = c_x.
x_poheaderx-langu_iso = c_x.
x_poheaderx-pmnttrms = c_x.
x_poheaderx-purch_org = c_x.
x_poheaderx-pur_group = c_x.
x_poheaderx-currency = c_x.
x_poheaderx-currency_iso = c_x.
x_poheaderx-doc_date = c_x.
x_poheaderx-incoterms1 = c_x.
x_poheaderx-incoterms2 = c_x.
ENDAT.
LOOP AT it_ekko_ekpo WHERE matnr = it_head_item-matnr.
*-- Collecting the contracts of materials of this PO.
it_contracts_tmp-ebeln = it_ekko_ekpo-ebeln.
APPEND it_contracts_tmp.
CLEAR it_contracts_tmp.
ENDLOOP.
**-Populate PO Item structure
x_poitem-po_item = it_head_item-ebelp. " PO Item no.
x_poitem-agreement = it_ekko_ekpo-ebeln. " Agreement NO
x_poitem-net_price = it_ekko_ekpo-netpr. " Net price
x_poitem-price_unit = it_ekko_ekpo-peinh. " price per unit
x_poitem-tax_code = it_ekko_ekpo-mwskz. " Tax Code
x_poitem-acctasscat = it_ekko_ekpo-knttp. " Account ass cata
x_poitem-short_text = it_head_item-txz01. " Item description
x_poitem-material = it_head_item-matnr. " Material no.
x_poitem-plant = p_werks. " Plant
x_poitem-stge_loc = p_werks. " Storage Loc
x_poitem-matl_group = it_head_item-matkl. " Material group
x_poitem-quantity = it_head_item-menge. " Ordered qty.
x_poitem-po_unit = it_head_item-meins. " Order unit
x_poitem-po_unit_iso = it_head_item-meins. " Order unit
APPEND x_poitem TO it_poitem.
CLEAR x_poitem.
**-Populate PO Item 'X' structure
x_poitemx-po_item = it_head_item-ebelp. " PO Item no.
x_poitemx-po_itemx = c_x.
x_poitemx-short_text = c_x.
x_poitemx-material = c_x.
x_poitemx-plant = c_x.
x_poitemx-stge_loc = c_x.
x_poitemx-agreement = c_x.
x_poitemx-matl_group = c_x.
x_poitemx-quantity = c_x.
x_poitemx-po_unit = c_x.
x_poitemx-po_unit_iso = c_x.
x_poitemx-net_price = c_x.
x_poitemx-price_unit = c_x.
x_poitemx-tax_code = c_x.
x_poitemx-acctasscat = c_x.
APPEND x_poitemx TO it_poitemx.
CLEAR x_poitemx.
**-Populate PO Header deliveryaddr structure
READ TABLE it_delivery_address WITH KEY addrnumber = it_head_item-adrnr.
IF sy-subrc = 0.
x_deliveryaddr-po_item = it_head_item-ebelp.
x_deliveryaddr-addr_no = it_delivery_address-addrnumber.
x_deliveryaddr-name = it_delivery_address-name1.
x_deliveryaddr-name_2 = it_delivery_address-name2.
x_deliveryaddr-street = it_delivery_address-street.
x_deliveryaddr-house_no = it_delivery_address-house_num1.
x_deliveryaddr-postl_cod1 = it_delivery_address-post_code1.
x_deliveryaddr-district = it_delivery_address-city2.
x_deliveryaddr-city = it_delivery_address-city1.
x_deliveryaddr-country = it_delivery_address-country.
x_deliveryaddr-region = it_delivery_address-region.
APPEND x_deliveryaddr TO it_deliveryaddr.
CLEAR x_deliveryaddr.
ELSE.
**-Populate PO Header plant details
READ TABLE it_plant_adrnr WITH KEY werks = it_head_item-werks.
IF sy-subrc = 0.
READ TABLE it_delivery_address WITH KEY addrnumber = it_plant_adrnr-adrnr.
IF sy-subrc = 0.
x_deliveryaddr-po_item = it_head_item-ebelp.
x_deliveryaddr-addr_no = it_delivery_address-addrnumber.
x_deliveryaddr-name = it_delivery_address-name1.
x_deliveryaddr-name_2 = it_delivery_address-name2.
x_deliveryaddr-street = it_delivery_address-street.
x_deliveryaddr-house_no = it_delivery_address-house_num1.
x_deliveryaddr-postl_cod1 = it_delivery_address-post_code1.
x_deliveryaddr-district = it_delivery_address-city2.
x_deliveryaddr-city = it_delivery_address-city1. "CITY1
x_deliveryaddr-country = it_delivery_address-country.
x_deliveryaddr-region = it_delivery_address-region.
APPEND x_deliveryaddr TO it_deliveryaddr.
CLEAR x_deliveryaddr.
ENDIF.
ENDIF.
ENDIF.
AT END OF ebeln.
READ TABLE it_head_item WITH KEY ebeln = it_head_item-ebeln.
SORT it_contracts_tmp.
DELETE ADJACENT DUPLICATES FROM it_contracts_tmp.
DESCRIBE TABLE it_contracts_tmp LINES l_contracts.
*--materials of the PO have different contracts
*--among themselves...therefore error out.
IF l_contracts > 1.
it_po_matnr_mul_cont-ebeln = it_head_item-ebeln.
it_po_matnr_mul_cont-matnr = it_head_item-matnr.
APPEND it_po_matnr_mul_cont.
CLEAR it_po_matnr_mul_cont.
CONTINUE.
ENDIF.
x_poheader-vendor = it_ekko_ekpo-lifnr. " Vendor no.
x_poheader-incoterms1 = it_ekko_ekpo-inco1. " Incoterms1
x_poheader-incoterms2 = it_ekko_ekpo-inco2. " Incoterms2
x_poheader-pmnttrms = it_ekko_ekpo-zterm. " Payment terms
x_poheader-currency = it_ekko_ekpo-waers. " currency
x_poheader-currency_iso = it_ekko_ekpo-waers. " currency iso
<b>**-Call BAPI to create purchase order
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = x_poheader
poheaderx = x_poheaderx
TABLES
return = it_return
poitem = it_poitem
poitemx = it_poitemx
poaddrdelivery = it_deliveryaddr.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.</b>
---Append BAPI error's to success log
READ TABLE it_return INTO x_return WITH KEY type = 'S'
number = '017'.
IF sy-subrc = 0.
v_succ_po = it_head_item-ebeln.
PERFORM succ_po_log.
*-- Change PO
PERFORM change_po. ELSE.
---Append BAPI error's to error log
PERFORM err_po_log.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " CREATE_PO
&----
*& Form err_po_log
&----
text
----
FORM err_po_log .
**-Details of error log
LOOP AT it_return INTO x_return.
CLEAR x_err_log.
x_err_log-ebeln = it_head_item-ebeln.
x_err_log-type = x_return-type.
x_err_log-number = x_return-number.
x_err_log-message = x_return-message.
APPEND x_err_log TO it_err_log.
CLEAR x_err_log.
ENDLOOP.
ENDFORM. " err_po_log
&----
*& Form succ_po_log
&----
Details of sucess log
----
FORM succ_po_log .
**-Details of sucess log
CLEAR x_succ_log.
x_succ_log-ebeln = it_head_item-ebeln.
x_succ_log-type = x_return-type.
x_succ_log-number = x_return-number.
x_succ_log-message = x_return-message.
APPEND x_succ_log TO it_succ_log.
CLEAR x_succ_log.
ENDFORM. " succ_po_log
&----
*& Form list_heading
&----
text
----
FORM list_heading .
**-List heading
FORMAT COLOR COL_HEADING.
WRITE:/1(132) sy-uline.
WRITE:/1 sy-vline,
55 'Summary Report'(013),
132 sy-vline.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE:/1(132) sy-uline.
ENDFORM. " list_heading
&----
*& Form f_display_succ_po_log
&----
Success Purchase Orders log
----
FORM f_display_succ_po_log .
SKIP 3.
**-List heading
WRITE:/1(132) sy-uline.
WRITE:/1 sy-vline,
40 'Success messages for HIH PO Creation'(024),
132 sy-vline.
WRITE:/1(132) sy-uline.
**-Column headings
FORMAT COLOR COL_HEADING.
WRITE:/1 sy-vline,
2 'Purchase Order'(015),
16 sy-vline,
17 'Error Type'(016),
28 sy-vline,
29 'Error Value'(017),
41 sy-vline,
42 'Error Message'(018),
132 sy-vline.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE:/1(132) sy-uline.
LOOP AT it_succ_log INTO x_succ_log.
WRITE:/1 sy-vline,
2 x_succ_log-ebeln,
16 sy-vline,
17 x_succ_log-type,
28 sy-vline,
29 x_succ_log-number,
41 sy-vline,
42 x_succ_log-message,
132 sy-vline.
WRITE:/1(132) sy-uline.
ENDLOOP.
WRITE:/1(132) sy-uline.
ENDFORM. " f_display_succ_po_log
&----
*& Form f_display_err_po_log
&----
Error Purchase Orders log
----
FORM f_display_err_po_log .
SKIP 3.
**-List heading
WRITE:/1(132) sy-uline.
WRITE:/1 sy-vline,
40 'Error messages for HIH PO creation'(025),
132 sy-vline.
WRITE:/1(132) sy-uline.
**-Column headings
FORMAT COLOR COL_HEADING.
WRITE:/1 sy-vline,
2 'Purchase Order'(015),
16 sy-vline,
17 'Error Type'(016),
28 sy-vline,
29 'Error Value'(017),
41 sy-vline,
42 'Error Message'(018),
132 sy-vline.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE:/1(132) sy-uline.
LOOP AT it_err_log INTO x_err_log.
WRITE:/1 sy-vline,
2 x_err_log-ebeln,
16 sy-vline,
17 x_err_log-type,
28 sy-vline,
29 x_err_log-number,
41 sy-vline,
42 x_err_log-message,
132 sy-vline.
AT END OF ebeln.
WRITE:/1(132) sy-uline.
ENDAT.
ENDLOOP.
ENDFORM. " f_display_err_po_log
&----
*& Form display_createdpo_rept
&----
List of PO already created
----
FORM display_createdpo_rept .
SKIP 3.
**-Column headings
FORMAT COLOR COL_HEADING.
WRITE:/1(132) sy-uline.
WRITE:/1 sy-vline,
55 'List of PO already created'(020),
132 sy-vline.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE:/1(132) sy-uline.
*-- Display PO created sucess report
LOOP AT it_sucess.
WRITE:/1 sy-vline,
15 'Purchase Order NO:'(021),
50 sy-vline,
60 it_sucess-ebeln,
132 sy-vline.
AT LAST.
WRITE:/1(132) sy-uline.
ENDAT.
ENDLOOP.
ENDFORM. " display_createdpo_rept
&----
*& Form display_contract_rept
&----
List of PO which doesnt have Contract Numbers
----
FORM display_contract_rept .
SKIP 3.
**-Column headings
FORMAT COLOR COL_HEADING.
WRITE:/1(132) sy-uline.
WRITE:/1 sy-vline,
55 'List of Contract Numbers'(022),
132 sy-vline.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE:/1(132) sy-uline.
LOOP AT it_contract.
WRITE:/1 sy-vline,
15 'Purchase Order NO:'(021),
50 sy-vline,
60 it_contract-ebeln,
132 sy-vline.
AT LAST.
WRITE:/1(132) sy-uline.
ENDAT.
ENDLOOP.
ENDFORM. " display_contract_rept
Thanks
Vikranth Khimavath
Message was edited by:
Khimavath Vikranth
2006 Dec 22 1:49 PM
we have to give data for all fields when creating po? plz tell me what r the mandatory fields required to create po.
2006 Dec 26 8:50 AM
hi
Vendor, purchasing org & purchasing grp are three mandatory field.
Hope this helps.
Regds,
Seema
2006 Dec 26 8:58 AM
HI Neela
The cominations will vary basing on the document types. Hence, the best way to approach this is create a document online via transaction ME21N. Through this we will know the necessary fields to be populated. If you can not manage to create a document, seek the help of your consultant to understand the same. This will definetely help us in handling the coding...
The important thing i want to highlight is, generally we miss out passing the item numbers as they will be generated internally. But it is always better to pass the item number while using BAPI's, to have the control while passing details like Schedule Lines, Conditions, Account Assignment...
Kind Regards
Eswar