Re: BAPI uploading data

Hi  Experts,
       I want to how exactly BAPI's are used as interfaces and for data transfering . Please provide me example codes for uploadinfg data into r/3 using BAPI's.
Thanks in advance.
Points will be awrded surely.
Rgds
Umakanth

Hi umakanth  ,
A BAPI is defined as a method of an SAP Business Object.
To use a BAPI method, an application program only needs to know how to call the method; that is, it needs to know the method's interface definition. A BAPI interface is defined by:
Import parameters
Export parameters
Import/export (table) parameters
The BAPIs in the R/3 System are currently implemented as function modules, all of which are held in the Function Builder. Each function module underlying a BAPI:
· Supports the Remote Function Call (RFC) protocol
· Has been assigned as a method to an SAP Business Object in the BOR
· Is processed without returning any screen dialogs to the calling application
steps involved in BAPI
In the application hierarchy of the BAPI Browser you can display all the SAP business object types for which BAPIs have been implemented:
Tools ->Business Framework -> BAPI Browser : BAPI45.
Expand the nodes and the subordinate nodes of one of the application components
To open an object type, double-click on it.
To display a list of the key fields of the object, expand the node Key fields
To display a list of the BAPIs available for this SAP business object type, expand the node Methods
To display the parameters of a BAPI, expand the node for the BAPI and then the Parameters node
Eg Program:
BAPI_GOODSMVT_CREATE to post Goods Movement
The following is an abap program making used of the BAPI function BAPI_GOODSMVT_CREATE to do Goods Receipts for Purchase Order after importing the data from an external system.
* BAPI TO Upload Inventory Data
* GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*                      02 - MB31 - Goods Receipts for Prod Order
*                      03 - MB1A - Goods Issue
*                      04 - MB1B - Transfer Posting
*                      05 - MB1C - Enter Other Goods Receipt
*                      06 - MB11
* Domain: KZBEW - Movement Indicator
*      Goods movement w/o reference
*  B - Goods movement for purchase order
*  F - Goods movement for production order
*  L - Goods movement for delivery note
*  K - Goods movement for kanban requirement (WM - internal only)
*  O - Subsequent adjustment of "material-provided" consumption
*  W - Subsequent adjustment of proportion/product unit material
report zbapi_goodsmovement.
parameters: p-file like rlgrap-filename default
                                 'c:sapdataTEST.txt'.
parameters: e-file like rlgrap-filename default
                                 'c:sapdatagdsmvterror.txt'.
parameters: xpost like sy-datum default sy-datum.
data: begin of gmhead.
        include structure bapi2017_gm_head_01.
data: end of gmhead.
data: begin of gmcode.
        include structure bapi2017_gm_code.
data: end of gmcode.
data: begin of mthead.
        include structure bapi2017_gm_head_ret.
data: end of mthead.
data: begin of itab occurs 100.
        include structure bapi2017_gm_item_create.
data: end of itab.
data: begin of errmsg occurs 10.
        include structure bapiret2.
data: end of errmsg.
data: wmenge like iseg-menge,
      errflag.
data: begin of pcitab occurs 100,
        ext_doc(10),           "External Document Number
        mvt_type(3),           "Movement Type
        doc_date(8),           "Document Date
        post_date(8),          "Posting Date
        plant(4),              "Plant
        material(18),          "Material Number
        qty(13),               "Quantity
        recv_loc(4),           "Receiving Location
        issue_loc(4),          "Issuing Location
        pur_doc(10),           "Purchase Document No
        po_item(3),            "Purchase Document Item No
        del_no(10),            "Delivery Purchase Order Number
        del_item(3),           "Delivery Item
        prod_doc(10),          "Production Document No
        scrap_reason(10),      "Scrap Reason
        upd_sta(1),            "Update Status
      end of pcitab.
call function 'WS_UPLOAD'
  exporting
    filename                      = p-file
    filetype                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
  tables
    data_tab                      = pcitab
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
if sy-subrc <> 0.
  message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  exit.
endif.
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'.   "01 - MB01 - Goods Receipts for Purchase Order
loop at pcitab.
  itab-move_type  = pcitab-mvt_type.
  itab-mvt_ind    = 'B'.
  itab-plant      = pcitab-plant.
  itab-material   = pcitab-material.
  itab-entry_qnt  = pcitab-qty.
  itab-move_stloc = pcitab-recv_loc.
  itab-stge_loc   = pcitab-issue_loc.
  itab-po_number  = pcitab-pur_doc.
  itab-po_item    = pcitab-po_item.
  concatenate pcitab-del_no pcitab-del_item into itab-item_text.
  itab-move_reas  = pcitab-scrap_reason.
  append itab.
endloop.
loop at itab.
  write:/ itab-material, itab-plant, itab-stge_loc,
          itab-move_type, itab-entry_qnt, itab-entry_uom,
          itab-entry_uom_iso, itab-po_number, itab-po_item,
                                              pcitab-ext_doc.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header             = gmhead
    goodsmvt_code               = gmcode
*   TESTRUN                     = ' '
* IMPORTING
    goodsmvt_headret            = mthead
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  tables
    goodsmvt_item               = itab
*   GOODSMVT_SERIALNUMBER       =
    return                      = errmsg
clear errflag.
loop at errmsg.
  if errmsg-type eq 'E'.
    write:/'Error in function', errmsg-message.
    errflag = 'X'.
  else.
    write:/ errmsg-message.
  endif.
endloop.
if errflag is initial.
  commit work and wait.
  if sy-subrc ne 0.
    write:/ 'Error in updating'.
    exit.
  else.
    write:/ mthead-mat_doc, mthead-doc_year.
    perform upd_sta.
  endif.
endif.
*       FORM UPD_STA                                                  *
form upd_sta.
  loop at pcitab.
    pcitab-upd_sta = 'X'.
    modify pcitab.
  endloop.
  call function 'WS_DOWNLOAD'
    exporting
      filename                      = p-file
      filetype                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
    tables
      data_tab                      = pcitab
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
endform.
REWARD POINTS IF HELPFUL
~Lakshmiraj~

Similar Messages

  • Bapi - upload data for infotypes 0016 and 0019

    hello,
    Please let me know bapi to upload data for infotypes 0016 and 0019 as i am unable to find any bapi for this infotypes.
    Please use a more meaningful subject in future - I've edited it for you this time.
    Edited by: Matt on Nov 6, 2008 12:08 PM

    Hi Sunny,
    My suggestion is go txcode BAPI.
    After this in the left side of the window complete information on BAPIs will be available search out in Human resource you may get the BAPI, in the mean while some one may help you.
    Cheers!!
    VEnk@

  • COR2 (Change Process Order) Upload & Data Change Using BAPI OR RFC

    Dear Experts,
                       I want to change the Transaction cor2(Change Process Order) material 1st line quantity, after that i have to upload records from line 2. I have all the data in itab. Will you people please have a suggestion to change and Upload data at the same time in a single program using some BAPI or RFC.
    Which BAPI or RFC will be helpfull in this regards.
    Thanks,
    Sohail

    I have done it through BDC recording, change on first line, then upload using bdc from 2nd line.

  • IS THERE ANY SUITABLE BAPI'S To Upload data to F-02  ..OR we should use BDC

    HI FRIENDS,
    IS THERE ANY SUITABLE BAPI'S To Upload data to F-02  ..OR we should use BDC..
    WAITING FOR UR REPLY?
    THANKS.
    KIRAN

    Hi,
    I need to change the BDC program which is already written for F-02 in 4.7E.The changes are like I need to add 8 new posting keys, Kindly let me know how I can do it ,if already have the coding for the same please share with me.
    Thanks in advance,
    Jyoti

  • Can anyone list problems/errors when uploading data using BDC's and BAPI's?

    Can anyone list the problems/errors when uploading data using BDC's and BAPI's?

    Hi,
    If you are actually creating a BDC to load data pls be more specific.
    Data format incorrect. Tab delimited/ etc
    Dates in wrong formats
    Currency incorrect formats
    Missing screens
    Wrong transaction code
    File not found,
    Missing Mandatory fields,
    Screen resoultion.
    You should always use refresh for your Bdcdata table.
    Loop at internal table.
    refresh Bdcdata.
    regards,
    sowjanya.

  • Bapi to upload data  for hrp1001

    Hi is there any standard Bapi to upload data in 1001.
    I know it can be done by lsmw or BDC ..but i wanted to aout any bapi

    Hi pratyush,
    Try using FM RH_INSERT_INFTY.
    Before RH_INSERT_INFTY, call function RH_PM_ENQUEUE, after RH_INSERT_INFTY, call function RH_PM_DEQUEUE.
    Regards,
    Dilek

  • Suitable BAPI interface to upload data intoKP26 T.code (CO)

    Hi All I need to know the BAPI interface to upload the data into KP26 Co Activity type /Price Planning
    I have these fields to create entries in KP26 t.code.
    The Fields are as follows:
    Layout (could use the standard layout 1-201)
    1.Version --
    2. Period from / to --
    3. Fiscal Year -
    4. Cost Center -
    5.  Activity type-
    6. Fixed price-
    7. Variable price-
    8. Price unit--- 
    PLease any body help me which BAPI is suitable for KP26 T.Code .. Its Urgent ...
    Regards
    Purushotham.Ineni.

    Hi thank you  for kind reply i need to create the entries  for CO Activity /Price planning .
    i have to upload data to KP26 which i have posted the fields ..
    i already cheked the function modules which you have been given .. it is not suitable ..
    Is there any ohter  BAPI is there ... le t me know ...
    regards
    purushotham.ineni

  • How to upload data into Classification-MM02 for each MATNR By using BAPI

    Hi all
          How to upload data into characterstic value in  classification- MM02 for each MATNR by using BAPI.

    Hi Siva,
    Please try BAPI BAPI_OBJCL_CHANGE.
    The object key should be material number and object table should be MARA.
    Regards
    Hiren K.Chitalia

  • BDC / Bapi to upload data for MI04

    Hi,
    Which is the best way to uplaod data to MI04 tcode. When i am trying with the BDC iin All screen mode it is throughing error after entering the quantity. Error is : Background processing not possible for material with serial number reqmt.
    Thanks

    use ''BAPI_MATPHYSINV_COUNT' bapi...
    u have to fill all the structures or ITAB which are mandatory. Then pass them to this BAPI. after that use BAPI_TRANSACTION_COMMIT to update the database
    and how to create .txt file to upload data to this transaction.
    the text file should contain all the fields which are necessary to pass to bapai structures /ITABs
    better , u can run the corresponding trn.. to know all mandt fields
    U can use GUI_upload to upload the flat file.
    Reward if useful

  • For transaction code MD61, I want to upload data using BAPI

    Hi,
    for transaction code MD61, I want to upload data using BAPI.
    Which BAPi I ll call ?
    Can anyone suggest me how to do it with any simple example program ?

    Refer the thread for details about coding-
    BAPI_REQUIREMENTS_CREATE
    Reards,
    Amit

  • BAPI in data upload

    Hi all,
    I am using the following BAPI to create equipment mater data, but after execution of the program, i am not finding the uploaded data. BAPI is not giving any return messages too..
      CALL FUNCTION 'BAPI_EQUI_CREATE'
          EXPORTING
         external_number         = external_number
            data_general            = data_general
          data_specific           = data_specific
         valid_date              = sy-datum
      DATA_INSTALL            =
    IMPORTING
      EQUIPMENT               =
      DATA_GENERAL_EXP        =
      DATA_SPECIFIC_EXP       =
       return                  = return1
    Please reply & have ur points.!!

    After executing this BAPI, did you get an equipment number back?
    If so, then equipment was created (since there is no error message in the return table), but before data is stored on database, you have to do a 'BAPI_TRANSACTION_COMMIT' (this is a standard function module for commiting data after BAPI-call.

  • Getting an error while using BAPI for data upload using FB50

    Hi,
    Can someone please help with the error below :
    To Upload Data Using FB50 , am using 'BAPI_ACC_DOCUMENT_POST' FM
    and passing values as
    obj_type = REACI
    obj_KEY = '$'
    obj_sys = t000-logsys
    getting errors errors in return as
    'Error in document: REACI $ R3_AFRICA
    G/L account 2511510 is not defined in chart of accounts CSGP(though the account exists in the COA)
    Control indicators for controlling area EU01 do not exist'.(we have not input any indicators)
    Thanks

    Control indicators for controlling area (t-code OKKP ) is a primary configuration before the company is set to production. Here we maintain which sub areas of controlling are activated. Have a look at those settings.
    Check the validity of the accounts/cost element in the KA03 to ensure the cost element is valid on the date of transaction.
    What is the error message number?

  • BAPI to upload data from a flat file to VA01

    Hi guys,
    I have a requirement wherein i need to upload data  from a flat file to VA01.Please tell me how do i go about this.
    Thanks and regards,
    Frank.

    Hi
    previously i posted code also
        Include           YCL_CREATE_SALES_DOCU                         *
         Form  salesdocu
         This Subroutine is used to create Sales Order
         -->P_HEADER           Document Header Data
         -->P_HEADERX          Checkbox for Header Data
         -->P_ITEM             Item Data
         -->P_ITEMX            Item Data Checkboxes
         -->P_LT_SCHEDULES_IN  Schedule Line Data
         -->P_LT_SCHEDULES_INX Checkbox Schedule Line Data
         -->P_PARTNER  text    Document Partner
         <--P_w_vbeln  text    Sales Document Number
    DATA:
      lfs_return like line of t_return.
    FORM create_sales_document changing P_HEADER  like fs_header
                                       P_HEADERX like fs_headerx
                                       Pt_ITEM   like t_item[]
                                       Pt_ITEMX  like t_itemx[]
                                       P_LT_SCHEDULES_IN  like t_schedules_in[]
                                       P_LT_SCHEDULES_INX like t_schedules_inx[]
                                       Pt_PARTNER  like t_partner[]
                                       P_w_vbeln  like w_vbeln.
    This Perform is used to fill required data for Sales order creation
      perform sales_fill_data changing p_header
                                       p_headerx
                                       pt_item
                                       pt_itemx
                                       p_lt_schedules_in
                                       p_lt_schedules_inx
                                       pt_partner.
    Function Module to Create Sales and Distribution Document
      perform sales_order_creation using p_header
                                         p_headerx
                                         pt_item
                                         pt_itemx
                                         p_lt_schedules_in
                                         p_lt_schedules_inx
                                         pt_partner.
      perform return_check using p_w_vbeln .
    ENDFORM.                                 " salesdocu
        Form  commit_work
        To execute external commit                                    *
    FORM commit_work .
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
       WAIT          = c_x
    ENDFORM.                                 " Commit_work
    Include ycl_sales_order_header          " To Fill Header data and Item data
    Include ycl_sales_order_header.
         Form  return_check
        To validate the sales order creation
    FORM return_check using pr_vbeln type vbeln.
    if pr_vbeln is initial.
        LOOP AT t_return into lfs_return .
          WRITE / lfs_return-message.
          clear lfs_return.
        ENDLOOP.                             " Loop at return
      else.
        perform commit_work.                 " External Commit
        Refresh t_return.
        fs_disp-text = text-003.
        fs_disp-number = pr_vbeln.
        append fs_disp to it_disp.
      if p_del eq c_x or p_torder eq c_x or
        p_pgi eq c_x or p_bill eq c_x.
        perform delivery_creation.           " Delivery order creation
        endif.                               " If p_del eq 'X'......
      endif.                                 " If p_w_vbeln is initial
    ENDFORM.                                 " Return_check
    *&      Form  sales_order_creation
          text
         -->P_P_HEADER  text
         -->P_P_HEADERX  text
         -->P_PT_ITEM  text
         -->P_PT_ITEMX  text
         -->P_P_LT_SCHEDULES_IN  text
         -->P_P_LT_SCHEDULES_INX  text
         -->P_PT_PARTNER  text
    FORM sales_order_creation  USING    P_P_HEADER like fs_header
                                        P_P_HEADERX like fs_headerx
                                        P_PT_ITEM like t_item[]
                                        P_PT_ITEMX like t_itemx[]
                                        P_P_LT_SCHEDULES_IN like t_schedules_in[]
                                        P_P_LT_SCHEDULES_INX like t_schedules_inx[]
                                        P_PT_PARTNER like t_partner[].
        CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
        EXPORTING
          sales_header_in     = p_p_header
          sales_header_inx    = p_p_headerx
        IMPORTING
          salesdocument_ex    = w_vbeln
        TABLES
          return              = t_return
          sales_items_in      = p_pt_item
          sales_items_inx     = p_pt_itemx
          sales_schedules_in  = p_p_lt_schedules_in
          sales_schedules_inx = p_p_lt_schedules_inx
          sales_partners      = p_pt_partner.
    ENDFORM.                    " sales_order_creation
    plzz reward if i am usefull plzz

  • Upload data from excel (not the excle file) into SAP

    Guys,
    how can we upload data from excel sheet into SAP? I mean just the data not the entire file,
    I have a requirement where user press a button in excel sheet and the data in the sheet will get uploaded into SAP.
    I am sure we have to use BAPI and some VB programming for macros, I will really appriciate if anyone can help how to achive this.
    some sample code exampe will help.
    Cheers!

    I think u r writing BDC for Uploading the data from excel flile to sap. for this is the code I am sending u can use then for Uploading data from excel to sap.
    DATA: lv_filename TYPE rlgrap-filename.
    FIELD-SYMBOLS : <fs>.
    DATA : l_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
    DATA : l_index TYPE i.
    PARAMETERS : startcol TYPE i ,
          startrow TYPE i ,
          endcol TYPE i ,
          endrow TYPE i .
    PARAMETERS: p_flnam LIKE rlgrap-filename.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flnam.
      CALL FUNCTION 'F4_FILENAME'
    EXPORTING
       program_name        = sy-repid
      FIELD_NAME          = ' '
       IMPORTING
         file_name           = p_flnam .
      MOVE p_flnam TO lv_filename.
    Uploading the flat file from the desktop
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                      = lv_filename
          i_begin_col                   = startcol
          i_begin_row                   = startrow
          i_end_col                     = endcol
          i_end_row                     = endrow
        TABLES
          intern                        = l_intern
    EXCEPTIONS
      INCONSISTENT_PARAMETERS       = 1
      UPLOAD_OLE                    = 2
      OTHERS                        = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      SORT l_intern BY row col.
      LOOP AT l_intern.
        MOVE l_intern-col TO l_index.
        ASSIGN COMPONENT l_index OF STRUCTURE itab TO <fs>.
        MOVE l_intern-value TO <fs>.
        AT END OF row.
          APPEND itab.
          CLEAR itab.
        ENDAT.
      ENDLOOP.
    I hope it will help u.
    Regards
    Nayan

  • Upload data from excel where one column has text of 3000 characters

    Guyz,
    I have a query. One of my requirments is to upload data from excel sheet & create a material. In the excel sheet one of the columns has text for BASIC DATA TEXT under ADDITIONAL DATA of a Material. This is a text of running length.
    the selection screen has feature of file upload & the users will upload excel files from their respective presentation servers.
    Now my problem is that I need a function module which can convert this column in excel sheet into an internal table & later call the BAPI for MM creation.
    I have used TEXT_CONVERT_XLS_TO_SAP & when i read my internal table to check this column length, it shows only 255 characters where as data in the excel sheet has 3000 characters (say for eg.)
    Can anybody throw some light on this.
    Thanks in advance
    GPK

    Hi,
    You can try using this function module and see that whether all your data is coming into the internal table properly.
    MS_EXCEL_OLE_STANDARD_DAT
    For the other part you needed to convert the internal table data into the structure as need by the BAPI and then call the create BAPI to create the materials in the SAP System.
    Hope this helps.
    Thanks,
    Samantak.

Maybe you are looking for