Skip to Content

how to integrate SAP using ComfyJ in Java

Hi,

I want to integrate SAP functionality same as mentioned in ( https://blogs.sap.com/2012/11/01/how-to-use-sap-gui-scripting-inside-java/#) using ComfyJ. Have anyone idea how can i integrate this using ComfyJ?

<code>//-Import-------------------------------------------------------------
    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.ComThread;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;

  public class SAPGUIScriptingLogon {

    public static void main(String[] args) {

      //-Variables------------------------------------------------------
        ActiveXComponent SAPROTWr, GUIApp, Connection, Session, Obj;
        Dispatch ROTEntry;
        Variant ScriptEngine;
         
      ComThread.InitSTA();

      //-Set SapGuiAuto = GetObject("SAPGUI")---------------------------
        SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
        try {
          ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
          //-Set application = SapGuiAuto.GetScriptingEngine------------
            ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
            GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());

          //-Set connection = application.Children(0)-------------------
            Connection = new ActiveXComponent(
              GUIApp.invoke("Children", 0).toDispatch());
          //-Set session = connection.Children(0)-----------------------
            Session = new ActiveXComponent(
              Connection.invoke("Children", 0).toDispatch());

          //-Set GUITextField Client------------------------------------
          //-
          //- session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "000"
          //-
          //------------------------------------------------------------
            Obj = new ActiveXComponent(Session.invoke("FindById",
              "wnd[0]/usr/txtRSYST-MANDT").toDispatch());
            Obj.setProperty("Text", "000");

          //-Set GUITextField User--------------------------------------
          //-
          //- session.findById("wnd[0]/usr/txtRSYST-BNAME").text = _
          //-   "BCUSER"
          //-
          //------------------------------------------------------------
            Obj = new ActiveXComponent(Session.invoke("FindById",
              "wnd[0]/usr/txtRSYST-BNAME").toDispatch());
            Obj.setProperty("Text", "BCUSER");

          //-Set GUIPasswordField Password------------------------------
          //-
          //- session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = _
          //-   "minisap"
          //-
          //------------------------------------------------------------
            Obj = new ActiveXComponent(Session.invoke("FindById",
              "wnd[0]/usr/pwdRSYST-BCODE").toDispatch());
            Obj.setProperty("Text", "minisap");

          //-Set GUITextField Language----------------------------------
          //-
          //- session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "DE"
          //-
          //------------------------------------------------------------
            Obj = new ActiveXComponent(Session.invoke("FindById",
              "wnd[0]/usr/txtRSYST-LANGU").toDispatch());
            Obj.setProperty("Text", "DE");

          //-Press enter------------------------------------------------
          //-
          //- session.findById("wnd[0]").sendVKey 0
          //-
          //------------------------------------------------------------
            Obj = new ActiveXComponent(Session.invoke("FindById",
              "wnd[0]").toDispatch());
            Obj.invoke("sendVKey", 0);

      }

      catch (Exception e) {

      }

      finally {
        ComThread.Release();
        System.exit(0);
      }

    }

  }
Add a comment
10|10000 characters needed characters exceeded

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.