How to call BAPI in a ABAP prog

Hi All
I have a concern regarding the usuage of BAPI in the ABAP program.
i have successfully created a BAPI and i have implemented a method as well using ADD API Method button.
Now after doin all the things in SWO1.
I wanted to know how to call this BAPI method in se38.
CAn anyone throw some light on this ?
Regards
Gaurav

Hi,
try this
*& Report ZKAR_MATMAS_BAPI
*& This program demonstrates how easy it is to create Material master
*& data using BAPI_MATERIAL_SAVEDATA
*& The program also generates a report post-execution displaying errors
*& as well as successful uploads
REPORT ZKAR_MATMAS_BAPI.
* TABLES
* FLAGS *
DATA: F_STOP. " Flag used to stop processing
* DATA DECLARATIONS *
DATA : V_EMPTY TYPE I, " No. of empty records
V_TOTAL TYPE I. " Total no. of records.
* STRUCTURES & INTERNAL TABLES
*BAPI structures
DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control Information
BAPI_MAKT LIKE BAPI_MAKT, " Material Description
BAPI_MARA1 LIKE BAPI_MARA, " Client Data
BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA
BAPI_MARC1 LIKE BAPI_MARC, " Plant View
BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC
BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View
BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW
BAPI_RETURN LIKE BAPIRET2. " Return Parameter
*--- Internal table to hold excel file data
DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
*--- Internal table to hold Matetrial descriptions
DATA: BEGIN OF IT_MAKT OCCURS 100.
        INCLUDE STRUCTURE BAPI_MAKT.
DATA: END OF IT_MAKT.
*--- Internal to hold the records in the text file
DATA : BEGIN OF IT_DATA OCCURS 100,
            WERKS(4), " Plant
            MTART(4), " Material type
            MATNR(18), " Material number
            MATKL(9) , " Material group
            MBRSH(1), " Industry sector
            MEINS(3), " Base unit of measure
            GEWEI(3), " Weight Unit
            SPART(2), " Division
            EKGRP(3), " Purchasing group
            VPRSV(1), " Price control indicator
            STPRS(12), " Standard price
            PEINH(3), " Price unit
            SPRAS(2), " Language key
            MAKTX(40), " Material description
            END OF IT_DATA.
* SELECTION SCREEN. *
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File
'C:\Material_master.XLS'.
PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session
PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,
P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,
P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,
P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK SCR1.
* AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*--- Validating file
  PERFORM VALIDATE_FILE USING P_FILE.
* START-OF-SELECTION
START-OF-SELECTION.
*--- Perform to convert the Excel data into an internal table
  PERFORM CONVERT_XLS_ITAB.
  IF NOT IT_DATA[] IS INITIAL.
*--- Perform to delete Header lines
    PERFORM DELETE_HEADER_EMPTY_RECS.
  ENDIF.
* END OF SELECTION. *
END-OF-SELECTION.
*--- Perform to upload Material Master data
  PERFORM UPLOAD_MATMAS.
* Form : validate_input_file
* Description : To provide F4 help for file if read from PC
FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      FILE_NAME     = F_FILE
    EXCEPTIONS
      MASK_TOO_LONG = 1
      OTHERS        = 2.
  IF SY-SUBRC <> 0.
    MESSAGE S010(ZLKPL_MSGCLASS). " 'Error in getting filename'.
  ENDIF.
ENDFORM. " validate_input_file
*& Form CONVER_XLS_ITAB
* text
FORM CONVERT_XLS_ITAB.
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME    = P_FILE
      I_BEGIN_COL = P_BEGCOL
      I_BEGIN_ROW = P_BEGROW
      I_END_COL   = P_ENDCOL
      I_END_ROW   = P_ENDROW
    TABLES
      INTERN      = IT_INTERN.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*--- Perform to move the data into an internal data
  PERFORM MOVE_DATA.
ENDFORM. " CONVERT_XLS_ITAB
*& Form MOVE_DATA
* text
FORM MOVE_DATA.
  DATA : LV_INDEX TYPE I.
  FIELD-SYMBOLS <FS>.
*--- Sorting the internal table
  SORT IT_INTERN BY ROW COL.
  CLEAR IT_INTERN.
  LOOP AT IT_INTERN.
    MOVE IT_INTERN-COL TO LV_INDEX.
*--- Assigning the each record to an internal table row
    ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <FS>.
*--- Asigning the field value to a field symbol
    MOVE IT_INTERN-VALUE TO <FS>.
    AT END OF ROW.
      APPEND IT_DATA.
      CLEAR IT_DATA.
    ENDAT.
  ENDLOOP.
ENDFORM. " MOVE_DATA
*& Form DELETE_HEADER_EMPTY_RECS
* To delete the Header and empty records
FORM DELETE_HEADER_EMPTY_RECS.
  DATA: LV_TABIX LIKE SY-TABIX.
  IF NOT P_HEADER IS INITIAL.
    LOOP AT IT_DATA.
      IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.
        DELETE IT_DATA FROM 1 TO P_HEADER.
* P_HEADER = 0.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDIF.
  CLEAR IT_DATA.
*--- To delete the empty lines from internal table
  LOOP AT IT_DATA.
    LV_TABIX = SY-TABIX.
    IF IT_DATA IS INITIAL.
      V_EMPTY = V_EMPTY + 1.
      DELETE IT_DATA INDEX LV_TABIX..
    ENDIF.
  ENDLOOP.
  CLEAR IT_DATA.
*--- Total no of recs in file
  DESCRIBE TABLE IT_DATA LINES V_TOTAL.
  IF V_TOTAL = 0.
    MESSAGE I013(ZLKPL_MSGCLASS). " No records in the file
    F_STOP = 'X'.
    STOP.
  ENDIF.
ENDFORM. " DELETE_HEADER_EMPTY_RECS
*& Form UPLOAD_MATMAS
* to upload Material Master data
FORM UPLOAD_MATMAS .
  LOOP AT IT_DATA.
* Header
    UNPACK IT_DATA-MATNR TO IT_DATA-MATNR.
    BAPI_HEAD-MATERIAL = IT_DATA-MATNR.
    BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.
    BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.
    BAPI_HEAD-BASIC_VIEW = 'X'.
    BAPI_HEAD-PURCHASE_VIEW = 'X'.
    BAPI_HEAD-ACCOUNT_VIEW = 'X'.
* Material Description
    REFRESH IT_MAKT.
    IT_MAKT-LANGU = IT_DATA-SPRAS.
    IT_MAKT-MATL_DESC = IT_DATA-MAKTX.
    APPEND IT_MAKT.
* Client Data - Basic
    BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.
    BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.
    BAPI_MARA1-UNIT_OF_WT = IT_DATA-GEWEI.
    BAPI_MARA1-DIVISION = IT_DATA-SPART.
    BAPI_MARAX-MATL_GROUP = 'X'.
    BAPI_MARAX-BASE_UOM = 'X'.
    BAPI_MARAX-UNIT_OF_WT = 'X'.
    BAPI_MARAX-DIVISION = 'X'.
* Plant - Purchasing
    BAPI_MARC1-PLANT = IT_DATA-WERKS.
    BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.
    BAPI_MARCX-PLANT = IT_DATA-WERKS.
    BAPI_MARCX-PUR_GROUP = 'X'.
* Accounting
    BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.
    BAPI_MBEW1-STD_PRICE = IT_DATA-STPRS.
    BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.
    BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEWX-PRICE_CTRL = 'X'.
    BAPI_MBEWX-STD_PRICE = 'X'.
    BAPI_MBEWX-PRICE_UNIT = 'X'.
*--- BAPI to create material
    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
    EXPORTING
    HEADDATA = BAPI_HEAD
    CLIENTDATA = BAPI_MARA1
    CLIENTDATAX = BAPI_MARAX
    PLANTDATA = BAPI_MARC1
    PLANTDATAX = BAPI_MARCX
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA = BAPI_MBEW1
* VALUATIONDATAX = BAPI_MBEWX
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA = BAPI_MVKE1
* SALESDATAX = BAPI_MVKEX
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
    IMPORTING
    RETURN = BAPI_RETURN
    TABLES
    MATERIALDESCRIPTION = IT_MAKT
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
    IF BAPI_RETURN-TYPE = 'E'.
      WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,IT_DATA-MATNR.
    ELSEIF BAPI_RETURN-TYPE = 'S'.
      WRITE: 'Successfully created material' ,IT_DATA-MATNR.
    ENDIF.
  ENDLOOP.
ENDFORM. " UPLOAD_MATMAS
Regards,
V.Balaji
Reward if Usefull...

Similar Messages

  • How to call  java program from ABAP

    Hi Experts,
         My requirement is to call java programs from ABAP. For that i have set up SAP JCO connection by using this link http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/739. [original link is broken] [original link is broken] [original link is broken] Connection gets sucessfully. After this how to call java program from ABAP as per our requirement. Please help me out.
      Also i tried this way also.. but while executing the DOS Command line appear & disappear in few seconds. So couldnt see the JAVA output. Please help me out to call java programs in ABAP..
    DATA:command TYPE string VALUE 'D:Javajdk1.6.0_20 injavac',
    parameter TYPE string VALUE 'D:java MyFirstProgram'.
    CALL METHOD cl_gui_frontend_services=>execute
    EXPORTING
    application = command
    parameter = parameter
    OPERATION = 'OPEN'
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    bad_parameter = 3
    file_not_found = 4
    path_not_found = 5
    file_extension_unknown = 6
    error_execute_failed = 7
    OTHERS = 8.
    Thanks.

    This depends on the version of your Netweaver Java AS. If you are running 7.0, you will have to use the Jco framework. The Jco framework is deprecated since 7.1 though. If you want to build a RFC server in 7.1 or higher, it is adviced that you set it up through JRA.
    Implement an RFC server in 7.0:
    http://help.sap.com/saphelp_nw04/helpdata/en/6a/82343ecc7f892ee10000000a114084/frameset.htm
    Implement an RFC server in 7.1 or higher:
    http://help.sap.com/saphelp_nwce72/helpdata/en/43/fd063b1f497063e10000000a1553f6/frameset.htm

  • How to call subroutines defined in ABAP program with type S

    how to call subroutines defined in ABAP program with type S? can you give an example?

    Normal executable program,
    REPORT  ZTEST_MAIN.
    perform sub1 in program ztest_sub.
    "you can call using in program addition
    Subroutine pool program
    PROGRAM  ZTEST_SUB.
    form sub1.
    endform.

  • How to call a idoc in abap program and updates catsdb table

    how to call a idoc in abap program and updates catsdb table
    thank you,
    Jagrut BharatKumar Shukla

    Hi Kishan,
    You can refer to following help document,
    http://help.sap.com/saphelp_nw04/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/content.htm
    Regards,
    Meera

  • From rfc how to call bapi

    Hi
    How to call BAPI FM's from RFC ??
    thanks
    kumar

    Hi Palnati,
                      Use statement  :
                      Call FUNCTION     'Bapi................'
                       DESTINATION     Dest(RFC destination in TCODE SM59)
                         EXPORTING      f1 = …
                                                    f2 = …
                         IMPORTING      f3  = …
                         TABLES            T1 = …
                         EXCEPTIONS ……….
    Reward points if helpful.
    Regards,
    Hemant

  • How to call BAPI from ABAP Inbound Proxy

    Hi All
    Can some one provide/giude  a sample code on how to call a BAPI from generated Method (Inbound Proxy) and how are the table parameters passed from Proxy to BAPI.
    Thanks
    Ravi/

    Hello Ravi,
    In the proxy before calling the BAPI, construct the table, fill it with the appropiate values by lopping over the proxy request object. Now use this table for calling BAPI
    Cheers,
    Naveen

  • How to call the webservice in abap program

    Hi All,
    I have created a web service for my RFC .  The RFC has Import and export paramaters.
    I want call the same web service into my  ABAP REPORT and at the same time i want pass the values to webservice  and get the result from webservice in my abap report,
    Please help me  how to call the web service and pass the values and get the values?
    Highly appreciate your assitance.
    Thanks,
    Kishan

    Hi Kishan,
    You can refer to following help document,
    http://help.sap.com/saphelp_nw04/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/content.htm
    Regards,
    Meera

  • How to Call BAPI From the Custom Controller

    Hi
    I developed frist WD Application Using RFC Adapter.
    i did the following steps
    1. created the project
    2. created the model.
    3. created the customer controller and mapped the model of the controller to the model.
    4. mapped controller context to the views
    5. created one action in the start view
    6. created one method in the customer controller.
    so please let me know the lines of code to call BAPI using RFC.
    and  how to pass input valus to the bapi and how to execute the BAPI
    plese send the reply ASAP
    regards
    mmukesh

    Hi
    i did like this
    In  Start View OnActionSearch () method code
    public void onActionsearch (com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
           wdThis.wdGetTestCustControllerController().executeGetlistBapi();
    in CustomController Init method
    public void wdDoInit()
        Bapi_Flight_Getlist_Input input = new Bapi_Flight_Getlist_Input();
        wdContext.nodeBapi_FlightGetlist_Input().bind(input);
        input.setDestination_From(new Bapisfldst());
        input.setDestination_To(new Bapisfldst());
    In CUSTOMECONTROLLER executeGetlistBapi();
    METHOD
    public void executeGetlistBapi( )
        //@@begin executeGetlistBapi()
        try{
           wdContext.currentBapi_FlightGetlist_InputElement().modelObject().execute();
           wdContext.nodeOutput().invalidate();
        }catch(Exception ex){
           ex.printStackTrace();
    Then let me know what is wrong in this
    i did as per pdf
    please correct if there is any worng in this code.
    this is flight example .
    regards
    mmukesh

  • How to call BAPI from R/3 system

    hi,
    i am doing small application by using Model. that is calling BAPI from R/3 system. but i am not able to get data from the back end system. please suggest me regarding this problem
    thanx
    tanvi

    steps:
    1) create Model
    2) bind Model to component controller ( you can use data modeler.) 2.1) open data modeler; if your model is not there, you can add by clicking add existing model;
    2.2) create data link between model and controller, it will open map dialog.
    2.3) click and drag BAPI_xxx_Input to context of controller and select all nodes inside
      - if there is any duplicate nodes, just rename it.
    3) map context to view controller
    3.1) map input parameters separately ( which takes value for IMPORT to BAPI. select only that fields
    3.2) do map for output (exact node which contains BAPI output)
    coding:
    1) in component controller you need to instantiate model and bind to context
    BAPI_xxx_Input my_input = new BAPI_xxx_input();
    wdContext.nodeBAPI_xxx_Input my_input().bind( my_input);
    2) create a method in the component controller so that we can execute it from any of views used.
    try{
      wdContext.currentBAPI_xxx_Input my_input().modelObject().execute();
    }catch(WDRFCException e) {
    e.printStackTrace();
    wdContext.node<ExactOutput>().invalidate();
    // this stmt will reflect new values
    3) Go to view and bind values to UI Elements
    in wdDoInit()
    IPrivate<Comp_Name>View.I<ExactOutput>Element  input = wdContext.create<BAPI_xxx_Input>Element();
    // see if this may demand model instance as parameter
    wdContext.node<BAPI_xxx_Input>().addElement( input);
    4) In OnAction you just executes the component controller method
    wdThis.wdGet<Com_Name>Controller().executeMyBapi();
    // executeMyBapi() is the method contains the mentioned try..catch code
    nikhiL

  • How to call an web dynpro abap application with an particular theme

    Dear friends,
    i have created one web dynpro abap application. i created one theme XYZ in portal with required font size. when i applied this theme on portal all web dynpro application use this theme.
    i want to use current theme for one application not for all.
    is it poosible to call an web dynpro abap appl with the particular theme where as others should not be temper with this theme.
    please guide me by some useful steps.
    regards
    sunil

    Sunil,
    Check if this helps.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/7015b1f9-535c-2910-c8b7-e681fe75aaf8?QuickLink=index&overridelayout=true
    Cheers!
    Sandeep Tudumu

  • How 2 call BAPI & pass table name so that it will insert table data 2 SAP

    Hi guys,
    Has anyone tried calling BAPI from BODS; Please share screen shots and details. I want to call BAPI fron BODS which will take table name as a parameter and insert that table data to SAP.

    HI,
    in case you mean BusinessObjects Data Services with BODS then I would suggest you post your question into the EIM area of the SDN forums.
    Ingo

  • How to call C++ Program in Abap

    Hi Friends,
      How can i call a C/C++ Program or a Function in an Abap Program.or an Abap Module or Bapi in a C/C++ Program.
    Regards,
    Gowtham Kuchipudi.

    Let's talk about ABAP -> C/C++
    You already have C functions being called in ABAP ! It is the C functions from the SAP Kernel.
    There are several approaches to your problem :
    - one could be to simply execute the program from the Shell (Unix or the Windows command)
    - antoher would be add the function to the SAP Kernel (which is a bit of a job since you have to recompile the Kernel)
    Regarding C/C++ -> ABAP, I am sure there are a lot of examples around like for the other languages (VB, Java, ...).
    Hope it helps.
    Cheers,
    Message was edited by: Guillaume Garcia

  • How to Call HANA Procedure in ABAP

    Hi Everyone,
    I am new to ABAP
    I have created a procedure in HANA that accepts two input parameters and outputs a table
    I am using HANA as a Secondary Database
    How can I call this procedure in my ABAP program?
    Regards,
    Vivek

    Hi Vivek,
    depends on how you would like to call it :-)
    1. Use native SQL to call the procedure (see report ADBC_DEMO_PROC_CALLS_HDB; available in any system with a minimum NetWeaver release 7.40 SP5).
    2. Create a DB Procedure Proxy and call the DB Procedure Proxy (Tutorial: How to consume SAP HANA Procedures in ABAP; only "directly" available if HANA is the primary DB underlying your system, for secondary DB system see discussion Execute Procedure with input parameters as table from ABAP).
    3. (Method of choice available as of NetWeaver 7.4 SP5): Create an ABAP managed DB procedure (instead of the native HANA procedure) as described in ABAP Managed Database Procedures - Introduction
    Cheers,
      Jasmin

  • How to call a webservice in ABAP?

    Hi,
    I want to call an external webservice in ABAP coding. Do you know how to write or configue it? Is there any documentation?
    Thanks!

    check out this weblog
    /people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap
    Raja
    PS: please search before posting a question

  • How to call transaction in an abap program

    how do we open a transaction thru an abap program and pass a parameter to it

    Use call transaction. You can fill up the parameters in the BDC internal table
    DATA:   bdc_tab LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
    DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
    CONSTANTS: c_tcode LIKE t130m-tcode VALUE 'FB01'. "Tcode you want to call
            CALL TRANSACTION c_tcode
                 USING  bdc_tab
                 MODE   'N'
                 UPDATE 'S'
                 MESSAGES INTO messtab.
    Error message will be captured in the messtab.
    You can goto the SAP help on Call transaction to see all the details and options.
    <b><REMOVED BY MODERATOR></b>
    Thanks.
    Message was edited by:
            Alvaro Tejada Galindo

Maybe you are looking for

  • Satellite Pro A300 crashes with blank screen

    I have a Satellite Pro A300, AMD CPU, ATI graphics, Vista. The system worked fine for a year but a few months ago it started crashing, the screen went blank, not blue, anything running, like music, stopped. This can happen after several hours or minu

  • Error in Drop Table in Oracle 10G

    Hi All, When I try to drop any of the table in one of the oracle 10G database schema I am getting the following error. As for I know this error will come in PL/SQL cursor block if the exact fetch returns more than one row. Can any one explained the r

  • Has anyone actually tried the BluetoothDemo demo?

    It works fine via emulatorm no matter how many connections I create, but when i transferred it to my K700i it doesn't seem to work. When I select Server nothing happens. So i tried it on a Nokia 6600 and it works, but then it doesn't show the list of

  • IPohne 4 gets very hot

    my iphone 4  8GB (iOS5.0.1) is know 2 weeks old and i noted: it gets very hot if i recording a video or charging it.  shortly after i recorded a video i couldn't hear anything out of the speaker and couldn't change the volume. after i have waited 15

  • Profiles and 6650 Fold

    Is it possible to either create new profiles or add existing settings to current profiles for my 6650 Fold cell phone ? Solved! Go to Solution.