Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

uploading data from excel to me22n

Former Member
0 Kudos

Hi Expert,

As i am trying to upload data from excel to me22n transaction code at item level from excel i am taking field are PONUMBER,ITEM,CC,DELIVERY DATE,QUANTITY.for that and i am using BAPI    BAPI_PO_CHANGE .i have written the below code but i have not written the code for bapi please any one

let me know how to write the code for bapi after gui_upload function module.

   *&---------------------------------------------------------------------*
*& Report  ZR_UPLOAD_PO_REP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_UPLOAD_PO_REP  line-size 255.

tables: ekes.
*************** Bapi structure declaration**************
*data:   return               like bapiret2 occurs 0,
*        wa_ret               like bapiret2,
data:        charactname          like bapicharactkey-charactname.
data: poconfirmation      TYPE STANDARD TABLE OF bapiekes.


************ Begin of po***************

DATA: i_poitem        TYPE STANDARD TABLE OF bapimepoitem,
      i_poitemx       TYPE STANDARD TABLE OF bapimepoitemx,

     i_poitem_sch    TYPE STANDARD TABLE OF bapimeposchedule,

     i_poitem_schx   TYPE STANDARD TABLE OF bapimeposchedulx,

     i_acct_ass      TYPE STANDARD TABLE OF bapimepoaccount,

     i_acct_assx     TYPE STANDARD TABLE OF bapimepoaccountx,

     i_services      TYPE STANDARD TABLE OF bapiesllc ,

     i_srvacc        TYPE STANDARD TABLE OF bapiesklc,

     i_return        TYPE STANDARD TABLE OF bapiret2,

     wa_header       TYPE bapimepoheader,

     wa_headerx      TYPE bapimepoheaderx,

     wa_poitem       TYPE bapimepoitem,

     wa_poitemx      TYPE bapimepoitemx,

     wa_poitem_sch   TYPE bapimeposchedule,

     wa_poitem_schx  TYPE bapimeposchedulx,

     wa_acct_ass     TYPE bapimepoaccount,

     wa_acct_assx    TYPE bapimepoaccountx,

     wa_services     TYPE bapiesllc,

     wa_srvacc       TYPE bapiesklc,

     wa_return       TYPE bapiret2,

     ws_po           TYPE bapimepoheader-po_number.



************* end of po***************


type-pools: truxs.

*Types: Begin of ty_final,
*       ebeln(10) type c,          " po number
*       ebelp(2) type c,           " item
*       ebtyp(2) type c,          " conformation category
*       eindt(10) type c,          " Delivery date
*       menge(15) type c,          " quantity
*       end of ty_final.
*
*
*data: wa_final type ty_final,
*      it_final type STANDARD TABLE OF ty_final.
*data: wa_output type ty_final,
*      it_output type STANDARD TABLE OF ty_final.


**// itab for placing the csv file data
data: begin of gtab occurs 10,
        line(500),
      end of gtab.


*data: date like ekes-eindt.
*data: date2 type char8.
*date = ekes-eindt.
*CONCATENATE date+6(2) date+4(2)  date+0(4) into date2 SEPARATED BY ', '.
*


types: begin of ty,
       cname type bapicharactkey-charactname,
*cval type ATWRT,
*cdesc type ATWTB,
      ebeln type ekes-ebeln,
      ebelp type ekes-ebelp,
      ebtyp type ekes-ebtyp,
*      date2 like ekes-eindt,
*     erdat(8)  type c,
     date2(10) type c,
      menge(2) type c,


end of ty.

*data: date like ekes-eindt.
*data: date2 type char8.
*
*CONCATENATE  date+6(2) date+4(2) date+0(4) into date2.

data: itab type standard table of ty,
      wa type ty.

*AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

selection-screen begin of block b1 with frame title text-001.
*parameters: p_file type string default 'C:\MM02_class.CSV' obligatory.  "File name and file path
*  PARAMETERS: p_file TYPE rlgrap-filename LOWER CASE OBLIGATORY.
parameters: p_file type string default 'C:\Documents and Setting\789098\Desktop\me23n.csv' OBLIGATORY.
selection-screen end of block b1.

*AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

START-OF-SELECTION.
* PERFORM select_excel_file.
  perform get_upload.

*&---------------------------------------------------------------------*
*&      Form  GET_UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_UPLOAD .


  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                = p_file
      FILETYPE                = 'ASC'
    TABLES
      DATA_TAB                = gtab
    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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



  Data : lv_date2 type ekes-eindt,          "sy-datum.
         lv_index type sy-index.
clear :wa,lv_index.
*
*loop at gtab into wa.
*
*lv_index = sy-tabix.
*  CONCATENATE wa-date2+6(4) wa-date2+3(2) wa-date2+0(2) INTO lv_date2.
*   condense lv_date2 no-gaps.
*   wa-date2 = lv_date2.
*
*modify gtab from wa index lv_index. " transporting date2.
*
*endloop.
*clear: wa.



  loop at gtab fro
    split  gtab-line at ',' into wa-ebeln wa-ebelp wa-ebtyp wa-date2 wa-menge.

    loop at gtab into wa.
 
endloop.
*


    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        PURCHASEORDER                = wa-ebeln
*     POHEADER                     =
*     POHEADERX                    =
*     POADDRVENDOR                 =
*     TESTRUN                      =
*     MEMORY_UNCOMPLETE            =
*     MEMORY_COMPLETE              =
*     POEXPIMPHEADER               =
*     POEXPIMPHEADERX              =
*     VERSIONS                     =
*     NO_MESSAGING                 =
*     NO_MESSAGE_REQ               =
*     NO_AUTHORITY                 =
*     NO_PRICE_FROM_PO             =
*   IMPORTING
*     EXPHEADER                    =
*     EXPPOEXPIMPHEADER            =
    TABLES
*     RETURN                       =
*     POITEM                       =
*     POITEMX                      =
*     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                =
*     POHISTORY                    =
*     POHISTORY_TOTALS             =
       POCONFIRMATION               = poconfirmation
              .
  endloop.

ENDFORM.                    " GET_UPLOAD

Regards,

Am

14 REPLIES 14

former_member213851
Active Contributor
0 Kudos

Hi Antha,

you can use either COMMIT WORK  or

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT

” EXPORTING

WAIT = "Using the command we can COMMIT AND WAIT

” IMPORTING

RETURN        = it_retutn "To return the COMMIT successful or fail message

after the FM BAPI_PO_CREATE1 in order to write the changes to the database.

Best Regards,

Sachin

0 Kudos

Hi Sachin,

I have use the bapi

  BAPI_PO_CHANGE in my program .when i am uploading data from excel to internal table

and then from internal table i am passing to bapi but it is not updating.

Regards,

Am

0 Kudos

Hi Antha,

1.After getting the data to your internal table from the GUI_UPLOAD, pass the data to the BAPI parameters which you have declared in the data declaration. For this, you need to loop the internal table and pass the corresponding fields of header , item etc to correspoding parameters of the BAPI and append the data wherever required.

2.Then, call the BAPI  'BAPI_PO_CHANGE' and pass all the parameters.

3.Use BAPI_TRANSACTION_COMMIT' to commit the DB changes you have passed to the BAPI.

With regards,

     

0 Kudos

Hi naveen,

For me22n modification can i use the bapi bapi_po_change.

Regards,

Am

0 Kudos

Hi Antha,

You can use BAPI bapi_po_change but after using that BAPI you have to add COMMIT WORK OR

FM BAPI_TRANSACTION_COMMIT in your code in order to write

changes to the database.

Best Regards,

Sachin

0 Kudos

Hi,

I have written the function module BAPI_TRANSACTION_COMMIT after BAPI_PO_CHANGE

still it is not updating the database.But when i have chek in the debugging mode it is comming

but not updating the data base table

Regards,

Am

0 Kudos

Hi Antha,

Pleasse use

WAIT UP TO 2 SECONDS.  after BAPI_PO_CHANGE and then use COMMIT WORK stmt.

Regards Sachin

Message was edited by: Sachin Adak

0 Kudos

Hi Sachin,

I have written the code below it is still not updating the database table here is my code.

   FORM GET_UPLOAD .
  data: v_file TYPE string.
  v_file = P_file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                = v_file
*      FILETYPE                = 'CSV'
    TABLES
      DATA_TAB                = gtab
    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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



  Data : lv_date2 type ekes-eindt,          "sy-datum.
         lv_index type sy-index.
  clear :wa,lv_index.
*
*loop at gtab into wa.
*
*lv_index = sy-tabix.
*  CONCATENATE wa-date2+6(4) wa-date2+3(2) wa-date2+0(2) INTO lv_date2.
*   condense lv_date2 no-gaps.
*   wa-date2 = lv_date2.
*
*modify gtab from wa index lv_index. " transporting date2.
*
*endloop.
*clear: wa.



  loop at gtab from 2.

    split  gtab-line at ',' into wa-ebeln wa-ebelp wa-ebtyp wa-date2 wa-menge.

*    loop at gtab into wa.
    CONCATENATE wa-date2+6(4) wa-date2+3(2) wa-date2+0(2) INTO lv_date2.
    condense lv_date2 no-gaps.

    wa-date2 = lv_date2.
*     modify gtab from wa index lv_index.
    clear: wa_poconfirmation.
    wa_poconfirmation-DELIV_DATE = lv_date2.
    wa_poconfirmation-PO_ITEM     = wa-ebelp.
    wa_poconfirmation-CONF_TYPE   = wa-ebtyp.
    wa_poconfirmation-QUANTITY    = wa-menge.
    append wa_poconfirmation to it_poconfirmation.
* endloop.
*
    data:  lv_po_updation_error.

    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        PURCHASEORDER                = wa-ebeln
*     POHEADER                     =
*     POHEADERX                    =
*     POADDRVENDOR                 =
*     TESTRUN                      =
*     MEMORY_UNCOMPLETE            =
*     MEMORY_COMPLETE              =
*     POEXPIMPHEADER               =
*     POEXPIMPHEADERX              =
*     VERSIONS                     =
*     NO_MESSAGING                 =
*     NO_MESSAGE_REQ               =
*     NO_AUTHORITY                 =
*     NO_PRICE_FROM_PO             =
*   IMPORTING
*     EXPHEADER                    =
*     EXPPOEXPIMPHEADER            =
    TABLES
     RETURN                       = it_ret
*     POITEM                       =
*     POITEMX                      =
*     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                =
*     POHISTORY                    =
*     POHISTORY_TOTALS             =
       POCONFIRMATION               = it_poconfirmation
              .

*    LOOP AT it_poconfirmation into wa_poconfirmation.

*      IF lv_po_updation_error NE 'X'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    WAIT UP TO 2 SECONDS.
*      ENDIF.

*    endloop.
*Read table it_poconfirmation.


  endloop.

ENDFORM.                    " GET_UPLOAD

Please can u have a look where i am doing wrong.Please check my parameter whether it is correct or not.

Regards,

Am

0 Kudos

Hi AM,

Please remove comments from LOOP-ENDLOOP as you can see BAPI_TRANSACTION_COMMIT will have no effect because of Cooment.

regards

Sachin

Former Member
0 Kudos

Hi AM,

You can check the example code in the documentation of the function BAPI_PO_CHANGE.

Make sure to pass the RETURN table, it will show in case of error messages.

0 Kudos

Hi ramakrishna,

As i you can see my code return value also u have pass but still it is not updating.

Regards,

Am

0 Kudos

  

 

Hi AM,

Please remove comments from LOOP-ENDLOOP as you can see BAPI_TRANSACTION_COMMIT will have no effect because of Cooment.

regards

Sachin

0 Kudos

Hi,

Any one let me know how to update as in my case it is not updating.

Regards,

Am

0 Kudos

Hi,

Its not possible to update the Confirmations using BAPI_PO_CHANGE unless you have the latest service pack.

See the discussion here.

http://scn.sap.com/thread/1359136

Thanks,
Shambu