BAPI_PO_CREATE

Actually I don't have much time left so I though of posting this thread again, I am working on an interface where I need to create PO's using BAPI_PO_CREATE but to my bad luck the code that I have written is not working properly and I have just about an hour left to subit the program to my manager so can you please help me to get out of this very critical situation. I have written the following code,
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,
        ref_no(2),
        c_code(4),
        doc_typ(4),
        doc_date(10),
        vend_no(10),
        purch_org(4),
        purch_grp(3),
        currency(3),
        item_no(3),
        material(18),
        Plant(4),
        Strg_loc(4),
        Quantity(13),
        Price(10),
        ord_unit(7),
        del_date(10),
        seq_num(5) type n,
      end of it_input_file.
data: it_ref_no_old(2)  type c.
data: it_record like it_input_file occurs 0 with header line.
data: it_record_x like it_input_file occurs 0 with header line.
data: ld_file LIKE rlgrap-filename.
data: it_ser_data like it_input_file occurs 0 with header line.
data: begin of it_pipe_data occurs 0,
        line(1000),
      end of it_pipe_data.
data:  file1(70) type c value '/tmp/test_file_',
       len type i.
data: begin of it_lfa1 occurs 0,
        lifnr like lfa1-lifnr,
      end of it_lfa1.
data: begin of it_t001 occurs 0,
        bukrs like t001-bukrs,
      end of it_t001.
data: begin of it_mara occurs 0,
        matnr like mara-matnr,
      end of it_mara.
data: begin of it_mard occurs 0,
        lgort like mard-lgort,
      end of it_mard.
data: begin of it_marc occurs 0,
        werks like marc-werks,
      end of it_marc.
data: begin of it_t024 occurs 0,
        ekgrp like t024-ekgrp,
      end of it_t024.
data: begin of it_t024e occurs 0,
        ekorg like t024e-ekorg,
      end of it_t024e.
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.
data: begin of it_err_log occurs 0,
        seq_num(10),
        bukrs(4),
        bukrs_err_desc(50),
        lifnr(10),
        lifnr_err_desc(50),
        ekorg(4),
        ekorg_err_desc(50),
        ekgrp(3),
        ekgrp_err_desc(50),
        matnr(18),
        matnr_err_desc(50),
        werks(4),
        werks_err_desc(50),
        lgort(4),
        lgort_err_desc(50),
      end of it_err_log.
data: v_fullpath type string,
      v_length type i.
Definition of Variables                                             *
data: v_semfile like RLGRAP-FILENAME.
Definition of Constants                                             *
data: c_bukrs_err_desc(50)           value 'Invalid company code',
      c_currency_err_desc(50)        value 'Invalid valid currency',
      c_lifnr_err_desc(50)           value 'Invalid valid Vendor',
      c_ekorg_err_desc(50)           value 'Invalid valid purchasing Organization',
      c_ekgrp_err_desc(50)           value 'Invalid valid Purchasing group',
      c_matnr_err_desc(50)           value 'Invalid valid Material',
      c_werks_err_desc(50)           value 'Invalid valid Plant',
      c_lgort_err_desc(50)           value 'Invalid valid Storage Location'.
Selection Screen                                                    *
selection-screen  begin of block b1 with frame title text-001.
parameters: p_ifname LIKE rlgrap-filename OBLIGATORY
                DEFAULT 'C:\'.
parameter : p_lfile TYPE c RADIOBUTTON GROUP g1,   " local file
            p_ufile TYPE c RADIOBUTTON GROUP g1 DEFAULT 'X'. " Unix file
selection-screen  end of block b1 .
selection-screen  begin of block b2 with frame.             " text-002.
parameters: p_user like sy-uname MODIF ID md1 default syst-uname.
selection-screen  end of block b2.
selection-screen  begin of block b3 with frame title text-003.
parameters: p_upld radiobutton group upld default 'X' ,
            p_upldex radiobutton group upld.
selection-screen  end of block b3.
at selection screen
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.
  if p_upld = 'X'.
    perform build_table.
    perform validate_data.
    perform disp_error_report.
  else.
    if p_ufile = 'X'.
      perform open_unix_dataset.
    else.
      perform open_files.
    endif.
    perform data_process.
  endif.
perform put_data.
end-of-selection.
*&      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,
          it_input_file-doc_date   TO  poheader-doc_date.
updating header data.
    if poheader-vendor       <> ' '.
      poheaderx-vendor       =  'X'.
    endif.
    if poheader-doc_type     <> ' '.
      poheaderx-doc_type     =  'X'.
    endif.
    if poheader-doc_date     <> ' '.
      poheaderx-doc_date     =  'X'.
    endif.
    if poheader-purch_org    <> ' '.
      poheaderx-purch_org    =  'X'.
    endif.
    if poheader-pur_group    <> ' '.
      poheaderx-pur_group    =  'X'.
    endif.
    if poheader-comp_code    <> ' '.
      poheaderx-comp_code    =  'X'.
    endif.
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.
    if poitem-plant <> ' '.
      poitemx-plant     =  'X'.
    endif.
    if poitem-material <> ' '.
      poitemx-material     =  'X'.
    endif.
    if poitem-stge_loc <> ' '.
      poitemx-stge_loc     =  'X'.
    endif.
    if poitem-quantity <> ' '.
      poitemx-quantity     =  'X'.
    endif.
  if poitem-price_unit <> ' '.
        poitemx-price_unit    =  'X'.
  endif.
  if poitem-ref_doc <> ' '.
        poitemx-ref_doc     =  'X'.
  endif.
  if poitem-po_unit <> ' '.
        poitemx-po_unit     =  'X'.
  endif.
    poitemx-po_item      =  it_input_file-item_no.
    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:/ 'PO created with PO number:' ,
          exppurchaseorder.
  ENDLOOP.
ENDFORM.                    " call_bapi
*&      Form  data_process
      text
-->  p1        text
<--  p2        text
FORM data_process .
  if it_input_file[] is initial.
    message E319 with 'There is no data to process!!'.
  else.
    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.
  endif.
ENDFORM.                    " data_process
*&      Form  put_data
      text
-->  p1        text
<--  p2        text
FORM put_data .
  it_ser_data-ref_no = '1'.
  it_ser_data-c_code = 'AEM'.
  it_ser_data-doc_typ = 'AB'.
  it_ser_data-vend_no = '100004'.
  it_ser_data-purch_org = 'A001'.
  it_ser_data-purch_grp = '522'.
  it_ser_data-currency  = 'USD'.
  it_ser_data-item_no   = '10'.
  it_ser_data-material  = '1000003'.
  it_ser_data-Plant     = '1005'.
       it_ser_data-Strg_loc
  it_ser_data-Quantity  = '100'.
  it_ser_data-Price     = '2000'.
  it_ser_data-ord_unit  = 'EA'.
       it_ser_data-del_date  =
  append it_ser_data.
  clear it_ser_data.
  loop at it_ser_data.
    concatenate it_ser_data-ref_no it_ser_data-c_code it_ser_data-doc_typ it_ser_data-vend_no it_ser_data-purch_org it_ser_data-purch_grp
                it_ser_data-currency it_ser_data-item_no it_ser_data-material it_ser_data-Plant it_ser_data-Quantity it_ser_data-Price
                it_ser_data-ord_unit into it_pipe_data separated by '|'.
    append it_pipe_data.
  endloop.
  clear it_pipe_data.
  open dataset file1 in text mode for output encoding default.
  if syst-subrc eq 0.
    loop at it_pipe_data.
      transfer it_pipe_data to file1.
    endloop.
    close dataset file1.
  endif.
ENDFORM.                    " put_data
*&      Form  validate_data
      text
-->  p1        text
<--  p2        text
FORM validate_data .
  loop at it_input_file.
    read table it_t001 with key bukrs = it_input_file-c_code.
    if syst-subrc <> 0.
      move: it_input_file-c_code  to it_err_log-bukrs,
            it_input_file-seq_num to it_err_log-seq_num,
            c_bukrs_err_desc      to it_err_log-bukrs_err_desc.
    endif.
    read table it_t024 with key ekgrp = it_input_file-purch_grp.
    if syst-subrc <> 0.
      move: it_input_file-purch_grp  to it_err_log-ekgrp,
            it_input_file-seq_num to it_err_log-seq_num,
            c_ekgrp_err_desc         to it_err_log-ekgrp_err_desc.
    endif.
    read table it_t024e with key ekorg = it_input_file-purch_org.
    if syst-subrc <> 0.
      move: it_input_file-purch_org  to it_err_log-ekorg,
            it_input_file-seq_num to it_err_log-seq_num,
            c_ekorg_err_desc         to it_err_log-ekorg_err_desc.
    endif.
    read table it_lfa1 with key lifnr = it_input_file-vend_no.
    if syst-subrc <> 0.
      move: it_input_file-vend_no    to it_err_log-lifnr,
            it_input_file-seq_num to it_err_log-seq_num,
            c_lifnr_err_desc         to it_err_log-lifnr_err_desc.
    endif.
    read table it_mara with key matnr = it_input_file-material.
    if syst-subrc <> 0.
      move: it_input_file-material   to it_err_log-matnr,
            it_input_file-seq_num to it_err_log-seq_num,
            c_matnr_err_desc         to it_err_log-matnr_err_desc.
    endif.
    read table it_marc with key werks = it_input_file-plant.
    if syst-subrc <> 0.
      move: it_input_file-plant      to it_err_log-werks,
            it_input_file-seq_num to it_err_log-seq_num,
            c_werks_err_desc         to it_err_log-werks_err_desc.
    endif.
    read table it_mard with key lgort = it_input_file-Strg_loc.
    if syst-subrc <> 0.
      move: it_input_file-strg_loc   to it_err_log-lgort,
            it_input_file-seq_num to it_err_log-seq_num,
            c_lgort_err_desc         to it_err_log-lgort_err_desc.
    endif.
  endloop.
ENDFORM.                    " validate_data
*&      Form  open_unix_dataset
      text
-->  p1        text
<--  p2        text
FORM open_unix_dataset .
  open dataset ld_file for input in text mode encoding default.
  do.
    read dataset ld_file into it_read_file.
    if sy-subrc NE 0.
      exit.
    endif.
    append it_read_file.
    clear it_read_file.
  enddo.
  close dataset ld_file.
  if NOT it_read_file[] is initial.
    loop at it_read_file.
      split it_read_file at '|' into it_file-item_no
                                      it_file-ref_no
                                      it_file-vend_no
                                      it_file-material
                                      it_file-quantity
                                      it_file-price
                                      it_file-ord_unit
                                      it_file-plant
                                      it_file-strg_loc
                                      it_file-purch_org
                                      it_file-purch_grp
                                      it_file-c_code
                                      it_file-doc_typ.
      append it_file.
      clear it_file.
    endloop.
  endif.
ENDFORM.                    " open_unix_dataset
*&      Form  open_files
      text
-->  p1        text
<--  p2        text
FORM open_files .
  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.                    " open_files
*&      Form  build_table
      text
-->  p1        text
<--  p2        text
FORM build_table .
  select bukrs into table it_t001
    from t001
    for all entries in it_input_file
    where bukrs = it_input_file-c_code.
  select ekgrp into table it_t024
   from t024
   for all entries in it_input_file
   where ekgrp = it_input_file-purch_grp.
  select ekorg into table it_t024e
    from t024e
    for all entries in it_input_file
    where ekorg = it_input_file-purch_org.
  select lifnr into table it_lfa1
     from lfa1
     for all entries in it_input_file
     where lifnr = it_input_file-vend_no.
  select matnr into table it_mara
     from mara
     for all entries in it_input_file
     where matnr = it_input_file-material.
  select werks into table it_marc
     from marc
     for all entries in it_input_file
     where werks = it_input_file-plant.
  select lgort into table it_mard
     from mard
     for all entries in it_input_file
     where lgort = it_input_file-Strg_loc.
ENDFORM.                    " build_table
*&      Form  disp_error_report
      text
-->  p1        text
<--  p2        text
FORM disp_error_report .
  if NOT it_err_log[] is initial.
    move: '0'                     to it_err_log-seq_num,
          'Vendor'                to it_err_log-lifnr,
          'Vendor Error'          to it_err_log-lifnr_err_desc,
          'Company Code'          to it_err_log-bukrs,
          'Company Code Error'    to it_err_log-bukrs_err_desc,
          'Purchase Org'          to it_err_log-ekorg,
          'Purchase Org Error'    to it_err_log-ekorg_err_desc,
          'Purchase Group'        to it_err_log-ekgrp,
          'Purchase Group Error'  to it_err_log-ekgrp_err_desc,
          'Plant'                 to it_err_log-werks,
          'Plant Error'           to it_err_log-werks_err_desc,
          'Storage Loc'           to it_err_log-lgort,
          'Storage Loc Error'     to it_err_log-lgort_err_desc,
          'Material'              to it_err_log-matnr,
          'Material Error'        to it_err_log-matnr_err_desc.
    append it_err_log.
    sort it_err_log by seq_num.
    loop at it_err_log where seq_num eq '0'.
      move 'Seq Num' to it_err_log-seq_num.
      modify it_err_log.
    endloop.
    concatenate 'c:\inventory_error_log' syst-datum syst-uzeit '.xls'
      into v_fullpath.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
  BIN_FILESIZE                    =
        FILENAME                        =  v_fullpath
        FILETYPE                        = 'DAT'
  APPEND                          = ' '
  WRITE_FIELD_SEPARATOR           = ' '
  HEADER                          = '00'
  TRUNC_TRAILING_BLANKS           = ' '
  WRITE_LF                        = 'X'
  COL_SELECT                      = ' '
  COL_SELECT_MASK                 = ' '
  DAT_MODE                        = ' '
  CONFIRM_OVERWRITE               = ' '
  NO_AUTH_CHECK                   = ' '
  CODEPAGE                        = ' '
  IGNORE_CERR                     = ABAP_TRUE
  REPLACEMENT                     = '#'
  WRITE_BOM                       = ' '
  TRUNC_TRAILING_BLANKS_EOL       = 'X'
  WK1_N_FORMAT                    = ' '
  WK1_N_SIZE                      = ' '
  WK1_T_FORMAT                    = ' '
  WK1_T_SIZE                      = ' '
     IMPORTING
       FILELENGTH                      = v_length
      TABLES
        DATA_TAB                        = it_err_log
  FIELDNAMES                      =
     EXCEPTIONS
       FILE_WRITE_ERROR                = 1
       NO_BATCH                        = 2
       GUI_REFUSE_FILETRANSFER         = 3
       INVALID_TYPE                    = 4
       NO_AUTHORITY                    = 5
       UNKNOWN_ERROR                   = 6
       HEADER_NOT_ALLOWED              = 7
       SEPARATOR_NOT_ALLOWED           = 8
       FILESIZE_NOT_ALLOWED            = 9
       HEADER_TOO_LONG                 = 10
       DP_ERROR_CREATE                 = 11
       DP_ERROR_SEND                   = 12
       DP_ERROR_WRITE                  = 13
       UNKNOWN_DP_ERROR                = 14
       ACCESS_DENIED                   = 15
       DP_OUT_OF_MEMORY                = 16
       DISK_FULL                       = 17
       DP_TIMEOUT                      = 18
       FILE_NOT_FOUND                  = 19
       DATAPROVIDER_EXCEPTION          = 20
       CONTROL_FLUSH_ERROR             = 21
       OTHERS                          = 22
    IF SY-SUBRC <> 0.
      write:/30 'Error in generating purchase order error log'.
      write:/30 syst-uline(44).
    else.
      write:/30 'Purchase Order error log'.
      write:/30 syst-uline(24).
      skip 2.
      write:/10 'Please check the error loag file at:', v_fullpath.
    ENDIF.
  else.
    write:/30 'Purchase Order data l log'.
    write:/30 syst-uline(24).
    skip 2.
    write:/10 'There is no error in the input file data, so please proceed to execute the load!!'.
  endif.
ENDFORM.                    " disp_error_report
and my input file looks like this:
1 1000 NB 20071210 V1 AE01 501 USD 10 M5 1003 100 1000 EA 20071110
1 1000 NB 20071210 V1 AE01 507 USD 10 P10 1003 100 2000 EA 20071110
2 1000 NB 20071210 V1 AE01 501 USD 10 M5 1003 50 1000 EA 20071110
the name of the fields in order are : refno., compnaycode,doc-typ,doc_date,vendor,purch_org,purch_grp,currency
tem no, material, plant, quantity, price, order unit, del_date.
The ref No. field in the text file acts as a unique identifier So basically my Program should create 2 PO's but to my surprise it created 5 or 6 po's with only first record.
Can you please help me out....
Thanks
Rajeev Gupta
Message was edited by:
        Rajeev Gupta
Title and Message were edited by:
        Alvaro Tejada Galindo

and have you set a breakpoint at loop at input file and at bapi_po_create ??
perhaps there is something wrong with the amount of items passed ?
kind regards
arthur

Similar Messages

  • Datas from info record should not overwrite BAPI_PO_CREATE parameters

    Hi,
    I intend to pass the netprice value while posting PO through BAPI_PO_CREATE.
    but the values from info record overwriting the parameters supplied.
    Please guide me how to avoid this overwritting.
    Thanks,
    Vempalli

    and have you set a breakpoint at loop at input file and at bapi_po_create ??
    perhaps there is something wrong with the amount of items passed ?
    kind regards
    arthur

  • PO Creation using BAPI_PO_CREATE

    Hello friends ,
    I have a weird thing going on . I used BAPI_PO_CREATE .
    When I look a the return table it displays message . Standard PO created .
    I then using BAPI_TRANSACTION_COMMIT to commit it to the database .
    After running the above Z program .
    When I go and alook for that po number in me23 or me23n or in table EKPO it says no document found .
    But if i check it after 2 - 3 minutes it shows the records in the database .
    Is this usual to not be able to see the document saveed immediately after its creation ?
    When I create a PO manually using me21 it save immediately .
    Please advise .
    Thanks,
    Teresa

    Yes . I am passing the wait parameter . One more thing the BASIS Team applied some oracle patches recently .
    Here is a snap shot of my code .
      CALL FUNCTION 'BAPI_PO_CREATE'
        EXPORTING
          PO_HEADER          = LS_PO_HEADER
          PO_HEADER_ADD_DATA = LS_PO_HEADER_ADD
        IMPORTING
          PURCHASEORDER      = L_PURCHASEORDER
        TABLES
          PO_ITEMS           = LT_PO_ITEMS
          PO_ITEM_ADD_DATA   = LT_PO_ITEMS_ADD
          PO_ITEM_SCHEDULES  = LT_PO_ITEMS_SCHED
          RETURN             = LT_RETURN.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT = 'X'.
    Thnx

  • Reg : Purchase orer creation using BAPI_PO_CREATE

    Hi Experts,
    I am in need of creating a PO using the BAPI(BAPI_PO_CREATE). I have to create the PO for the account assignemnt category 'S' and item category '2'.
      Inspite of the account assignment category 'S' configured in my system still the BAPI is throughing the error saying that the account assignment category is wrong.
    Could any one of you suggest me a solution for this.
    Advanced thanks to every one.
    Regards,
    Ramkishore.

    Hi ,
             may i know what values are been passed to bapi??
    Regards,
    Mohan.

  • Problem creating Purchase Order with Bapi_po_create  Return Message is ""

    Hello everybody
    When I get to create PO with bapi_po_create . I get this message in the return parameter :"Enter the PURCH_ORG".
    I think that I have implemented it very well but I don´t get the results that I was expected : No PO was created.
    Please see the following codes and let me know if something is wrong. Thanks .
    =====================================
    *& Report  Z_PED_TRAS                                                  *
    REPORT  z_ped_tras  .
    Definición de la tabla asociada la tabla interna bdcdata
    *DATA :in_data LIKE bdcdata OCCURS 0 WITH HEADER LINE.
    Definición de la estructura que contendrá los pedidos
    DATA : s_cabeceras_pedidos LIKE bapiekkoc,
           s_pos_pedidos LIKE bapiekpoc.
    DATA : t_cabeceras_pedidos LIKE  bapiekkoc OCCURS 0 WITH HEADER LINE,
           t_pos_pedidos LIKE  bapiekpoc OCCURS 0 WITH HEADER LINE,
           t_final_cabeceras_pedidos LIKE  bapiekkoc OCCURS 0 WITH HEADER
    LINE,
           t_final_pos_pedidos LIKE  bapiekpoc OCCURS 0 WITH HEADER LINE.
    Data : item_schedule like BAPIEKET occurs 0 with header line.
    *DATA : BEGIN OF pedidos,
          ematn TYPE mepo1211-ematn, "Número de material
          menge TYPE mepo1211-menge, "Cantidad de pedido
          name1 TYPE mepo1211-name1," Centro destino
          lgobe TYPE mepo1211-lgobe, "Almacén
         END OF pedidos.
    *DATA: s_pedidos  LIKE pedidos,
         wa_pedidos LIKE pedidos,
         t_pedidos LIKE pedidos OCCURS 0 .
    Variables  auxiliaires
    Variables para la ejecución del explorador de archivos
    DATA: l_temp_dir TYPE string.
    DATA: l_filter TYPE string.
    DATA: l_files TYPE filetable.
    DATA: l_rc TYPE i.
    DATA: l_file TYPE filename.
    DATA: l_filename TYPE string.
    DATA: excel TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
    DATA: s_excel TYPE alsmex_tabline.
    DATA: qid LIKE apqi-qid.
    Declaración de parametros de selección
    PARAMETERS :
       p_center LIKE bapiekkoc-suppl_plnt OBLIGATORY,"" Proveedor/Centro
       p_ekorg LIKE bapiekkoc-purch_org OBLIGATORY , " Organización compras
       p_ekgrp LIKE bapiekkoc-pur_group OBLIGATORY, " Grupo de compras
       p_bukrs LIKE bapiekkoc-co_code OBLIGATORY,"Sociedad"
       p_date LIKE sy-datum DEFAULT sy-datum OBLIGATORY,  "fecha
       test AS CHECKBOX DEFAULT 'X'.
      p_center LIKE mepo_topline-superfield, " Proveedor/Centro
      p_ekorg LIKE mepo1222-ekorg, " Organización de compras
      p_ekgrp LIKE mepo1222-ekgrp, " Grupo de compras
      p_bukrs LIKE mepo1222-bukrs,"Sociedad"
      p_date LIKE sy-datum," Fecha
      test AS CHECKBOX DEFAULT 'X'.
    PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'C:PEDIDOS.XLS'. " Ruta
    Carga del explorador de ficheros **
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      l_temp_dir = 'C:A'.
      l_filter = '.'.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          default_extension       = '*.xls'
          file_filter             = l_filter
          initial_directory       = l_temp_dir
        CHANGING
          file_table              = l_files
          rc                      = l_rc
        EXCEPTIONS
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          not_supported_by_gui    = 4
          OTHERS                  = 5.
      IF NOT l_files[] IS INITIAL.
        READ TABLE l_files INTO l_file INDEX 1.
        p_file = l_file.
        TRANSLATE p_file TO UPPER CASE.
      ENDIF.
    START-OF-SELECTION.
      IF p_file NE space.
        PERFORM upload_data.
        PERFORM fill_data.
        PERFORM llamar_bapi.
      ENDIF.
    END-OF-SELECTION.
    *&      Form  Upload_data
          text
    -->  p1        text
    <--  p2        text
    FORM upload_data .
      IF excel IS INITIAL .
        CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
          EXPORTING
            filename                = p_file
            i_begin_col             = 1
            i_begin_row             = 2
            i_end_col               = 4
            i_end_row               = 50000
          TABLES
            intern                  = excel
          EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.
        IF sy-subrc <> 0.
          WRITE :/'Hay un problema al cargar los datos delfichero excell'.
        ENDIF.
        SORT excel DESCENDING BY row col.
      ENDIF.
    ENDFORM.                    " Upload_data
    *&      Form  fill_excell
          text
    -->  p1        text
    <--  p2        text
    FORM fill_data .
      DATA :  cant TYPE i ,
              value_row TYPE i VALUE 1,
              data_aux TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
    Leer las filas del fichero excell.
      IF test NE 'X'.
        s_cabeceras_pedidos-suppl_plnt = p_center.
        s_cabeceras_pedidos-purch_org = p_ekorg.
        s_cabeceras_pedidos-pur_group = p_ekgrp .
        s_cabeceras_pedidos-co_code = p_bukrs .
        s_cabeceras_pedidos-doc_date = p_date.
        APPEND  s_cabeceras_pedidos TO t_cabeceras_pedidos.
        cant = excel-row.
        DO cant TIMES.
          LOOP AT excel WHERE row EQ value_row.
            APPEND excel TO data_aux.
          ENDLOOP.
          SORT data_aux BY col.
          LOOP AT data_aux.
            CASE data_aux-col.
              WHEN '1'.
                s_pos_pedidos-pur_mat = data_aux-value.
              WHEN '2'.
                s_pos_pedidos-DISP_QUAN = data_aux-value.
              WHEN '3'.
                s_pos_pedidos-plant = data_aux-value.
              WHEN '4'.
                s_pos_pedidos-store_loc = data_aux-value.
            ENDCASE.
          ENDLOOP.
          APPEND s_pos_pedidos TO t_pos_pedidos.
        ENDDO.
      ENDIF.
    ENDFORM.                    " fill_data
    *&      Form  llamar_Bapi
          text
    -->  p1        text
    <--  p2        text
    FORM llamar_bapi .
    data : T_RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE,
           PORDER LIKE BAPIEKKOC-PO_NUMBER.
    t_final_cabeceras_pedidos[] = t_cabeceras_pedidos[].
    t_final_pos_pedidos[] = t_pos_pedidos[].
      CALL FUNCTION 'BAPI_PO_CREATE'
        EXPORTING
          po_header                        = t_final_cabeceras_pedidos
    IMPORTING
       PURCHASEORDER                     = PORDER
        TABLES
          po_items                       = t_final_pos_pedidos
          po_item_schedules                = item_schedule
          RETURN                           = T_RETURN
      IF sy-subrc EQ 0 .
        WRITE :/ 'P O created well'.
      ELSE .
        WRITE :/ 'P .O was not created  well'.
        endif.
      ENDFORM.                    " llamar_Bapi

    Hi,
    When we use BAPI_PO_CREATE1 to create service PO, following tables are populated at item level:
    a) POITEM
    b) POITEMX
    c) POACCOUNT
    d) POACCOUNTX
    e) POSERVICES
    f) POSRVACCESSVALUES
    For service items: POITEM-PCKG_NO = u20180000000001u2019. (assign package no as a dummy number)
    Set PCKG_NO flag in POITEMX table as u2018Xu2019.
    Package No is the link that connect POITEM table to POACCOUNT table through tables POSERVICES and POSRVACCESSVALUES.
    Set POACCOUNT-SERIAL_NO to u201801u2019.
    Set same PCKG_NO to u20180000000001u2019 in POSERVICES table. Maintain two entries in POSERVICES table like this:
    WA_POSERVICES-PCKG_NO = u20180000000001u2019.
    WA_POSERVICES-LINE_NO = u20180000000001u2019.
    WA_POSERVICES-OUTL_IND = u2018Xu2019.
    WA_POSERVICES-SUBPCKG_NO = u20180000000003u2019. (Dummy No.)
    WA_POSERVICES-QUANTITY = u2018100.000u2019.
    WA_POSERVICES-BASE_UOM = u2018EAu2019.
    WA_POSERVICES-PRICE_UNIT = u20181u2019.
    WA_POSERVICES-GR_PRICE = u2018100.000u2019.
    WA_POSERVICES-SHORT_TEXT = u2018SERVICE TESTu2019.
    APPEND WA_POSERVICES TO IT_POSERVICES.
    WA_POSERVICES- PCKG_NO = u20180000000003u2019.
    WA_POSERVICES- LINE_NO = u20180000000002u2019.
    WA_POSERVICES-QUANTITY = u201810.000u2019.
    WA_POSERVICES- BASE_UOM = u2018EAu2019.
    WA_POSERVICES--PRICE_UNIT = u20181u2019.
    WA_POSERVICES-GR_PRICE = u2018100.000u2019.
    WA_POSERVICES-SHORT_TEXT = u2018SERVICE 1u2019.
    WA_POSERVICES-MATL_GROUP = u20180012u2019.
    APPEND WA_POSERVICES TO IT_POSERVICES.
    Set PCKG_NO as SUB_PCKG_NO in table POSRVACCESSVALUES this:
    WA_POSRVACCESSVALUES-PCKG_NO = u20180000000003u2019.
    WA_POSRVACCESSVALUES-LINE_NO = u20180000000002u2019.
    WA_POSRVACCESSVALUES-SERNO_LINE = u201801u2019.
    WA_POSRVACCESSVALUES-SERIAL_NO = u201801u2019.
    WA_POSRVACCESSVALUES-QUANTITY = u201910.000u2019.
    APPEND WA_POSRVACCESSVALUES TO IT_ POSRVACCESSVALUES.
    This logic will work definitely and PO Service Items will be created.
    Thanks & Regards.
    Dhina..

  • Free item and BAPI_PO_CREATE

    Hi experts,
    When creating a PO with BAPI_PO_CREATE I need to set the indicator "Free" (MEPO1211-UMSON) of the item.
    The question is, can I do it with this bapi? I can't find the field in the bapi.
    Thanks a lot

    Hi,
    I get it. What it's needed to do is:
    wa_po_items_add_data-ir_ind = ' '.
    append wa_po_items_add_data to t_po_items_add_data.
    and mark ITEM_ADD_DATA_RELEVANT     = 'X' when calling the bapi
    Thanx for your help

  • Bapi_po_create is not creating Purchase Orders for multiple records in file

    Hi All.
    iam trying to create contracts and Purchase Orders  In me21n,me31k .
    here iam using bdc for contract creation against services and using bapi_po_create for PO Creations.
    in this process i could create contracts and POs for the first record in the file but for second record bapi_po_create couldnt create POs and the return table in bapi says
    1.document contains no items.
    2.no services or limits have been maintained.
    wil be waiitng for  r great answer.
    bye.
    regards.
    seeta.

    Hi Seeta Ram,
    Did you pass the table PO_ITEM_SCHEDULES to BAPI_PO_CREATE with the coresponding Item numbers for each item in the table PO_ITEMS?
    Regards,
    Vitz.

  • PO service is not created using BAPI_PO_CREATE FM

    Hi,
          CALL FUNCTION 'BAPI_PO_CREATE'
            EXPORTING
              po_header                  = wa_header
              po_header_add_data         = wa_hdr_add
              header_add_data_relevant   = wa_hdr_flg
            IMPORTING
              purchaseorder              = v_po
            TABLES
              po_items                   = i_line
              po_item_schedules          = i_sch
              po_item_account_assignment = i_po_acc
              po_services                = i_po_ser
              po_srv_accass_values       = i_po_srv
              po_services_text           = i_po_sertxt
              return                     = i_return
              poaddrdelivery             = i_del_addr.
    TheIT_RETURN returned me the below 2 lines.
    1. Sum of percentages >200.0< exceeds 100 %
    2. Document contains no items
    Regards
    Deepthi.

    Hi,
    wa_header-DOC_DATE = 20080901
    wa_header-DOC_TYPE = 'Z0RD'.
    wa_header-CO_CODE = '3082'.
    wa_header-PURCH_ORG = 'P000'.
    wa_header-PUR_GROUP = '052'..
    wa_header-VENDOR = '0005021295'.
    wa_header-CREATED_BY = sy-uname.
    wa_header-ZZEXPTYPE = '9015'.
    wa_hdr_add-PMNTTRMS = 'Z004'.
    wa_hdr_add-CURRENCY = 'USD'.
    wa_hdr_add-REF_1 = 'CONVERSION'.
    wa_hdr_add-OUR_REF = '5172APN'.
    wa_hdr_flg = 'X'.
    w_line-PO_ITEM = '00010'.
    w_line-ITEM_CAT = '9'.
    w_line-ACCTASSCAT = 'N'.
    w_line-MAT_GRP = '088'.
    w_line-SHORT_TEXT = 'Alarm System Installation'.
    w_line-DISTRIB = space.
    w_line-PLANT = '3082'.
    w_line-UNIT = 'AU'.
    w_line-NET_PRICE = '2000.0000'.
    w_line-PCKG_NO = '0000000010'.
    w_line-TRACKINGNO = '10'.
    w_line-TAX_CODE = 'I0'.
    append w_line to i_line.
    w_sch-PO_ITEM = '00010'.
    w_sch-SERIAL_NO = '01'.
    w_sch-DELIV_DATE = '20100901'.
    w_sch-QUANTITY = '2000.000'.
    w_sch-CREATE_IND = 'X'.
    append w_sch to i_sch.
    w_po_acc-PO_ITEM = '00010'.
    w_po_acc-SERIAL_NO = '01'.
    w_po_acc-w_po_acc-w_po_acc-QUANTITY = ' 2000.000'.
    w_po_acc-DISTR_PERC = '0.0'.
    w_po_acc-G_L_ACCT = '0000622025'.
    w_po_acc-CO_AREA = 'FC01'.
    w_po_acc-NETWORK = '000004003658'.
    w_po_acc-ACTIVITY = '0210'.
    append w_po_acc to i_po_acc.
    w_po_ser-PCKG_NO = '0000000010'.
    w_po_ser-LINE_NO = '0000000001'.
    w_po_ser-w_po_ser-SUBPCKG_NO = '0000000010'.
    w_po_ser-QUANTITY = '2000.00'.
    w_po_ser-BASE_UOM = 'LE'.
    w_po_ser-GR_PRICE = '1.00'.
    w_po_ser-SHORT_TEXT = 'Alarm System Installation'.
    w_po_ser-distrib = space.
    w_po_ser-TAX_CODE = 'I0'.
    w_po_ser-MATL_GROUP = '001'.
    append w_po_ser to i_po_ser.
    w_po_srv-PCKG_NO = '0000000010'.
    w_po_srv-LINE_NO = '0000000001'.
    w_po_srv-PERCENTAGE = '100.0'.
    w_po_srv-SERIAL_NO = '01'.
    w_po_srv-QUANTITY = '1.00'.
    append w_po_src to i_po_srv
    w_po_sertxt-PCKG_NO = '0000000010'.
    w_po_sertxt-LINE_NO = '0000000001'.
    w_po_sertxt-TEXT_LINE = 'CONVERSION'.
    append w_po_sertxt to i_po_sertxt.
    w_del_addr-po_item = '00010'.
    w_del_addr-addr_no = '0000068279'.
    append w_del_addr to i_del_addr.
    data:  v_po         TYPE ebeln,
              i_return    TYPE STANDARD TABLE OF bapireturn.
          CALL FUNCTION 'BAPI_PO_CREATE'
            EXPORTING
              po_header                  = wa_header
              po_header_add_data         = wa_hdr_add
              header_add_data_relevant   = wa_hdr_flg
            IMPORTING
              purchaseorder              = v_po
            TABLES
              po_items                   = i_line
              po_item_schedules          = i_sch
              po_item_account_assignment = i_po_acc
              po_services                = i_po_ser
              po_srv_accass_values       = i_po_srv
              po_services_text           = i_po_sertxt
              return                     = i_return
              poaddrdelivery             = i_del_addr.
    Regards,
    Deepthi.

  • In BAPI_PO_CREATE - Error- Purchase Order No. is not importing

    Hi,
    I have a Report for PO creation - Where records get entered from Excel.
    FM - ALSM_EXCEL_TO_INTERNAL_TABLE, BAPI_PO_CREATE
    Problem -
    Excel has app. 100 similar records out of them 7 to 8 records are giving Error.                                  
    In RETURN - Itab -  Error msg -  " Document No. 45... not within defined interval ".
    But same record get entered using ME21N.
    Number Range is same for all excel records. even doc. type & plant is same.
    When debugg - In BAPI_PO_CREATE -  IMPORTING - It's giving Purchaseorder 'Blank'.

    If you're using external numbering (number supplied in incoming data), fix the contents of the Excel file....it appears to contain blanks....file error in data content or in importing the file?

  • PURCHASE ORDER WITH OUT BAPI_PO_CREATE CAN WE CREATE?

    PURCHASE ORDER WITH OUT calling BAPI_PO_CREATE CAN WE CREATE?
    Don't Post your question with all Caps. Follow the Rules of Engagement
    Edited by: Vijay Babu Dudla on Apr 23, 2009 1:46 AM

    [Create Purchase order with program|can we create purchase order through report programming?]
    Plz be clear about your requirement instead of posting questions like these.
    Don't violate forum rules with Duplicate posts

  • HEADER TEXT in purchase orders using BAPI_PO_CREATE

    How to update HEADER TEXT in purchase orders using BAPI_PO_CREATE or BAPI_PO_CREATE1?Please advice for both types.

    Hi Srini ,
    IF you are using the BAPI_PO_CREATE , we are not having the parameter to pass Header Text.
    If you want to get Header Text  directly then Use  BAPI_PO_CREATE1 wiht a parameter POTEXTHEADER (I am not sure it is  there in 4.7).
    If  BAPI_PO_CREATE1 does not exist in  4.7 then  use create_text function module to update the the Header text
    Hope it helps
    Rgds
    Sree M
    Edited by: Sree  Merugu on Jun 13, 2008 5:10 PM

  • Details scenario navigation steps for async_sync bridge for bapi_po_create

    ·     Integrating web application and SAP R/3 system. A third party web-based purchasing application posts XML data to the XI plain HTTP adapter for purchase order creation. The purchase order data is mapped to RFC-XML;
              BAPI_PO_CREATE is then called to create the purchase order.

    Hi
    check this links
    Demonstrating Use of Synchronous-Asynchronous Bridge to Integrate Synchronous and Asynchronous systems using ccBPM in SAP Xi - Use of Synch - Asynch bridge in ccBPM
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1403 [original link is broken] [original link is broken] [original link is broken] - Use of Synch - Asynch bridge in ccBPM
    Asyn - Synch BPM - Async/Sync Communication using JMS adapter without BPM (SP 19)
    There is an example of the Sync/Async Bridge in th SWCV: SAP BASIS.
    Namespace: http://sap.com/xi/XI/System/Patterns
    Go through this link to get a good idea as to how to Define Sync/Async Communication
    This blog also should give you some idea...
    https://www.sdn.sap.com/sdn/weblogs.sdn?blog=/pub/wlg/1403 [original link is broken] [original link is broken] [original link is broken]
    http://help.sap.com/saphelp_nw04/helpdata/en/83/d2a84028c9e469e10000000a1550b0/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c4/dc06418752ef6fe10000000a1550b0/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/f9/66bf40ad090366e10000000a1550b0/RN_XI_DE_neu.pdf
    regards
    srinivas

  • Multiple Line items in BAPI_PO_CREATE

    Hi Everyone,
    I am trying to create a webdynpro application for Creating a Purchase Order using "BAPI_PO_CREATE". Could you help in getting the code for adding a new line item while creating a purchase order using the above BAPI. Adding a new line item means similar to that of in the Transaction "ME21N". I need a table where each row is for a line item. Let me know if my question is not clear.
    Please help me resolve this issue. I would appreciate your help.
    Regards,
    Gopal.

    Hi Raghu,
    Thanks a lot for your reply. I tried your method. Now, I have got a different problem. I managed to combine the two model nodes "A" and "B" into one Value node "C". Now, I binded my table to Value node "C". I have also created two tables and binded them to node A and node B. Now, once the user inputs the values in to the table of Node "C" before executing the BAPI, I should copy the values of the table "C" to the tables of Node "A" and Node "B".
    So, for copying the values from one table to another, I followed the following code.
    IPrivate<Name>View.ISourceValueNode iSourceValueNode= wdContext.nodeSourceValueNode();
    IPrivate<Name>View.ISourceValueElement iSourceValueElement;
    IPrivate<Name>View.ITargetRFC Element iTargetRFCElement;
    for(int i=0;i<wdContext.nodeTargetRFC().size();i++){
    iTargetRFCElement = wdContext.nodeTargetRFC().getTargetRFCElementAt(i);
    iSourceValueElement = iSourceValueNode.createSourceValueNodeElement();
    iSourceValueElement.set<attribute name>(iTargetRFCElement.get<Attribute name>());
    iSourceValueNode.addElement(iSourceValueElement);
    iSourceValueNode.moveNext();
    But, the values are copying in to the second rows of tables "A" and "B" and leaving the first row as Blank. How can I avoid this? Do you understand what I mean?
    My explanation might a bit confusing. Let me know if you need more clarification. Thanks a lot for your help and support.
    Regards,
    Gopal.

  • BAPIEKPOC-PO_PRICE (BAPI_PO_CREATE), ME21n, and BAPI_PO_CREATE1 ?????

    In the item table passed to BAPI_PO_CREATE, there is a column called PO_PRICE in the structure PAPIEKPOC.  An "X" in this field tells the system not to step on the PR price with the PIR price.
    So first question: is thre an equivalent of this field in BAPI_PO_CREATE1, either in the BAPIMEPOITEM structure or somewhere else ????
    And second question, where in IMG/SPRO do you configure the online transaction ME21N so that it doesn't step on the PR price with the PIR price?  (I'm assuming there's got to be a way to do this, if the BAPI can be configured.)

    Okay,
    David,
    Just refer below two links hope it will help you enough
    http://sap.ittoolbox.com/groups/technical-functional/sap-log-mm/valuation-price-in-po-1425092?cv=expanded
    http://kowboyz.blogspot.com/2008/05/copy-price-from-pr-to-po.html
    Edited by: Amit Gujargoud on Nov 6, 2008 8:01 PM

  • How to pass enhanced fields in BAPI_PO_CREATE

    Dear Memebers,
    I have a requirement to pass the Enhanced fileds in Module Function BAPI_PI_CREATE using VB.NET can anyone send me sample.
    Thanks,
    Nasir

    Dear Nasir,
    In order to pass enhanced fields to the BAPI_PO_CREATE function module, populate a table of type BAPIPAREX and pass it to the EXTENSIONIN tables parameter of the FM.
    (Sample Code): Suppose you enhanced Purchasing Document Item Table EKPO with Append structure ZEKPO with the fields ZNAME1 and ZDATA1.
    DATA: GT_EXTENSION TYPE TABLE OF BAPIPAREX,
               WA_EXTENSION TYPE BAPIPAREX.
    CLEAR WA_EXTENSION.
    WA_EXTENSION-STRUCTURE = 'ZEKPO'. " 'Name of the Append Structure for Standard PO header/item table'
    CONCATENATE WA_EKPO-ZNAME1 WA_EKPO-ZDATA1 INTO WA_EXTENSION-VALUEPART1. (Ensure that the total character length of these fields is less than 240)
    APPEND WA_EXTENSION TO GT_EXTENSION.
    Similarly, you need to pass the ZEKPOX structure with the relevant check boxes. For this, you need to refer to the documentation for Function Module but generally, Passing Enhanced Fields work this way.
    Regards,
    Amit Sharma

Maybe you are looking for

  • Replacement Nano under warranty also defective.  Will not pay shipping 2x!!

    I had a Nano 2nd Gen purchased last December. It had an audio jack problem and needed to be replaced. I do not have Apple Care, btw. I had to pay shipping to get the Nano replaced; about $30, a shipping fee that is a bit ridiculous in and of itself.

  • How to view information based on selection from table

    I currently have a roles table, usersinroles table, and a users table. The users table has a user ID, the roles table has a Role ID, and the usersinroles table has Role ID and user ID as foreign keys. Many users can have many roles. On one page I hav

  • [Office Web Apps] WacPipe.CreateIdFromRawId: could not find basedoc

    Hi, I have a problem with getting PowerPoint file information from urls like: http://server/_layouts/MobilePresentation.ashx?PresentationId=/sites/xyz/presentation.pptx When I am trying to access this url I got an error: Unknown SPRequest error occur

  • Coloring charts depending on its input values

    Hi all, I need to create bar chart where colors of individual values will be changing depending on values. For example query like this: select null, ename, sal from emp; should display bar in red color when employee's salary is less than 2000, and if

  • HELPE ME OUT I REALLY NEED SOME HELP ON MOTION!!!

    Hi I'm a high school student and I'm having a problem on motion. I need help on page 350 on step #6. Well my problem is that the lesson book tells me to select the sweep behavior and duplicate it, But there is no disclosure triangle to see the behavi