11-16-2006 7:59 PM
Hello I want to create an order traslate (ME21N)
By the BAPI BAPI_PO_CREATE1
Some example?
Message was edited by:
Erick Aragon Zepeda
11-16-2006 8:38 PM
Here is an example program.
report zrich_0001.
constants : c_x value 'X'.
data: del_date type sy-datum.
data: pohead type bapimepoheader.
data: poheadx type bapimepoheaderx.
data: exp_head type bapimepoheader.
data: return type table of bapiret2 with header line.
data: poitem type table of bapimepoitem with header line.
data: poitemx type table of bapimepoitemx with header line.
data: posched type table of bapimeposchedule with header line.
data: poschedx type table of bapimeposchedulx with header line.
data: ex_po_number type bapimepoheader-po_number.
parameters: p_matnr type ekpo-matnr.
parameters: p_werks type ekpo-werks.
parameters: p_lgort type ekpo-lgort.
parameters: p_menge type ekpo-menge.
parameters: p_lifnr type ekko-lifnr.
parameters: p_ekorg type ekko-ekorg.
parameters: p_ekgrp type ekko-ekgrp.
parameters: p_bukrs type ekko-bukrs.
* Header Level Data
pohead-comp_code = p_bukrs.
pohead-doc_type = 'NB' .
pohead-creat_date = sy-datum .
pohead-vendor = p_lifnr.
pohead-purch_org = p_ekorg.
pohead-pur_group = p_ekgrp.
pohead-langu = sy-langu .
pohead-doc_date = sy-datum.
poheadx-comp_code = c_x.
poheadx-doc_type = c_x.
poheadx-creat_date = c_x.
poheadx-vendor = c_x.
poheadx-langu = c_x.
poheadx-purch_org = c_x.
poheadx-pur_group = c_x.
poheadx-doc_date = c_x.
* Item Level Data
poitem-po_item = 1.
poitem-material = p_matnr.
poitem-plant = p_werks.
poitem-stge_loc = p_lgort.
poitem-quantity = p_menge.
append poitem.
poitemx-po_item = 1.
poitemx-po_itemx = c_x.
poitemx-material = c_x.
poitemx-plant = c_x .
poitemx-stge_loc = c_x .
poitemx-quantity = c_x .
poitemx-tax_code = c_x .
poitemx-item_cat = c_x .
poitemx-acctasscat = c_x .
append poitemx.
* Schedule Line Level Data
posched-po_item = 1.
posched-sched_line = 1.
posched-del_datcat_ext = 'D'.
del_date = sy-datum + 1.
write del_date to posched-delivery_date.
posched-deliv_time = '000001'.
posched-quantity = p_menge.
append posched.
poschedx-po_item = 1.
poschedx-sched_line = 1.
poschedx-po_itemx = c_x.
poschedx-sched_linex = c_x.
poschedx-del_datcat_ext = c_x.
poschedx-delivery_date = c_x.
poschedx-quantity = c_x.
append poschedx.
call function 'BAPI_PO_CREATE1'
exporting
poheader = pohead
poheaderx = poheadx
testrun = ' '
importing
exppurchaseorder = ex_po_number
expheader = exp_head
tables
return = return
poitem = poitem
poitemx = poitemx
poschedule = posched
poschedulex = poschedx.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
if not ex_po_number is initial.
call function 'DEQUEUE_ALL'.
else.
call function 'DEQUEUE_ALL'.
* message i036.
endif.
Regards,
Rich Heilman
11-16-2006 8:04 PM
11-16-2006 8:38 PM
Here is an example program.
report zrich_0001.
constants : c_x value 'X'.
data: del_date type sy-datum.
data: pohead type bapimepoheader.
data: poheadx type bapimepoheaderx.
data: exp_head type bapimepoheader.
data: return type table of bapiret2 with header line.
data: poitem type table of bapimepoitem with header line.
data: poitemx type table of bapimepoitemx with header line.
data: posched type table of bapimeposchedule with header line.
data: poschedx type table of bapimeposchedulx with header line.
data: ex_po_number type bapimepoheader-po_number.
parameters: p_matnr type ekpo-matnr.
parameters: p_werks type ekpo-werks.
parameters: p_lgort type ekpo-lgort.
parameters: p_menge type ekpo-menge.
parameters: p_lifnr type ekko-lifnr.
parameters: p_ekorg type ekko-ekorg.
parameters: p_ekgrp type ekko-ekgrp.
parameters: p_bukrs type ekko-bukrs.
* Header Level Data
pohead-comp_code = p_bukrs.
pohead-doc_type = 'NB' .
pohead-creat_date = sy-datum .
pohead-vendor = p_lifnr.
pohead-purch_org = p_ekorg.
pohead-pur_group = p_ekgrp.
pohead-langu = sy-langu .
pohead-doc_date = sy-datum.
poheadx-comp_code = c_x.
poheadx-doc_type = c_x.
poheadx-creat_date = c_x.
poheadx-vendor = c_x.
poheadx-langu = c_x.
poheadx-purch_org = c_x.
poheadx-pur_group = c_x.
poheadx-doc_date = c_x.
* Item Level Data
poitem-po_item = 1.
poitem-material = p_matnr.
poitem-plant = p_werks.
poitem-stge_loc = p_lgort.
poitem-quantity = p_menge.
append poitem.
poitemx-po_item = 1.
poitemx-po_itemx = c_x.
poitemx-material = c_x.
poitemx-plant = c_x .
poitemx-stge_loc = c_x .
poitemx-quantity = c_x .
poitemx-tax_code = c_x .
poitemx-item_cat = c_x .
poitemx-acctasscat = c_x .
append poitemx.
* Schedule Line Level Data
posched-po_item = 1.
posched-sched_line = 1.
posched-del_datcat_ext = 'D'.
del_date = sy-datum + 1.
write del_date to posched-delivery_date.
posched-deliv_time = '000001'.
posched-quantity = p_menge.
append posched.
poschedx-po_item = 1.
poschedx-sched_line = 1.
poschedx-po_itemx = c_x.
poschedx-sched_linex = c_x.
poschedx-del_datcat_ext = c_x.
poschedx-delivery_date = c_x.
poschedx-quantity = c_x.
append poschedx.
call function 'BAPI_PO_CREATE1'
exporting
poheader = pohead
poheaderx = poheadx
testrun = ' '
importing
exppurchaseorder = ex_po_number
expheader = exp_head
tables
return = return
poitem = poitem
poitemx = poitemx
poschedule = posched
poschedulex = poschedx.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
if not ex_po_number is initial.
call function 'DEQUEUE_ALL'.
else.
call function 'DEQUEUE_ALL'.
* message i036.
endif.
Regards,
Rich Heilman
11-17-2006 1:28 AM
When I run the program the error is Material OB-TS5104-4441 not maintained by Purchasing.
Some idea???
11-17-2006 1:51 AM
11-17-2006 2:09 AM
Hi Erick
Alternatively you can extract a material from table MARA where field PSTAT contains character E.
For your information, below characters identifies various views that are maintained for a material.
<b>A Work scheduling
B Accounting
C Classification
D MRP
E Purchasing
F Production resources/tools
G Costing
K Basic data
L Storage
P Forecasting
Q Quality management
S Warehouse management
V Sales
X Plant stocks
Z Storage location stocks</b>
Hope this helps.
Kind Regards
Eswar
11-17-2006 5:56 PM
The purchasing view on the material master has been maintained and the field PSTAT contains the character E (KVEDLB)....
The company sells material of footwear and textile. Therefore I must also fill the size of the material This affects. So that I see that in your code you do not put the size.
11-17-2006 10:26 AM
I have a samll Question :
I have in entry of Method an internal table , and I ignore the fields contain on it.
the goal is to separate each two fields with separator. and write it in text file.
how I can do that :
Ex:
Internal table
PP OO KK
MM CC TT
What I want to do is :
PP;OO;KK
MM;CC;TT
Note That I ignore the structure of the table. I know just that is table
11-17-2006 10:29 AM
Hi Erick,
Refer sample Code below:
&----
*& Report YDM_PO_CREATE *
*& *
&----
*& *
*& *
&----
REPORT ydm_po_create.
*-- Input File Declaration
TYPES: BEGIN OF ty_input_file,
column1 TYPE char50,
column2 TYPE char50,
column3 TYPE char50,
column4 TYPE char50,
column5 TYPE char50,
column6 TYPE char50,
column7 TYPE char50,
column8 TYPE char50,
column9 TYPE char50,
column10 TYPE char50,
column11 TYPE char50,
column12 TYPE char50,
column13 TYPE char50,
column14 TYPE char50,
column15 TYPE char50,
column16 TYPE char50,
column17 TYPE char50,
column18 TYPE char50,
END OF ty_input_file.
DATA: i_input_file TYPE STANDARD TABLE OF ty_input_file,
wa_input_file TYPE ty_input_file.
CONSTANTS: c_path TYPE char20 VALUE 'C:\',
c_mask TYPE char9 VALUE ',*.*,*.*.',
c_mode TYPE char1 VALUE 'O',
c_filetype TYPE char10 VALUE 'ASC',
c_x TYPE char01 VALUE 'X'.
PARAMETERS : p_fname LIKE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
*-- Browse Presentation Server
PERFORM f4_presentation_file.
START-OF-SELECTION..
*-- Read presentation server file
PERFORM f1003_upload_file.
IF NOT i_input_file[] IS INITIAL.
PERFORM split_data.
ENDIF.
*&----
*& Form f4_presentation_file
*&----
*& F4 Help for presentation server
*&----
FORM f4_presentation_file .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = c_path
mask = c_mask
mode = c_mode
title = text-001
IMPORTING
filename = p_fname
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " f4_presentation_file
*&----
*& Form f1003_upload_file
*&----
*& Upload File
*&----
FORM f1003_upload_file .
DATA: lcl_filename TYPE string.
lcl_filename = p_fname.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lcl_filename
filetype = c_filetype
has_field_separator = c_x
TABLES
data_tab = i_input_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
ENDFORM. " f1003_upload_file
&----
*& Form split_data
&----
Collect data for creating Purchase Order
----
FORM split_data .
DATA: i_poitem TYPE STANDARD TABLE OF bapimepoitem,
i_poitemx TYPE STANDARD TABLE OF bapimepoitemx,
i_poitem_sch TYPE STANDARD TABLE OF bapimeposchedule,
i_poitem_schx TYPE STANDARD TABLE OF bapimeposchedulx,
i_acct_ass TYPE STANDARD TABLE OF bapimepoaccount,
i_acct_assx TYPE STANDARD TABLE OF bapimepoaccountx,
i_services TYPE STANDARD TABLE OF bapiesllc ,
i_srvacc TYPE STANDARD TABLE OF bapiesklc,
i_return TYPE STANDARD TABLE OF bapiret2,
wa_header TYPE bapimepoheader,
wa_headerx TYPE bapimepoheaderx,
wa_poitem TYPE bapimepoitem,
wa_poitemx TYPE bapimepoitemx,
wa_poitem_sch TYPE bapimeposchedule,
wa_poitem_schx TYPE bapimeposchedulx,
wa_acct_ass TYPE bapimepoaccount,
wa_acct_assx TYPE bapimepoaccountx,
wa_services TYPE bapiesllc,
wa_srvacc TYPE bapiesklc,
wa_return TYPE bapiret2,
ws_po TYPE bapimepoheader-po_number.
break gbpra8.
wa_services-pckg_no = 10.
wa_services-line_no = 1.
wa_services-outl_no = '0'.
wa_services-outl_ind = c_x.
wa_services-subpckg_no = 20.
APPEND wa_services TO i_services.
wa_srvacc-pckg_no = 10.
wa_srvacc-line_no = 1.
wa_srvacc-serno_line = 01.
wa_srvacc-serial_no = 01.
wa_srvacc-percentage = 100.
APPEND wa_srvacc TO i_srvacc.
LOOP AT i_input_file INTO wa_input_file.
IF wa_input_file-column2 EQ 'HD'.
wa_header-doc_type = wa_input_file-column3.
wa_header-creat_date = sy-datum.
wa_header-created_by = sy-uname.
wa_header-vendor = wa_input_file-column4.
PERFORM conversion_output USING wa_header-vendor
CHANGING wa_header-vendor.
wa_header-comp_code = 'DE03'.
wa_header-purch_org = 'DE03'.
wa_header-pur_group = 'DE1'.
wa_header-vper_start = wa_input_file-column9.
wa_header-vper_end = wa_input_file-column10.
wa_headerx-comp_code = c_x.
wa_headerx-doc_type = c_x.
wa_headerx-creat_date = c_x.
wa_headerx-created_by = c_x.
wa_headerx-vendor = c_x.
wa_headerx-purch_org = c_x.
wa_headerx-pur_group = c_x.
wa_headerx-vper_start = c_x.
wa_headerx-vper_end = c_x.
ENDIF.
IF wa_input_file-column2 EQ 'IT'.
wa_poitem-po_item = wa_input_file-column3.
wa_poitem-short_text = wa_input_file-column6.
wa_poitem-plant = wa_input_file-column8.
wa_poitem-quantity = '1'.
wa_poitem-tax_code = 'V0'.
wa_poitem-item_cat = 'D'.
wa_poitem-acctasscat = 'K'.
wa_poitem-matl_group = wa_input_file-column7.
wa_poitem-pckg_no = '10'.
APPEND wa_poitem TO i_poitem .
wa_poitemx-po_item = wa_input_file-column3.
wa_poitemx-po_itemx = c_x.
wa_poitemx-short_text = c_x.
wa_poitemx-plant = c_x.
wa_poitemx-quantity = c_x.
wa_poitemx-tax_code = c_x.
wa_poitemx-item_cat = c_x.
wa_poitemx-acctasscat = c_x.
wa_poitemx-matl_group = c_x.
wa_poitemx-pckg_no = c_x.
APPEND wa_poitemx TO i_poitemx.
wa_poitem_sch-po_item = wa_input_file-column3.
wa_poitem_sch-delivery_date = sy-datum.
APPEND wa_poitem_sch TO i_poitem_sch.
wa_poitem_schx-po_item = wa_input_file-column3.
wa_poitem_schx-po_itemx = c_x.
wa_poitem_schx-delivery_date = c_x.
APPEND wa_poitem_schx TO i_poitem_schx.
wa_acct_ass-po_item = 10.
wa_acct_ass-serial_no = 01.
wa_acct_ass-gl_account = '0006360100'.
wa_acct_ass-co_area = '1000'.
wa_acct_ass-costcenter = 'KC010000'.
APPEND wa_acct_ass TO i_acct_ass.
wa_acct_ass-po_item = 10.
wa_acct_ass-serial_no = 02.
wa_acct_ass-gl_account = '0006360100'.
wa_acct_ass-co_area = '1000'.
wa_acct_ass-costcenter = 'KC010000'.
APPEND wa_acct_ass TO i_acct_ass.
wa_acct_assx-po_item = 10.
wa_acct_assx-serial_no = 01.
wa_acct_assx-po_itemx = c_x.
wa_acct_assx-serial_nox = c_x.
wa_acct_assx-gl_account = c_x.
wa_acct_assx-co_area = c_x.
wa_acct_assx-costcenter = c_x.
APPEND wa_acct_assx TO i_acct_assx.
wa_acct_assx-po_item = 10.
wa_acct_assx-serial_no = 02.
wa_acct_assx-po_itemx = c_x.
wa_acct_assx-serial_nox = c_x.
wa_acct_assx-gl_account = c_x.
wa_acct_assx-co_area = c_x.
wa_acct_assx-costcenter = c_x.
APPEND wa_acct_assx TO i_acct_assx.
wa_services-pckg_no = 20.
wa_services-line_no = 2.
wa_services-service = wa_input_file-column9.
wa_services-quantity = '100'.
wa_services-gr_price = '100'.
wa_services-userf1_txt = wa_input_file-column13.
APPEND wa_services TO i_services.
wa_srvacc-pckg_no = 20.
wa_srvacc-line_no = 1.
wa_srvacc-serno_line = 02.
wa_srvacc-serial_no = 02.
wa_srvacc-percentage = 100.
APPEND wa_srvacc TO i_srvacc.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_header
poheaderx = wa_headerx
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
NO_MESSAGING =
NO_MESSAGE_REQ =
NO_AUTHORITY =
NO_PRICE_FROM_PO =
IMPORTING
exppurchaseorder = ws_po
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
return = i_return
poitem = i_poitem
poitemx = i_poitemx
POADDRDELIVERY =
poschedule = i_poitem_sch
poschedulex = i_poitem_schx
poaccount = i_acct_ass
POACCOUNTPROFITSEGMENT =
poaccountx = i_acct_assx
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
poservices = i_services
posrvaccessvalues = i_srvacc
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
.
break gbpra8.
LOOP AT i_return INTO wa_return.
ENDLOOP.
ENDFORM. " split_data
&----
*& Form conversion_output
&----
Conversion exit input
----
FORM conversion_output USING p_ip
CHANGING p_op.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_ip
IMPORTING
output = p_op.
ENDFORM. " conversion_output
Reward points if this Helps.
Manish