Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ABAP
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==ABAP syntax== This brief description of the ABAP syntax begins with the ubiquitous [["Hello, World!" program|"Hello"]]. ===Hello world=== <syntaxhighlight lang="abap"> REPORT TEST. WRITE 'Hello, World!'. </syntaxhighlight> This example contains two statements: <code>REPORT</code> and <code>WRITE</code>. The program displays a list on the screen. In this case, the list consists of the single line "Hello, World!". The <code>REPORT</code> statement indicates that this program is a report. This program could be a module pool after replacing the <code>REPORT</code> statement with <code>PROGRAM</code>. ===Chained statements=== Consecutive statements with an identical first (leftmost) part can be combined into a "chained" statement using the chain operator <code>:</code>. The common part of the statements is written to the left of the colon, the differing parts are written to the right of the colon and separated by commas. The colon operator is attached directly to the preceding token, without a space (the same applies to the commas in the token list on, as can be seen in the examples below). Chaining is often used in <code>WRITE</code> statements. <code>WRITE</code> accepts just one argument, so if for instance you wanted to display three fields from a structure called FLIGHTINFO, you would have to code: <syntaxhighlight lang="abap"> WRITE FLIGHTINFO-CITYFROM. WRITE FLIGHTINFO-CITYTO. WRITE FLIGHTINFO-AIRPTO. </syntaxhighlight> Chaining the statements results in a more readable and more intuitive form: <syntaxhighlight lang="abap"> WRITE: FLIGHTINFO-CITYFROM, FLIGHTINFO-CITYTO, FLIGHTINFO-AIRPTO. </syntaxhighlight> In a chain statement, the first part (before the colon) is not limited to the statement name alone. The entire common part of the consecutive statements can be placed before the colon. Example: <syntaxhighlight lang="abap"> REPLACE 'A' WITH 'B' INTO LASTNAME. REPLACE 'A' WITH 'B' INTO FIRSTNAME. REPLACE 'A' WITH 'B' INTO CITYNAME. </syntaxhighlight> could be rewritten in chained form as: <syntaxhighlight lang="abap"> REPLACE 'A' WITH 'B' INTO: LASTNAME, FIRSTNAME, CITYNAME. </syntaxhighlight> ===Comments=== ABAP has 2 ways of defining text as a [[Comment (computer programming)|comment]]: * An [[asterisk]] (*) in the leftmost column of a line makes the entire line a comment * A [[double quotation mark]] (") anywhere on a line makes the rest of that line a comment Example: <syntaxhighlight lang="abap"> *************************************** ** Program: BOOKINGS ** ** Author: Joe Byte, 07-Jul-2007 ** *************************************** REPORT BOOKINGS. * Read flight bookings from the database SELECT * FROM FLIGHTINFO WHERE CLASS = 'Y' "Y = economy OR CLASS = 'C'. "C = business (...) </syntaxhighlight> ===Spaces=== Code in ABAP is whitespace-sensitive. <syntaxhighlight lang=abap> x = a+b(c). </syntaxhighlight> assigns to variable x the substring of the variable a, starting from b with the length defined by the variable c. <syntaxhighlight lang=abap> x = a + b( c ). </syntaxhighlight> assigns to variable x the sum of the variable a and the result of the call to method b with the parameter c. ===ABAP statements=== In contrast with languages like C/C++ or Java, which define a limited set of language-specific statements and provide most functionality via libraries, ABAP contains an extensive amount of built-in statements. These statements traditionally used sentence-like structures and avoided symbols, making ABAP programs relatively verbose. However, in more recent versions of the ABAP language, a terser style is possible.<ref>{{Cite web |url=http://help.sap.com/abapdocu_740/en/abenmesh_for_abexa.htm |title=Example of an ABAP program with many expressions |access-date=2015-06-19 |archive-date=2015-06-19 |archive-url=https://web.archive.org/web/20150619113952/http://help.sap.com/abapdocu_740/en/abenmesh_for_abexa.htm |url-status=live}}</ref> An example of statement based syntax (whose syntax originates in COBOL) versus expression-based syntax (as in C/Java): <syntaxhighlight lang=abap> ADD TAX TO PRICE. * is equivalent to PRICE = PRICE + TAX . </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)