Read BAPI from java

Hi All,
I had a requirement of reading values from BAPI through  Java. Can anybody give me links or documents on how to connect to R/3 system from java. I know this can be done through JCO API or JCA API, but i could not find enough supportive documents in SDN. So please help me out.
Regards
Raghu

Dear Raghu
You can read the BAPI values using JCO objects and I providing you wiht the sample code for the same
public class BapiClass {
     static JCO.Client R3Client=null;
     IRepository R3repository=null;
     JCO.Function function=null;
     JCO.Table dataTable=null;
     String client = "040";
     String login = "developer";
     String pass = "sappmcoe1";
     String language = "en";
     String hostname = "hostname";
     String system = "00";
     String rfcException=null;
     String loginId=null;
// Variables for BAPI Vaues
     String DLCode=null;
     String Status=null;
     String Icon=null;
     String ToolTip=null;
     Alerts alert;
     ArrayList dataList = new ArrayList();
     ArrayList errorList= new ArrayList();
     Iterator alertsIter=null;
     Iterator errorIter=null;
     public BapiClass(){
     public void setLoginId(String loginId) {
          this.loginId = loginId;
     public Iterator getAlertsIterator(){
          return alertsIter;
     public String getAlerts()
          int row=0;
          rfcException = "No Exception";
          try {
//Creating Connection               
R3Client = JCO.createClient(
                         client,
                         login,
                         pass,
                         language,
                         hostname,
                         system);
               R3repository = JCO.createRepository("MyRepository", R3Client);
               }catch (Exception e)
                    rfcException = "<b>Error connecting to database system</b><BR>"+e.toString();
                    return rfcException;
            try{
//Invoking BAPI
                    IFunctionTemplate ftemplate =R3repository.getFunctionTemplate("ZSE_GETALERTS_NEW");          
                    function = new JCO.Function(ftemplate);
                    JCO.ParameterList input=function.getImportParameterList();
                    //input.setValue(loginId,"I_USERID");
                    input.setValue(loginId,"I_USERID");
                R3Client.execute(function);
//E_ALERTS is the BAPI Output Table Name
     dataTable = function.getExportParameterList().getTable("E_ALERTS");
                      row = dataTable.getNumRows();
                      for (int i = 0; i < dataTable.getNumRows(); i++)
                           dataTable.setRow(i);
                           DLCode = dataTable.getString("DLCODE");
                           Status=dataTable.getString("STATUS");
                           Icon = dataTable.getString("ICON");
                           ToolTip=dataTable.getString("TOOLTIP");
                             alert=new Alerts(DLCode,Status,Icon,ToolTip);
                           dataList.add(i, alert);
                      alertsIter = dataList.iterator();
                 catch (Exception ex) {
                 ex.getStackTrace();
                 rfcException = "<b>Error connecting to database system</b><BR>"+ex.toString();
                 return rfcException;
          return rfcException;          
Regards
Noel

Similar Messages

  • How to find particular CRM BAPIs from Java code of ISA B2B application?

    Hi Guys,
    I am newbie in CRM ISA field. I am supporting CRM ISA 5.0 B2B application.
    Basically I had a question about how to go about finding the BAPIs which are getting called from the Java side of ISA.
    I know that the framework uses JCO connection in order to execute BAPIs in the back-end and usually these BAPIs are standard.
    So I can put a break-point on the CRM bapis and see which is called when.
    But if I want to track BAPIs from Java code, what should be my approach?
    Please help.
    Thanks!

    Hi,
    To setup the trace logs you need to use the following URL.
    https://<system domain name>:port/<application_name>/admin
    typically it should look like as below:
    https://abc.com:50001/b2b/admin
    Here there is an option to start and stop the logs and after stopping it will generate a Zip file which you need to download and from there you can easily find out the BAPI's or teh RFC calls.
    Also when you search you should alwways keep one thing mind that these FM's normally start with CRM_ISA*
    Hope it helps.
    Regards
    Sidd

  • Is RFC destination is required for accessing BAPI from java/VB program.

    I am not able to understant that all BAPI are Remote enabled ,but no where I observed that RFC destination is required.
    Can any body tell me exact flow and things step by step.
    Any example/full source code so that I can call from java program.
    I have tried some java code posted here but not able to understand ..
    please provide me setttings also in SAP and java system

    Hi Nagaraju,
    Thank you very much. your post resolve one of my basic need .really appreciate your post.
    I was not able to execute bapi BAPI_MATERIAL_GETLIST but I executed BAPI_PO_GETDETAIL succesfully.
    Still I have 2 doubt.
    [1]. I called BAPI function module(BAPI_PO_GETDETAIL) from simple java program,But I need to call API method ( GETDETAIL) created for this BAPI not direct BAPI function module.
    [2] this is something apart from original topic.
    I have tested your java code in java as well as similar in ECC 6.0
    But I am not getting any output in JAVA program.
    I am getting output in ECC6.0 only when I will take internal table lt_mara[] with header line.
    if I will take separate workarea output is not coming. I think this is the problem in JAVA also.
    Please see the code and tell me where I am wrong.
    REPORT ZTEST1.
    types: begin of ty_mara .
       include STRUCTURE BAPIMATRAM.
    TYPES: END OF ty_mara.
    types: begin of ty_list .
      include STRUCTURE BAPIMATLST.
    TYPES: END OF ty_list.
    data: lt_mara type STANDARD TABLE OF ty_mara with HEADER LINE.
    data: lt_list type STANDARD TABLE OF ty_list,
          ls_list like LINE OF lt_list.
    START-of-SELECTION.
    lt_mara-SIGN = 'I'.
    lt_mara-option = 'EQ'.
    lt_mara-matnr_low = '000000000000000088'. "'P1001087'.
    lt_mara-matnr_high = ''.
    APPEND lt_mara.
    lt_mara-SIGN = 'I'.
    lt_mara-option = 'EQ'.
    lt_mara-matnr_low = '000000000000000089'. "'P1001087'.
    lt_mara-matnr_high = ''.
    APPEND lt_mara.
    CALL FUNCTION 'BAPI_MATERIAL_GETLIST'
    TABLES
      MATNRSELECTION                     = lt_mara
      MATNRLIST                          = lt_list[]   .
    WRITE / 'output:  '.
    LOOP AT lt_list into ls_list .
      write: ls_list .
    ENDLOOP.
    REPORT ZTEST2.
    types: begin of ty_mara .
       include STRUCTURE BAPIMATRAM.
    TYPES: END OF ty_mara.
    types: begin of ty_list .
      include STRUCTURE BAPIMATLST.
    TYPES: END OF ty_list.
    data: lt_mara type STANDARD TABLE OF ty_mara, ">> Without header line
           ls_mara like line of lt_mara.
    data: lt_list type STANDARD TABLE OF ty_list,
          ls_list like LINE OF lt_list.
    START-of-SELECTION.
    ls_mara-SIGN = 'I'.
    ls_mara-option = 'EQ'.
    ls_mara-matnr_low = '000000000000000088'. "'P1001087'.
    ls_mara-matnr_high = ''.
    APPEND ls_list to lt_mara.
    ls_mara-SIGN = 'I'.
    ls_mara-option = 'EQ'.
    ls_mara-matnr_low = '000000000000000089'. "'P1001087'.
    ls_mara-matnr_high = ''.
    APPEND ls_list to lt_mara.
    CALL FUNCTION 'BAPI_MATERIAL_GETLIST'
    TABLES
      MATNRSELECTION                     = lt_mara
      MATNRLIST                          = lt_list[]          .
    WRITE / 'output:  '.
    LOOP AT lt_list into ls_list .
      write: ls_list .
    ENDLOOP.

  • Reading files from Java embedding.

    Dear All,
    My BPEL process has a Java embedding node, and it invokes a Java class, in which an xsl file is being read for transformation.
    I deploy the xsl files directory together with BPEL package (the jar). In the package, I put the file dir at the root level, which means the jar structure looks like the following:
    /BPEL-INF
    /META-INF
    /xsd
    /xsl
    *.wsdl
    *.bpel
    bpel.xml
    The java class is package in /BPEL-INF dir, it's supposed to read files from /xsl dir.
    My question is, how should I put the file path?
    I tried "/xsl/***.xsl" and "../xsl/***.xsl", neither works. Although "/xsl/***.xsl" worked when testing in JDeveloper, but FileNotFound after deployment.
    Thanks,
    Haibo

    I solved this issue by putting the files dir in /BPEL-INF/classes/. and use ClassLoader to read in those files.

  • Reading Excel from Java

    Hello,
    I would want to read excel data from Java. I do not want to register any excel drivers as I will not be able to know the file to be read before hand. Are there any better ways to solve this ?
    Thanks in Advance,
    Prasanna

    hi prasanna
    if you are using jdbc-odbc bridge I would recommend you to test the
    program with excel files with varying sizes like 3,5, 12, 20 etc. There
    is a some problem with the driver that it chops off some data.
    For example if you have 20k excel file the driver may read in 9k chunks so you get 18k of data read and the driver ignores rest 2k.
    Make sure of that it works on all sizes of input data.
    bib/-

  • READING XML FROM JAVA

    I am developing web services based GIS, I have XML file which was generated from Geoserver. I dont know how to link Java with XML and query XML from Java. I need help pls.
    PAI

    there are apis to parse xml using java,
    http://www.cafeconleche.org/books/xmljava/chapters/ch09s06.html
    try this link..
    regards
    Shanu

  • Read item from Java class and call to stored function/procedure of database

    Hi,
    I am looking solution that I was trying to find becasue of I am not expert and novice of ADF so I am getting problem to do. I am trying migrating from oracle forms to JDeveloper[ADF].
    I want to call database stored function from JSF pages by java bean class of a button press event (manually created) and after button event I have called java class which I created manually. But I can not read that values what I given into jsp page.
    question1: How can I read jsp pages items value to java class ?
    question2: How can I call to database stored function/procedure with that parameter?
    question3: How can I use return value of that stored function/procedure ?
    Please reply me .
    Thanks,
    zakir
    ===
    Edited by: Zakir Hossain on Mar 29, 2009 10:22 AM

    ---

  • Access registry (read/write) from java

    Hi folks,
    I'm struggeling with a Java/COM bridge to read/write the registry from my java application. The documentation from Sun on this is very sparely. Would be grateful for any hints!
    Regards,
    C.H. Liljegren

    Hi Bud,
    After a long time of asking everybody and then getting no response from any of the guys from the forum .I finally decided to do it myself and guess what I do succeded in reading and writing from the registry of windows from a Java program .
    I dont have the code now its there in my office . I will send it to u tomorrow .
    But one thing I came to know that if u wanna do some thing u have to take the initiative.
    I will send u the code tomorrow.
    Take Care.
    Manoj.

  • Reading CATALINA_HOME from java program

    Hi ,
    IN one of my application i have to create a file from the java program under my webapp.
    How do i do that , if i give the whole path i am able to do that , but this application has to run on both windows and unix machines.
    And i am really not looking to edit the source files.
    Is there any way i can give like
    CATALINA_HOME/webapps/MyWebapp/<filename>
    Thanks

    you could try with $catalina.home/webapps/MyWebapp/<filename> could work depending on how your application loads/saves the file.

  • Logging/reading exception from Java in c++

    Hi!
    Can anyone tell me what is wrong with this code?
    I try to call toString from c++ on an exception that occurs in Java.
    I want to find out which exception it is and send it to my logging system.
    The code fails on the call to CallObjectMethod. The application stops and exits?
    Both ex and getMessage_id is not NULL.
    I have tried to call m_env->ExceptionClear() from many different places. They are commented out in the code.
    I have tried both GetObjectClass and FindClass but there are no difference.
    Any suggestions are appreciated.
    jthrowable e = m_env->ExceptionOccurred();
    if (e) {
       m_env->ExceptionDescribe();
       //m_env->ExceptionClear();
       jclass ex = m_env->GetObjectClass(e);
       // I have tried to do this instead of the call over.
       //jclass ex = m_env->FindClass("java/lang/Throwable");
       if(ex == NULL){
          //does not enter this if test
          m_logfile->write("object call ex == NULL");
       //m_env->ExceptionClear();     
       jmethodID getMessage_id = m_env->GetMethodID(ex, "toString", "()Ljava/lang/String;");
       if(getMessage_id == NULL){
          //does not enter this if test
          m_logfile->write("object call getMessage_id == NULL");
       //m_env->ExceptionClear();
       jstring errmsg = (jstring)m_env->CallObjectMethod(ex, getMessage_id);
    }Thanks,
    Jonas     

    Hi!
    Can anyone tell me what is wrong with this code?Just a guess.
    jclass ex = m_env->GetObjectClass(e);This returns an instance of "Class".
    jstring errmsg =
    = (jstring)m_env->CallObjectMethod(ex,
    getMessage_id);
    This is passing in an instance of "Class" ('ex')
    right?
    Don't you want an instance of something like
    "Throwable"?
    You are right.
    The CallObjectMethod method takes a jobject and not a jclass as a parameter.
    The ex parameter should be replaced with the jthrowable object e.
    //the right code is
    jstring errmsg = (jstring)m_env->CallObjectMethod(e, getMessage_id);
    Thanks,
    Jonas

  • Reading file from Java Web App?

    My application has a custom configuration file that I want to read at runtime.
    What directory should I put the file in and how should my code locate the file at runtime?
    Obviously, I don't want to hardcode paths.
    Is there an easy way to find the file at runtime if it's in my classpath root?
    (sorry for the repetition, I posted a vartion of this question at the end of another thread.)

    Just read your post in the other thread ... another why of doing this could be to set your own environment variable and then use it within your app.
    ie. in a DOS window (or better still, use the Environment Variables option within the Properties of My Computer).
    c:\>set myAppCfgFile = c:\myapp\myconfig.inithen in Java.
    String pathAndFilename = System.getenv("myAppCfgFile"); // note, environment variables are not case sensitive (or shouldn't be).

  • Calling BAPI from java screen

    Hi All
    I want to develop Order entry form in PDK, in that i need to call BAPI...namely "BAPI_SALESORDER_CREATEFROMDAT2".
    Can anybody send me the sample code...
    [email protected]
    Thanks for ur help
    Pradeep

    In PDK you can import RFC modules. For that you have to create a jco connection. The code for calling an simple rfc ....
    package com.satyam.callrfc;
    import com.sap.mw.jco.JCO;
    import com.sapportals.portal.prt.component.*;
    public class rfc extends AbstractPortalComponent
         private JCO.Client jcoClient;
    // proxy for rfc you already assigned...     
         Insert_pgm_PortType insFunc=new Insert_pgm_PortType();
         Zinsert_Pgm_Input ip=new Zinsert_Pgm_Input();
         Zinsert_Pgm_Output op=new Zinsert_Pgm_Output();
        public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
        this.connect();
         insFunc.messageSpecifier.setJcoClient(jcoClient);
    //setting input params
         ip.setAssociate_Id1("44");
         ip.setCourse_Objt1(2);
         ip.setQlty_Content1(5);
         ip.setSeq_Content1(2);
         ip.setTraining_Id1("22");
         try{
    //calling rfc
         op=insFunc.zinsert_Pgm(ip);
         }catch(Exception e){}
    //display output
              response.write(op.getMessage());
              this.disconnect();
         private void connect() {
                   try {
                        jcoClient =
                             JCO.createClient("client","userid","password","EN","application_system","system_no");
                             jcoClient.connect();
                   } catch (Exception e) {
                        System.out.println("Error connecting to SAP ::" + e.getMessage());
                        e.printStackTrace();
         private void disconnect() {
                   try {
                        jcoClient.disconnect();
                   } catch (Exception e) {
                        System.out.println(
                             "Error dis-connecting to SAP ::" + e.getMessage());
                        e.printStackTrace();
    Hope this helps
    gEorgE

  • Reading Xml from Java--urgent

    Hello
    I nead thyis realy very urgen.I have XmlParser and xml.jar.
    I unpacked xml.jar. When I tried to compile xmp\lparser i got 10 errors.
    He can't find packages(w3c,dom).
    What to do?
    If you know adress where i can find api for Xml it would be great help.
    I nead very simlpe thing to read value of 2 nodes whish are always there asme and iI am very new in XML.
    I have to finish my graduation project tonight (i ma writeing jsp aplication).
    thank you a lot for any help.

    Take a look at Xerces at xml.apache.org.
    Alan Yackel

  • Access SAP Tables from Java Program

    Hi All,
    We have a requirement to integrate attendance portal(which is done in java) with SAP.
    Our problem is how to access SAP tables from a Java program?
    Database is Sybase.
    Please suggest us a good solution.
    Thanks in advance...

    Did you go through Sap Help?
    Calling BAPIs from Java - BAPI User Guide CA-BFA) - SAP Library
    Regards,
    Philip.

  • Reading character '�' from a notepad text file

    Hi, I created a text file using plain editor ( notepad), when I try to read the character '�' a got the � symbol.
    What I have to do ?
    Thanks in advance.

    Hi, and yes , at this point of time I can not resolve the problem, the problem it's not only with the �, but with �, �, � � � Spanish characters !
    They can be creted using a plain text editor, but i can not read it from java !
    Thanks a LOT again.

Maybe you are looking for