Java的字节码和ABAP load的比较

I use this small blog to help my new colleagues on board who have Java programming background to understand the hello world example written in ABAP.

Hello World example in Java

The following example could be done in pure text editor without Java IDE. You should have JDK installed as prerequisite and corresponding environment variable setup correctly.

Once done, type javac -version in command line, you should see the following output: ( result may vary based on your JDK version )

Java的字节码和ABAP load的比较

In my laptop the javac.exe is in this folder:

Java的字节码和ABAP load的比较

(1) Create a folder in c:\temp\testPackage.
(2) Create a file HelloWorld.java in text editor with source code below:

package testPackage;
import tool.Tools;
public class HelloWorld {
	public HelloWorld() {
	}
	static public void main(String[] arg){
		System.out.println("Hello World");
		Tools.Print();
	}
}

Create another folder in C:\temp\tool.
And another Tools.java:

package tool;

public class Tools{
	static public void Print(){
		System.out.println("I am tool!");
	}
}

This example shows that the HelloWorld class has dependency on Tools class.

(1) Now compile HelloWorld class via javac:

Java的字节码和ABAP load的比较

Once done, HelloWorld.class is generated:

Java的字节码和ABAP load的比较

Also the same for Tools.class, even though we do NOT manually compile Tools.java via javac.

Java的字节码和ABAP load的比较

(2) Now make some change on Tools.java:

Java的字节码和ABAP load的比较

And execute HelloWorld, still the old string before change is printed:

Java的字节码和ABAP load的比较

(3) Compile Tools.java again, new version of Tools.class is generated.

Java的字节码和ABAP load的比较

This time execute HelloWorld and you could observe the new string printed out.

Java的字节码和ABAP load的比较

And the byte code for HelloWorld is still unchanged.

Java的字节码和ABAP load的比较

Byte Code in ABAP – ABAP Load

The following texts are copied from ABAP help:

Result of generating an ABAP program using ABAP Compiler. The statements in the byte code are associated with C functions. When the ABAP program is executed, the byte code is loaded into the PXA as the program load and interpreted by the ABAP runtime environment (virtual machine), which accesses the associated C functions.

Java的字节码和ABAP load的比较

Let’s repeat the same test in ABAP.

(1) Create a new include ZTOOL and activate it:

form print.
 WRITE: / 'Hello World.'.
endform.

And create a new HelloWorld report and activate it as well.

REPORT ZHELLOWORLD.
INCLUDE ztool.

START-OF-SELECTION.
PERFORM print.

(2) Execute report RSDEPEND to analyze the dependency of report ZHELLOWORLD. ( You can find some examples how to use this report RSDEPEND from blog Use report RSDEPEND to analyze ABAP load dependencies )

The result shows that ZHELLOWORLD has dependency on ZTOOL. The timestamp of ZHELLOWORLD is larger than ZTOOL since it is activated later than ZHELLOWORLD.

Java的字节码和ABAP load的比较

(3) Make some changes on ZHELLOWORLD, for example add one line comment and activate it again.

This time the timestamp of ZHELLOWORLD changes, however ZTOOL remains unchanged.

Java的字节码和ABAP load的比较

(4) Now make changes on ZTOOL, activate the change. Don’t touch ZHELLOWORLD.

This time the timestamp of ZHELLOWORLD is also changed which equals exactly to the change timestamp of ZTOOL.

Java的字节码和ABAP load的比较

The generated ABAP load for a given report could be found from table REPOLOAD:

Java的字节码和ABAP load的比较

Further reading

I have written a series of blogs which compare the language feature among ABAP, JavaScript and Java. You can find a list of them below:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
Java的字节码和ABAP load的比较

上一篇:SAP CRM WebClient UI和ABAP Webdynpro页面的互相跳转


下一篇:一步步创建ABAP post exit增强