0% found this document useful (0 votes)
65 views5 pages

SAP ABAP Guide

SAP ABAP GUIDE

Uploaded by

Bittoo Bose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views5 pages

SAP ABAP Guide

SAP ABAP GUIDE

Uploaded by

Bittoo Bose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SAP ABAP Guide

ABAP - New ABAP Syntax


New ABAP Syntax for S4HANA
1. Inline Declarations
One of the most significant improvements in the new ABAP syntax is the ability to declare
variables inline. This feature helps to write cleaner and more concise code.

Old Syntax 📜:

DATA: lv_value TYPE i.


lv_value = 5.

New Syntax 💡:

DATA(lv_value) = 5.

With inline declarations, you can define and initialize variables in a single line, making your
code more readable and reducing clutter.

2. Table Expressions

Table expressions allow you to access table entries directly without using explicit READ
TABLE statements, streamlining your code.

Old Syntax 📜:

READ TABLE lt_table INTO ls_row WITH KEY id = lv_id.

New Syntax 💡:

ls_row = lt_table[ id = lv_id ].


The new syntax aligns with modern ABAP programming practices, making use of inline
declarations and more SQL-like data manipulation.

Old Syntax 📜:

LOOP AT lt_table INTO ls_row.


v_sum = v_sum + ls_row-qty.
ENDLOOP.
New Syntax 💡:

SELECT SUM( itm~qty) AS v_qty


FROM @lt_table AS itm
WHERE id = @lv_id
INTO @DATA(V_QTY).
This feature not only makes the code shorter but also enhances performance by reducing the
number of lines executed.

3. String Templates
String templates simplify string handling by embedding expressions directly within a string. This
is especially useful for creating dynamic strings.

Old Syntax 📜:

CONCATENATE 'Hello' lv_name '!' INTO lv_greeting.

New Syntax 💡:

lv_greeting = |Hello { lv_name }!|.


The new syntax simplifies the operation using a compound assignment operator (+=). This
operator adds the value of v_amt directly to v_sum, making the code more concise and easier to
read.

Old Syntax 📜:

v_sum = v_sum + v_amt.

New Syntax 💡:

v_sum += v_amt.

4. FOR Loop Expressions


The new FOR loop expressions enable more functional and concise loop constructs, often used
within DATA declarations and internal table operations.

Old Syntax 📜:

DATA: lt_result TYPE TABLE OF i.


LOOP AT lt_source INTO lv_source.
APPEND lv_source TO lt_result.
ENDLOOP.

New Syntax 💡:
DATA(lt_result) = VALUE #( FOR lv_source IN lt_source ( lv_source ) ).
This syntax allows you to create and populate internal tables in a single statement, leading to
more efficient and readable code.

5. Conditional Logic with SWITCH and COND


The SWITCH and COND expressions provide more powerful and readable conditional logic.

SWITCH Example:

Old Syntax 📜:

IF lv_value = 1.
lv_result = 'One'.
ELSEIF lv_value = 2.
lv_result = 'Two'.
ELSE.
lv_result = 'Other'.
ENDIF.

New Syntax 💡:
lv_result = SWITCH #( lv_value WHEN 1 THEN 'One' WHEN 2 THEN 'Two' ELSE 'Other' ).
COND Example:

Old Syntax 📜:

IF lv_value > 0.
lv_sign = 'Positive'.
ELSEIF lv_value < 0.
lv_sign = 'Negative'.
ELSE.
lv_sign = 'Zero'.
ENDIF.

Old Syntax 📜:

lv_sign = COND #( WHEN lv_value > 0 THEN 'Positive' WHEN lv_value < 0 THEN 'Negative'
ELSE 'Zero' ).

6. SQL Enhancements for Database Access


ABAP 7.4 and above bring several improvements to Open SQL, including new clauses and
inline declarations.

Old Syntax 📜:

SELECT * FROM sflight INTO TABLE lt_flights WHERE carrid = lv_carrid.


New Syntax 💡:

SELECT FROM sflight FIELDS * INTO TABLE @DATA(lt_flights) WHERE carrid =


@lv_carrid.

These enhancements streamline database access code and make it more consistent with the rest
of the ABAP syntax.

7. Internal Tables and APPEND Statement

The new syntax introduced in modern ABAP allows for a more concise and readable way to
populate internal tables. This is often referred to as inline declaration and value expressions.
Here’s the equivalent example using the new syntax:

Old Syntax 📜:

DATA: lt_data TYPE TABLE OF ty_data,


ls_data TYPE ty_data.

ls_data-id = 1.
ls_data-value = 'aaa'.
APPEND ls_data TO lt_data.

ls_data-id = 2.
ls_data-value = 'bbb'.
APPEND ls_data TO lt_data.

New Syntax 💡:

DATA(lt_data) = VALUE #(
( id = 1 value = 'aaa' )
( id = 2 value = 'bbb' )
).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy