Inline Declarations in ABAP 7.4

3
10305

Dear SAPLearners,

DATA TYPE declarations is the first thing we do when we start ABAP coding. We declare the variables at the start of the subroutine, method and report program etc.. Most of the program lines we write are only for these data type declarations.

With ABAP 7.4 version, these data type declarations can be completely avoided. Whaat..? No more DATA TYPE declaration ? then How my ABAP code works with out them ? Don’t worry Inline Declarations will help and save you from those extra keyboard strokes for DATA TYPE declarations.

ABAP 7.4

In this blog you will learn about Inline Declarations in ABAP 7.4. There are many new features introduced in ABAP 7.4 and the ABAP stack is optimized for SAP HANA.

Inline Declarations

Now you can declare the variables and field-symbols at the same position where you are using them. Inline declarations are possible only for DATA and FIELD-SYMBOL.

1. LEFT ASSIGNMENT

Old Syntax

DATA lv_name TYPE string.
 
lv_name = 'SAPLEARNERS.COM'.

New Syntax

DATA(lv_name) = 'SAPLEARNERS.COM'.

2. LOOP STATEMENT

Old Syntax

DATA: lw_mara TYPE ty_mara, 

LOOP AT lt_mara INTO lw_mara. 
  WRITE: lw_mara-matnr,lw_mara-ernam. .... 
ENDLOOP.

New Syntax

LOOP AT lt_mara INTO DATA(lw_mara). 
   WRITE: lw_mara-matnr,lw_mara-ernam. .... 
ENDLOOP.

3. READ STATEMENT

Old Syntax

DATA: lw_mara TYPE ty_mara. 

READ TABLE lt_mara INTO lw_mara INDEX 1.

New Syntax

READ TABLE lt_mara INTO DATA(lw_mara) INDEX 1.

 4. SELECT STATEMENT

Old Syntax

TYPES: BEGIN OF ty_mara, 
       matnr TYPE matnr, 
       ersda TYPE ersda, 
       ernam TYPE ernam, 
       laeda TYPE laeda, 
       aenam TYPE aenam, 
       END OF ty_mara. 

DATA: lt_mara TYPE STANDARD TABLE OF ty_mara. 

SELECT matnr 
       ersda 
       ernam 
       laeda 
       aenam FROM mara 
             INTO TABLE lt_mara UP TO 10 ROWS.

New Syntax

SELECT matnr 
       ersda 
       ernam 
       laeda 
       aenam FROM mara 
             INTO TABLE @DATA(lt_mara) UP TO 10 ROWS.

Also Read: LET keyword in ABAP 7.4

So, now you know this new ABAP 7.4 feature, try and implement it next time you write any ABAP code and let me know how you feel about it.

Are you working on SAP ABAP 7.4?

To answer this question, log on to your SAP system.

  • In the menu bar navigate to System → Status.
  • In the popup window, under SAP system data section click on display button under “Product Version” field.

You can see list of installed software component versions like below

SAP Netweaver 7.40

From list of installed software components, look for the Release version of SAP_BASIS and SAP_ABA components to check the SAP Netweaver version.

Congrats! You have successfully learned about new syntax in ABAP 7.4 and stay tuned for more tutorials.

Please feel free to comment and let us know your feedback. Subscribe for updates