BAPI -PO CREATION

Hi all,
Please suggest me how to create purchase order using BAPI

Here is a sample FORM routine.
*      Form  create_purchase_order
form create_purchase_order.
  constants : c_x value 'X'.
  data: del_date type sy-datum.
  data: pohead  type bapimepoheader.
  data: poheadx type bapimepoheaderx.
  data: exp_head type bapimepoheader.
  data: return  type table of bapiret2 with header line.
  data: poitem  type table of bapimepoitem with header line.
  data: poitemx type table of bapimepoitemx with header line.
  data: posched  type table of bapimeposchedule with header line.
  data: poschedx type table of bapimeposchedulx with header line.
  data: ex_po_number type bapimepoheader-po_number.
* Header Level Data
pohead-comp_code = '0010'.
  pohead-doc_type   = 'NB'     .
  pohead-creat_date = sy-datum   .
pohead-vendor = p_lifnr.
pohead-purch_org = '0010'.
  pohead-pur_group = 'EMG'.
  pohead-langu      = sy-langu   .
  pohead-doc_date   = sy-datum.
  poheadx-comp_code  = c_x.
  poheadx-doc_type   = c_x.
  poheadx-creat_date = c_x.
  poheadx-vendor     = c_x.
  poheadx-langu      = c_x.
  poheadx-purch_org  = c_x.
  poheadx-pur_group  = c_x.
  poheadx-doc_date   = c_x.
* Item Level Data
  poitem-po_item  = 1.
  poitem-material = xresb-matnr.
  poitem-plant    = xresb-werks.
  poitem-stge_loc = xresb-lgort.
  poitem-quantity = p_bdmng.
  append poitem.
  poitemx-po_item    = 1.
  poitemx-po_itemx   = c_x.
  poitemx-material   = c_x.
  poitemx-plant      = c_x .
  poitemx-stge_loc   = c_x .
  poitemx-quantity   = c_x .
  poitemx-tax_code   = c_x .
  poitemx-item_cat   = c_x .
  poitemx-acctasscat = c_x .
  append poitemx.
* Schedule Line Level Data
  posched-po_item        = 1.
  posched-sched_line     = 1.
  posched-del_datcat_ext = 'D'.
  del_date = sy-datum + 1.
  write del_date to posched-delivery_date.
  posched-deliv_time     = '000001'.
  posched-quantity       = p_bdmng.
  append posched.
  poschedx-po_item        = 1.
  poschedx-sched_line     = 1.
  poschedx-po_itemx       = c_x.
  poschedx-sched_linex    = c_x.
  poschedx-del_datcat_ext = c_x.
  poschedx-delivery_date  = c_x.
  poschedx-quantity       = c_x.
  append poschedx.
  call function 'BAPI_PO_CREATE1'
       exporting
            poheader         = pohead
            poheaderx        = poheadx
            testrun          = ' '
       importing
            exppurchaseorder = ex_po_number
            expheader        = exp_head
       tables
            return           = return
            poitem           = poitem
            poitemx          = poitemx
            poschedule       = posched
            poschedulex      = poschedx.
  call function 'BAPI_TRANSACTION_COMMIT'
       exporting
            wait = 'X'.
  if not ex_po_number is initial.
    call function 'DEQUEUE_ALL'.
  else.
    call function 'DEQUEUE_ALL'.
    message i036.
  endif.
endform.

Similar Messages

  • BAPI for Creation of inspection lot

    I have two scenario:-
    1.Can any body help to find BAPI for creation of Inspection lot for the material under PO envisaged for PDI.
    2. Can any body find me a BAPI or FM which can creates inspection lot in QALS table without inspection lot origin under 01 i.e. 0101 or Z01SI01.
    My objective is to creation inspection lot without assigning Inspection type of Z01SI01 or Z01SI02 and so on in the material code under a respective Plant 1004 or 1005 0r 1006 so on.
    In my Z Development for creation of inspection lot BDC is run for QA01 as this code created inspection lot on when material code has inspection type Z01SI01 i.e. location of source inspection and vendr code particular classification under 010 vendor class inspection type Z01SI01. System search both the inspection type for both material and vendor then create inspection lot in QALS table by assiging inspection matching inspection on the lot.
    I want to get rid of assignment of inspection on the materilal. If any BAPI or FM is avalable for creation of inspection without assigning inspection type on material code. I want to create inspection lot in which Inpsection type assignment can be done based on vendor class only.
    YPB

    2. Can any body find me a BAPI or FM which can creates inspection lot in QALS table without inspection lot origin under 01 i.e. 0101 or Z01SI01.
    I am very sure that this is not possible.You can not create inspection lot without inspection lot origin or inspection type.
    Regards
    Sujit

  • BAPI for creation of subcontract PO

    Hi all,
       Currently iam doing a BAPI for creation of subcontract Purchase Order using the BAPI_PO_CREATE1. But in this BAPI iam unable to find the table for entering Components.
    Regards,
    Sun.

    Hi,
    I wil give you how to fill the components of PO items, it is a sample code;
    *zPoHeader
      if kna1-kunnr eq 'BOR020'.
        zpoheader-comp_code   = '0040'.
      endif.
      if  kna1-kunnr eq 'BOR040'.
        zpoheader-comp_code   = '0048'.
      endif.
      zpoheader-doc_type    = 'ZSA'.
      zpoheader-doc_date    = mkpf-budat.
      zpoheader-vendor      = 'BOR050'. "şimdilik
      zpoheader-pmnttrms    = 'Z030'.
      zpoheader-purch_org   = '1100'.
      zpoheader-pur_group   = '101'. "malzeme ÜZERINDEKI marc-ekgrp
      zpoheader-currency    = zsaleshead-waers.
      zpoheader-item_intvl  = 10.
      zpoheaderx-comp_code  = 'X'.
      zpoheaderx-doc_type   = 'X'.
      zpoheaderx-vendor     = 'X'.
      zpoheaderx-purch_org  = 'X'.
      zpoheaderx-pur_group  = 'X'.
      zpoheaderx-currency   = 'X'.
      zpoheaderx-doc_date   = 'X'.
      zpoheaderx-pmnttrms   = 'X'.
      zpoheaderx-item_intvl = 'X'.
    *zPoitem
      loop at i_posnr.
        lv_ebelp = lv_ebelp + 10.
        zpoitem-po_item    =  lv_ebelp.
        zpoitem-material   = i_posnr-matnr.
        if kna1-kunnr eq 'BOR020'.
          zpoitem-plant      = '0040'.
          zpoitem-stge_loc   = '4001'.
        endif.
        if kna1-kunnr eq 'BOR040'.
          zpoitem-plant      = '0048'.
          zpoitem-stge_loc   = '4801'.
        endif.
        zpoitem-quantity   = i_posnr-menge.
        zpoitem-po_unit    = i_posnr-meins.
        zpoitem-net_price  = i_posnr-bfiyat.
        zpoitem-price_unit = 1.
        zpoitem-tax_code   = 'V0'.
        zpoitemx-po_item    = lv_ebelp.
        zpoitemx-po_itemx   = 'X'.
        zpoitemx-material   = 'X'.
        zpoitemx-plant      = 'X'.
        zpoitemx-stge_loc   = 'X'.
        zpoitemx-quantity   = 'X'.
        zpoitemx-po_unit    = 'X'.
        zpoitemx-net_price  = 'X'.
        zpoitemx-price_unit = 'X'.
        zpoitemx-tax_code   = 'X'.
        append: zpoitem, zpoitemx.
        clear : zpoitem, zpoitemx.
      endloop.
      call function 'BAPI_PO_CREATE1'
        exporting
        poheader                     = zpoheader
        poheaderx                    = zpoheaderx
    tables
       return                       = zreturn3
       poitem                       = zpoitem
       poitemx                      = zpoitemx.
    Send me your results,
    Kenan.

  • In BAPI PO CREATION How to handled errors datas

    Hi friends ,
    In BAPI PO CREATION upload the datas How to handle/capture errors datas.?
    arun

    Hi,
    After completion of the program IT_RETURN table will have all the messages in it.
    Loop the IT_RETURN internal table and display the data.
    Regards
    Sudheer

  • Bapi for creation of a contract against services.

    Hi.
    i just want to know the correct bapi for creation of contracts against services..here i was tried with BAPI_CONTRACT_CREATE but the documentation says that it is not supported for exxternal or internal services.
    so iam not sure if this bapi is the one for contract creation for services.
    any way i was tried to test this function module but i havent got  Contract created.
    wil be waiting for an excellent answer.
    bye.
    reegards.
    seetaram.

    Hi Ram,
    Try the function module
    BAPI_CONTRACT_CREATEFROMDATA.
    Once you create the contract, update the technical objects for the contracts
    using two function modules called one after another.
    IWOL_WV_ADD_OBJECTS
    IWOL_WV_POST_OBJECT_LIST
    Regards,
    Chandra Sekhar

  • How to run the BAPI after creation or Modification ?

    HI Abapers,
    How to run the BAPI after creation or Modification ? What is the step by step procedure to run the the BAPI?
    Immediate reply is highely appriciable.
    Regards,
    Chow.

    Hi
    If you have done with BAPI creation correctly Run it similar to the fun mdule which we run in SE37 calling this BAPi in the program with CALL FUNCTION and passing the necessary parameters
    see the sample bapi code how it is called in Program
    data : w_resb_header like bapirkpfc.
    data: begin of itab_resb occurs 0.
    include structure bapiresbc.
    data: end of itab_resb.
    data: begin of itab_bapi_return occurs 0.
    include structure bapireturn.
    data: end of itab_bapi_return.
    data : w_resb_no like bapirkpfc-res_no.
    w_resb_header-plant = p_werks.
    w_resb_header-res_date = sy-datum.
    w_resb_header-created_by = sy-uname.
    w_resb_header-cost_ctr = '0000010001'.
    w_resb_header-move_type = '201'.
    w_resb_header-gr_rcpt = w_room_time.
    w_resb_header-part_acct = 'OR'.
    *ITEM DATA
    loop at i_details.
    itab_resb-material = i_details-matnr.
    itab_resb-plant = i_details-werks.
    itab_resb-store_loc = i_details-lgort.
    itab_resb-quantity = i_details-qty.
    itab_resb-unit = i_details-meins.
    append itab_resb.
    clear itab_resb.
    clear i_details.
    endloop.
    call function 'BAPI_RESERVATION_CREATE'
    exporting
    reservation_header = w_resb_header
    NO_COMMIT =
    MOVEMENT_AUTO =
    importing
    reservation = w_resb_no
    tables
    reservation_items = itab_resb
    return = itab_bapi_return
    call function 'BAPI_TRANSACTION_COMMIT'
    exporting
    wait = 'X'
    IMPORTING
    RETURN =    .
    wait up to 5 seconds.
    w_resb_no contains your reservations numnber
    Regards
    Anji

  • BAPI for Creation of Maintenance Plan (TCode - IP01)

    Hello
    Kindly help me with the BAPI for Creation of Maintenance Plan (TCode - IP01)
    Thanks and Regards
    Avishek

    Hi
       Check Tcode: IBIP. and LSMW method and below link it may be helpful.
    [link|Re: LSMW for uploading equipment.]
    Thanks,
    Asit Purbey.

  • BAPI for Creation of the Project in ECC using Standard Templates

    Hi,
    I want BAPI for Creation of the Project in ECC using project id and project standard template ID
    and BAPI for Updating of project and WBS element  using  project id and WBS element ID

    One idea is to write a wrapper FM that is remote enabled and internally call BBP_PD_CTR_CREATE for your own use.

  • Bapi for Creation of PO(Purchase Order) with Factor & Length

    Dear Experts,
    we wnat to create Po automatically by using Bapi.
    I come to know, there are some bapis like BAPI_PO_CREATE1,BAPI_PO_CREATE.
    Normal PO, we are able to create with these bapis.
    But we want to give factor & Length in PO Creation.
    Because we are using the Mill Products(cable Industry).
    so how to create the PO with Factor & Length.
    Plese help me to sort this issue.
    Thanks in advance,
    Regards,
    Rahul
    Edited by: M.Rahul Reddy on Oct 15, 2009 1:07 PM
    Dear Experts,
    I am looking for  your valuable sujjection to sort the issue.

    This is version problem in the Sap system.
    we are communicating with SAP people.

  • BAPI for creation of material documents/movements

    Hi Everebody:
    I need some help regarding to bapis for the creation of mateial documents and/or movements. I have been trying to implement bapi BAPI_GOODSMVT_CREATE, but this bapi does not have (import) the posting time in document, which is very important for my porpuse.
    So, I would appretiate a lot any information anybody could give about any bapi I could use to create material documents or material movements but incluidng the posting time in document (field MKPF-OIB_BLTIME).
    Regards

    You can check MB_CREATE_GOODS_MOVEMENT which has mkpf as inporting parameter.

  • BAPI for creation of Production Order with Ref to sales order

    Hi all,
    we are using BAPI_PRODORD_CREATE  for creating Production Order with ref to sales order.
    As per the Business Scenario, we are not creating any masters like BOM and Routing, instead
    we are creating Routing directly into the Production Order under operation overview screen.
    during creation of routing system is generating a default operation.
    the following is the error results after running the Bapi.
    "No routing selected"
    Best Regards.
    GTNRNR.

    Hi GTNRNR,
    with out creation of BOM you created routing and in routing for the operations which components did you allocated so that can be used to manufacture the final product. Can you be please specific?
    Regards,
    Madhu.G

  • Bapi for creation of equipment master

    hi friends ,
    I have to made a BDC program for creation of equipment master .
    for that  I am using bapi i.e. ' BAPI_EQUI_CREATE '.
    I had matched the fields of transaction IE01 but in the additinal data part i could not able to map 'Partner' fields .
    pls some body can guide what should i do for it.

    Hi Das,
    If u r going to create equipment no against this Bapi BAPI_EQUI_CREATE"
    then u need to pass material no, Equipment type, Serial No. there is no need to give partner no .
    If its good, then plz give point.

  • BAPI for creation of Authorization Objects in BI 7.0

    Hi BW Gurus,
    Greetings!!!
    Is there any BAPI Available for creation of Authorization Objects in BI 7.0.
    The data will be transferred through flatfiles.
    Kindly provide me the info as earliest as possible.
    Best Regards,
    Priya

    Got the Workaround...
    Priya

  • Bapi for creation of employee(pernr)?

    Hi,
    Is there any Bapi with which we can create an employee(Pernr)?
    I need to call this BAPI from .net connecctor.
    We have BAPI_APPLICANT_CREATE for applicant creation. Like this, do we have any thing for employee creation?
    Thanks in advance,
    RSS.

    You could have a look at the function modules starting with HR_INFOTYPE* especially HR_INFOTYPE_OPERATION.  However, I've only used this to create things such as absences and absence quotas for an existing employee and it may not be possible to use it to create an employee from scratch.

  • BAPI for Creation of Stock

    Hi Freinds,
    I need to trigger the creation of a stock from a BAPI.
    So in MIGO i am using movement type 501 and type as Others.
    I could see a bapi BAPI_GOODSMVT_CREATE for that .But in the checktable for the tcodes t158g , i could not find MIGO.So i doubt if i can use this BAPI for the creation of a stock.
    Please let me know if there is a BAPI for the creation of stocks.
    Thanks and Regards,
    Anoop

    Hello,
    Use the belwo bapi.
    BAPI_WHSE_TO_CREATE_STOCK
    Reward if helps.
    Thanks,
    Krishna

  • BAPI for creation of PO

    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

    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

Maybe you are looking for