Regarding BAPI_PO_CREATE

Hi,
Pls let me know the correct OSS notes that need to  implemnt to correct the net price problems in 4.6 C when we are using BAPI_PO_CREATE?
Thanks!!
ram

Hi,
please check this note .
Note 129006 - E06215 Please enter net price
reward points if useful.
thanks,
satheesh.

Similar Messages

  • 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

  • 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

  • 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..

  • 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.

  • 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.

  • 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

  • Street Number getting Truncated in BAPI_PO_CREATE and CHANGE

    Dear All
    For an PO create interface, we are trying to use BAPI_PO_CREATE and BAPI_PO_CHANGE .
    The issue is in the structure POADDRDELIVERY. Here we give delivery address of the Purchase Order line item which later gets populated in Delivery address tab in PO item
    As per SAP standard STREET filed in this structure will hold 60 characters. When I am testing the Function Module also,(SE37) I am able to enter 60 characters in STREET field. But when the PO is created in SAP through FM processing, the no of characters of STREET field is truncated
    Only first 40 characters are populated in PO item. Also after execution of FM , if we see this field in display mode there also only 40 characters are displayed, rest 20 not present .
    Why all 60 characters in STREET field in BAPI cannot be passed to Purchase Order ?
    Can you please let me know your thoughts
    Regards
    Shyam

    Dear Jurgen
    Thanks for the feedback.
    Checked along with ABAPer. but unfortunately our SAP release ECC 6.0 702 for which this note cannot be applied.
    Please let me know if any other possibilities.
    Regards
    Shyam

  • A custom field added in BAPI_PO_CREATE and BAPI_PO_CREATE1

    Hi,
      I am trying to create a Service Purchase Order Single Account Assignment.
    A Custom field ZZEXPTYPE(Expense Type) is added in BAPI_PO_CREATE and passed the value '9015', The PO Is created Successfully but when I add same Custom Field ZZEXPTYPE(Expense Type) in BAPI_PO_CREATE1 whose value is '9015' ,It throws an Error Message as " Please enter a valid (SBU Specific) expense type!" . 
      The functional consultant says that Expense Type '9015' is correct. please Let me know what must be done.
    Regards,
    Deepthi.

    Extension to add Expense Type only
          IF NOT  w_src-zzexptype IS INITIAL.
            w_extensionin-structure = 'BAPI_TE_MEPOHEADER'.
            w_extensionin-valuepart1+10(4) = w_src-zzexptype.
            APPEND w_extensionin TO i_extensionin.
            CLEAR w_extensionin.
            w_extensionin-structure = 'BAPI_TE_MEPOHEADERX'.
            w_extensionin-valuepart1+10(4) = 'X'.
            APPEND w_extensionin TO i_extensionin.
            CLEAR w_extensionin.
          ENDIF.
    Call BAPI
          CALL FUNCTION 'BAPI_PO_CREATE1'
            EXPORTING
              poheader          = w_poheader
              poheaderx         = w_poheaderx
            IMPORTING
              exppurchaseorder  = gv_ebeln
            TABLES
             return            = i_return
             poitem            = i_poitem[]
             poitemx           = i_poitemx[]
             extensionin       = i_extensionin[].
    Commit the Transaction
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
             WAIT          = 'X'.

  • Quantity field in bapi  BAPI_PO_CREATE

    Hi ,
    What is the filed name to pass the QUANTITY in the lineitems table*(PO_ITEMS) for the Bapi BAPI_PO_CREATE
    FIleld name DISP_QUAN is not accepting the Quantity and showing the error as  ENTER QUANTITY
    when BAPI is executed.
    Regards
    Ajay

    Hai.
    check this.
    REPORT zpo_bapi_purchord_tej.
    DATA DECLARATIONS *
    TYPE-POOLS slis.
    TYPES: BEGIN OF ty_table,
    v_legacy(8),
    vendor TYPE bapimepoheader-vendor,
    purch_org TYPE bapimepoheader-purch_org,
    pur_group TYPE bapimepoheader-pur_group,
    material TYPE bapimepoitem-material,
    quantity(13),
    delivery_date TYPE bapimeposchedule-delivery_date,
    net_price(23),
    plant TYPE bapimepoitem-plant,
    END OF ty_table.
    TYPES: BEGIN OF ty_alv,
    v_legs(8),
    success(10),
    v_legf(8),
    END OF ty_alv.
    TYPES: BEGIN OF ty_alv1,
    v_legf1(8),
    v_msg(500),
    END OF ty_alv1.
    *-----Work area declarations.
    DATA: x_table TYPE ty_table,
    x_header TYPE bapimepoheader,
    x_headerx TYPE bapimepoheaderx,
    x_item TYPE bapimepoitem,
    x_itemx TYPE bapimepoitemx,
    x_sched TYPE bapimeposchedule,
    x_schedx TYPE bapimeposchedulx,
    x_commatable(255),
    x_alv TYPE ty_alv,
    x_alv1 TYPE ty_alv1,
    x_alv2 TYPE ty_alv1.
    *-----Internal table declarations.
    DATA: it_table TYPE TABLE OF ty_table,
    it_commatable LIKE TABLE OF x_commatable,
    it_item TYPE TABLE OF bapimepoitem,
    it_itemx TYPE TABLE OF bapimepoitemx,
    it_sched TYPE TABLE OF bapimeposchedule,
    it_schedx TYPE TABLE OF bapimeposchedulx,
    it_alv TYPE TABLE OF ty_alv,
    it_alv1 TYPE TABLE OF ty_alv1,
    it_alv2 TYPE TABLE OF ty_alv1.
    DATA: po_number TYPE bapimepoheader-po_number,
    x_return TYPE bapiret2,
    it_return TYPE TABLE OF bapiret2,
    v_file TYPE string,
    v_temp(8),
    v_succsount TYPE i VALUE 0,
    v_failcount TYPE i VALUE 0,
    v_total TYPE i.
    DATA: v_temp1(5) TYPE n VALUE 0.
    DATA: x_event TYPE slis_t_event,
    x_fieldcat TYPE slis_t_fieldcat_alv,
    x_list_header TYPE slis_t_listheader,
    x_event1 LIKE LINE OF x_event,
    x_layout1 TYPE slis_layout_alv,
    x_variant1 TYPE disvariant,
    x_repid2 LIKE sy-repid.
    DATA : it_fieldcat TYPE TABLE OF slis_t_fieldcat_alv.
    SELECTION-SCREEN *
    SELECTION-SCREEN BEGIN OF BLOCK v_b1 WITH FRAME.
    *-----To fetch the flat file.
    PARAMETERS: p_file TYPE rlgrap-filename.
    SELECTION-SCREEN END OF BLOCK v_b1.
    AT SELECTION-SCREEN *
    AT SELECTION-SCREEN.
    IF p_file IS INITIAL.
    MESSAGE text-001 TYPE 'E'.
    ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    *-----To use F4 help to find file path.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    IMPORTING
    file_name = p_file.
    v_file = p_file.
    START-OF-SELECTION *
    START-OF-SELECTION.
    PERFORM gui_upload.
    LOOP AT it_table INTO x_table.
    PERFORM header_details.
    v_temp = x_table-v_legacy.
    LOOP AT it_table INTO x_table WHERE v_legacy = v_temp.
    PERFORM lineitem.
    PERFORM schedule.
    ENDLOOP.
    DELETE it_table WHERE v_legacy = v_temp.
    PERFORM bapicall.
    MOVE po_number TO x_alv-success.
    APPEND x_alv TO it_alv.
    CLEAR x_alv.
    *-----To clear the item details in internal table after the operation for a header.
    REFRESH: it_item,
    it_itemx,
    it_sched,
    it_schedx.
    CLEAR: v_temp1.
    ENDLOOP.
    v_total = v_succsount + v_failcount.
    PERFORM display_alv.
    FORM GUI_UPLOAD *
    FORM gui_upload .
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_file
    filetype = 'ASC'
    TABLES
    data_tab = it_commatable
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17
    IF sy-subrc = 0.
    *-----To fetch the comma seperated flat file into an internal table.
    LOOP AT it_commatable INTO x_commatable.
    IF x_commatable IS NOT INITIAL.
    SPLIT x_commatable AT ',' INTO
    x_table-v_legacy
    x_table-vendor
    x_table-purch_org
    x_table-pur_group
    x_table-material
    x_table-quantity
    x_table-delivery_date
    x_table-net_price
    x_table-plant.
    APPEND x_table TO it_table.
    ENDIF.
    CLEAR x_table.
    ENDLOOP.
    ENDIF.
    ENDFORM. " gui_upload
    FORM HEADER_DETAILS *
    FORM header_details .
    MOVE 'NB' TO x_header-doc_type.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    input = x_table-vendor
    IMPORTING
    output = x_table-vendor
    MOVE x_table-vendor TO x_header-vendor.
    MOVE x_table-purch_org TO x_header-purch_org.
    MOVE x_table-pur_group TO x_header-pur_group.
    x_headerx-doc_type = 'X'.
    x_headerx-vendor = 'X'.
    x_headerx-purch_org = 'X'.
    x_headerx-pur_group = 'X'.
    ENDFORM. " header_details
    FORM LINEITEM *
    FORM lineitem .
    v_temp1 = v_temp1 + 10.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    input = v_temp1
    IMPORTING
    output = v_temp1.
    MOVE v_temp1 TO x_item-po_item.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    input = x_table-material
    IMPORTING
    output = x_table-material.
    MOVE x_table-material TO x_item-material.
    MOVE x_table-quantity TO x_item-quantity.
    MOVE x_table-net_price TO x_item-net_price.
    MOVE x_table-plant TO x_item-plant.
    x_itemx-po_item = v_temp1.
    x_itemx-material = 'X'.
    x_itemx-quantity = 'X'.
    x_itemx-net_price = 'X'.
    x_itemx-plant = 'X'.
    APPEND x_item TO it_item.
    APPEND x_itemx TO it_itemx.
    CLEAR: x_item, x_itemx.
    ENDFORM. " lineitem1
    FORM SCHEDULE *
    FORM schedule .
    MOVE x_table-delivery_date TO x_sched-delivery_date.
    MOVE v_temp1 TO x_sched-po_item.
    x_schedx-delivery_date = 'X'.
    x_schedx-po_item = v_temp1.
    APPEND x_sched TO it_sched.
    APPEND x_schedx TO it_schedx.
    CLEAR: x_sched, x_schedx.
    ENDFORM. " schedule
    FORM BAPICALL *
    FORM bapicall .
    CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
    poheader = x_header
    poheaderx = x_headerx
    IMPORTING
    exppurchaseorder = po_number
    TABLES
    return = it_return
    poitem = it_item
    poitemx = it_itemx
    poschedule = it_sched
    poschedulex = it_schedx.
    IF po_number IS NOT INITIAL.
    v_succsount = v_succsount + 1.
    MOVE x_table-v_legacy TO x_alv-v_legs.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
    v_failcount = v_failcount + 1.
    MOVE x_table-v_legacy TO x_alv-v_legf.
    MOVE x_table-v_legacy TO x_alv1-v_legf1.
    LOOP AT it_return INTO x_return.
    IF x_alv1-v_msg IS INITIAL.
    MOVE x_return-message TO x_alv1-v_msg.
    ELSE.
    CONCATENATE x_alv1-v_msg x_return-message INTO x_alv1-v_msg SEPARATED BY space.
    ENDIF.
    ENDLOOP.
    APPEND x_alv1 TO it_alv1.
    CLEAR x_alv1.
    ENDIF.
    ENDFORM. " bapicall
    FORM DISPLAY_ALV *
    FORM display_alv .
    PERFORM x_list_header.
    PERFORM build_fieldcat CHANGING x_fieldcat.
    x_repid2 = sy-repid.
    x_event1-name = 'TOP_OF_PAGE'.
    x_event1-form = 'TOP_OF_PAGE'.
    APPEND x_event1 TO x_event.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = x_repid2
    is_layout = x_layout1
    it_fieldcat = x_fieldcat
    i_callback_user_command = 'USER_COMMAND'
    i_callback_top_of_page = 'TOP_OF_PAGE'
    i_save = 'A'
    is_variant = x_variant1
    it_events = x_event
    TABLES
    t_outtab = it_alv
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDFORM. " display_master_data
    FORM USER_COMMAND *
    FORM user_command USING ucomm LIKE sy-ucomm selfield
    TYPE slis_selfield.
    READ TABLE it_alv INTO x_alv INDEX selfield-tabindex.
    CLEAR : x_alv2,it_alv2[].
    LOOP AT it_alv1 INTO x_alv1 WHERE v_legf1 = x_alv-v_legf.
    x_alv2 = x_alv1.
    APPEND x_alv2 TO it_alv2 .
    ENDLOOP.
    DATA : it_fieldcat TYPE slis_t_fieldcat_alv.
    DATA : x3_fieldcat LIKE LINE OF it_fieldcat.
    CLEAR : x3_fieldcat,it_fieldcat[].
    CLEAR x3_fieldcat.
    x3_fieldcat-col_pos = '1'.
    x3_fieldcat-fieldname = 'V_LEGF1'.
    x3_fieldcat-reptext_ddic = text-111.
    x3_fieldcat-ref_tabname = 'IT_ALV2'.
    APPEND x3_fieldcat TO it_fieldcat.
    CLEAR x3_fieldcat.
    CLEAR x3_fieldcat.
    x3_fieldcat-col_pos = '1'.
    x3_fieldcat-fieldname = 'V_MSG'.
    x3_fieldcat-reptext_ddic = text-112.
    x3_fieldcat-ref_tabname = 'IT_ALV2'.
    APPEND x3_fieldcat TO it_fieldcat.
    CLEAR x3_fieldcat.
    x_layout1-colwidth_optimize = 'X'.
    x_layout1-zebra = 'X'.
    IF it_alv2[] IS NOT INITIAL.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = x_repid2
    is_layout = x_layout1
    it_fieldcat = it_fieldcat
    i_save = 'A'
    i_callback_top_of_page = 'TOP'
    is_variant = x_variant1
    it_events = x_event
    TABLES
    t_outtab = it_alv2
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    ENDIF.
    ENDFORM.
    FORM USER_COMMAND *
    FORM top.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    it_list_commentary = 'Commentry'.
    ENDFORM.
    FORM BUILD_FIELDCAT *
    FORM build_fieldcat CHANGING et_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: x1_fieldcat TYPE slis_fieldcat_alv.
    CLEAR x1_fieldcat.
    x1_fieldcat-col_pos = '1'.
    x1_fieldcat-fieldname = 'V_LEGS'.
    x1_fieldcat-reptext_ddic = text-108.
    x1_fieldcat-ref_tabname = 'IT_ALV'.
    APPEND x1_fieldcat TO et_fieldcat.
    CLEAR x1_fieldcat.
    x1_fieldcat-col_pos = '2'.
    x1_fieldcat-fieldname = 'SUCCESS'.
    x1_fieldcat-key = 'X'.
    x1_fieldcat-reptext_ddic = text-109.
    x1_fieldcat-ref_tabname = 'IT_ALV'.
    APPEND x1_fieldcat TO et_fieldcat.
    CLEAR x1_fieldcat.
    x1_fieldcat-col_pos = '3'.
    x1_fieldcat-fieldname = 'V_LEGF'.
    x1_fieldcat-key = 'X'.
    x1_fieldcat-reptext_ddic = text-110.
    x1_fieldcat-ref_tabname = 'IT_ALV'.
    APPEND x1_fieldcat TO et_fieldcat.
    CLEAR x1_fieldcat.
    ENDFORM. " build_fieldcat
    FORM BUILD_LIST_HEADER *
    FORM x_list_header.
    DATA: x_list_header1 TYPE slis_listheader.
    *-----List Header: type H
    CLEAR x_list_header1 .
    x_list_header1-typ = 'H'.
    x_list_header1-info = text-105.
    APPEND x_list_header1 TO x_list_header.
    *-----List Key: type S
    x_list_header1-typ = 'S'.
    x_list_header1-key = text-106.
    x_list_header1-info = v_total.
    APPEND x_list_header1 TO x_list_header.
    *-----List Key: Type S
    CLEAR x_list_header1 .
    x_list_header1-typ = 'S'.
    x_list_header1-key = text-107.
    x_list_header1-info = v_succsount.
    APPEND x_list_header1 TO x_list_header.
    ENDFORM. " build_list_header
    FORM TOP_OF_PAGE *
    FORM top_of_page.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    it_list_commentary = x_list_header.
    ENDFORM. " TOP_OF_PAGE
    regards.
    sowjanya.b

  • Help using /AFS/BAPI_PO_CREATE with multiple schedule lines

    I'm using /AFS/BAPI_PO_CREATE to create POs and everything works fine until I pass an item with multiple schedule lines. 
    When you pass multiple schedules it is giving each of the schedule lines under an item the same grid value!  So if I want to order one black, one white shirt...  both grid values are changed to black when the PO is created.
    I'm wondering if you need to pass some sort of sequence value into the BAPI when you have multiple schedule lines for an item.  Does anyone know?

    Hi Justin
    Please make sure that you are specifying the <b>item number</b> while passing the ITEM Details and their correponding SCHEDULE lines.
    Though i couldnt find FM: /AFS/BAPI_PO_CREATE in our system, i guess it is similar to BAPI_PO_CREATE.
    Kind Regards
    Eswar

  • Problem in bapi   BAPI_PO_CREATE

    Hi,
    I am using Bapi BAPI_PO_CREATE To upload data in ME21.
    Please send me the Sample code if possible along with the Data.
    Regards
    AJay

    Hi,
    *& Report  ZDS_BAPI_PO
    REPORT  ZDS_BAPI_PO.
    DATA: PO_NUM TYPE BAPIMEPOHEADER-PO_NUMBER.
    DATA :WA_HEADER TYPE BAPIMEPOHEADER,
          WA_HEADERX TYPE BAPIMEPOHEADERX.
    DATA: IT_ITEM TYPE TABLE OF BAPIMEPOITEM,
          IT_ITEMX TYPE TABLE OF BAPIMEPOITEMX,
          WA_ITEM TYPE  BAPIMEPOITEM,
          WA_ITEMX TYPE BAPIMEPOITEMX,
          IT_RETURN TYPE TABLE OF BAPIRET2,
          WA_RETURN TYPE BAPIRET2.
    WA_HEADER-COMP_CODE = '1000 '.
    WA_HEADER-DOC_TYPE = 'NB'.
    WA_HEADER-ITEM_INTVL = '00001'.
    WA_HEADER-VENDOR = '0000001000' .
    WA_HEADER-PMNTTRMS = '0001' .
    WA_HEADER-PURCH_ORG = '1000' .
    WA_HEADER-PUR_GROUP = '001' .
    WA_HEADER-CURRENCY = 'EUR '.
    WA_HEADERX-COMP_CODE = 'X'.
    WA_HEADERX-DOC_TYPE = 'X'.
    WA_HEADERX-ITEM_INTVL = 'X'.
    WA_HEADERX-VENDOR = 'X' .
    WA_HEADERX-PMNTTRMS = 'X' .
    WA_HEADERX-PURCH_ORG = 'X' .
    WA_HEADERX-PUR_GROUP = 'X' .
    WA_ITEM-PO_ITEM = '00001' .
    WA_ITEM-MATERIAL = '100-100'.
    WA_ITEM-PLANT = '1000'.
    WA_ITEM-STGE_LOC = '0001'.
    WA_ITEM-QUANTITY = '15.000'.
    WA_ITEM-TAX_CODE = 'V0'.
    WA_ITEM-ITEM_CAT = '0'.
    *WA_ITEM-ACCTASSCAT = 'K'.
    APPEND WA_ITEM TO IT_ITEM.
    WA_ITEMX-PO_ITEM = '00001' .
    WA_ITEMX-MATERIAL = 'X'.
    WA_ITEMX-PLANT = 'X'.
    WA_ITEMX-STGE_LOC = 'X'.
    WA_ITEMX-QUANTITY = 'X'.
    WA_ITEMX-TAX_CODE = 'X'.
    WA_ITEMX-ITEM_CAT = 'X'.
    WA_ITEMX-ACCTASSCAT = 'X'.
    APPEND WA_ITEMX TO IT_ITEMX.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        POHEADER                     = WA_HEADER
        POHEADERX                    = WA_HEADERX
    *   POADDRVENDOR                 =
    *   TESTRUN                      =
    *   MEMORY_UNCOMPLETE            =
    *   MEMORY_COMPLETE              =
    *   POEXPIMPHEADER               =
    *   POEXPIMPHEADERX              =
    *   VERSIONS                     =
    *   NO_MESSAGING                 =
    *   NO_MESSAGE_REQ               =
    *   NO_AUTHORITY                 =
    *   NO_PRICE_FROM_PO             =
    IMPORTING
        EXPPURCHASEORDER             = PO_NUM
    *   EXPHEADER                    =
    *   EXPPOEXPIMPHEADER            =
    TABLES
        RETURN                       = IT_RETURN
        POITEM                       = IT_ITEM
        POITEMX                      = IT_ITEMX
    *   POADDRDELIVERY               =
    *   POSCHEDULE                   =
    *   POSCHEDULEX                  =
    *   POACCOUNT                    =
    *   POACCOUNTPROFITSEGMENT       =
    *   POACCOUNTX                   =
    *   POCONDHEADER                 =
    *   POCONDHEADERX                =
    *   POCOND                       =
    *   POCONDX                      =
    *   POLIMITS                     =
    *   POCONTRACTLIMITS             =
    *   POSERVICES                   =
    *   POSRVACCESSVALUES            =
    *   POSERVICESTEXT               =
    *   EXTENSIONIN                  =
    *   EXTENSIONOUT                 =
    *   POEXPIMPITEM                 =
    *   POEXPIMPITEMX                =
    *   POTEXTHEADER                 =
    *   POTEXTITEM                   =
    *   ALLVERSIONS                  =
    *   POPARTNER                    =
    *   POCOMPONENTS                 =
    *   POCOMPONENTSX                =
    *   POSHIPPING                   =
    *   POSHIPPINGX                  =
    *   POSHIPPINGEXP                =
    IF PO_NUM IS NOT INITIAL.
      WRITE:/ 'Po is generated :::::::-',PO_NUM.
    ELSE.
    LOOP AT IT_RETURN INTO WA_RETURN.
      write: / WA_RETURN-MESSAGE.
    ENDLOOP.
    endif.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
       WAIT          = 'X'
    * IMPORTING
    *   RETURN        =
    Regards,
    Dhruv Shah

Maybe you are looking for