22 - SAP ABAP New Syntax
22 - SAP ABAP New Syntax
1
SAP ABAP New Syntax or ABAP 7.4 / 7.5
▪ During the release of ABAP version 7.4, SAP introduced a new approach to ABAP
programming.
▪ In this new approach of ABAP programming, SAP introduced various new ABAP
elements.
▪ This new approach to ABAP programming is called as SAP ABAP new syntax.
▪ This new approach to the ABAP programming has been introduced from ABAP version
7.4 onwards, So the SAP ABAP new syntax is also called as ABAP 7.4 / 7.5
2
SAP ABAP New Syntax or ABAP 7.4 / 7.5(Contd.)
▪ These new syntax has been added without removing the old syntax.
▪ These new syntax works in both ECC and S/4 HANA systems as it is based upon ABAP
3
Advantages
▪ SAP ABAP new syntax are more efficient and convenient way to write the code as we
4
Disadvantages
directly starts with new syntax and they have not seen the old syntax.
5
Inline Data Declarations
▪ In old way of data declaration, we need to declare the objects like variables, types,
internal tables and work areas first then we can use those objects.
▪ In the new way of data declaration, there is no need to declare the objects separately.
▪ In SAP ABAP new syntax, instead of IF statement, we can use the COND statement.
▪ In IF statement, we need to specify the variable which is getting filled in every condition.
▪ In COND statement, we need not to mention the variable which is getting filled in every
condition, so COND statement is more effective way for conditional logic rather than IF
statement.
7
SWITCH Statement as a Replacement of CASE
▪ In SAP ABAP new syntax, instead of CASE statement, we can use the SWITCH statement.
▪ In CASE statement, we need to specify the variable which is getting filled in every
condition.
▪ In SWITCH statement, we need not to mention the variable which is getting filled in
every condition.
8
String Expression as a Replacement of CONCATENATE
▪ In SAP ABAP new syntax, instead of CONCATENATE, we can use the string expressions.
▪ While using string expression, we need to use the pipe( | ) symbol at the starting and at
the end.
9
String Expression as a Replacement of CONCATENATE(Contd.)
⮚ There is no need of type casting for numeric data types as string expression works for
both character and numeric data types whereas string operation CONCATENATE is only
applicable for character data types, for numeric data types we need to do the type
casting first.
1
0
VALUE Expression as a Replacement of APPEND
▪ We use APPEND statement to insert the records at the last of the internal table.
▪ In SAP ABAP new syntax, instead of APPEND statement, we can use VALUE expression.
tables.
▪ It is a powerful utility where we can achieve the result with minimal coding.
1
1
VALUE Expression as a Replacement of APPEND(Contd.)
1. Define the type before using it with VALUE keyword. The type defined is structure type
or table type.
1
2
Use of BASE in VALUE Expression
▪ When we don’t want to overwrite the existing values of the internal table we use BASE
in value expression.
▪ The values of the BASE table acts as a initial values for the target table and after that the
▪ It is very useful in loops when we want to append the rows to the target internal table
1
3
CORRESPONDING Operator
▪ Previously to move data to from one internal table to another internal table which has a
different structure, we need to firstly pass the data from one work area to another work
area and then use the APPEND statement to insert the data to another internal table.
▪ In SAP ABAP new syntax, The CORRESPONDING operator is used to move data between
1
4
CORRESPONDING Operator( Contd.)
⮚ CORRESPONDING - Moves data between the internal tables for the matching columns.
⮚ CORRESPONDING WITH MAPPING - This is used to map the data of one column to
another column.
⮚ CORRESPONDING WITH EXCEPT - This is used to move the data of the selected matching
columns.
1
5
ALPHA Keyword With IN or OUT as a Replacement of Conversion FM’s
▪ In SAP ABAP new syntax, instead of using these function modules, we can use the
ALPHA keyword with IN which is used to add the leading zero’s and ALPHA keyword with
▪ In SAP ABAP new syntax, instead of CREATE OBJECT, we can use the NEW keyword to
1
7
LET Expression
▪ A LET expression defines variables or field symbols in an expression and assign values to
them.
⮚ Variables or field-symbols defined for LET expression can’t be used outside the scope of
the expression.
1
8
LET Expression(Contd.)
⮚ Variables or field-symbols defined for LET expressions can’t be redefined even if they are
⮚ LET expression can be used in expressions like COND, SWITCH, VALUE, NEW, REDUCE
etc.
1
9
CONV Operator
▪ Previously when we pass values to function module or class methods parameters, the
variables which are used to pass the values must have the same data type as that of
▪ If the variables don’t have the same data type, then we do the type casting by taking the
2
0
CONV Operator( Contd.)
▪ In SAP ABAP new syntax, instead of doing the type casting using helper variables and
passing helper variables, we can use CONV operator to convert the value to specified
data type.
2
1
REDUCE Operator As a Replacement of LOOP
▪ Reduce operator creates a result of specified data type after going through iterations.
▪ Previously we make a LOOP on the internal table and calculate the count, total, subtotal
etc.
▪ In SAP ABAP new syntax, instead of LOOP, we can use REDUCE operator to calculate the
2
2
REDUCE Operator As a Replacement of LOOP(Contd.)
▪ In the syntax - REDUCE = keyword, <type> = data type of the result , INIT = initial value ,
FOR = initialize iteration , THEN = increment , UNTIL = iteration end condition , NEXT =
operation.
▪ In the REDUCE syntax, even if THEN keyword is not specified the default increment value
is 1.
2
3
FILTER Operator
▪ FILTER operator is used to filter the internal table and getting the subset of data into a
▪ Previously, we filter the data by creating a loop with where condition and appending the
▪ In SAP ABAP new syntax, instead of loop with where condition and appending the
2
4
FILTER Operator(Contd.)
⮚ FILTER with single values - In this we pass the filtering values using WHERE condition and
⮚ FILTER with filter table - In this we need two internal tables. One internal table has the
actual data on which filtering is applied and another is filter internal table which has the
2
5
FILTER Operator(Contd.)
⮚ The internal table on which FILTER operator is used must have at least one sorted key or
one hash key used for access. Filter operation will not work on internal table without
⮚ EXCEPT can be used with filter statement in single values as well as filter table.
2
6
New Features of OPEN SQL
▪ ABAP data objects used in open SQL statements are called as host variables and they are
prefixed with @.
▪ We can use the conditional statements like CASE in the select list.
▪ We can use the aggregate functions like SUM, COUNT, MAX, MIN, AVG.
▪ We can use the arithmetic expressions like + , - , * , DIV, MOD, ABS, FLOOR, CEIL.
2
7
Table Expressions as Replacement of READ TABLE
▪ We use READ TABLE statement to read the first matching record from the internal table.
▪ We read a record from the internal table based upon key or index.
▪ In SAP ABAP new syntax, instead of READ TABLE, we can use the table expressions.
2
8
Table Expressions as Replacement of READ TABLE(Contd.)
▪ While using table expression, If the table entry does not exist, system throws the
exception CX_SY_ITAB_LINE_NOT_FOUND.
2
9
JOIN Improvement - Use of symbol *
▪ Previously, if we want to fetch the data of all columns of a table, we can not use * for
▪ In SAP ABAP new syntax, we can use * to fetch the data of all columns of a particular
3
0
Thank You
3
1