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: 

Add Line to Existing PO: via "BAPI_PO_CHANGE" or something else ????

Former Member
0 Kudos

Can I use "BAPI_PO_CHANGE" to add a line item to a PO?

In particular, if I call this BAPI with rows in "poitem" that don't correspond to line items already in the PO, will the BAPI add these new lines?

If not, what is the right way to do this via BAPI?

Thanks for any advice you can provide.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Documentation of the FM BAPI_PO_CHANGE says:

Function module BAPI_PO_CHANGE enables you to change purchase orders. The Change method uses the technology behind the online transaction ME22N.

As we can insert a new item in the ME22N, it will allow us to insert a new PO Line using this FM.

Regards,

Naimesh Patel

9 REPLIES 9

naimesh_patel
Active Contributor
0 Kudos

Documentation of the FM BAPI_PO_CHANGE says:

Function module BAPI_PO_CHANGE enables you to change purchase orders. The Change method uses the technology behind the online transaction ME22N.

As we can insert a new item in the ME22N, it will allow us to insert a new PO Line using this FM.

Regards,

Naimesh Patel

0 Kudos

Thanks for responding, NP.

I saw that statement in the documentation, but wanted to make sure that it means add lines as well as change lines.

I hope you're correct - that it is that simple!!!

Have you actually done this yourself, or are you just "trusting the documentation" ?

If anyone else has actually done this, please let me know.

Thanks

djh

former_member181923
Active Participant
0 Kudos

Even though I've already awarded points to NP, I'm leaving this question open because I want to be sure that some one has actually done this (add a new line to a PO via BAPI_PO_CHANGE.)

<removed_by_moderator>

Edited by: Julius Bussche on Oct 21, 2008 4:44 PM

0 Kudos

Yes, I have used it before to create a new line.

All you have to do is, pass the relevent filed ON in the Xstrucuture for all the required fields.

E.g.


PO_ITEM-PO_ITEM = new_item
APPEND..

PO_ITEMx-PO_ITEM  = new_item
PO_ITEMx-PO_ITEMX = 'X'.
APPEND ...

Regards,

Naimesh Patel

0 Kudos

TYPES : BEGIN OF ty_ekko,

ebeln TYPE ebeln,

ekorg TYPE ekorg,

ekgrp TYPE bkgrp,

END OF ty_ekko.

DATA : it_flatfile TYPE TABLE OF ty_ekko ,

wa_flatfile TYPE ty_ekko,

it_ekko1 TYPE TABLE OF ty_ekko,

wa_ekko1 TYPE ty_ekko.

DATA : v_file TYPE string.

DATA : wa_header TYPE bapimepoheader,

wa_headerx TYPE bapimepoheaderx.

DATA: it_return TYPE TABLE OF bapiret2.

DATA: it_return1 TYPE TABLE OF bapiret2.

*DATA : BEGIN OF it_bapi_poheader OCCURS 0.

  • INCLUDE STRUCTURE bapimepoheader.

*DATA : END OF it_bapi_poheader.

*

*DATA : BEGIN OF it_bapi_poheaderx OCCURS 0.

  • INCLUDE STRUCTURE bapimepoheaderx.

*DATA : END OF it_bapi_poheaderx.

*

*DATA : BEGIN OF it_bapi_poitem OCCURS 0.

  • INCLUDE STRUCTURE bapimepoitem.

*DATA : END OF it_bapi_poitem.

*

*DATA : BEGIN OF it_bapi_poitemx OCCURS 0.

  • INCLUDE STRUCTURE bapimepoitemx.

*DATA : END OF it_bapi_poitemx.

*

*DATA : BEGIN OF it_bapireturn OCCURS 0.

  • INCLUDE STRUCTURE bapiret2.

*DATA : END OF it_bapireturn.

PARAMETERS : p_file TYPE ibipparms-path.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

START-OF-SELECTION.

MOVE p_file TO v_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

has_field_separator = 'X'

TABLES

data_tab = it_flatfile.

IF NOT it_flatfile IS INITIAL.

SELECT ebeln ekorg ekgrp

FROM ekko

INTO TABLE it_ekko1

FOR ALL ENTRIES IN it_flatfile

WHERE ebeln = it_flatfile-ebeln .

ENDIF.

LOOP AT it_flatfile INTO wa_flatfile.

READ TABLE it_ekko1 INTO wa_ekko1 WITH KEY ebeln = wa_flatfile-ebeln.

IF sy-subrc EQ 0.

IF wa_flatfile-ekorg NE wa_ekko1-ekorg OR

wa_flatfile-ekgrp NE wa_ekko1-ekgrp.

  • wa_header-po_number = wa_flatfile-ebeln.

wa_header-purch_org = wa_flatfile-ekorg.

wa_header-pur_group = wa_flatfile-ekgrp.

  • wa_headerx-po_number = wa_flatfile-ebeln.

wa_headerx-purch_org = 'X'.

wa_headerx-pur_group = 'X'.

ENDIF.

ENDIF.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = wa_ekko1-ebeln

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

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

return = it_return

  • POITEM =

  • POITEMX =

  • POADDRDELIVERY =

  • POSCHEDULE =

  • POSCHEDULEX =

  • POACCOUNT =

  • POACCOUNTPROFITSEGMENT =

  • POACCOUNTX =

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

  • POCOMPONENTS =

  • POCOMPONENTSX =

  • POSHIPPING =

  • POSHIPPINGX =

  • POSHIPPINGEXP =

  • POHISTORY =

  • POHISTORY_TOTALS =

  • POCONFIRMATION =

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ENDLOOP.

You can test it in your dev using my code . Pls check and let us know.

former_member194669
Active Contributor
0 Kudos

You need to fill up

POITEM-PO_ITEM ( with new item number) and fill up the other fields you have data

then

POITEMX-PO_ITEM - give same item number given in the POITEM-PO_ITEM

POITEMX-PO_ITEMX - set to 'X'

and also provide PURCHASEORDER - PO number

PS (please remember to fill up all the required fields for creating PO)

a®s

Edited by: a®s on Oct 21, 2008 10:38 AM

former_member181995
Active Contributor
0 Kudos

David,

My guess we can add new line item too.

just from table structures BAPIMEPOITEMX component PO_ITEMX = 'X'.

Rest all parameters should be filled in same structure(BAPIMEPOITEMX ) correctly like po item number should in increased by 1 from exsisting line items.

former_member181923
Active Participant
0 Kudos

Thanks to all for the "guarantee" and the examples. I'd award more points except I'd run out of points. Yes - I know about the "x" tables - they work the same way as in the PO create BAPI - but it's probably good you all mentioned them because others may read this thread. Thanks again.

0 Kudos

Important information you need to send for creation.

poitem

poitemx

POSCHEDULE

POSCHEDULEX

For poitem, you need to pass item number, material, itemcategory, quantity, plant.

the same you need to mark in poitemx.

For Schedule line you need to send item, delivery date , quantity.

same you need to mark 'X'.

w_ponum = 4500000049.

CALL FUNCTION 'BAPI_PO_CHANGE'
  EXPORTING
    purchaseorder = w_ponum
  TABLES
    return        = t_bapiret2
    poitem        = t_bapimepoitem
    poitemx       = t_bapimepoitemx
    POSCHEDULE    = t_schedule
    POSCHEDULEX   = t_schx.

With out Schedule lines information it is not possible to create the new item line.