In this post, you will learn about Inline Data Declarations. The inline data declarations are available from ABAP release 7.40.
Declaring data inline means, declaring the data variables, tables, field symbols, etc. in the first statement where they are used as an operand.
In the below example, the variable lv_number_of_authors is first declared and then used in the following statement.
DATA lv_number_of_authors TYPE i.
lv_number_of_authors = 2.Instead of this, you can write as below. This is an inline data declaration.
DATA(lv_number_of_authors) = 2.In SAP, wherever operands are used, the inline declaration is possible. This is basically, instead of a programmer defining the variables’ type explicitly, allowing the compiler to decide the type.
So, without writing too much about it, I will just leave you with examples of inline data declarations.
| Context | Explicit Data Declaration | Inline Data Declaration |
|---|---|---|
| Variables | DATA lv_number_of_authors TYPE i.lv_number_of_authors = 2. | DATA(lv_number_of_authors) = 2. |
| Variables | DATA lv_var2.lv_var2 = lv_var1. | DATA(lv_var2) = lv_var1. |
| Looping on Internal Tables | DATA ls_work_area LIKE LINE OF lt_itab.LOOP AT lt_itab INTO ls_work_area."Processing stepsENDLOOP. | LOOP AT lt_itab INTO DATA(ls_work_area)."Processing stepsENDLOOP. |
| Looping on Internal Tables | FIELD-SYMBOLS <fs_row> LIKE LINE OF lt_itab.LOOP AT lt_itab ASSIGNING <fs_row>."Processing stepsENDLOOP. | LOOP AT lt_itab ASSIGNING FIELD-SYMBOL(<fs_row>)."Processing stepsENDLOOP. |
| Temporary Internal Table | DATA: lt_tmp_table LIKE lt_itab.lt_tmp_table = lt_itab. | DATA(lt_tmp_table) = lt_itab. |
| Reading Internal Table | DATA ls_work_area LIKE LINE OF lt_itab.READ TABLE lt_itab INTO ls_work_area INDEX 1.IF sy-subrc EQ 0."Code for successful READELSE."Code for failed READENDIF. | READ TABLE lt_itab INTO DATA(ls_work_area) INDEX 1.IF sy-subrc EQ 0."Code for successful READELSE."Code for failed READENDIF. |
| Reading Internal Table | FIELD-SYMBOLS <fs_row> like LINE OF lt_itab.READ TABLE lt_itab ASSIGNING <fs_row> INDEX 1.IF sy-subrc EQ 0."Code for successful READELSE."Code for failed READENDIF. | READ TABLE lt_itab ASSIGNING FIELD-SYMBOL(<fs_row>) INDEX 1.IF sy-subrc EQ 0."Code for successful READELSE."Code for failed READENDIF. |
| Reading Internal Table | Note:Old READ statement is used for demonstration.New READ syntax can be used as shown here. | TRY.DATA(ls_work_area1) = lt_itab[ 1 ]."Code for successful READCATCH cx_sy_itab_line_not_found."Code for failed READENDTRY. |
| SELECT Query | TYPES:BEGIN OF ty_fls,carrid TYPE sflight-carrid,connid TYPE sflight-connid,fldate TYPE sflight-fldate,END OF ty_fls.DATA lt_flights TYPE STANDARD TABLE OF ty_fls.SELECT carrid connid fldateFROM sflightINTO TABLE lt_flights. | SELECT carrid, connid, fldateFROM sflightINTO TABLE @DATA(lt_flights). |
| Method Call | DATA lv_result TYPE char5. sample_method(EXPORTING iv_input = iv_testIMPORTING iv_result = lv_result ). | sample_method(EXPORTING iv_input = iv_testIMPORTING iv_result = DATA(lv_result) ). |
| Support Variable | DATA lv_count TYPE i.FIND 'J' IN 'JAGDISH' MATCH COUNT lv_count. | FIND 'J' IN 'JAGDISH' MATCH COUNT DATA(lv_count). |
| Objects | DATA lo_obj TYPE REF TO lcl_abap.CREATE OBJECT lo_obj. | DATA(lo_obj) = NEW lcl_abap( ). |
| Factory ALV, Object, and Exceptions | DATA : | SELECT * FROM scarr INTO TABLE @DATA(lt_out_tab). |
Declaring data using this method reduces the number of lines of code, changes like adding a field to the structure are easy to implement and it gives flexibility to the programmer and eliminates the need to use too many helper variables.
Read about more such ABAP expressions and exciting new syntaxes: ABAP Expressions (7.4+)
If you like the content, please subscribe…