Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPO_PO_CREATE1 giving errors while creating PO by uploading a file?

Former Member
0 Kudos

Hi,

when i am creating Purchase Order using BAPO_PO_CREATE1 by uploading a File, it is giving below errors

1-> No instance of object type PurchaseOrder has been created. External reference:

2-> PO header data still faulty

3-> No master record exists for vendor 100017

4-> Vendor 100017 does not exist

5-> Can delivery date be met?

and i passed data to bapi as below

CONSTANTS: c_x TYPE c VALUE 'X',

c_err TYPE bdc_mart VALUE 'E'.

*Structures to hold PO header data

DATA : header LIKE bapimepoheader ,

headerx LIKE bapimepoheaderx .

*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

rettab LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: bapi_err_count TYPE i,

bapi_warnings TYPE i,

ponumber LIKE ekpo-ebeln,

item_num LIKE ekpo-ebelp.

DATA : BEGIN OF i_dbtab OCCURS 0,

bukrs LIKE ekko-bukrs, " company code

bsart LIKE ekko-bsart, " Po document type

bedat(10) TYPE c, " po document data

lifnr LIKE ekko-lifnr, " vendor

ekorg LIKE ekko-ekorg, " Purchase organisation

ekgrp LIKE ekko-ekgrp, " Purchase group

currency like ekko-waers,

item like ekpo-ebelp,

matnr(18) TYPE n, " Article

werks LIKE ekpo-werks, " Werks

mat_grp type matkl,

menge(10) TYPE c, " Menge

netwr type BAPICUREXT. " nat value

DATA : END OF i_dbtab.

DATA : wa_dbtab LIKE i_dbtab.

&----


  • SELECTION-SCREEN DESIGN *

&----


PARAMETERS: p_file LIKE rlgrap-filename MEMORY ID m01 OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = ''

static = ''

CHANGING

file_name = p_file.

START-OF-SELECTION.

PERFORM f_file_upload.

IF i_dbtab[] IS NOT INITIAL.

PERFORM f_po_create.

ENDIF.

&----


*& Form f_file_upload

&----


FORM f_file_upload .

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_dbtab

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

OTHERS = 11.

IF sy-subrc <> 0.

MESSAGE e004 WITH 'File upload Failed'.

ENDIF.

ENDFORM. " f_file_upload

&----


*& Form F_po_create

&----


FORM f_po_create.

DATA : cc TYPE i,

l_lifnr LIKE lfa1-lifnr.

LOOP AT i_dbtab INTO wa_dbtab.

cc = cc + 1.

IF cc = 1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_dbtab-lifnr

IMPORTING

output = l_lifnr.

*POPULATE HEADER DATA FOR PO

header-comp_code = wa_dbtab-bukrs.

header-doc_type = wa_dbtab-bsart. "Standard Order

header-creat_date = sy-datum.

header-vendor = wa_dbtab-lifnr.

header-purch_org = wa_dbtab-ekorg.

header-pur_group = wa_dbtab-ekgrp.

header-currency = wa_dbtab-currency.

*POPULATE HEADER FLAG.

headerx-comp_code = c_x.

headerx-doc_type = c_x.

headerx-creat_date = c_x.

headerx-vendor = c_x.

headerx-purch_org = c_x.

headerx-pur_group = c_x.

headerX-currency = c_x.

  • headerX-currency_iso = c_x.

ENDIF.

*POPULATE ITEM DATA.

item-po_item = wa_dbtab-item.

item-material = wa_dbtab-matnr.

item-plant = wa_dbtab-werks.

item-matl_group = wa_dbtab-mat_grp.

item-quantity = wa_dbtab-menge.

item-net_price = wa_dbtab-netwr.

APPEND item.

CLEAR item.

*POPULATE ITEM FLAG TABLE

itemx-po_item = wa_dbtab-item.

itemx-po_itemx = c_x.

itemx-material = c_x.

itemx-plant = c_x .

itemx-matl_group = c_x.

itemx-quantity = c_x .

itemx-net_price = c_x.

APPEND itemx.

CLEAR itemx.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = header

poheaderx = headerx

IMPORTING

exppurchaseorder = ponumber

TABLES

return = rettab

poitem = item

poitemx = itemx.

PERFORM f_bapi_errors.

*

IF bapi_err_count = 0.

PERFORM bapi_commit.

  • PERFORM f_bapi_errors.

WRITE: 'Created Po no:', ponumber COLOR 5.

else.

PERFORM bapi_commit.

ENDIF.

ENDFORM. " F_po_change

----


  • FORM f_bapi_errors *

----


FORM f_bapi_errors.

CLEAR: bapi_err_count, bapi_warnings.

LOOP AT rettab.

CASE rettab-type.

WHEN 'S' OR 'I'.

WHEN 'W'.

ADD 1 TO bapi_warnings.

WRITE rettab-message COLOR 3.

  • PERFORM zjnc_dump_list USING 'RETTAB[]' 'RETTAB' 'Bapi Errors Table'.

WHEN OTHERS.

ADD 1 TO bapi_err_count.

WRITE rettab-message COLOR 6.

  • PERFORM zjnc_dump_list USING 'RETTAB[]' 'RETTAB' 'Bapi Errors Table'.

ENDCASE.

ENDLOOP. " LOOP AT RETTAB

  • IF bapi_err_count <> 0.

  • MESSAGE e999 WITH 'Note Messages and inform SAP Support'.

  • ENDIF.

REFRESH rettab.

ENDFORM. "f_bapi_errors

&----


*& Form bapi_commit

&----


FORM bapi_commit.

  • commit the changes

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X' " COMMIT WORK AND WAIT

IMPORTING

return = rettab. " Confirmations

ENDFORM. "bapi_commit

can anyone me how to solve it.

3 REPLIES 3

Former Member
0 Kudos

First u check whether the Vendor -- 100017 exists in table LFA1 or not. All the vendors that ur using should be in LFA1 (Vendor Master).

rejish_balakrishnan
Contributor
0 Kudos

HI,

Also 'Can delivery date be met ' is the usual information meesage u get when u give date atleast a day after today as date .

Write an inner join for vendor master table and the PO details

(Which is also a recommened way of checking value from master table all the time )

Former Member
0 Kudos

Thank U