Talk about the relationship between the two programming languages ​​C language and ABAP

Why should this article put C language and ABAP together, instead of other languages ​​such as Java and ABAP? Because the bottom layer of ABAP language is based on C/C++ implementation, including its keywords (such as the simplest keyword WRITE C++ implementation has more than 2,000 lines) and virtual machine (ABAP Runtime). A group of computer scientists within SAP invented the great language ABAP, and various SAP applications implemented by it have helped customers in more than 180 countries and regions around the world to run their businesses better.

Through Google we can search for some introductions about these SAP computer scientists, such as this link :

For example, the sc_km_check_feature_2 decorated with kernel module as shown in the figure below, and each ABAP keyword, its C language implementation code can be viewed in the Netweaver system inside SAP, but on the client system, it is in the form of binary object files Storage, cannot view source code.

The purpose of this article is to deepen the understanding of the language by ABAP consultants through some introductions to the C language and the ABAP compilation process.

Write a Hello World program in C language and save it as study.c:

Compile with the command line gcc ./study.c --verbose , the parameter verbose can be used for us to view the compilation details. The above command line produces a long string of output on my Ubuntu system:

We can analyze step by step. First use the parameter -E to view the target file study.i generated by preprocessing:

gcc -E study.c -o study.i

It can be seen that the source code file is only 78 bytes, and the output file generated after compilation and preprocessing has 17116 bytes.

Why is it expanding so much? The reason is because the first line of my source code file, #include<stdio.h> stdio.h replaced by the preprocessor with the actual content of stdio.h, and if there is a declaration of #include other files in stdio.h, this replacement The process executes recursively. So we can’t see the source code part written in study.c until the end of study.i.

The first line of statement #include<stdio.h> in the source code file study.c, please remember that ABAP will be mentioned later.

Use the command line gcc -S to view the assembly code generated after compiling study.c:

Seeing these pushq, popq, %rbp , Jerry couldn’t help but think of the time when I and other brothers in the dormitory sat in the last row of the classroom and read the weekly sports newspaper in the undergraduate assembler programming class.

After working for more than ten years, Jerry has to admit that the computer courses offered by the undergraduate at that time, such as data structures, operating systems, computer composition principles, compilation principles, assembly programming, and computer graphics are all useful. May give you more time to learn these basic theoretical knowledge.

Although Jerry didn’t study assembler programming well at the beginning, at least I kept the textbooks properly, in case the company’s work arrangement requires me to pick up the things I learned in school more than ten years ago.

Let’s talk about ABAP.

SAP note 1230076 Generation of ABAP loads: Tips for the analysis introduces a tool program: RSDEPEND. This note mentions that even the simplest-looking ABAP Hello World report actually depends on many standard Repository objects, which depend on our Suppose we call them A, B, C. Suppose that any one of A, B, and C has been changed. For example, A is an include program, which uses a DDIC structure. At a certain time, the system imports a Transport Request, which contains the DDIC for this DDIC. The structure is changed, then the load of this simplest Hello World report becomes the obsolete state. Before re-executing the report, ABAP Runtime (translated into ABAP 运行时Chinese) will automatically do a load invalidation operation to generate a latest version of load.

What is ABAP load? See the official definition in ABAP help:

In the ABAP environment, a load describes a binary representation of a repository object which is optimized for fast access, in the memory or on the database.

Translated into Chinese: ABAP load is the binary representation of the Repository object, which is specially optimized for fast access to the ABAP environment, and can be stored in a database table or loaded in memory.

Let’s use a practical example to understand what happens when an ABAP report is activated and run.

Create a very simple transparent table ZLOADTEST:

Write a simple report named ZTESTLOAD. The source code of the report is stored in the DATA field of the table REPOSRC in a compressed format.

The source code of the test report is very simple, read all the data in the table:

Activate this simple report (yes, in the ABAP world, we used to say activate, not compile). The ABAP load generated after activation is stored in the fields LDATA and QDATA of the table REPOLOAD.

The content stored in these two fields is the storage form of the ABAP load mentioned in the previous ABAP help in the database table.

Menu Goto->Navigate to->Switch to Classic Debugger :

Goto->System Areas->Internal Information :

Enter CONT in the System Area area, and you can see the instructions contained in ABAP load in the NAME column of the figure below. Of course, unlike the open source JVM, the JVM bytecode instruction set can be found online, and these ABAP load instructions are SAP internal, so they cannot be explained here.

Then execute the aforementioned tool report RSDEPEND, enter the parameter program name = ZTESTLOAD , and get the result. The ABAP Load timestamp of the test report is 07:21:02. The standard Include that this report depends on is:

  • <REPINI>

  • <SYSINI>

  • <SYSSEL>

  • DB__SSEL

It can be seen that every standard ABAP report automatically includes these includes. If the developer explicitly includes any of them, he will encounter a syntax error:

Module %_PF_STATUS is already defined as a OUTPUT module

Do you think this <REPINI> is very similar to the #include<stdio.h> mentioned in the C language section above?

Next we do a few more rounds of testing.

Test 1

Modify the description of the transparent table, and then reactivate the transparent table.

Execute RSDEPEND, you can see that only the Last Changed field of the transparent table has changed, and the ABAP Time Stamp and Screen Time Stamp are unchanged. This is the result we expect, because we only modified the description information of the transparent table, not the structure. .

Execute the test report ZTESTLOAD again, use RSDEPEND to detect, and find that the ABAP Load timestamp of the test report has not changed, which means that even if the description information of the dependent transparent table changes, the ABAP report using the transparent table does not need to be recompiled, because Transparent table description information does not need to be used during report execution.

Test 2

Add a new column to the transparent table and activate it again.

At this time, it is found through RSDEPEND that all the three timestamps of the transparent table have changed, as shown in the blue rectangle in the following figure. However, the timestamp of the test report ABAP Load itself remains unchanged, which is reasonable, because after we added a new column to the transparent table, the test report has not been executed.

After executing ZTESTLOAD again, this time it is found that its ABAP Load has been automatically invalidated, and the timestamp has changed from 07:21:02 to 07:36:02.

This also explains a phenomenon: some friends have observed that when the system is just upgraded, or after a batch of new transmission requests are imported into the system, the system response speed is very slow when the SAP application is used for the first time. The reason is actually explained by the two tests above: the system spends time doing related ABAP Load invalidation. The system cannot respond to user requests until these Load invalidations that the application depends on are over.

In order to avoid users waiting for a long time when using the application for the first time, the transaction code SGEN can be used to perform Load invalidation in advance. For the detailed usage of SGEN, please refer to the following article

I hope this article will be helpful to consultants who want to understand some of the implementation details of the ABAP language.

Summarize

ABAP is the programming language adopted for the realization of business logic and underlying system platform of SAP products such as CRM, S/4HANA, etc. based on Netweaver technology stack. ABAP is a high-level object-oriented programming language whose runtime and kernel are implemented based on C/C++. This article introduces some low-level implementation details of the ABAP language through some specific ABAP report examples.

The text and pictures in this article are from InfoQ

loading.gif

This article is reprinted from https://www.techug.com/post/talk-about-the-relationship-between-c-language-and-abap-2.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment