Welcome to the SAP ABAP Tutorials. The objective of these tutorials is to get an in-depth understanding of SAP ABAP. The tutorial starts with an overview of SAP ABAP. In addition to these tutorials, we will also cover common issues, Interview questions, and How To’s of SAP ABAP.
ABAP (Advanced Business Application Programming) is a programming language for developing applications for the SAP R/3 system, a widely-installed business application subsystem. The latest version, ABAP Objects, is object-oriented programming. SAP will run applications written using ABAP/4, the earlier ABAP version, as well as applications using ABAP Objects. SAP's original business model for R/3 was developed before the idea of an object-oriented model was widespread. The transition to the object-oriented model reflects increased customer demand for it. ABAP Objects uses a single inheritance model and full support for object features such as encapsulation, polymorphism, and persistence. ABAP language syntax
ABAP is not case sensitive.
Every statement begins with a keyword and ends with a period. ( WRITE is the keyword to print on screen )
WRITE 'Hello World!'.
Chained statements. If consecutive statements have identical parts at the beginning, then ABAP allows you to chain these statements into a single statement. First, write the identical part once and then place a colon (:). Then write the remaining parts of the individual statements separated by commas. Normal Statements:
WRITE: 'Hello', 'ABAP'.
Comments. If you want to make the entire line as a comment, then enter an asterisk (*) at the beginning of the line.
* This is a comment line
If you want to make a part of the line as a comment, then enter a double quote (“) before the comment.
WRITE 'COMMENT'. "Start of comment Create an instance of a class that implements a certain interface, but you won’t know the name of the class you want to create until run time. In Java or .NET you would have used the reflection mechanism, but can you handle this case in ABAP Here’s a short code snippet showing how: DATA: iv_classname TYPE social name. DATA: iv_interface TYPE REF TO IF_INTERFACE_NAME. DATA: gr_error TYPE REF TO cx_dynamic_check. DATA: gv_message TYPE string. iv_classname = 'CL_CLASSNAME'. TRY. CREATE OBJECT iv_interface TYPE (iv_classname). CATCH cx_sy_create_object_error INTO gr_error. gv_message = gr_error->get_text( ). WRITE /1 gv_message. CATCH cx_sy_dyn_call_param_missing INTO gr_error. gv_message = gr_error->get_text( ). WRITE /1 gv_message. ENDTRY. Let’s have a look at the code. In the first four rows, you define several variables of data types. iv_classname holds the name of the class (that’s the name which will be known only in run time) iob_object – a reference to an interface that the class you’ll instantiate implements. The other two variables are for error handling purposes. Now, you use the CREATE OBJECT ABAP statement. CREATE OBJECT iv_interface TYPE (iv_classname). Note that had you known the class name during compile time, you could use the following statement: CREATE OBJECT iv_interface TYPE CLASSNAME. The difference? No parenthesis, plus you give the class name instead of a string containing the class name. Let’s move on. In case the class does not exist on the system you’re running (or you provided a wrong class name), you’ll get the exception CX_SY_CREATE_OBJECT_ERROR, saying that the class you’re trying to instantiate couldn’t be found. In case there are missing parameters, you will get aCX_SY_DYN_CALL_PARAM_MISSING exception. CREATE OBJECT iv_interface TYPE (iv_classname) EXPORTING param1 = value1 param2 = value2. You now know a little bit about dynamically instantiating objects in your code – a great way to implement dynamic and extensible factory methods.
Parameters in ABAP
Parameters statements are almost the same as data statements but it used for the user inputs. The variables declared using parameters statement are known as parameters and these will be displayed on the selection screen while running the program. The user needs to enter or modify the values there and again continue the program execution. The syntax of parameters statement is
- parameters variable name[length] [data type] [decimals] [default value].
- parameters variable name like previous defined variable name [default value].
Parameter's statement has a lot of additions for use.
- MEMORY ID
- MATCH CODE OBJECT
- MODIF ID
- LOWER CASE
- AS CHECKBOX
- RADIO BUTTON GROUP
- FOR TABLE
- AS MATCH CODE STRUCTURE
These core tutorials will help you to learn the fundamentals of SAP ABAP. For an in-depth understanding and practical experience,explore Online SAP ABAP Training
Data Types: Data statement is used for defining variables in our ABAP programming. The syntax of data statement:
- data variable name[length] [data type] [decimals] [default value].
- data variable name like previous defined variable name [default value].
After watching different data types used in ABAP we can see the usage of data statements with some examples. Character data types used in ABAP
- Type c: ( Used for the character, the maximum length between 1- 65535 and the default value will blank)
- Type n: ( Used for numeric text, the maximum length between 1- 65535, valid values will be 1 – 9 and the default value will 0)
- Type d: ( Used for a date, fixed-length 8, valid values will be 1 – 9 and the default value will 00000000)
- Type t: ( Used for time, fixed-length 6, valid values will be 1 – 9 and the default value will 000000)
- Type x: ( Used for hexadecimal and maximum length between 1- 65535)
Numeric data types used in ABAP
- Type I: ( Used for integer, fixed-length 4, maximum decimals is 0,valid values between-231 to +231 and default value will be 0)
- Type p: ( Used for packed decimal, the maximum length between 8- 15, maximum decimals is 14, valid values between 0-9 and the default value will be 0)
- Type f: ( Used for floating-point, maximum length 8, valid values between -1E-307 to 1E308 and the default value will be 0.0)
Sample data statement declarations Data x. (Here variable x will be treated as a character because the character is the default data type) data x(2) type c . (Here variable x will be treated as a character with length 2) data x type I value 100. (Here variable x will be treated as the integer with default value 100) data x type d value 20110112. (Here variable x will be treated as date with the specified default value) By using like addition with data statement all the properties like data type, length of the previously defined variable will be assigned to the new variable. Data x1(2) type c. Data x2 like x1.