Skip to Content

Hello community,

over a month ago I posted here an integration scenario, where FreeBASIC meets ABAP via Eclipse.

Here is now another integration scenario, where Java meets ABAP via Eclipse. This means you can code and compile your Java sources and use it via Java Native Interface (JNI) inside ABAP. To use the JNI in ABAP, I build a COM library which wrapped all JNI functions and ABAP can use COM libraries. ABAP in Eclipse offers now an ideal platform for this kind of development.

Here now the first impressions of a polyglot development with Java and ABAP inside Eclipse:

At first the Java perspective with the code.




    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;

    public class SwingGUI extends JFrame{

      //-Instance variables---------------------------------------------
        private static String strControl;
        private static SwingGUI frame;

      //-External request-----------------------------------------------
        public static String getstrControl() {
          return strControl;

        public static void resetstrControl() {
          strControl = "";

        public class btnPressActionListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
            try {
              strControl = "PressMe";
            catch (Exception ex) {


        public class btnQuitActionListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
            try {
              strControl = "Quit";
            catch (Exception ex) {


        public SwingGUI() {
          strControl = "";

          //-Press me button--------------------------------------------
            JButton btnPress = new JButton("Press me");
            btnPress.setBounds(10, 10, 295, 24);
            btnPress.addActionListener(new btnPressActionListener());

          //-Quit button------------------------------------------------
            JButton btnQuit = new JButton("Quit");
            btnQuit.setBounds(10, 34, 295, 24);
            btnQuit.addActionListener(new btnQuitActionListener());


        public static void main(String[] args) {
          frame = new SwingGUI();
          frame.setLocation(100, 50);
          frame.setSize(320, 200);
          frame.setTitle("GUI test");



As you can see, nothing special – only a window with two buttons.

At second the ABAP perspective with the code.



  Report zJavaTest.

    Include zCOMJavaIncl.

    PerForm RunJava.

    Include zCOMJavaInclSubs.


"-Subroutines begin-----------------------------------------------------

    Form MyJavaProc.

        Data strClazz Type i.
        Data Args Type i.
        Data Clazz Type i.
        Data Mid Type i.
        Data Control Type i.
        Data ResetControl Type i.
        Data strRes Type i.
        Data ResStr Type String.

      "-Call Java main method-------------------------------------------
        PerForm JNI_FindClass Using 'java.lang.String' Changing strClazz.
        PerForm JNI_NewObjectArray Using 1 strClazz 0 Changing Args.
        PerForm JNI_FindClass Using 'SwingGUI' Changing Clazz.
        PerForm JNI_GetStaticMethodID Using Clazz 'main'
          '([Ljava.lang.String;)V' Changing Mid.
        PerForm JNI_CallStaticVoidMethodA Using Clazz Mid Args.

      "-Get methods for event loop--------------------------------------
        PerForm JNI_GetStaticMethodID Using Clazz 'getstrControl'
          '()Ljava.lang.String;' Changing Control.
        PerForm JNI_GetStaticMethodID Using Clazz 'resetstrControl'
          '()V' Changing ResetControl.

      "-Event loop------------------------------------------------------
        While ResStr <> 'Quit'.
          PerForm JNI_CallStaticObjectMethodA Using Clazz Control 0
            Changing strRes.
          PerForm Sleep Using 128.
          PerForm GetString Using strRes Changing ResStr.

            Case ResStr.

              When 'PressMe'.

                "-Your PressMe routine here-----------------------------
                  Call Function 'POPUP_TO_INFORM' Exporting
                    titel = 'PressMe' txt1 = 'Button pressed' txt2 = ''.
                  PerForm JNI_CallStaticVoidMethodA Using Clazz
                    ResetControl 0.




    Form RunJava.

        Data JVMDLL Type String.
        Data hJVM Type i Value 0.
        Data rc Type i Value 0.

      Create Object oJava 'COMJAVA'.
      If sy-subrc = 0 And oJava-Type = 'OLE2'.

        Call Method Of oJava 'Is64WOW' = rc.
        If rc <> 0.
          JVMDLL = 'C:\\Program Files (x86)\\Java\\jre7\\bin\\client\\jvm.dll'.
          JVMDLL = 'C:\\Program Files\\Java\\jre7\\bin\\client\\jvm.dll'.

        PerForm JVM_SetInitArgsOption Using 1

        PerForm OpenJavaVM Using JVMDLL Changing rc.
        If rc = JNI_OK.

          "-Call your Java routine--------------------------------------
            PerForm MyJavaProc.

          PerForm CloseJavaVM Changing rc.


        Free Object oJava.
        System-Call ObjMgr PerForm Garbage Collection.



"-Subroutines end-------------------------------------------------------

Okay, the coding technique is not really state of the art, but this example show us, how easy it is possible to combine the Java world on the presentation server and the ABAP world on the application server – and all in one IDE.

Last but not least the result, a Java Swing window with different elements, here two buttons, controls the ABAP program.


And with this method it is possible to include the Java source and build the class file on the fly, with the method CreateJavaFile, the property set JavaCompiler and the method CompileJava.

The JNI is not an easy to understand Interface, but if you get used the ways of JNI thinking, it is no more difficult than other interfaces.

Even at the risk of repeating myself, ABAP in Eclipse offers a wide horizont of polyglot programming in one IDE. Now it is not longer necessary to switch between different IDEs. I like it very much ๐Ÿ™‚



To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Daniel Ruiz

    Hi Stefan,

    would you have the JNI code in a github or something or willing to share it? – I’d like to try using and testing the stuff of this post at home in my trial system.

    quite cool man.




Leave a Reply