Application Development and Automation 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: 
Read only

BAPI_PO_CREATE problem, kindly help

Former Member
0 Likes
2,778

Hello all,

I am trying to create PO by reading data from a text file.

when i execute the code , BAPI returns the following error: "E 06101 No master record exists for vendor 100014"

I posted PO with the same data in ME21N and also in SE37 using BAPI_PO_CREATE. But only when i try to post through my program i get this error. Also Vendor 100014 exists with purchasing information in it. I tried with other vendors too, 100011,100012 etc, i get the same error while trying to create PO using the program. Can any one please direct me to fix this problem.

Thanks.

Karan

1 ACCEPTED SOLUTION
Read only

Former Member
1,935

hi,

-->"I posted PO with the same data in ME21N and also in SE37 using BAPI_PO_CREATE."

check the BAPI Version,if your programm are using the right one.

And check the BAPI document, if you have miss some important information to create this bapi.

Regards

8 REPLIES 8
Read only

Former Member
0 Likes
1,935

Open BAPI_PO_CREATE in SE37 and use find to search for the error message line in main program.

search for 101 and hopefully you will find the error message point in the code and then put a temp break-point over there and a block before thet , run your program again.

But if you could not find the error message in the code then it means that message is thrown in some called FM.

You can also try searching this message by SE91 ->error message --> where used. If found, put the breakpoint similarly.

If now found,then in that case you need to debug it completely.

Cheers,

Ram

Read only

Former Member
1,936

hi,

-->"I posted PO with the same data in ME21N and also in SE37 using BAPI_PO_CREATE."

check the BAPI Version,if your programm are using the right one.

And check the BAPI document, if you have miss some important information to create this bapi.

Regards

Read only

0 Likes
1,935

i feel the issue is the alpha conversion of the vendor number.

use fm

CONVERSION_EXIT_ALPHA_INPUT

vendor_variable = '10014'

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = vendor_variable

IMPORTING

OUTPUT = vendor_variable .

after the function call vendor_variable will be

0000010014.

you need to use the new vendor number with preceeding 0's.

in SE37 - you will not face this problem as SAP take care of it automatically.

Regards

Raja

Read only

0 Likes
1,935

I think Raja is on the right track also.

You can use the function modules as he suggested, or just put the vendor number into a type N field, like this:


DATA: w_vendor       LIKE EKKO-LIFNR,
      w_vendor_n(10) TYPE N.
* Lets assign w_vendor the vendor number 10014 (you would
* get this from your text file)
  w_vendor = '10014'.
* Convert vendor number 10014 to vendor number 00000010014
  w_vendor_n = w_vendor.
* Now use w_vendor_n in the BAPI.
  CALL FUNCTION 'BAPI_PO_CREATE' ...

That should help.

Cheers,

Brad

Read only

0 Likes
1,935

Hello every one,

Thanks a lot for your replies, Brad and Raja, it looks like your solutions fixed the problem, i dont get that error message anymore, but i do get some other error message

"A ME159 Function modules invoked in wrong sequence".

Any idea on why i getn that error message, i have my code below, can you please help me on this.

  • FILE READ DECLARATIONS*

types:begin of zinrec_type,

bukrs like ekko-bukrs ,

ekorg like ekko-ekorg ,

ekgrp like ekko-ekgrp ,

bsart like ekko-bsart ,

lifnr like ekko-lifnr ,

bedat like ekko-bedat ,

ernam like ekko-ernam ,

ihrez like ekko-ihrez ,

ebelp like ekpo-ebelp ,

matnr like ekpo-matnr ,

werks like ekpo-werks ,

lgort like ekpo-lgort ,

eindt like eket-eindt ,

menge type menge_bi ,

meins like ekpo-meins ,

netpr type bprei_bi,

peinh type peinh_bi ,

end of zinrec_type.

types:zinrec_typed(512) type c.

  • HEADER DECLARATIONS

types:begin of zpo_hdr,

ebeln like ekko-ebeln ,

bukrs like ekko-bukrs ,

ekorg like ekko-ekorg ,

ekgrp like ekko-ekgrp ,

bsart like ekko-bsart ,

lifnr like ekko-lifnr ,

bedat like ekko-bedat ,

ernam like ekko-ernam ,

end of zpo_hdr.

TYPES:begin of zad_hdrec,

IHREZ like EKKO-ihrez,

end of zad_hdrec.

*ITEM DECLARATIONS

types:begin of zpo_itm ,

ebelp like ekpo-ebelp ,

matnr like ekpo-matnr ,

werks like ekpo-werks ,

lgort like ekpo-lgort ,

meins like ekpo-meins ,

peinh like ekpo-peinh ,

end of zpo_itm.

types:begin of zpo_sch,

ebelp like ekpo-ebelp,

eindt like eket-eindt,

menge like ekpo-menge,

end of zpo_sch.

  • INTERNAL TABLES FOR ITEM LEVEL

data:begin of gt_item occurs 0,

ebelp like ekpo-ebelp ,

matnr like ekpo-matnr ,

werks like ekpo-werks ,

lgort like ekpo-lgort ,

meins like ekpo-meins ,

netpr like ekpo-netpr,

peinh like ekpo-peinh ,

end of gt_item.

data:begin of gt_sch occurs 0,

ebelp like ekpo-ebelp,

eindt like eket-eindt,

menge like ekpo-menge,

end of gt_sch.

data:inrec(512) type c.

data:wa_inrec type zinrec_type.

data:gt_inrec type zinrec_type occurs 0.

data:gt_inrecd type zinrec_typed occurs 0 with header line.

data:wa_hdrrec type zpo_hdr.

data:wa_ad_hdrec type zad_hdrec.

data:wa_sch type zpo_sch.

data:wa_itmrec type zpo_itm.

data:wa_prev_hdr type zpo_hdr.

data:gt_hdr type zpo_hdr occurs 0.

data:wa_inrec_cnt type i.

data:wa_error_cnt type i.

data:wa_po_cnt type i.

*DECLARATIONS FOR MOVING VALUES INTO BAPI

data:begin of i_po_hed.

include structure BAPIEKKOC.

data:end of i_po_hed.

data:begin of i_po_ad_hed.

include structure BAPIEKKOA.

data:end of i_po_ad_hed.

data:begin of i_po_item occurs 0.

include structure BAPIEKPOC.

data:end of i_po_item.

data:begin of i_po_sch occurs 0.

include structure BAPIEKET.

data:end of i_po_sch.

data:begin of i_po_return occurs 0.

include structure BAPIRETURN.

data:end of i_po_return.

data:begin of i_po_num occurs 0.

include structure BAPIEKKOC.

data:end of i_po_num.

data:w_vendor_n(10) TYPE N.

*SELECTION SCREEN

selection-screen:begin of block blk1 with frame title text-001.

parameters:p_dtop radiobutton group grp1.

parameters:p_unix radiobutton group grp1.

parameters:p_infile(128) type c lower case default

'/usr/iface/VO2/in/fback/create_po.txt'.

parameters:p_delim type c obligatory default ','.

selection-screen:end of block blk1.

************************************************************************

                                    • AT SELECTION-SCREEN FOR FILE OPEN DIALOG ************

at selection-screen.

if p_unix ne space.

open dataset p_infile for input in text mode.

if sy-subrc ne 0.

message e999(zg) with text-002.

endif.

endif.

  • SPLITTING FILE CONTENTS AT DELIMIT

start-of-selection.

if p_unix ne space.

do.

read dataset p_infile into inrec.

if sy-subrc ne 0.

exit.

endif.

split inrec at p_delim into wa_inrec-bukrs

wa_inrec-ekorg

wa_inrec-ekgrp

wa_inrec-bsart

wa_inrec-lifnr

wa_inrec-bedat

wa_inrec-ernam

wa_inrec-ihrez

wa_inrec-ebelp

wa_inrec-matnr

wa_inrec-werks

wa_inrec-lgort

wa_inrec-eindt

wa_inrec-menge

wa_inrec-meins

wa_inrec-netpr

wa_inrec-peinh.

append wa_inrec to gt_inrec.

enddo.

else.

*UPLOAD FILE CONTENTS

call function 'UPLOAD'

  • EXPORTING

  • CODEPAGE = ' '

  • FILENAME = ' '

  • FILETYPE = ' '

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

tables

data_tab = gt_inrecd

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

  • SPLITTING FILE CONTENTS AT DELIMIT

loop at gt_inrecd.

split gt_inrecd at p_delim into wa_inrec-bukrs

wa_inrec-ekorg

wa_inrec-ekgrp

wa_inrec-bsart

wa_inrec-lifnr

wa_inrec-bedat

wa_inrec-ernam

wa_inrec-ihrez

wa_inrec-ebelp

wa_inrec-matnr

wa_inrec-werks

wa_inrec-lgort

wa_inrec-eindt

wa_inrec-menge

wa_inrec-meins

wa_inrec-netpr

wa_inrec-peinh.

append wa_inrec to gt_inrec.

endloop.

endif.

loop at gt_inrec into wa_inrec.

move-corresponding wa_inrec to wa_hdrrec.

move-corresponding wa_inrec to wa_ad_hdrec.

move-corresponding wa_inrec to wa_itmrec.

move-corresponding wa_inrec to wa_sch.

if wa_prev_hdr ne wa_hdrrec.

if sy-tabix ne 1.

perform create_po.

endif.

move wa_hdrrec to wa_prev_hdr.

move-corresponding wa_itmrec to gt_item.

append gt_item.

append wa_sch to gt_sch.

else.

move wa_hdrrec to wa_prev_hdr.

move-corresponding wa_itmrec to gt_item.

append gt_item.

append wa_sch to gt_sch.

endif.

endloop.

perform create_po.

perform summary_report.

&----


*& Form create_po

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form create_po.

Refresh: i_po_item,

i_po_sch.

          • move header to bapi hdr

w_vendor_n = wa_hdrrec-lifnr.

i_po_hed-DOC_DATE = wa_hdrrec-bedat.

i_po_hed-DOC_TYPE = wa_hdrrec-bsart.

i_po_hed-CO_CODE = wa_hdrrec-bukrs.

i_po_hed-PURCH_ORG = wa_hdrrec-ekorg.

i_po_hed-PUR_GROUP = wa_hdrrec-ekgrp.

i_po_hed-VENDOR = w_vendor_n.

i_po_hed-CREATED_BY = wa_hdrrec-ernam.

i_po_ad_hed-REF_1 = wa_ad_hdrec-ihrez.

            • move items to bapi itm

LOOP AT gt_item.

i_po_item-PO_ITEM = gt_item-ebelp.

i_po_item-PUR_MAT = gt_item-matnr.

i_po_item-STORE_LOC = gt_item-lgort.

i_po_item-PLANT = gt_item-werks.

i_po_item-UNIT = gt_item-meins.

i_po_item-NET_PRICE = gt_item-netpr.

i_po_item-PRICE_UNIT = gt_item-peinh.

ENDLOOP.

LOOP AT gt_sch.

i_po_sch-PO_ITEM = gt_sch-ebelp.

i_po_sch-DELIV_DATE = gt_sch-eindt.

i_po_sch-QUANTITY = gt_sch-menge.

ENDLOOP.

            • call BAPI

CALL FUNCTION 'BAPI_PO_CREATE'

EXPORTING

PO_HEADER = i_po_hed

PO_HEADER_ADD_DATA = i_po_ad_hed

  • HEADER_ADD_DATA_RELEVANT =

  • PO_ADDRESS =

SKIP_ITEMS_WITH_ERROR = 'X'

  • ITEM_ADD_DATA_RELEVANT = 'X'

IMPORTING

PURCHASEORDER = i_po_num-PO_NUMBER

TABLES

PO_ITEMS = i_po_item

  • PO_ITEM_ADD_DATA =

PO_ITEM_SCHEDULES = i_po_sch

  • PO_ITEM_ACCOUNT_ASSIGNMENT =

  • PO_ITEM_TEXT =

RETURN = i_po_return

  • PO_LIMITS =

  • PO_CONTRACT_LIMITS =

  • PO_SERVICES =

  • PO_SRV_ACCASS_VALUES =

  • PO_SERVICES_TEXT =

  • PO_BUSINESS_PARTNER =

  • EXTENSIONIN =

  • POADDRDELIVERY =

.

          • Bapi commit work**********

commit work.

endform. " create_po

Read only

0 Likes
1,935

Thats a bizarre error Karan.

A few things come to mind:

<b>1.</b> There are appends missing in the create_po subroutine. Maybe these are causing the problem. have a look at my comments.

LOOP AT gt_item.

i_po_item-PO_ITEM = gt_item-ebelp.
i_po_item-PUR_MAT = gt_item-matnr.
i_po_item-STORE_LOC = gt_item-lgort.
i_po_item-PLANT = gt_item-werks.
i_po_item-UNIT = gt_item-meins.
i_po_item-NET_PRICE = gt_item-netpr.
i_po_item-PRICE_UNIT = gt_item-peinh.
" Should be append i_po_item "
ENDLOOP.

LOOP AT gt_sch.

i_po_sch-PO_ITEM = gt_sch-ebelp.
i_po_sch-DELIV_DATE = gt_sch-eindt.
i_po_sch-QUANTITY = gt_sch-menge.
"should be append i_po_sch "
ENDLOOP.

<b>2.</b> This error is caused by erroneous coding in a PO userexit. In this case, try commenting out all the userexits/BADIs implemented in the purchase order transaction. Then run the BAPI again.

<b>3.</b> There is a SAP bug. Check out OSS.

Also, you seem not to be refreshing gt_item and gt_sch anywhere. I think that you need to do this in your main loop at the begining of each new PO (not sure as did not check too closely).

Hope that helps.

Brad

Read only

0 Likes
1,935

Brad,

That works, ur option 1. Thanks a lot , i am able to do what i want.

Karan.

Read only

Former Member
0 Likes
1,935

Hi Karan, could you kindly provide me with the text file format that you are uploading for PO Create? Yor help will be greatly appreciated.