In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to analyze SAP ABAP keyword grammar diagrams and ABAP code automatic generation tool Code Composer, the content of the article is of high quality, so the editor shares it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
When I was doing SAP CRM Fiori application development, I read this book when I was learning JavaScript:
The book uses this syntax diagram to explain the syntax of JavaScript:
In fact, there is a similar syntax diagram in the ABAP help documentation, but it is hidden in an inconspicuous corner and is not well known:
Take the keyword APPEND as an example to view its grammar diagram:
Click on the hyperlink and the grammar diagram is displayed, which I think is much more intuitive than the text description in the help document:
Click the question mark to see a detailed description of each component in the picture:
We sometimes find that the ABAP code written does not work as expected by the runtime, often because of a specious understanding of the functions of the ABAP keyword described in the ABAP help documentation. If you read some keywords to help the document and find it obscure, you might as well take a look at its grammar diagram from a different point of view.
Jerry learned SAP Commerce before and found that a large number of .java files were automatically generated when setting up the development environment and executing the ant all command line to build the project. My colleagues told me that the contents of these Java files were generated based on a Java template engine called Velocity.
These files, which end with .vm in the Hybris installation package, are the template files for Velocity:
Open these template files and find that it consists of the static content shown in the blue area of the following figure and the variables shown in the red area.
When generating Java files based on these template files, variables that begin with $are replaced by the actual values calculated by the runtime, such as $currentDateTime with the timestamp of the actual execution of the ant all command-line build project.
An example of a Java file generated based on the template file shown above:
So is there a template engine like Java Velocity in ABAP?
Like JavaScript, there is a concept of string String Template in ABAP:
The ABAP string template is defined within two vertical bars, as shown in line 14 of the above figure. The string template contains static string text and ABAP variable names. At run time, these ABAP variables that act as placeholders are replaced by the values they actually contain.
The following figure is an example of a string template in JavaScript, without excessively changing the separator from the vertical bar of ABAP to single quotation marks:
Using ABAP's string template, we can also implement requirements similar to Java Velocity's dynamically generated code. Jerry's previous articles talked briefly about static and dynamic proxies for Java and SAP ABAP, as well as ABAP's attempts at aspect-oriented programming.
The source code of the ABAP class that needs to be created dynamically is pieced together with a string template, stored in the inner table lt_source, and then the keyword GENERATE SUBROUTINE POOL is called to create a temporary ABAP class whose life cycle exists only during the current session.
If you want to generate a global ABAP class, that is, it can be persisted on the ABAP server after generation, and can be opened through SE24 and SE80, the inner table containing the source code of the ABAP class implementation is passed to the creation API of the ABAP class, that is, the function SEO_CLASS_CREATE_COMPLETE.
The following code creates a new ABAP class under the $TMP package based on the contents stored in the inner table mt_sourcecode.
These are the two most commonly used ways for ABAP to automatically generate code.
In fact, there is a third way, which can be used in some SAP frameworks such as BRFplus to automatically generate ABAP classes:
Help documentation can be found through the keyword ABAP CODE COMPOSER.
The following Jerry shows how to use ABAP Code Composer to automatically generate code through a practical example.
Like Java Velocity, we automatically generate new code based on an ABAP template. Create an ABAP Include to act as a template, named ZSINGLETON:
The template code is as follows, defining the basic skeleton of an ABAP class implemented using singleton design pattern (Singleton).
Variables that start with and end with $in this ABAP template act like variables in Java Velocity, acting as placeholders, and the runtime is replaced by the actual value passed in by the caller of the template.
@ if and @ end, like Velocity's # if and # end, provide simple conditional branching processing and control when generating actual code from a template.
A total of four variables are defined in my ZSINGLETON template:
$Illuminated PARAMMAY class$
$Illuminated PARAMMAL global $
$Illuminated PARAMML interface$
$Illuminated PARAMMAL offer $
Finally, write an ABAP program and use the Code Composer consumption ZSINGLETON template to pass in the actual values of the above four variables to generate a persistent ABAP singleton class named ZCL_JERRY specified in line 18.
The following figure is the source code of the ABAP class generated through the ABAP template and ABAP Code Composer. You can see that the variables defined by $in the previous template have been replaced by the actual values passed in when the template was called to generate the ABAP class.
On how to analyze the SAP ABAP keyword grammar map and ABAP code automatic generation tool Code Composer to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.