One of the most useful concepts introduced in SAP NetWeaver 7.
4 is ABAP inline
declarations, this will help an ABAP Developer to simplify programming help to reduce
unnecessary data declarations in a program.
Inline declarations are most useful in reducing onetime and local data declarations in a
ABAP Object, for example If you want to store some value inside in a Function
Module/Perform and you don`t need to access them globally, you can declare a inline
variable and use it locally.
Inline declaration with ‘VALUE’ and ‘NEW’:
Now there is no need to declare a variable, work area or an internal table and then
assign value to it. With new ABAP we can do the above two steps process in a single
step.
DATA(gv) = ‘Dummy Value’.
DATA(gs_struc1) = VALUE ekko( ). ” Work area
DATA(gt_itab1) = VALUE ekko_tty( ). ” Internal table , ekko_tty is table type
DATA(gv_1) = VALUE char2( ).
DATA(gv_2) = VALUE int4( ). “Inbuilt data type
DATA : gt_range TYPE RANGE OF i,
gt_range1 TYPE RANGE OF i.
Creating range table
gt_range = VALUE #( sign = ‘I’ option = ‘EQ’ ( low = ’10’ )
( low = ’11’ )
( low = ’12’ )
( low = ’13’ ) ).
To define the range with low and high value
gt_range1 = VALUE #( sign = ‘I’ option = ‘EQ’ ( low = 10 high = 20 ) ).
Creating class object with ‘NEW’ operator
OLD
DATA :go_obj TYPE REF TO CL_BSP_DLC_FA_VIEW.
CREATE OBJECT go_obj EXPORTING iv_component = ‘dummy value’
iv_viewname = ‘Value2’.
If there is no constructor value
CREATE OBJECT go_obj.
New
DATA(go_obj_new) = NEW CL_BSP_DLC_FA_VIEW( iv_component = ‘dummy value’ iv_vi
ewname = ‘Value2’ ).
OR
DATA :go_obj_new1 TYPE REF TO CL_BSP_DLC_FA_VIEW.
go_obj_new1 = NEW #( iv_component = ‘dummy value’ iv_viewname = ‘Value2’ ). ” Use ‘#’
when type is already defined
* If there is no constructor value
DATA(go_obj_new) = NEW class_name( ).
Below is the more example of declaring a plain variable to store some string.
Using ABAP before ABAP 7.4
DATA: LV_TEXT TYPE STRING.
LV_TEXT = 'This is declaration before 7.4'.
Below is the example After ABAP 7.4, you need to use DATA keyword with open and close
brackets '(' to declare variable.
DATA(LV_TEXT) = 'This is Declaration for 7.4'.
Using Workarea inline in ABAP 7.4
Before ABAP 7.4
DATA: WA_MARA TYPE MARA.
SELECT SINGLE *
FROM MARA
INTO WA_MARA WHERE MATNR = '0001'.
WRITE:/ wa_mara-matnr, wa_mara-mtart.
After ABAP 7.4, you need to use @ symbol for using variables in ABAP 7.4 Open SQL
statements
SELECT SINGLE * FROM MARA
INTO @DATA(wa_MARA) WHERE MATNR = '0001'.
WRITE:/ wa_mara-matnr, wa_mara-mtart.