Few day before I found an interesting Blog on SAP Java Connector outbound connection by Gregor wolf . https://weblogs.sdn.sap.com/pub/wlg/739 . I then thought of creating Java Editor inside ABAP! I have created one using simple ABAP programs which will run using the JDK stored locally. The theme of this blog is to Create, Modify, Compile and Execute java programs inside ABAP particularly inside ABAP editor.
Part1: Creating java File:
Part1 uses program zjavacreate.
In Part 1 java file is created. Using the editor-call function for Itab we can call a blank text area in which we can write our java program. On saving the program in the editor area the Itab gets upload which is saved into the local disk as .java file using Function module GUI_DOWNLOAD.
Getting Class File Name
Editor with default PSVM
Code is entered for sample.java and saved (ctrl+s)
Program logic for java file Creation.
Part2 uses program zjavamodify
We can modify an existing java file. The java file is loaded into an Itab using Function module GUI_UPLOAD. The editor-call for this itab will fill the editor area with the existing java file which is modified and then saved back in the same location using GUI_DONLOAD.
Modify existing java file:
Sample File is selected for modification
Sample.java is modified and saved
(Note the error System.out.println (Modify here);
Program logic for modification
Compilation is the most important step. Initially a batch file is created with the content as in the following image. The jCompiler class file and class path is created and stored in the working directory of sapgui logon which is responsible for the creation of error and output file for the newly created java file. The Function module dsvas_ws_execute_50 is used to invoke the batch file which will create an error report file and an output report file. On execution the batch file appears and disappears.
Batch file in the notepad mode
Bat file pops up during compilation and disappears
Program logic for compilation
2.3: Output Display
The content of error or output file is put into an Itab using GUI_UPLOAD and displayed in the list area.
Sample. java with Error After correction and recompilation
Program logic for output display
Note: While using these programs be cautious in setting the path for java file and also store the jCompiler file, class path and class file in the sapgui logon working directory also your batch file need to be created in that directory only. Also please note that awt is not handled!