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: 

BAPI for creation of PO

Former Member
0 Kudos

Hi All,

This is the first time that i have got to work with BAPI .

Can some 1 tell me the BAPI to create a purchase order.

And also is bapi same as using a function module in calling .

How do we pass the parameters and get back the result.

I got 1 bapi 'Z_CREATE_PURCHASE_ORDER_BAPI ' but im not able to make out how to pass the parameters and get back the result.

Thanks

Mustameer

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Please try by using the BAPI BAPI_PO_CREATE1 . BAPI is similar to function module in calling.

Regards

Abhishek

8 REPLIES 8

Former Member
0 Kudos

Hi,

Please try by using the BAPI BAPI_PO_CREATE1 . BAPI is similar to function module in calling.

Regards

Abhishek

0 Kudos

Abhishek,

Can you please tell me how do i pass the parameters to an BAPI.

If i go on to execute 'BAPI_PO_CREATE' it doesnt ask for any parameters but just returns some empty tables.

Thanks

Mustameer

0 Kudos

go to the bapi_po_create1 and c the Function Module Documentation. It explains u how to pass parameters.

Hope it helps.

Regards,

Bikash

0 Kudos

Hi Raghavendra,

Im getting the error saying that Field "BAPIMEPOHEADER" is unknown.

Let me know the changes that i need to do or an alternative code if possible for the understanding.

The other problem is that im using an BDC to record the creation of PO and in the process if the PO has more than 1 line item im not able to handle this situation.

The excel file looks something like this.

Vendor,ordertype,purchaseOrg,Purc Grp,Deliv date,plant,Storage Loc,Exclusion indicator at header level,material,PO Quantity,Exclusion indicator at itemlevel,tracking number .

1000,OP,5000,osc,29.01.2005,bare,mak,X,1,ONKN,X,1234

1000,OP,5000,osc,29.01.2005,bare,mak,X,2,ONKN,X,12

1000,OP,5000,osc,29.01.2005,bare,mak,X,3,ONKN,X,123

2000,OS,2000,mps,30.01.2005,deer,jak,X,33,OPVN,X,2345

3000,MS,6000,dds,02.02.2005,jack,jak,X,94,OVJS,X,9999

How do i handle these line items in the PO creation.

0 Kudos

Please check this program for BDC po..

report zaribabdcprog1 no standard page heading line-size 255.

tables: ekko, "Purchase Info - Header level

ekpo, "Purchase Info - Item level

ekes. "Vendor Confirmations

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

*Declaration of Internal Table

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

data: begin of i_itab1 occurs 0,

bedat like ekko-bedat, "Document Date

bsart like ekko-bsart, "Order type

lifnr like ekko-lifnr, "Vendor

bukrs like ekko-bukrs, "Company Code

ekorg like ekko-ekorg, "Purchasing Orgn.

ekgrp like ekko-ekgrp, "Purchasing Group

ebelp like ekpo-ebelp, "Item No.

ematn like ekpo-ematn, "Material

txz01 like ekpo-txz01, "Short text

menge like ekpo-menge, "Qty

eindt like ekes-eindt, "Delivery date

netpr like ekpo-netpr, "Net Price

matkl like ekpo-matkl, "Material group

ewerk like ekpo-werks. "Plant

data: end of i_itab1.

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

include bdcrecx1.

start-of-selection.

perform open_group.

perform bdc_dynpro using 'SAPLMEGUI' '0014'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'MEPO_TOPLINE-BEDAT'.

perform bdc_field using 'MEPO_TOPLINE-BSART'

'NB'.

perform bdc_field using 'MEPO_TOPLINE-SUPERFIELD'

'SAMSUNG samsung traders'.

perform bdc_field using 'MEPO_TOPLINE-BEDAT'

'07/23/2003'.

perform bdc_field using 'DYN_6000-LIST'

' 1'.

perform bdc_dynpro using 'SAPLMEGUI' '0014'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'MEPO_TOPLINE-BSART'

'NB'.

perform bdc_field using 'MEPO_TOPLINE-SUPERFIELD'

'SAMSUNG samsung traders'.

perform bdc_field using 'MEPO_TOPLINE-BEDAT'

'07/23/2003'.

perform bdc_field using 'BDC_CURSOR'

'MEPO1222-BUKRS'.

perform bdc_field using 'MEPO1222-EKORG'

'MRK1'.

perform bdc_field using 'MEPO1222-EKGRP'

'BR'.

perform bdc_field using 'MEPO1222-BUKRS'

'RAPI'.

perform bdc_field using 'DYN_6000-LIST'

' 1'.

perform bdc_dynpro using 'SAPLMEGUI' '0014'.

perform bdc_field using 'BDC_OKCODE'

'=MEV4001BUTTON'.

perform bdc_field using 'MEPO_TOPLINE-BSART'

'NB'.

perform bdc_field using 'MEPO_TOPLINE-SUPERFIELD'

'SAMSUNG samsung traders'.

perform bdc_field using 'MEPO_TOPLINE-BEDAT'

'07/23/2003'.

perform bdc_field using 'BDC_CURSOR'

'MEPO1222-BUKRS'.

perform bdc_field using 'MEPO1222-EKORG'

'MRK1'.

perform bdc_field using 'MEPO1222-EKGRP'

'BR'.

perform bdc_field using 'MEPO1222-BUKRS'

'RAPI'.

perform bdc_field using 'DYN_6000-LIST'

' 1'.

perform bdc_dynpro using 'SAPLMEGUI' '0014'.

perform bdc_field using 'BDC_OKCODE'

'=MESAVE'.

perform bdc_field using 'MEPO_TOPLINE-BSART'

'NB'.

perform bdc_field using 'MEPO_TOPLINE-SUPERFIELD'

'SAMSUNG samsung traders'.

perform bdc_field using 'MEPO_TOPLINE-BEDAT'

'07/23/2003'.

perform bdc_field using 'MEPO1222-EKORG'

'MRK1'.

perform bdc_field using 'MEPO1222-EKGRP'

'BR'.

perform bdc_field using 'MEPO1222-BUKRS'

'RAPI'.

perform bdc_field using 'BDC_CURSOR'

'MEPO1211-NAME1(01)'.

perform bdc_field using 'MEPO1211-EBELP(01)'

'10'.

perform bdc_field using 'MEPO1211-EMATN(01)'

'COMPRESSOR'.

perform bdc_field using 'MEPO1211-TXZ01(01)'

'comp'.

perform bdc_field using 'MEPO1211-MENGE(01)'

' 10'.

perform bdc_field using 'MEPO1211-EEIND(01)'

'07/23/2003'.

perform bdc_field using 'MEPO1211-NETPR(01)'

''.

perform bdc_field using 'MEPO1211-WGBEZ(01)'

'01'.

perform bdc_field using 'MEPO1211-NAME1(01)'

'MRK1'.

perform bdc_field using 'DYN_6000-LIST'

' 1'.

perform bdc_dynpro using 'SAPLSPO2' '0101'.

perform bdc_field using 'BDC_OKCODE'

'=OPT1'.

perform bdc_transaction using 'ME21N'.

perform close_group.

0 Kudos

Hi Raghavendra,

The code that you have given doesnt consider the line items .

if i have more than 1 line item then it doesnt work..

Regards

Mustameer

Former Member
0 Kudos

Please find the code below to change purchase order using bapi, in the same program replace BAPI_PO_CHANGE with BAPI_PO_CREATE1 and do your required coding it will work.

Hope This Info Helps YOU.

Reward Points If It Helps YOU.

Regards,

Raghav

report zmm_po_year_end_mass_change
      no standard page heading
      message-id zh.

*-------------------------------------------------------------*
*                  Database Table Declarations
*-------------------------------------------------------------*
tables : ekko,      " Purchase order header
         ekpo,      " purchase order Line item
         t001w,     " Plant master table
         t024e.     " Purchasing organzation.

*-------------------------------------------------------------*
*                  Type Pools Declarations
*-------------------------------------------------------------*
type-pools: slis.       " GLOBALE TYPEN FÜR GENERISCHE LISTBAUSTEINE

*-------------------------------------------------------------*
*                  Structure table declaration
*-------------------------------------------------------------*
* For Prod order header data to be pass to BAPI funtion
data : t_poheader like     bapimepoheader.

* For Prod order header X data to be pass to BAPI funtion
data:  t_poheaderx like    bapimepoheaderx.

*-------------------------------------------------------------*
*                 BAPI INTERNAL TABLES
*-------------------------------------------------------------*

* Internal table for Return table inported by BAPI FM
data : i_return  like bapiret2 occurs 0 with header line.

* Internal table for PO item return table inported by BAPI FM
data : i_poitem  like bapimepoitem occurs 0 with header line.

* Internal table for changing shceduled qty by BAPI FM
data : i_schedule like bapimeposchedule occurs 0 with header line.

* Internal table for changing shceduled qty by BAPI FM
data : i_poschedulex like bapimeposchedulx occurs 0 with header line.

* Internal table for PO item 'x' return table inported by BAPI FM
data : i_poitemx like bapimepoitemx occurs 0 with header line.


*-------------------------------------------------------------*
*                  Internal Table Declaration
*-------------------------------------------------------------*
* Internal table for PO orders to be processed.
data : begin of i_orders occurs 0,
           chk(1),
           ebeln like ekko-ebeln,      " Purchase order
           ebelp like ekpo-ebelp,      " Item No of Purchasing Document
           aedat like ekko-aedat,      " Creation Date
           erekz like ekpo-erekz,      " Final Invoice Indicator
           twrkz like ekpo-twrkz,      " partial Invoice indicator
           etenr like eket-etenr,      " Delivery schedule line counter
           menge like eket-menge,      " Scheduled quantity
           wemng like eket-wemng,      " Delivered quantity
           loekz like ekpo-loekz,      " Deletion Indicator
           inqty like ekbe-menge,      " Invoice quantity  (From i_ekbe)
           knttp like ekpo-knttp.      " Account assignemnt DEVK907644
data : end of i_orders.

* Internal table for EKBE data " DEVK907004
data : begin of i_ekbe occurs 0,
           ebeln like ekko-ebeln,      " Purchase order
           ebelp like ekpo-ebelp,      " Item No of Purchasing Document
           zekkn like ekbe-zekkn,      "
           vgabe like ekbe-vgabe,      " Transaction/event type
           belnr like ekbe-belnr,
           buzei like ekbe-buzei,
           bewtp like ekbe-bewtp,      " PO history category
           menge like ekbe-menge,      " Invoicing quantity
           shkzg like ekbe-shkzg.      " DR / Cr Indicator
data : end of i_ekbe.

* Internal table for successful records
data : begin of i_suc_req occurs 0.
        include structure i_orders.
data : end of i_suc_req.

* Internal table for Error records
data : begin of i_err occurs 0.
        include structure i_orders.
data : end of i_err.

*-------------------------------------------------------------*
*                   Variables Declarations
*-------------------------------------------------------------*
data :
       v_lines type i,              " For checking line items
       v_lines_2 type i,            " For checking line items
       v_index like sy-tabix,       " For internal table counter
       v_chk_color(2) type n,       " For color coding
       v_header(2)    type n,       " For top-of-page
       v_flag.

*-------------------------------------------------------------*
*                   Constants Declaration
*-------------------------------------------------------------*


*-------------------------------------------------------------*
*                  Selection - Screen
*-------------------------------------------------------------*
selection-screen begin of block blk1 with frame.
select-options :
  s_ebeln for ekko-ebeln ,    " Purchase order
  s_aedat for ekko-aedat obligatory,    " Creation date
  s_werks for ekpo-werks,               " Plant
  s_ekorg for ekko-ekorg.               " Purchasing org
selection-screen end of block blk1.

selection-screen begin of block prs with frame.
parameters: p_report as checkbox default 'X'.
selection-screen end of block prs.

*-------------------------------------------------------------*
*                  Ranges Declaration
*-------------------------------------------------------------*
ranges : s_knttp for ekpo-knttp. " Account assignment " DEVK907628

*----------------------------------------------------------------------*
*&********  E N D   O F   D A T A    D E C L A R A T I O N S  **********
*&****  B E G I N N I N G    O F     P R O G R A M    L O G I C  *******
*----------------------------------------------------------------------*

*-------------------------------------------------------------*
*                  INITILIZATION
*-------------------------------------------------------------*
initialization.


*-------------------------------------------------------------*
*                  At selection Screen
*-------------------------------------------------------------*
at selection-screen.
  perform check_inputs.

*-------------------------------------------------------------*
*&                TOP OF PAGE
*-------------------------------------------------------------*
top-of-page.

  if p_report eq 'X'.
    perform display_header.   " To display the header
  endif.


*-------------------------------------------------------------*
*                  Start of selection
*-------------------------------------------------------------*
start-of-selection.

*  Extract orders
  perform extract_orders.

* Extract EKBE Invoice qty
  perform extract_ekbe_inv_qty.

* Extract Inv qty and make checkbox for each record
  perform po_to_be_changed.

  if p_report eq 'X'.
    set pf-status 'PROCESS'.
    perform display_orders_with_checkbox.
  else.
    perform bapi_process.              " BAPI Process
    perform display_success_records.   " Succesfull Records
    perform display_error_records.     " Error Records
  endif.

*-------------------------------------------------------------*
*                  At User Command
*-------------------------------------------------------------*
at user-command.
  case sy-ucomm.
    when 'PROC'.
      perform delete_orders.
      perform bapi_process.                " BAPI Process

      clear v_lines.
      describe table i_suc_req lines v_lines.

      clear v_lines_2.
      describe table i_err lines v_lines_2.

      if v_lines > 0 and v_lines_2 > 0.
        perform display_success_records.   " Succesfull Records
        perform display_error_records.     " Error Records
      elseif v_lines > 0 and v_lines_2 = 0.
        perform display_success_records.   " Succesfull Records
        message s007 with 'No error records found'.
      elseif v_lines = 0 and v_lines_2 > 0.
        perform display_error_records.   " Error Records
        message s007 with 'No Success records found'.
      elseif v_lines = 0 and v_lines_2 = 0.
        message i007 with 'No Records have been processed'.
        stop.
      endif.

    when 'EXIT'.
      leave to screen 0.

  endcase.



*-------------------------------------------------------------*
*                  end of selection
*-------------------------------------------------------------*
end-of-selection.

*&---------------------------------------------------------------------*
*&      Form  check_inputs
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_inputs.

*  Purchase order validation

*If PO is entered only then continue    "DEVK907080

  if not s_ebeln is  initial.
    select single ebeln from ekko
            into ekko-ebeln
            where ebeln in s_ebeln.
    if sy-subrc ne 0.
      message e007 with 'Please select valid Purchase order'.
    endif.

  endif.                                                    "DEVK907080


* Plant Validation
  if not s_werks is initial.
    select single werks from t001w
           into t001w-werks
           where werks in s_werks.
    if sy-subrc ne 0.
      message e007 with 'Please select valid Plant'.
    endif.
  endif.

* Purchasing Organization Validation
  if not s_ekorg is initial.
    select single ekorg from t024e
           into t024e-ekorg
           where ekorg in s_ekorg.
    if sy-subrc ne 0.
      message e007 with 'Please select valid Purchasing organization'.
    endif.
  endif.

endform.                    " check_inputs

*&---------------------------------------------------------------------*
*&      Form  extract_orders
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form extract_orders.
* Get Purchase order data from EKKO , EKPO and Scheduled Quantities
* from EKET validating user input those orders which are having
*          Account assignment = 'P'
*     and  Purchasing group   = 'CON'
*     and  Deletion Indicator NE 'X'.
*these orders should not get extracted from these tables


*" DEVK907628
* the account assignment cat "Z" needs to be excluded

  refresh s_knttp[].

  s_knttp-sign    = 'I'.
  s_knttp-option  = 'EQ'.
  s_knttp-low     = 'P'.
  append s_knttp.
  clear s_knttp. " DEVK907644

  s_knttp-sign    = 'I'.
  s_knttp-option  = 'EQ'.
  s_knttp-low     = 'Z'.
  append s_knttp.
  clear s_knttp. " DEVK907644


  clear i_orders.
  refresh i_orders.

  select p~ebeln p~aedat                          " EKKO Data
         f~ebelp f~werks f~erekz f~twrkz f~knttp  " EKPO Data
         b~menge b~wemng b~etenr                  " EKET Data
  into   corresponding fields of table i_orders
  from   ( ( ekko as p
             inner join ekpo  as f on p~ebeln = f~ebeln     )
             inner join eket as  b on b~ebeln = f~ebeln  and
                                      b~ebelp = f~ebelp     )
  where p~ebeln  in  s_ebeln  and                " Purchase order
        p~aedat  in  s_aedat  and                " Creation Date
        p~ekorg  in  s_ekorg  and                " Purchasing Org
        p~ekgrp  ne  'CON'    and                " Purchasing group
        f~loekz  ne  'X'      and                " Deletion ind
        f~werks  in  s_werks  .                  " Plant
*" DEVK907628 Start
* !!
*        f~elikz  EQ 'X'       AND                " Delivery com indi
*        f~erekz  EQ 'X'."     and                " Final Invoice indi

* DEVK907644 Delete the reqs which are are having "P" and "Z".
  sort i_orders by ebeln ebelp knttp.

  delete i_orders where knttp in s_knttp.

  clear v_lines.

  describe table i_orders lines v_lines.

  if v_lines = 0.
    message i007 with 'No records found'.
    stop.
  endif.

endform.                    " extract_orders

*&---------------------------------------------------------------------*
*&      Form  PO_to_be_changed
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form po_to_be_changed.

* Calculate Invoiced quantity and create check box entries.

  clear v_index.

  sort i_orders by ebeln ebelp.

  loop at i_orders.
    v_index = v_index + 1.                                                     " WHY?????
*    MOVE : 'X' TO i_orders-chk.                                               "CHECKS EACH RECORD,SO NOT REQD.

    loop at i_ekbe where ebeln = i_orders-ebeln
                   and   ebelp = i_orders-ebelp.

      if i_ekbe-shkzg = 'H'.                                                  "IF DEBIT,THEN MAKE QTY. NEGATIVE
        i_ekbe-menge = i_ekbe-menge * - 1.
      endif.

      i_orders-inqty = i_orders-inqty + i_ekbe-menge.

    endloop.

    modify i_orders index v_index transporting chk inqty.

  endloop.

endform.                    " PO_to_be_changed

*&---------------------------------------------------------------------*
*&      Form  bapi_process
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form bapi_process.

  clear i_poitem. clear i_poitemx.
  refresh i_poitem. refresh i_poitemx.

  loop at i_orders where chk = 'X'.

* Refreshing  and clearing all the the tables used in Bapi.DEVK907080
    clear:  i_return,i_poitem, i_poitemx,i_schedule,i_poschedulex.
    refresh:  i_return,i_poitem, i_poitemx,i_schedule,i_poschedulex.
* End of Refreshing and clearing    DEVK907080


* If Ordered qty for PO = 0 then delete the invoice no
    if  i_orders-wemng = 0.
      move : 'X'  to i_poitem-delete_ind.       " Deletion Ind
      move : 'X'  to i_poitemx-delete_ind.      " Deletion Ind
*   !! start
      move : 'X'  to i_poitem-final_inv.        " Final invoice
      move : 'X' to i_poitem-no_more_gr.       " Delivery com ind
      move : 'X' to i_poitemx-final_inv.        " Final invoice
      move : 'X' to i_poitemx-no_more_gr.       " Delivery com ind
*   !! end

* If Ordered QTY more than 0
*      and it is less than Scheduled qty
*          then change the scheduled QTY = ordered qty
    elseif i_orders-wemng > 0 and i_orders-wemng < i_orders-menge.
      i_schedule-po_item = i_orders-ebelp.      " PO order
      i_poschedulex-po_item = i_orders-ebelp.   " PO order

      i_schedule-sched_line = i_orders-etenr.    " sched line item
      i_poschedulex-sched_line = i_orders-etenr. " sched line item

      i_schedule-quantity = i_orders-wemng.      " Changing sched qty
      i_poschedulex-quantity = i_orders-wemng.   " sched line item

      clear v_flag.
      v_flag = 'X'.
      i_orders-menge = i_schedule-quantity.
      append i_schedule. append i_poschedulex.

*-------------------  Invoice qty calc -------------------*
*
* Checks where Scheduled QTY = Deliverd QTY ----
*
*-------------------  Invoice qty calc -------------------*

*      in this case use invoiced QTY and Final invoice indicator
*      to delete the item
    elseif i_orders-wemng = i_orders-menge.

* if final invoice indicator is checked
*      and Scheduled QTY = Invoice QTY then delete item
      if i_orders-erekz eq 'X'
            and i_orders-inqty = i_orders-menge.
        move : 'X'  to i_poitem-delete_ind.   " Deletion Ind
        move : 'X'  to i_poitemx-delete_ind.  " Deletion Ind
*   !! start
      move : 'X'  to i_poitem-final_inv.        " Final invoice
      move : 'X' to i_poitem-no_more_gr.       " Delivery com ind
      move : 'X' to i_poitemx-final_inv.        " Final invoice
      move : 'X' to i_poitemx-no_more_gr.       " Delivery com ind
*   !! end


* If final invoice unchecked
*        and scheduled = invoice qty, Do not delete item
      elseif i_orders-erekz eq ' '
             and i_orders-inqty = i_orders-menge.

        continue.

* if final partial invoice indicator checked then dont delete item
      elseif i_orders-twrkz = 'X'.
        move : ' '  to i_poitem-delete_ind.   " Deletion Ind
        move : ' '  to i_poitemx-delete_ind.  " Deletion Ind
*   !! start
        move : ' '  to i_poitem-final_inv.        " Final invoice
        move : ' ' to i_poitem-no_more_gr.       " Delivery com ind
        move : ' ' to i_poitemx-final_inv.        " Final invoice
        move : ' ' to i_poitemx-no_more_gr.       " Delivery com ind
*   !! end



* if invoiced quantity = 0
*        and final invoice indicator checked
      elseif i_orders-inqty = 0
            and i_orders-erekz = 'X'.
        move : 'X'  to i_poitem-delete_ind.   " Deletion Ind
        move : 'X'  to i_poitemx-delete_ind.  " Deletion Ind
*   !! start
      move : 'X'  to i_poitem-final_inv.        " Final invoice
      move : 'X' to i_poitem-no_more_gr.       " Delivery com ind
      move : 'X' to i_poitemx-final_inv.        " Final invoice
      move : 'X' to i_poitemx-no_more_gr.       " Delivery com ind
*   !! end

      else.

        continue.

      endif.


    endif.

* BAPI will run for every Purchase order
    on change of i_orders-ebeln.

      move: i_orders-ebeln to t_poheader-po_number,    " Purchase number
                 'X'           to  t_poheaderx-po_number.  " Indicator
    endon.

    move : i_orders-ebelp    to i_poitem-po_item,     " Purchase order
           i_orders-ebelp    to i_poitemx-po_item.    " Line Item

    append i_poitem. append i_poitemx.

    clear i_return.
    refresh i_return.

    call function 'BAPI_PO_CHANGE'
         exporting
              purchaseorder = i_orders-ebeln
              poheader      = t_poheader
              poheaderx     = t_poheaderx
         tables
              return        = i_return
              poitem        = i_poitem
              poschedule    = i_schedule
              poschedulex   = i_poschedulex
              poitemx       = i_poitemx.

* Save the deletion mark

    commit work." and wait.

    loop at i_return.

      if i_return-type eq 'S' or i_return-type eq 'I'
          or i_return-type eq 'W'.

        if v_flag ne 'X'.
        move : 'X'  to i_orders-loekz.            " Dele ind for disp it
        endif.
        move-corresponding i_orders to i_suc_req.

        append i_suc_req. clear i_suc_req.

      elseif i_return-type eq 'E'.

*   Move error record into i_err for processing those manually
        move-corresponding i_orders to i_err.
        append i_err. clear i_err.

      endif.

    endloop.

  endloop.

* Delete Duplicate Entries from Internal tables
  delete adjacent duplicates from i_suc_req comparing ebeln ebelp.

  delete adjacent duplicates from i_err comparing ebeln ebelp.

endform.                    " bapi_process
*&---------------------------------------------------------------------*
*&      Form  display_success_records
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_success_records.

  write:/001 sy-uline(89).
  format intensified on.
  write:/001 sy-vline.
  format color col_heading.

  write:029 'Purchase Order Success Records'.

  write:089 sy-vline.
  format color col_background.

  write:/001 sy-uline(089).
  write:/001 sy-vline.
  format color col_heading.

*  Display the field headings
  write: 001 sy-vline,
         003 'Pur Order',
         018 sy-vline,
         020 'Item No',
         027 sy-vline,
         029 'Creation Date',
         043  sy-vline,
         045 'Scheduled Qty',
         061  sy-vline,
         063 'Delivered Qty',
         079 sy-vline,
         081 'Dele Ind',      " Deletion Indicator
         089 sy-vline.

  format color off.

  loop at i_suc_req.
*      To provide color codings.
    v_chk_color = sy-tabix mod 2.

    if v_chk_color = 0.
      format color col_normal.
    else.
      format color col_background.
    endif.

    write:/001 sy-vline,
           003 i_suc_req-ebeln ," Purchase order
           018 sy-vline,
           020 i_suc_req-ebelp ," Creation Date
           027 sy-vline,
           029 i_suc_req-aedat ," Item No of Purchasing Document
           043 sy-vline,
           045 i_suc_req-menge ," Scheduled quantity
           061 sy-vline,
           063 i_suc_req-wemng ," Delivered quantity
           079 sy-vline,
           081 i_suc_req-loekz, " Deletion Indicator
           089 sy-vline.

  endloop.

  write :/1 sy-uline(89).

endform.                    " display_success_records

*&---------------------------------------------------------------------*
*&      Form  display_error_records
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_error_records.

  if v_lines > 0.
    skip 2.
  endif.

  write:/001 sy-uline(89).
  format intensified on.
  write:/001 sy-vline.
  format color col_heading.

  write:029 'Purchase Order Error Records'.

  write:089 sy-vline.
  format color col_background.

  write:/001 sy-uline(089).
  write:/001 sy-vline.
  format color col_heading.

*  Display the field headings
  write: 001 sy-vline,
         003 'Pur Order',
         018 sy-vline,
         020 'Item No',
         027 sy-vline,
         029 'Creation Date',
         043  sy-vline,
         045 'Scheduled Qty',
         061  sy-vline,
         063 'Delivered Qty',
         079 sy-vline,
         081 'Del Ind',      " Deletion Indicator
         089 sy-vline.

  format color off.

  loop at i_err.
*      To provide color codings.
    v_chk_color = sy-tabix mod 2.

    if v_chk_color = 0.
      format color col_normal.
    else.
      format color col_negative.
    endif.

    write:/001 sy-vline,
           003 i_err-ebeln ," Purchase order
           018 sy-vline,
           020 i_err-ebelp ," Creation Date
           027 sy-vline,
           029 i_err-aedat ," Item No of Purchasing Document
           043 sy-vline,
           045 i_err-menge ," Scheduled quantity
           061 sy-vline,
           063 i_err-wemng ," Delivered quantity
           079 sy-vline,
           081 i_err-loekz, " Deletion Indicator
           089 sy-vline.
  endloop.

  write :/1 sy-uline(89).


endform.                    " display_error_records

*&---------------------------------------------------------------------*
*&      Form  delete_orders
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form delete_orders.

  clear v_index.

  loop at i_orders.
    v_index = sy-tabix + 5.
    read line v_index field value i_orders-chk.
    if i_orders-chk eq space.
      modify i_orders transporting chk.
    endif.
  endloop.

  delete i_orders where chk eq ' '.

  set pf-status 'PROCESS' excluding 'PROC'.

endform.                    " delete_orders

*&---------------------------------------------------------------------*
*&      Form  extract_ekbe_inv_qty
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form extract_ekbe_inv_qty.
* Get the invoicing qty.
  clear i_ekbe.
  refresh i_ekbe.

  if v_lines > 0.
*    SELECT ebeln ebelp vgabe bewtp menge shkzg    " DEVK907004
    select * from ekbe              " DEVK907004
          into corresponding fields of table i_ekbe
          for all entries in i_orders
          where  ebeln = i_orders-ebeln      " Purchase order
          and    ebelp = i_orders-ebelp      " Purchase order Line item
          and    vgabe = '2'.                " Transaction/event type

    sort i_ekbe by ebeln ebelp.
  endif.

endform.                    " extract_ekbe_inv_qty


*&---------------------------------------------------------------------*
*&      Form  display_orders_with_checkbox
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_orders_with_checkbox.
  loop at i_orders.
*      To provide color codings.
    v_chk_color = sy-tabix mod 2.

    if v_chk_color = 0.
      format color col_normal.
    else.
      format color col_background.
    endif.

    write:/001 sy-vline,
           002 i_orders-chk as checkbox,
           005 sy-vline,
           007 i_orders-ebeln ," Purchase order
           018 sy-vline,
           020 i_orders-ebelp ," Creation Date
           027 sy-vline,
           029 i_orders-aedat ," Item No of Purchasing Document
           043 sy-vline,
           045 i_orders-menge ," Scheduled quantity
           061 sy-vline,
           063 i_orders-wemng ," Delivered quantity
           079 sy-vline.

  endloop.

  write :/1 sy-uline(79).
endform.                    " display_orders_with_checkbox

*&---------------------------------------------------------------------*
*&      Form  display_header
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_header.

  write:/001 sy-uline(79).
  format intensified on.
  write:/001 sy-vline.
  format color col_heading.

  write:024 'Purchase Orders to be Processed'.
*  text-011.       " 'Master Data Information' .

  write:079 sy-vline.
  format color col_background.


  write:/001 sy-uline(079).
  write:/001 sy-vline.
  format color col_heading.

*  write:004 sy-vline.

*  Display the field headings
  write: 001 sy-vline,
         002  'Chk',
         005 sy-vline,
         007 'PO Order',
         018 sy-vline,
         020 'Item No',
         027 sy-vline,
         029 'Creation Date',
         043  sy-vline,
         045 'Scheduled Qty',
         061  sy-vline,
         063 'Delivered Qty',
         079 sy-vline.

*  WRITE:079 sy-vline.
  format color col_background.

  write:/001 sy-uline(079).

endform.                    " display_header

Former Member
0 Kudos

Hi Khan,

Bapi is function module only parameters passig is same as a normal funtion module. come bapi_po_crete have

structures : PO_HEADER " for po header data like vendor ekprg,ekgrp... say first screen of me21.

same as above bapi will have structures :

PO_ITEMS " item data

PO_ITEM_ADD_DATA " tax data

PO_ITEM_SCHEDULES " Schedules data

PO_ITEM_ACCOUNT_ASSILIKE "acconts data

you have to populate these structures as per your requirment and pass to bapi.

thnaks