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: 

Error in : Purchase order Creation using BAPI_PO_CREATE1

former_member125661
Contributor
0 Kudos

Hell guys,

I am trying to create a PO using a BAPI - BAPI_PO_CREATE1

I want the new PO to have all the characteristics of an existing PO. whose PO # is stored in wa_order_split_create-docnr and for the new PO, i want the quantity from wa_order_split_create-qty_acptd and the delivery data to be wa_order_split_create-dly_date. But this process and code below gives a short dump in the std FM - MEPO_DOC_ITEM_GET . It raises an exception of failure. I am trying to create many new PO's in the loop below. If there is just one row, sometimes, it creates the PO even with the exception failure ( which is pretty weird).

Am i making any mistake while filling the header or item or schedule lines for the BAPI_PO_CREATE1 ? Any tips or clues why I am getting a dump ?


DATA: i_insert,
        i_create_order,
        i_cycle     TYPE cycle,
        i_qty_acpt  TYPE dzmeng,
        i_dly_date  TYPE vbak-vdatu,
        i_item      TYPE roijnomiio .

  DATA: i_order TYPE symsgv,
        i_return TYPE swd_return .

  DATA: i_vbak      TYPE vbak,
        i_vbap      TYPE vbap,
        i_ekko      TYPE ekko,
        i_ekpo      TYPE ekpo,
        i_bsoh      TYPE bapisdhd1,
        i_bsohx     TYPE bapisdhd1x,
        i_bpoh      TYPE bapimepoheader,
        i_bpohx     TYPE bapimepoheaderx,
        i_vbeln     TYPE vbeln_va,
        i_posnr     TYPE posnr_va,
        i_contr     TYPE vbeln_va,
        i_conit     TYPE posnr_va,
        i_ebeln     TYPE ebeln,
        i_ebelp     TYPE ebelp,
        i_pargr     TYPE pargr,
        i_thead     TYPE thead,
        i_line      TYPE tline,
        i_note      TYPE txw_note,
        i_new_vbeln TYPE vbeln_va,
        i_new_ebeln TYPE ebeln,
        i_wa_bsoi   TYPE bapisditm,
        i_wa_bsoix  TYPE bapisditmx,
        i_wa_bsop   TYPE bapiparnr,
        i_wa_bsos   TYPE bapischdl,
        i_wa_bsosx  TYPE bapischdlx,
        i_wa_vbpa   TYPE vbpa,
        i_wa_vbkd   TYPE vbkd,
        i_wa_bpoi   TYPE bapimepoitem,
        i_wa_bpoix  TYPE bapimepoitemx,
        i_wa_bpos   TYPE bapimeposchedule,
        i_wa_bposx  TYPE bapimeposchedulx,
        i_wa_bpop   TYPE bapiekkop,
        i_wa_ekpa   TYPE ekpa,
        i_message   TYPE char72,
        i_bapiretn  TYPE bapiret2,
        i_bapiret2  TYPE TABLE OF bapiret2 INITIAL SIZE 1,
        i_vbpa      TYPE TABLE OF vbpa INITIAL SIZE 1,
        i_vbkd      TYPE TABLE OF vbkd INITIAL SIZE 1,
        i_ekpa      TYPE TABLE OF ekpa INITIAL SIZE 1,
        i_bsoi      TYPE TABLE OF bapisditm INITIAL SIZE 1,
        i_bsoix     TYPE TABLE OF bapisditmx INITIAL SIZE 1,
        i_bsos      TYPE TABLE OF bapischdl INITIAL SIZE 1,
        i_bsosx     TYPE TABLE OF bapischdlx INITIAL SIZE 1,
        i_bsop      TYPE TABLE OF bapiparnr INITIAL SIZE 1,
        i_bpoi      TYPE TABLE OF bapimepoitem INITIAL SIZE 1,
        i_bpoix     TYPE TABLE OF bapimepoitemx INITIAL SIZE 1,
        i_bpos      TYPE TABLE OF bapimeposchedule INITIAL SIZE 1,
        i_bposx     TYPE TABLE OF bapimeposchedulx INITIAL SIZE 1,
        i_bpop      TYPE TABLE OF bapiekkop INITIAL SIZE 1,
        i_text_tab  TYPE TABLE OF tline INITIAL SIZE 1,
        i_line_tab  TYPE TABLE OF tline INITIAL SIZE 1,
        i_txw_note  TYPE TABLE OF txw_note INITIAL SIZE 1,
        i_oij_el_doc_mot TYPE oij_el_doc_mot .

  CONSTANTS: c_char_c VALUE 'C',
             c_char_e VALUE 'E',
             c_char_p VALUE 'P',
             c_char_g VALUE 'G',
             c_char_i VALUE 'I',
             c_char_s VALUE 'S',
             c_char_x VALUE 'X',
             c_zsw(3) VALUE 'ZSW',
             c_nomit_stat(4) VALUE 'ZDNY' .

  DATA : lv_nomtk_split        TYPE oij_nomtk.
  DATA : i_order_split_create  TYPE TABLE OF zsws_order_split.
  DATA : wa_order_split_create TYPE zsws_order_split.



  LOOP AT i_order_split_create INTO wa_order_split_create.

    IF NOT i_create_order IS INITIAL .

      CLEAR: i_create_order .

 
          MOVE: wa_order_split_create-docnr  TO i_ebeln,
                wa_order_split_create-docitm TO i_ebelp .

          CALL FUNCTION 'ME_EKKO_SINGLE_READ'
               EXPORTING
                    pi_ebeln         = i_ebeln
               IMPORTING
                    po_ekko          = i_ekko
               EXCEPTIONS
                    no_records_found = 1
                    OTHERS           = 2.

          IF sy-subrc <> 0 .

          ENDIF .

* Fill PO Header
          i_bpoh-comp_code   = i_ekko-bukrs .
          i_bpoh-doc_type    = i_ekko-bsart .
          i_bpoh-vendor      = i_ekko-lifnr .
          i_bpoh-langu       = i_ekko-spras .
          i_bpoh-pmnttrms    = i_ekko-zterm .
          i_bpoh-purch_org   = i_ekko-ekorg .
          i_bpoh-pur_group   = i_ekko-ekgrp .
          i_bpoh-currency    = i_ekko-waers .
          i_bpoh-agreement   = i_ekko-konnr .
          i_bpoh-incoterms1  = i_ekko-inco1 .
          i_bpoh-incoterms2  = i_ekko-inco2 .

* Fill PO update indicator 'X'
          i_bpohx-comp_code  = c_char_x .
          i_bpohx-doc_type   = c_char_x .
          i_bpohx-vendor     = c_char_x .
          i_bpohx-langu      = c_char_x .
          i_bpohx-pmnttrms   = c_char_x .
          i_bpohx-purch_org  = c_char_x .
          i_bpohx-pur_group  = c_char_x .
          i_bpohx-currency   = c_char_x .
          i_bpohx-agreement  = c_char_x .
          i_bpohx-incoterms1 = c_char_x .
          i_bpohx-incoterms2 = c_char_x .

          CALL FUNCTION 'ME_EKPO_SINGLE_READ'
               EXPORTING
                    pi_ebeln         = i_ebeln
                    pi_ebelp         = i_ebelp
               IMPORTING
                    po_ekpo          = i_ekpo
               EXCEPTIONS
                    no_records_found = 1
                    OTHERS           = 2.

          IF sy-subrc <> 0 .
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF .

* Fill PO Item
          i_wa_bpoi-po_item    = i_ekpo-ebelp .
          i_wa_bpoi-material   = i_ekpo-matnr .
          i_wa_bpoi-plant      = i_ekpo-werks .
          i_wa_bpoi-stge_loc   = i_ekpo-lgort .
          i_wa_bpoi-quantity   = wa_order_split_create-qty_acptd .
          i_wa_bpoi-po_unit    = i_ekpo-meins .
          i_wa_bpoi-tax_code   = i_ekpo-mwskz .
          i_wa_bpoi-val_type   = i_ekpo-bwtar .
          i_wa_bpoi-item_cat   = i_ekpo-pstyp .
          i_wa_bpoi-acctasscat = i_ekpo-knttp .
          i_wa_bpoi-agreement  = i_ekpo-konnr .
          i_wa_bpoi-agmt_item  = i_ekpo-ktpnr .

          APPEND i_wa_bpoi TO i_bpoi .

* Fill PO Item update indicator 'X'
          i_wa_bpoix-po_item    = i_ekpo-ebelp .
          i_wa_bpoix-po_itemx   = c_char_x .
          i_wa_bpoix-material   = c_char_x .
          i_wa_bpoix-plant      = c_char_x .
          i_wa_bpoix-stge_loc   = c_char_x .
          i_wa_bpoix-quantity   = c_char_x .
          i_wa_bpoix-po_unit    = c_char_x .
          i_wa_bpoix-tax_code   = c_char_x .
          i_wa_bpoix-val_type   = c_char_x .
          i_wa_bpoix-item_cat   = c_char_x .
          i_wa_bpoix-acctasscat = c_char_x .
          i_wa_bpoix-agreement  = c_char_x .
          i_wa_bpoix-agmt_item  = c_char_x .

          APPEND i_wa_bpoix TO i_bpoix .

* Fill PO Item Schedule
          i_wa_bpos-po_item       = i_ekpo-ebelp .
          i_wa_bpos-sched_line    = '0001' .
          i_wa_bpos-delivery_date = wa_order_split_create-dly_date .
          i_wa_bpos-quantity      = wa_order_split_create-qty_acptd .

          APPEND i_wa_bpos TO i_bpos .

* Fill PO Item schedule update indicator 'X'
          i_wa_bposx-po_item       = i_ekpo-ebelp .
          i_wa_bposx-sched_line    = '0001' .
          i_wa_bposx-delivery_date = c_char_x .
          i_wa_bposx-quantity      = c_char_x .

          APPEND i_wa_bposx TO i_bposx .

          CLEAR: i_pargr .
          SELECT SINGLE pargr
            INTO i_pargr
            FROM t161
           WHERE bstyp = i_ekko-bstyp
             AND bsart = i_ekko-bsart .

          CLEAR i_ekpa[].

          CALL FUNCTION 'MM_READ_PARTNERS'
               EXPORTING
                    application = c_char_p
                    ebeln       = i_ebeln
                    bstyp       = i_ekko-bstyp
                    pargr       = i_pargr
               TABLES
                    x_ekpa      = i_ekpa[].


          LOOP AT i_ekpa INTO i_wa_ekpa .
            i_wa_bpop-partnerdesc = i_wa_ekpa-parvw .
            i_wa_bpop-langu = sy-langu .

            IF NOT i_wa_ekpa-lifn2 IS INITIAL .
              i_wa_bpop-buspartno = i_wa_ekpa-lifn2 .
            ELSE .
              i_wa_bpop-buspartno = i_wa_ekpa-parnr .
            ENDIF .

            APPEND i_wa_bpop TO i_bpop .
            CLEAR: i_wa_ekpa, i_wa_bpop .
          ENDLOOP .

          CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

          CALL FUNCTION 'BAPI_PO_CREATE1'
               EXPORTING
                    poheader         = i_bpoh
                    poheaderx        = i_bpohx
               IMPORTING
                    exppurchaseorder = i_new_ebeln
               TABLES
                    return           = i_bapiret2
                    poitem           = i_bpoi[]
                    poitemx          = i_bpoix[]
                    poschedule       = i_bpos[]
                    poschedulex      = i_bposx[].

          i_order = i_new_ebeln .
          SHIFT i_order LEFT DELETING LEADING '0' .

          i_return-errortype = c_char_i .
          i_return-workarea  = c_zsw .
          i_return-message   = '064' .
          i_return-variable1 = i_order .

        loop at i_bapiret2 into i_bapiretn where type ca 'EAX' .
        append i_bapiretn to t_bapi_return .
      endloop .

      if t_bapi_return[] is initial .
         i_create_order = c_char_x .

           CALL FUNCTION 'SWD_POPUP_MESSAGE_SEND'
               EXPORTING
                    act_return = i_return. "Popup with new PO no.

       
        
      ENDCASE .                                     " Docind

    ENDIF .

  ENDLOOP.

7 REPLIES 7

Former Member
0 Kudos

Hi,

You are not filling the PO items in loop (EKPO).

Probably thats why it is creating PO with one item and otherwise giving the dump.

Hope it helps.

Regards,

Shashank

0 Kudos

No Shashank, there is only one line item all the time. I can go ahead and safely make the ebelp = 10 all the time.

Former Member
0 Kudos

Hello Shareen,

What does the dump say... Did u try putting in Commit after ur call to BAPI?

0 Kudos

I tried to call BAPI_TRANSACTION_COMMIT, it started to give another RAISE EXCEPTIOn, saying EBELN missing

former_member181962
Active Contributor
0 Kudos

Hi Shareen,

I think in the following parts of the code,

CALL FUNCTION 'MM_READ_PARTNERS'

EXPORTING

application = c_char_p

ebeln = i_ebeln

bstyp = i_ekko-bstyp

pargr = i_pargr

TABLES

x_ekpa = i_ekpa[].

Error in : Purchase order Creation using BAPI_PO_CREATE1

Posted: Mar 20, 2006 7:39 PM Reply E-mail this post

Hell guys,

I am trying to create a PO using a BAPI - BAPI_PO_CREATE1

I want the new PO to have all the characteristics of an existing PO. whose PO # is stored in wa_order_split_create-docnr and for the new PO, i want the quantity from wa_order_split_create-qty_acptd and the delivery data to be wa_order_split_create-dly_date. But this process and code below gives a short dump in the std FM - MEPO_DOC_ITEM_GET . It raises an exception of failure. I am trying to create many new PO's in the loop below. If there is just one row, sometimes, it creates the PO even with the exception failure ( which is pretty weird).

Am i making any mistake while filling the header or item or schedule lines for the BAPI_PO_CREATE1 ? Any tips or clues why I am getting a dump ?

DATA: i_insert,

i_create_order,

i_cycle TYPE cycle,

i_qty_acpt TYPE dzmeng,

i_dly_date TYPE vbak-vdatu,

i_item TYPE roijnomiio .

DATA: i_order TYPE symsgv,

i_return TYPE swd_return .

DATA: i_vbak TYPE vbak,

i_vbap TYPE vbap,

i_ekko TYPE ekko,

i_ekpo TYPE ekpo,

i_bsoh TYPE bapisdhd1,

i_bsohx TYPE bapisdhd1x,

i_bpoh TYPE bapimepoheader,

i_bpohx TYPE bapimepoheaderx,

i_vbeln TYPE vbeln_va,

i_posnr TYPE posnr_va,

i_contr TYPE vbeln_va,

i_conit TYPE posnr_va,

i_ebeln TYPE ebeln,

i_ebelp TYPE ebelp,

i_pargr TYPE pargr,

i_thead TYPE thead,

i_line TYPE tline,

i_note TYPE txw_note,

i_new_vbeln TYPE vbeln_va,

i_new_ebeln TYPE ebeln,

i_wa_bsoi TYPE bapisditm,

i_wa_bsoix TYPE bapisditmx,

i_wa_bsop TYPE bapiparnr,

i_wa_bsos TYPE bapischdl,

i_wa_bsosx TYPE bapischdlx,

i_wa_vbpa TYPE vbpa,

i_wa_vbkd TYPE vbkd,

i_wa_bpoi TYPE bapimepoitem,

i_wa_bpoix TYPE bapimepoitemx,

i_wa_bpos TYPE bapimeposchedule,

i_wa_bposx TYPE bapimeposchedulx,

i_wa_bpop TYPE bapiekkop,

i_wa_ekpa TYPE ekpa,

i_message TYPE char72,

i_bapiretn TYPE bapiret2,

i_bapiret2 TYPE TABLE OF bapiret2 INITIAL SIZE 1,

i_vbpa TYPE TABLE OF vbpa INITIAL SIZE 1,

i_vbkd TYPE TABLE OF vbkd INITIAL SIZE 1,

i_ekpa TYPE TABLE OF ekpa INITIAL SIZE 1,

i_bsoi TYPE TABLE OF bapisditm INITIAL SIZE 1,

i_bsoix TYPE TABLE OF bapisditmx INITIAL SIZE 1,

i_bsos TYPE TABLE OF bapischdl INITIAL SIZE 1,

i_bsosx TYPE TABLE OF bapischdlx INITIAL SIZE 1,

i_bsop TYPE TABLE OF bapiparnr INITIAL SIZE 1,

i_bpoi TYPE TABLE OF bapimepoitem INITIAL SIZE 1,

i_bpoix TYPE TABLE OF bapimepoitemx INITIAL SIZE 1,

i_bpos TYPE TABLE OF bapimeposchedule INITIAL SIZE 1,

i_bposx TYPE TABLE OF bapimeposchedulx INITIAL SIZE 1,

i_bpop TYPE TABLE OF bapiekkop INITIAL SIZE 1,

i_text_tab TYPE TABLE OF tline INITIAL SIZE 1,

i_line_tab TYPE TABLE OF tline INITIAL SIZE 1,

i_txw_note TYPE TABLE OF txw_note INITIAL SIZE 1,

i_oij_el_doc_mot TYPE oij_el_doc_mot .

CONSTANTS: c_char_c VALUE 'C',

c_char_e VALUE 'E',

c_char_p VALUE 'P',

c_char_g VALUE 'G',

c_char_i VALUE 'I',

c_char_s VALUE 'S',

c_char_x VALUE 'X',

c_zsw(3) VALUE 'ZSW',

c_nomit_stat(4) VALUE 'ZDNY' .

DATA : lv_nomtk_split TYPE oij_nomtk.

DATA : i_order_split_create TYPE TABLE OF zsws_order_split.

DATA : wa_order_split_create TYPE zsws_order_split.

LOOP AT i_order_split_create INTO wa_order_split_create.

IF NOT i_create_order IS INITIAL .

CLEAR: i_create_order .

MOVE: wa_order_split_create-docnr TO i_ebeln,

wa_order_split_create-docitm TO i_ebelp .

CALL FUNCTION 'ME_EKKO_SINGLE_READ'

EXPORTING

pi_ebeln = i_ebeln

IMPORTING

po_ekko = i_ekko

EXCEPTIONS

no_records_found = 1

OTHERS = 2.

IF sy-subrc <> 0 .

ENDIF .

  • Fill PO Header

i_bpoh-comp_code = i_ekko-bukrs .

i_bpoh-doc_type = i_ekko-bsart .

i_bpoh-vendor = i_ekko-lifnr .

i_bpoh-langu = i_ekko-spras .

i_bpoh-pmnttrms = i_ekko-zterm .

i_bpoh-purch_org = i_ekko-ekorg .

i_bpoh-pur_group = i_ekko-ekgrp .

i_bpoh-currency = i_ekko-waers .

i_bpoh-agreement = i_ekko-konnr .

i_bpoh-incoterms1 = i_ekko-inco1 .

i_bpoh-incoterms2 = i_ekko-inco2 .

  • Fill PO update indicator 'X'

i_bpohx-comp_code = c_char_x .

i_bpohx-doc_type = c_char_x .

i_bpohx-vendor = c_char_x .

i_bpohx-langu = c_char_x .

i_bpohx-pmnttrms = c_char_x .

i_bpohx-purch_org = c_char_x .

i_bpohx-pur_group = c_char_x .

i_bpohx-currency = c_char_x .

i_bpohx-agreement = c_char_x .

i_bpohx-incoterms1 = c_char_x .

i_bpohx-incoterms2 = c_char_x .

CALL FUNCTION 'ME_EKPO_SINGLE_READ'

EXPORTING

pi_ebeln = i_ebeln

pi_ebelp = i_ebelp

IMPORTING

po_ekpo = i_ekpo

EXCEPTIONS

no_records_found = 1

OTHERS = 2.

IF sy-subrc <> 0 .

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

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

ENDIF .

  • Fill PO Item

i_wa_bpoi-po_item = i_ekpo-ebelp .

i_wa_bpoi-material = i_ekpo-matnr .

i_wa_bpoi-plant = i_ekpo-werks .

i_wa_bpoi-stge_loc = i_ekpo-lgort .

i_wa_bpoi-quantity = wa_order_split_create-qty_acptd .

i_wa_bpoi-po_unit = i_ekpo-meins .

i_wa_bpoi-tax_code = i_ekpo-mwskz .

i_wa_bpoi-val_type = i_ekpo-bwtar .

i_wa_bpoi-item_cat = i_ekpo-pstyp .

i_wa_bpoi-acctasscat = i_ekpo-knttp .

i_wa_bpoi-agreement = i_ekpo-konnr .

i_wa_bpoi-agmt_item = i_ekpo-ktpnr .

APPEND i_wa_bpoi TO i_bpoi .

  • Fill PO Item update indicator 'X'

i_wa_bpoix-po_item = i_ekpo-ebelp .

i_wa_bpoix-po_itemx = c_char_x .

i_wa_bpoix-material = c_char_x .

i_wa_bpoix-plant = c_char_x .

i_wa_bpoix-stge_loc = c_char_x .

i_wa_bpoix-quantity = c_char_x .

i_wa_bpoix-po_unit = c_char_x .

i_wa_bpoix-tax_code = c_char_x .

i_wa_bpoix-val_type = c_char_x .

i_wa_bpoix-item_cat = c_char_x .

i_wa_bpoix-acctasscat = c_char_x .

i_wa_bpoix-agreement = c_char_x .

i_wa_bpoix-agmt_item = c_char_x .

APPEND i_wa_bpoix TO i_bpoix .

  • Fill PO Item Schedule

i_wa_bpos-po_item = i_ekpo-ebelp .

i_wa_bpos-sched_line = '0001' .

i_wa_bpos-delivery_date = wa_order_split_create-dly_date .

i_wa_bpos-quantity = wa_order_split_create-qty_acptd .

APPEND i_wa_bpos TO i_bpos .

  • Fill PO Item schedule update indicator 'X'

i_wa_bposx-po_item = i_ekpo-ebelp .

i_wa_bposx-sched_line = '0001' .

i_wa_bposx-delivery_date = c_char_x .

i_wa_bposx-quantity = c_char_x .

APPEND i_wa_bposx TO i_bposx .

CLEAR: i_pargr .

SELECT SINGLE pargr

INTO i_pargr

FROM t161

WHERE bstyp = i_ekko-bstyp

AND bsart = i_ekko-bsart .

CLEAR i_ekpa[].

CALL FUNCTION 'MM_READ_PARTNERS'

EXPORTING

application = c_char_p

ebeln = i_ebeln

bstyp = i_ekko-bstyp

pargr = i_pargr

TABLES

x_ekpa = <b>i_ekpa[].</b>

LOOP AT i_ekpa INTO i_wa_ekpa .

i_wa_bpop-partnerdesc = i_wa_ekpa-parvw .

i_wa_bpop-langu = sy-langu .

IF NOT i_wa_ekpa-lifn2 IS INITIAL .

i_wa_bpop-buspartno = i_wa_ekpa-lifn2 .

ELSE .

i_wa_bpop-buspartno = i_wa_ekpa-parnr .

ENDIF .

APPEND i_wa_bpop TO i_bpop .

CLEAR: i_wa_ekpa, i_wa_bpop .

ENDLOOP .

CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = i_bpoh

poheaderx = i_bpohx

IMPORTING

exppurchaseorder = i_new_ebeln

TABLES

return = i_bapiret2

<b> poitem = i_bpoi[]

poitemx = i_bpoix[]

poschedule = i_bpos[]

poschedulex = i_bposx[].</b>

,

it should be only i_bpoi, i_bpoix, i_bpos, i_bposx but not i_bpoi[], i_bpoix[], i_bpos[], i_bposx[].

CHange the code as follows:

DATA: i_insert,

i_create_order,

i_cycle TYPE cycle,

i_qty_acpt TYPE dzmeng,

i_dly_date TYPE vbak-vdatu,

i_item TYPE roijnomiio .

DATA: i_order TYPE symsgv,

i_return TYPE swd_return .

DATA: i_vbak TYPE vbak,

i_vbap TYPE vbap,

i_ekko TYPE ekko,

i_ekpo TYPE ekpo,

i_bsoh TYPE bapisdhd1,

i_bsohx TYPE bapisdhd1x,

i_bpoh TYPE bapimepoheader,

i_bpohx TYPE bapimepoheaderx,

i_vbeln TYPE vbeln_va,

i_posnr TYPE posnr_va,

i_contr TYPE vbeln_va,

i_conit TYPE posnr_va,

i_ebeln TYPE ebeln,

i_ebelp TYPE ebelp,

i_pargr TYPE pargr,

i_thead TYPE thead,

i_line TYPE tline,

i_note TYPE txw_note,

i_new_vbeln TYPE vbeln_va,

i_new_ebeln TYPE ebeln,

i_wa_bsoi TYPE bapisditm,

i_wa_bsoix TYPE bapisditmx,

i_wa_bsop TYPE bapiparnr,

i_wa_bsos TYPE bapischdl,

i_wa_bsosx TYPE bapischdlx,

i_wa_vbpa TYPE vbpa,

i_wa_vbkd TYPE vbkd,

i_wa_bpoi TYPE bapimepoitem,

i_wa_bpoix TYPE bapimepoitemx,

i_wa_bpos TYPE bapimeposchedule,

i_wa_bposx TYPE bapimeposchedulx,

i_wa_bpop TYPE bapiekkop,

i_wa_ekpa TYPE ekpa,

i_message TYPE char72,

i_bapiretn TYPE bapiret2,

i_bapiret2 TYPE TABLE OF bapiret2 INITIAL SIZE 1,

i_vbpa TYPE TABLE OF vbpa INITIAL SIZE 1,

i_vbkd TYPE TABLE OF vbkd INITIAL SIZE 1,

i_ekpa TYPE TABLE OF ekpa INITIAL SIZE 1,

i_bsoi TYPE TABLE OF bapisditm INITIAL SIZE 1,

i_bsoix TYPE TABLE OF bapisditmx INITIAL SIZE 1,

i_bsos TYPE TABLE OF bapischdl INITIAL SIZE 1,

i_bsosx TYPE TABLE OF bapischdlx INITIAL SIZE 1,

i_bsop TYPE TABLE OF bapiparnr INITIAL SIZE 1,

i_bpoi TYPE TABLE OF bapimepoitem INITIAL SIZE 1,

i_bpoix TYPE TABLE OF bapimepoitemx INITIAL SIZE 1,

i_bpos TYPE TABLE OF bapimeposchedule INITIAL SIZE 1,

i_bposx TYPE TABLE OF bapimeposchedulx INITIAL SIZE 1,

i_bpop TYPE TABLE OF bapiekkop INITIAL SIZE 1,

i_text_tab TYPE TABLE OF tline INITIAL SIZE 1,

i_line_tab TYPE TABLE OF tline INITIAL SIZE 1,

i_txw_note TYPE TABLE OF txw_note INITIAL SIZE 1,

i_oij_el_doc_mot TYPE oij_el_doc_mot .

CONSTANTS: c_char_c VALUE 'C',

c_char_e VALUE 'E',

c_char_p VALUE 'P',

c_char_g VALUE 'G',

c_char_i VALUE 'I',

c_char_s VALUE 'S',

c_char_x VALUE 'X',

c_zsw(3) VALUE 'ZSW',

c_nomit_stat(4) VALUE 'ZDNY' .

DATA : lv_nomtk_split TYPE oij_nomtk.

DATA : i_order_split_create TYPE TABLE OF zsws_order_split.

DATA : wa_order_split_create TYPE zsws_order_split.

LOOP AT i_order_split_create INTO wa_order_split_create.

IF NOT i_create_order IS INITIAL .

CLEAR: i_create_order .

MOVE: wa_order_split_create-docnr TO i_ebeln,

wa_order_split_create-docitm TO i_ebelp .

CALL FUNCTION 'ME_EKKO_SINGLE_READ'

EXPORTING

pi_ebeln = i_ebeln

IMPORTING

po_ekko = i_ekko

EXCEPTIONS

no_records_found = 1

OTHERS = 2.

IF sy-subrc <> 0 .

ENDIF .

  • Fill PO Header

i_bpoh-comp_code = i_ekko-bukrs .

i_bpoh-doc_type = i_ekko-bsart .

i_bpoh-vendor = i_ekko-lifnr .

i_bpoh-langu = i_ekko-spras .

i_bpoh-pmnttrms = i_ekko-zterm .

i_bpoh-purch_org = i_ekko-ekorg .

i_bpoh-pur_group = i_ekko-ekgrp .

i_bpoh-currency = i_ekko-waers .

i_bpoh-agreement = i_ekko-konnr .

i_bpoh-incoterms1 = i_ekko-inco1 .

i_bpoh-incoterms2 = i_ekko-inco2 .

  • Fill PO update indicator 'X'

i_bpohx-comp_code = c_char_x .

i_bpohx-doc_type = c_char_x .

i_bpohx-vendor = c_char_x .

i_bpohx-langu = c_char_x .

i_bpohx-pmnttrms = c_char_x .

i_bpohx-purch_org = c_char_x .

i_bpohx-pur_group = c_char_x .

i_bpohx-currency = c_char_x .

i_bpohx-agreement = c_char_x .

i_bpohx-incoterms1 = c_char_x .

i_bpohx-incoterms2 = c_char_x .

CALL FUNCTION 'ME_EKPO_SINGLE_READ'

EXPORTING

pi_ebeln = i_ebeln

pi_ebelp = i_ebelp

IMPORTING

po_ekpo = i_ekpo

EXCEPTIONS

no_records_found = 1

OTHERS = 2.

IF sy-subrc <> 0 .

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

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

ENDIF .

  • Fill PO Item

i_wa_bpoi-po_item = i_ekpo-ebelp .

i_wa_bpoi-material = i_ekpo-matnr .

i_wa_bpoi-plant = i_ekpo-werks .

i_wa_bpoi-stge_loc = i_ekpo-lgort .

i_wa_bpoi-quantity = wa_order_split_create-qty_acptd .

i_wa_bpoi-po_unit = i_ekpo-meins .

i_wa_bpoi-tax_code = i_ekpo-mwskz .

i_wa_bpoi-val_type = i_ekpo-bwtar .

i_wa_bpoi-item_cat = i_ekpo-pstyp .

i_wa_bpoi-acctasscat = i_ekpo-knttp .

i_wa_bpoi-agreement = i_ekpo-konnr .

i_wa_bpoi-agmt_item = i_ekpo-ktpnr .

APPEND i_wa_bpoi TO i_bpoi .

  • Fill PO Item update indicator 'X'

i_wa_bpoix-po_item = i_ekpo-ebelp .

i_wa_bpoix-po_itemx = c_char_x .

i_wa_bpoix-material = c_char_x .

i_wa_bpoix-plant = c_char_x .

i_wa_bpoix-stge_loc = c_char_x .

i_wa_bpoix-quantity = c_char_x .

i_wa_bpoix-po_unit = c_char_x .

i_wa_bpoix-tax_code = c_char_x .

i_wa_bpoix-val_type = c_char_x .

i_wa_bpoix-item_cat = c_char_x .

i_wa_bpoix-acctasscat = c_char_x .

i_wa_bpoix-agreement = c_char_x .

i_wa_bpoix-agmt_item = c_char_x .

APPEND i_wa_bpoix TO i_bpoix .

  • Fill PO Item Schedule

i_wa_bpos-po_item = i_ekpo-ebelp .

i_wa_bpos-sched_line = '0001' .

i_wa_bpos-delivery_date = wa_order_split_create-dly_date .

i_wa_bpos-quantity = wa_order_split_create-qty_acptd .

APPEND i_wa_bpos TO i_bpos .

  • Fill PO Item schedule update indicator 'X'

i_wa_bposx-po_item = i_ekpo-ebelp .

i_wa_bposx-sched_line = '0001' .

i_wa_bposx-delivery_date = c_char_x .

i_wa_bposx-quantity = c_char_x .

APPEND i_wa_bposx TO i_bposx .

CLEAR: i_pargr .

SELECT SINGLE pargr

INTO i_pargr

FROM t161

WHERE bstyp = i_ekko-bstyp

AND bsart = i_ekko-bsart .

CLEAR i_ekpa[].

CALL FUNCTION 'MM_READ_PARTNERS'

EXPORTING

application = c_char_p

ebeln = i_ebeln

bstyp = i_ekko-bstyp

pargr = i_pargr

TABLES

x_ekpa = i_ekpa.

LOOP AT i_ekpa INTO i_wa_ekpa .

i_wa_bpop-partnerdesc = i_wa_ekpa-parvw .

i_wa_bpop-langu = sy-langu .

IF NOT i_wa_ekpa-lifn2 IS INITIAL .

i_wa_bpop-buspartno = i_wa_ekpa-lifn2 .

ELSE .

i_wa_bpop-buspartno = i_wa_ekpa-parnr .

ENDIF .

APPEND i_wa_bpop TO i_bpop .

CLEAR: i_wa_ekpa, i_wa_bpop .

ENDLOOP .

CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = i_bpoh

poheaderx = i_bpohx

IMPORTING

exppurchaseorder = i_new_ebeln

TABLES

return = i_bapiret2

poitem = i_bpoi

poitemx = i_bpoix

poschedule = i_bpos

poschedulex = i_bposx.

i_order = i_new_ebeln .

SHIFT i_order LEFT DELETING LEADING '0' .

i_return-errortype = c_char_i .

i_return-workarea = c_zsw .

i_return-message = '064' .

i_return-variable1 = i_order .

loop at i_bapiret2 into i_bapiretn where type ca 'EAX' .

append i_bapiretn to t_bapi_return .

endloop .

if t_bapi_return[] is initial .

i_create_order = c_char_x .

CALL FUNCTION 'SWD_POPUP_MESSAGE_SEND'

EXPORTING

act_return = i_return. "Popup with new PO no.

ENDCASE . " Docind

ENDIF .

ENDLOOP.

0 Kudos

Ravi Kath,

I dont see any difference with your above said modification. It still gives the same EXCEPTION RAISE dump. What BAPI_CREATE_PO1 is doing is , it is repeatedly reading a structure called POT . Sometimes, POT has some values and sometimes it doesnt. When it doesn't it raises an exception.

0 Kudos

Hi Shareen
I am using this BAPI and am experiencing the same issue. I cant find the solution anywhere.
Have you found the solution? Please let me know if you have. Thanks!