As we have seen in previous articles that we use ABAP as programing language for SAP, in this article we will see some basic syntax that we will have to use. The ABAP programming contains ABAP statements and comments. Some Introductory statements of a Program and their syntax are as below:
Statement | Description | Syntax |
CLASS-POOL | Introduces a Class Pool | CLASS-POOL [MESSAGE-ID id]. |
FUNCTION-POOL | Introduces a Function Pool | FUNCTION-POOL name of function module like ZFM_BILL_FUNCTION. |
INTERFACE-POOL | Introduces an Interface Pool | INTERFACE-POOL. |
PROGRAM | Introduces a Subroutine Pool or Module Pool | PROGRAM name of the program like SAPMZ_BILL_PROGRAM. |
REPORT | Introduces An Executable Program | REPORT name of the report like ZBILL_REPORT. |
TYPE POOLS | Introduces a Type Pool | TYPE-POOLS name of type pool like SLIS. |
Things to be consider while writing statements in ABAP:
- ABAP Editor will automatically convert all the text of code to Uppercase weather the code written in lowercase or uppercase except the text strings which are written in single quotation marks.
- There is no restriction on the layout of statements, you can type multiple code statements in a single line, or single line code to multiple lines.
Colon Notation
You can chain together consecutive statement with the help of colon (:) operator and commas which are used to terminate a statement. For example
WRITE ‘Welcome’. WRITE ‘To’. WRITE ‘Technocrats Club’.
Now if you use Colon Notation you can chain together these statements
WRITE: ‘Welcome’, ‘To’, ‘Technocrats Club’.
Comments
There are two types of comments in SAP-ABAP
Full Line Comment: By Placing an asterisk (*) sign at the first position of line of source code, you can comment the whole statement in that line. For example:
* Technocrats club is blogging site
Partial Line Comment: By entering a double quote (“) after a statement. For example:
WRITE ‘HELLO’ . * Technocrats club is blogging site
Both the Comments don’t need to be terminated by a period because they may not extend across more than one line.
Blank Lines
The SKIP command is used to insert a blank line in output of a Report. For Example:
WRITE 'This is the 1st line'. SKIP. WRITE 'This is the 2nd line'.
The above SKIP command produces the following output −
This is the 1st line
This is the 2nd line
To insert multiple blank lines in Report output.
SKIP number_of_lines.
The SKIP command can also position the cursor on a desired line on the page.
SKIP TO LINE line_number.
This command is used to dynamically move the cursor up and down on the page.
Inserting Lines
ULINE command is used to insert a horizontal line across the output. For Example:-
WRITE 'Technocrats Club'. ULINE.
The above code produces the following output:-
Technocrats Club
__________________
Syntax to show Different Messages in SAP ABAP
MESSAGE command is used to display different type of messages like Error Message, Warning Message, any Information Message, Success or Abort message etc. to user. The message is defined by a Message ID which is specified in the REPORT statement at the beginning of program.
Message ID: The message ID is a code that defines a set of 1,000 messages and the program will access those messages when the MESSAGE command is used.
The messages are numbered from 000 to 999. If we associate with each number, then a message is text up to a maximum of 80 characters. When message number is called, the corresponding text is displayed.
There are different types of Messages to show in SAP ABAP which are shown below.
Message Code | Type | Description |
A | Abend or Termination | This message class is used to terminate or cancel the transaction that the user is currently using. This message is displayed in modal dialogue box. |
E | Error | This message class is used to show any error message in program when the system detects any error in source code and the application halts at its current point. It is either displayed in a separate dialogue box or in status bar of screen. |
I | Information | This message class is used to show any information or acknowledgement according to requirement. It is display in the modal dialogue box. Further transaction will continue after pressing Enter Key. |
W | Warning | W messages displayed in the status bar of screen. It will interrupt the transaction so that user can make some corrections. To continue the application, users have to press the Enter Key. W messages are similar to E messages. |
S | Success | S messages do not interrupt the program. This message gives information to user at the bottom of the screen in the status bar. The information displayed is positive in nature and it is just meant for user feedback. |
X | Abort | This message aborts the program and generates an ABAP short dump. |
Basic Syntax to show a message in ABAP:
MESSAGE ‘ <message in single quotes>’ TYPE ‘<message character code>’.
Following are the Syntax’s for different messages in SAP ABAP:-
Abend Message
MESSAGE 'This message terminates the transaction.' TYPE 'A'.
Error Message
MESSAGE 'Error Occurs !!’ TYPE 'E'.
Information Message
MESSAGE 'Information: Tomorrow is holiday of second Saturday.' TYPE 'I'.
Success Message
MESSAGE 'Completed Successfully..' TYPE 'S'.
Abort Message
MESSAGE ‘Short dump occurs in program.' TYPE 'X'.
Let me know your thoughts on this article in the comments 🙂