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: 

creation of purchase order using bapi

Former Member
0 Kudos

hi gurus,

Can anyone give me an example of how to create purchase order using bapi

6 REPLIES 6

Former Member
0 Kudos

hi,

plz check the below example ;

*DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.

*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
       RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
data : w_header(40) value 'PO Header'.

data : ws_langu like sy-langu.

*text-001 = 'PO Header' - define as text element
selection-screen begin of block b1 with frame title text-001.
parameters : company like header-comp_code  default '2700'      ,
             doctyp  like HEADER-DOC_TYPE   default 'NB'        ,
             cdate   like HEADER-CREAT_DATE default sy-datum    ,
             vendor  like HEADER-VENDOR     default '0010000023',
             pur_org like HEADER-PURCH_ORG  default '2700'      ,
             pur_grp like HEADER-PUR_GROUP  default '001'       .

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.
parameters : item_num like ITEM-PO_ITEM  default '00001',
             material like ITEM-MATERIAL default 'CRANE'   ,
             plant    like ITEM-PLANT    default '2700' ,
             quantity like ITEM-QUANTITY default 100.

selection-screen end of block b2.



*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*DATA POPULATION
*&---------------------------------------------------------------------*
ws_langu = sy-langu.   "Language variable

*POPULATE HEADER DATA FOR PO
HEADER-COMP_CODE  = company    .
HEADER-DOC_TYPE   = doctyp     .
HEADER-CREAT_DATE = cdate      .
HEADER-VENDOR     = vendor     .
HEADER-LANGU      = ws_langu   .
HEADER-PURCH_ORG  = pur_org    .
HEADER-PUR_GROUP  = pur_grp    .

*&---------------------------------------------------------------------*
*POPULATE HEADER FLAG.
*&---------------------------------------------------------------------*
HEADERX-comp_code  = c_x.
HEADERX-doc_type   = c_x.
HEADERX-creat_date = c_x.
HEADERX-vendor     = c_x.
HEADERX-langu      = c_x.
HEADERX-purch_org  = c_x.
HEADERX-pur_group  = c_x.
HEADERX-doc_date   = c_x.


*&---------------------------------------------------------------------*
*POPULATE ITEM DATA.
*&---------------------------------------------------------------------*
ITEM-PO_ITEM  = item_num.
ITEM-MATERIAL = material.
ITEM-PLANT    = plant.
ITEM-QUANTITY = quantity.
APPEND ITEM.

*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG TABLE
*&---------------------------------------------------------------------*
ITEMX-PO_ITEM    = item_num.
ITEMX-MATERIAL   = C_X.
ITEMX-PLANT      = C_X .
ITEMX-STGE_LOC   = C_X .
ITEMX-QUANTITY   = C_X .
ITEMX-TAX_CODE   = C_X .
ITEMX-ITEM_CAT   = C_X .
ITEMX-ACCTASSCAT = C_X .
APPEND ITEMX.

*&---------------------------------------------------------------------*
*BAPI CALL
*&---------------------------------------------------------------------*
CALL FUNCTION 'BAPI_PO_CREATE1'
  EXPORTING
    POHEADER                     = HEADER
    POHEADERX                    = HEADERX
*   POADDRVENDOR                 =
*   TESTRUN                      =
* IMPORTING
*   EXPPURCHASEORDER             =
*   EXPHEADER                    =
*   EXPPOEXPIMPHEADER            =
 TABLES
   RETURN                       = RETURN
   POITEM                       = ITEM
   POITEMX                      = ITEMX.

*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 EXPORTING
   WAIT          = 'X'
* IMPORTING
*   RETURN        =
          .

end-of-selection.
*&---------------------------------------------------------------------*
*Output the messages returned from BAPI call
*&---------------------------------------------------------------------*
LOOP AT RETURN.
 WRITE / RETURN-MESSAGE.
ENDLOOP.

thanx.

Edited by: Dhanashri Pawar on Oct 13, 2008 8:16 AM

Former Member
0 Kudos

FM: BAPI_PO_CREATE1 and check the documentation of this FM.

Regards

Kannaiah

Former Member
0 Kudos

Hi,

Use FM BAPI_PO_CREATE1...

check this sample code...


*DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.

*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
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
data : w_header(40) value 'PO Header'.

data : ws_langu like sy-langu.

data: V_EXPPURCHASEORDER like BAPIMEPOHEADER-PO_NUMBER.
*text-001 = 'PO Header' - define as text element
selection-screen begin of block b1 with frame title text-001.
parameters : company like header-comp_code default '1000' ,
doctyp like HEADER-DOC_TYPE default 'NB' ,
cdate like HEADER-CREAT_DATE default sy-datum ,
vendor like HEADER-VENDOR default 'RAJ',
pur_org like HEADER-PURCH_ORG default '0001' ,
pur_grp like HEADER-PUR_GROUP default '001' .

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.
parameters : item_num like ITEM-PO_ITEM default '00020',
material like ITEM-MATERIAL default 'M-127' ,
plant like ITEM-PLANT default '0001' ,
quantity like ITEM-QUANTITY default 200.

selection-screen end of block b2.
*&---------------------------------------------------------------------
**START-OF-SELECTION.
*&---------------------------------------------------------------------
**DATA POPULATION
*&---------------------------------------------------------------------
ws_langu = sy-langu. "Language variable

*POPULATE HEADER DATA FOR PO
HEADER-COMP_CODE = company .
HEADER-DOC_TYPE = doctyp .
HEADER-CREAT_DATE = cdate .
HEADER-VENDOR = vendor .
HEADER-LANGU = ws_langu .
HEADER-PURCH_ORG = pur_org .
HEADER-PUR_GROUP = pur_grp .

&---------------------------------------------------------------------
*POPULATE HEADER FLAG.
&---------------------------------------------------------------------
HEADERX-comp_code = c_x.
HEADERX-doc_type = c_x.
HEADERX-creat_date = c_x.
HEADERX-vendor = c_x.
HEADERX-langu = c_x.
HEADERX-purch_org = c_x.
HEADERX-pur_group = c_x.
*HEADERX-doc_date = c_x.
&---------------------------------------------------------------------
*POPULATE ITEM DATA.
&---------------------------------------------------------------------
ITEM-PO_ITEM = item_num.
ITEM-MATERIAL = material.
ITEM-PLANT = plant.
ITEM-QUANTITY = quantity.
APPEND ITEM.
&---------------------------------------------------------------------
*POPULATE ITEM FLAG TABLE
&---------------------------------------------------------------------
ITEMX-PO_ITEM = item_num.
ITEMX-MATERIAL = C_X.
ITEMX-PLANT = C_X .
*ITEMX-STGE_LOC = C_X .
ITEMX-QUANTITY = C_X .
*ITEMX-TAX_CODE = C_X .
*ITEMX-ITEM_CAT = C_X .
*ITEMX-ACCTASSCAT = C_X .
APPEND ITEMX.
&---------------------------------------------------------------------
*BAPI CALL
&---------------------------------------------------------------------
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = HEADER
POHEADERX = HEADERX

POADDRVENDOR = 
TESTRUN = 
IMPORTING
EXPPURCHASEORDER = V_EXPPURCHASEORDER

EXPHEADER = 
EXPPOEXPIMPHEADER = 
TABLES
RETURN = RETURN
POITEM = ITEM
POITEMX = ITEMX.

&---------------------------------------------------------------------
*Confirm the document creation by calling database COMMIT
&---------------------------------------------------------------------
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'

IMPORTING 
RETURN = 
.
end-of-selection.
****&---------------------------------------------------------------------*
****Output the messages returned from BAPI call
****&---------------------------------------------------------------------*
*LOOP AT RETURN.
WRITE / v_EXPPURCHASEORDER.
*ENDLOOP.

Regards,

Omkaram.

Edited by: Omkaram Yanamala on Oct 13, 2008 11:47 AM

madan_ullasa
Contributor
0 Kudos

Hi use BAPI_PO_CREATE.. I have an eg. of changing a PO using BAPI. This is almost similar to create.. Go thru and let me know if u need more info..

Dont forget to use 'BAPI COMMIT' after the function call...

DATA:

*Update Short text, qty, net price, item no.,

*agreement no. and agreement line no.

it_po_item TYPE TABLE OF bapimepoitem,

*Select fields

it_po_item_x TYPE TABLE OF bapimepoitemx,

*Delivery date

it_po_schedule TYPE TABLE OF bapimeposchedule,

*Select fields

it_po_schedule_x TYPE TABLE OF bapimeposchedulx,

*Return parameters

it_return TYPE TABLE OF bapiret2,

*PO Account

it_po_account TYPE TABLE OF bapimepoaccount,

*Select fields

it_po_account_x TYPE TABLE OF bapimepoaccountx,

  • Condition Types

it_po_cond TYPE TABLE OF bapimepocond,

*Select fields

it_po_cond_x TYPE TABLE OF bapimepocondx,

it_po_text type table of BAPIMEPOTEXT.

  • Structures

DATA:

st_po_header TYPE bapimepoheader,

st_po_header_x TYPE bapimepoheaderx,

st_po_item LIKE LINE OF it_po_item,

st_po_item_x LIKE LINE OF it_po_item_x,

st_po_schedule LIKE LINE OF it_po_schedule,

st_po_schedule_x LIKE LINE OF it_po_schedule_x,

st_return TYPE bapiret2,

st_po_account LIKE LINE OF it_po_account,

st_po_account_x LIKE LINE OF it_po_account_x,

st_po_cond LIKE LINE OF it_po_cond,

st_po_cond_x LIKE LINE OF it_po_cond_x,

st_po_text like line of it_po_text.

  • Variables

DATA : po_number TYPE bapimepoheader-po_number,

w_item_no(10) TYPE n VALUE '1'.

START-OF-SELECTION.

  • test values

po_number = '94490'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = po_number

IMPORTING

OUTPUT = po_number

.

st_po_item-po_item = w_item_no.

st_po_item-quantity = '00.000'.

st_po_item-delete_ind = 'X'.

  • st_po_item-short_text = 'ZMU-test1'.

  • st_po_item-agreement = '0060000128'.

  • st_po_item-agmt_item = '1'.

  • st_po_item-net_price = '1'.

st_po_item_x-po_item = w_item_no.

st_po_item_x-po_itemx = 'X'.

st_po_item_x-delete_ind = 'X'.

st_po_item_x-quantity = 'X'.

  • st_po_item_x-short_text = 'X'.

  • st_po_item_x-agreement = 'X'.

  • st_po_item_x-agmt_item = 'X'.

  • st_po_item_x-net_price = 'X'.

  • st_po_schedule-po_item = w_item_no.

  • st_po_schedule-delivery_date = '9/19/2008'.

  • st_po_schedule-quantity = '1'.

*

  • st_po_schedule_x-po_item = w_item_no.

  • st_po_schedule_x-po_itemx = 'X'.

  • st_po_schedule_x-delivery_date = 'X'.

  • st_po_schedule_x-quantity = 'X'.

*

*

*

  • st_po_cond-itm_number = w_item_no.

  • st_po_cond-cond_type = 'PB00'.

  • st_po_cond-cond_value = '1.000'.

  • st_po_cond-currency = 'USD'.

  • st_po_cond-change_id = 'U'.

*

*

  • st_po_cond_x-itm_number = w_item_no.

  • st_po_cond_x-itm_numberx = 'X'.

  • st_po_cond_x-cond_type = 'X'.

  • st_po_cond_x-cond_value = 'X'.

  • st_po_cond_x-currency = 'X'.

  • st_po_cond_x-change_id = 'X'.

*

  • st_po_text-PO_NUMBER = po_number.

  • st_po_text-PO_ITEM = w_item_no.

  • st_po_text-TEXT_LINE = 'MU_TEST1 MU_TEST2'.

*

APPEND:

st_po_item_x TO it_po_item_x,

st_po_item TO it_po_item.

  • st_po_schedule_x TO it_po_schedule_x,

  • st_po_schedule TO it_po_schedule,

  • st_po_cond TO it_po_cond,

  • st_po_cond_x TO it_po_cond_x,

  • st_po_text to it_po_text.

*

  • st_po_text-PO_NUMBER = po_number.

  • st_po_text-PO_ITEM = w_item_no.

  • st_po_text-TEXT_LINE = 'MU_TEST2'.

  • st_po_text-TEXT_FORM = '03'.

  • append st_po_text to it_po_text.

PERFORM function_call.

LOOP AT it_return INTO st_return.

WRITE:/ st_return-message, 'Message type =', st_return-type,/.

ENDLOOP.

REFRESH:

it_return,

it_po_item,

it_po_item_x,

it_po_cond,

it_po_cond_x.

*

  • PERFORM update_price.

*

  • WRITE:/ 'After update - Messages'.

  • LOOP AT it_return INTO st_return.

  • WRITE:/ st_return-message, 'Message type =', st_return-type,/.

  • ENDLOOP.

*

data: begin of test occurs 0,

f1,

end of test.

----


  • FORM function_call *

----


  • ........ *

----


FORM function_call.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = po_number

  • POHEADER =

  • POHEADERX =

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • IMPORTING

  • EXPHEADER =

TABLES

return = it_return

poitem = it_po_item

poitemx = it_po_item_x

  • POADDRDELIVERY =

  • poschedule = it_po_schedule

  • poschedulex = it_po_schedule_x

  • poaccount =

  • POACCOUNTPROFITSEGMENT =

  • poaccountx =

  • POCONDHEADER =

  • POCONDHEADERX =

  • pocond = it_po_cond

  • pocondx = it_po_cond_x

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POTEXTHEADER =

POTEXTITEM = it_po_text

  • POPARTNER =

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = st_return.

ENDFORM.

Former Member
0 Kudos

Hi

Go to the Below link,

Regards,

Vikram.S

former_member585060
Active Contributor
0 Kudos

Hi,

Read the documentation of the transaction BAPI and use the menu:

Materials Management -> Purchasing -> PurchaseOrder -> CreateFromData1 -> Documentation

Regards

Bala Krishna