BAPI_PO

Hi Gurus,
I am woking on an interface where I need to use BAPI for PO creation for multiple line items  and for this I have written the following code:
*& Report  Z_TEST1                                                      *
REPORT  Z_TEST1  .
internal table to store the data
data:  poheader LIKE bapimepoheader,
       poheaderx LIKE  bapimepoheaderx,
       poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
       poitemx LIKE  bapimepoitemx  OCCURS 0 WITH HEADER LINE,
       return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
       return2 LIKE  bapiret2 OCCURS 0 WITH HEADER LINE,
       exppurchaseorder  LIKE  bapimepoheader-po_number,
       poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
       poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.
data: begin of it_input_file OCCURS 0,
        item_no(3),
        ref_no(2),
        vend_no(10),
        material(18),
        Quantity(13),
        Price(10),
        ord_unit(7),
        Plant(4),
        Strg_loc(4),
        purch_grp(4),
        purch_org(4),
        c_code(4),
        doc_typ(4),
        del_date(10),
      end of it_input_file.
data: it_ref_no_old(2)  type c,
      it_record        like line of it_input_file,
      it_record_x      like line of it_input_file.
data: ld_file LIKE rlgrap-filename.
data: begin of it_read_file occurs 0,
        line(1000),
      end of it_read_file.
data: it_file like it_input_file occurs 0 with header line.
Definition of Variables                                             *
data: v_semfile like RLGRAP-FILENAME.
Selection Screen                                                    *
selection-screen  begin of block b1 with frame title text-001.
parameters: p_ifname like rlgrap-filename obligatory.
selection-screen  end of block b1.
*selection-screen  begin of block b2 with frame title text-002.
*parameters: p_ifnam2 like rlgrap-filename obligatory DEFAULT  '/usr/sap/'.
*selection-screen  end of block b2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ifname.
  CALL FUNCTION 'F4_FILENAME'   "allows user to select path/file
     EXPORTING
        program_name  = 'Z_PO_Creation'
        dynpro_number = syst-dynnr
        field_name    =  'p_ifname'
     IMPORTING
        file_name     = p_ifname.
START-OF-SELECTION *
start-of-selection.
  perform get_data.
  perform data_process.
end-of-selection.
*&      Form  get_data
      text
-->  p1        text
<--  p2        text
FORM get_data .
  v_semfile = p_ifname.
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename                = v_semfile
      filetype                = 'DAT'
    TABLES
      data_tab                = it_input_file
    EXCEPTIONS
      conversion_error        = 1
      file_open_error         = 2
      file_read_error         = 3
      invalid_table_width     = 4
      invalid_type            = 5
      no_batch                = 6
      unknown_error           = 7
      gui_refuse_filetransfer = 8
      OTHERS                  = 9.
ENDFORM.                    " get_data
*&      Form  call_bapi
      text
-->  p1        text
<--  p2        text
FORM call_bapi .
  LOOP AT it_input_file.
moving header data.
    MOVE: it_input_file-vend_no    TO  poheader-vendor,
          it_input_file-doc_typ    TO  poheader-doc_type,
          it_input_file-purch_org  TO  poheader-purch_org,
          it_input_file-purch_grp  TO  poheader-pur_group,
          it_input_file-c_code     TO  poheader-comp_code.
updating header data.
    poheaderx-vendor     =  'X'.
    poheaderx-doc_type   =  'X'.
    poheaderx-doc_date   =  'X'.
    poheaderx-purch_org  =  'X'.
    poheaderx-pur_group  =  'X'.
    poheaderx-comp_code  =  'X'.
moving item data.
    MOVE: it_input_file-item_no    TO  poitem-po_item,
          it_input_file-plant      TO  poitem-plant,
          it_input_file-Strg_loc   TO  poitem-stge_loc,
          it_input_file-material   TO  poitem-material,
          it_input_file-quantity   TO  poitem-quantity,
          it_input_file-price      TO  poitem-price_unit,
          it_input_file-ref_no     TO  poitem-ref_doc,
          it_input_file-ord_unit   TO  poitem-po_unit.
updating Item data.
    poitemx-po_item      =  it_input_file-item_no.
    poitemx-plant        =  'X'.
    poitemx-stge_loc     =  'X'.
    poitemx-material     =  'X'.
    poitemx-quantity     =  'X'.
    move: it_input_file-del_date      TO  poschedule-delivery_date.
    move: 'X'                          TO        poschedulex-delivery_date.
    APPEND:  poitem, poitemx.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        poheader         = poheader
        poheaderx        = poheaderx
      IMPORTING
        exppurchaseorder = exppurchaseorder
      TABLES
        poitem           = poitem
        poitemx          = poitemx
        poschedule       = poschedule
        poschedulex      = poschedulex
        return           = return.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      IMPORTING
        return = return2.
    WRITE:/ exppurchaseorder.
  ENDLOOP.
ENDFORM.                    " call_bapi
*&      Form  data_process
      text
-->  p1        text
<--  p2        text
FORM data_process .
  sort it_input_file by ref_no.
  clear: it_ref_no_old.
  loop at it_input_file into it_record.
    if  it_record-ref_no ne it_ref_no_old .
      loop AT it_input_file into it_record_x
                           where  ref_no = it_record-ref_no .
      endloop.
      if  syst-subrc = 0 .
        PERFORM call_bapi.
      endif.
    endif.
    it_ref_no_old = it_record-ref_no.
  endloop.
ENDFORM.                    " data_process.
The program is not showing me any error but when I tried to run it in the debug mode, the return statement at Call Bapi returns the folloowing errors:
1. E   |BAPI                |001   |No instance of object type PurchaseOrder
2. E   |MEPO             |002   |PO header data still faulty
Can you please help me out how to get rid of it.
Thanks
Rajeev Gupta

I see doc_date is not populated in your PO header structure but you flagged it.
Try passing this and any other required fields in the header.
Also, where are you appending poheader and poheaderx?
Thanks,
SKJ

Similar Messages

  • Purchase order (STO) schedule line change through BAPI_PO CHANGE

    Hi Gurus,
    we have requirement in user exit of MIGO ; to change the purchase order(STO) Scheduline change through BAPI_PO_Change.
    Current process.
    STO -> outbound delivery through VL10B -> PGI -> MIGO to the receipt
    It is working fine MIGO if we give fully quanitty issued in the quantify field of MIGO.
    but if we give less quantity what ever PGI ed earlier then inside the user exit of MIGO it is giving error message 06 089 -> Quanity is smaller than the quantity Issued while changing the STO scheduline line through BAPI_PO_CHNAGE
    If anybody having any idea 06 089 -> Quanity is smaller than the quantity Issued please help me.
    Best Regards,
    Radhakrishna.

    Check the following link it will help u
    http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm

  • Extension paramter in BAPI_PO*

    Hi All,
    I have added some custom fields in PO transaction.
    Now when i am trying to update the custom fields for PO using BAPI for create or change BAPI_PO_CHANGE,
    There are paramteres EXTENSIONIN and EXTENSIONOUT.
    Could you let me know how and what to fill these parameters?
    regards
    Shiva

    first you create a custom structure with the required fields. And the first field should be EBELP (Key field).
    eg: if you want to pass data to custom fields like ZXXX(length 10), ZYYY(length 20).
    then do as follows.
    Create a custom structure as follows.
    Structure name: ZCUSTOM (let)
    EBELP
    ZXXX
    ZYYY.
    then in your program pass data as follows.
    EXTENSIONIN-STRUCTURE = 'ZCUSTOM'.
    EXTENSIONIN-FIELD1+0(10) = '0000000010'.  "Line item number.
    EXTENSIONIN-FIELD1+10(10) = Value for ZXXX.
    EXTENSIONIN-FIELD1+20(20) = Value for ZYYY.
    append EXTENSIONIN.
    then pass EXTENSIONIN to BAPI.

  • Using bapi_pochange

    hii frnds
    has any body used FM bapi_po change . actualy i have to modify the shedule line and pass it on the this bapi . i have got the shedule line from bapi_detail but not able to pass the changed line itmes using this fm . kindly help
    Regards
    rohit

    I am attaching the piece of code which is used while using BAPI for PO Change.
    Check if this helps -
    Populate the item schedule details
    Line item
      i_item_schedules-po_item = i_po_items-po_item.
      i_schedules_x-po_itemx   = c_x.
      i_schedules_x-po_item    = i_po_items-po_item.
    Schedule Line No
      i_item_schedules-sched_line = c_0001.
      i_schedules_x-sched_line    = c_0001.
      i_schedules_x-sched_linex   = c_x.
    Delivery date
      write i_pohdr-erdat to i_item_schedules-delivery_date.
      i_schedules_x-delivery_date    = c_x.
    Quantity
      i_item_schedules-quantity   = i_poitem-menge + l_wemng.
      i_schedules_x-quantity      = c_x.
      append i_item_schedules.
      append i_schedules_x.
    Pass this to parameters -
                  poschedule    = i_item_schedules
                  poschedulex   = i_schedules_x
    of BAPI
    ashish
    Message was edited by:
            Ashish Gundawar

  • PO updation after GR

    Dear Expert
    we want to update the conditions of PO ,  after the reversal of  GR  but System is not allowing any changes in the Condition of the PO .Is it a standard SAP behaviour then if so then must be some sap notes on the same , please provide the SAP note otherwise please provide the setting which i have do , so that condition can be updated after GR reversal .
    Regards

    hi,
    check few notes:
    439110
    622634 - BAPI_PO_CHANGE: New PD despite follow-on documents
    582252 - BAPI_PO_CREATE1/..._CHANGE: Header conditions are incorrect
    549843 - BAPI_PO_CREATE: Technical fields available
    539950 - BAPI_PO_CREATE1: n condition records for a condition type
    537221 - BAPI_PO_...: Conversion factors incorrect for conditions
    529531 - BAPI_PO_CHANGE: New pricing is no longer possible (V1227)
    529287 - BAPI_PO_CHANGE: Price merge is not possible
    428621 - EnjoySAP purchase order BAPIs - price det. & cond. change
    425996 - BAPI_PO_CREATE1: Termination msge 00151 w/ header conditions
    399791 - Enjoy-BAPI_PO...: Condition values are not transferred
    197958 - BAPIs for purchase orders - Missing functions

  • PO Creation in EP

    Hi,
            I want to create Purchase order in EP.What is the methodology to fetch quotation available in R/3 in EP? Useful and step by     step solution is highly appreciable.
    Thanks,
    Kundan

    hi
    First you need to get connection from R/3 using JCOs.
    for that you need to add ABAP(R/3) system in SLD,create JCO's(MODEL DATA n METADATA Destinations).
    using those jcos create RFC model for your project in your NWDS workbench and call create purchase order bapi(search bapi_po*)
    and do the mappings..
    Deploy your project into J2EE server.
    search in sdn for creating system in sld , jcos and also for utlizing bapi in webdynpro application.
    Regards
    sowmya

  • Customer fields schedule line

    hi
    has any one added customer fields in schedule line.
    pls help!!!
    regards
    Meghana

    excuse me - I'm using BAPI_PO CHANGE not BADI.
    Thanks again

  • Can I update Customer specific fields with BAP_PO_CHANGE

    Using 4.7 and APO 4.0. We're having to create multiple schedule lines (EKET) for PO Items for TP/VS functionallity. I've found a neat trick for doing this by using BADI ME_PURCHDOC_POSTED to trigger an FM in a new task.
    This FM waits until PO is unlocked and then uses BADI_PO_CHANGE to "split" the schedule lines. However I'm having trouble finding an easy way to populate new customer (Z) fields on the Schedule Line at the same time.
    Any Ideas??? 
    Thanks
    Charles

    excuse me - I'm using BAPI_PO CHANGE not BADI.
    Thanks again

Maybe you are looking for

  • "File path not found" when opening an Encore DVD project made 2 years ago

    Configuration: XP SP3, Encore DVD CS3 coming from Creative Suite. 2Gb RAM, fast-enough-CPU, large-enough-harddisk (~70Gb space). The project, as I remember, should has been made with Encore DVD 2.0 2 years ago. The project file is placed on the C:\ w

  • Migrating oracle 11.2.0.1.0 32bit to oracle 11.2.0.1.0 64bit on windows

    Hi experts, Please tell me steps to Migrate Oracle 11.2.0.1.0 32bit to 11.2.0.1.0 64bit on Microsoft Windows.(i.e. from Microsoft windows server 2003 SP2 to Microsoft windows 2008R2 SP1) I am thinking to do the same via data-pump. Please provide me t

  • Unable to perform daily backup

    Dear all, We are running daily backup in the afternoon, but I don't know why the daily backup takes more than 20 minus without any progresss. Here is the log. Please advice. Daily Backup Database begun on date Tue Mar 31 13:18:45 HKT 2009 Recovery Ma

  • CIN domain process ..??

    Hi experts Can anybody explaine in detail about CIN process (End to End in legacy system) In domain, without SAP how CIN process being processed..??? expalined me in 4 point of view. 1.Procurement exciseable material - 2.Production exciseable materia

  • Deleting Artwork in Itunes

    For some reason several (Many) of my albums have picked up the same album art from a completely different album - the wrong one and I can not delete that artwork to search for the correct art. When I go into "Get Info" no artwork appears. How in the