You are on page 1of 5

Inline Data Declarations

• The following examples show inline data declarations: Instead of declaring a variable statically as a global
variable in the program or a local variable in the current context (subroutine, function module, or method),
the declaration is delayed until the statement is executed.

• The name of the variable is enclosed in parentheses and there are no gaps between the data addition, the
opening and closing parentheses, and the name.

• The type of the variable is determined automatically from the context of the statement: In the first example
below, the variable gx_excp will have the type REF TO cx_sy_move_cast_error.

• The variable is created in the statement in which it is declared – it cannot be addressed beforehand.
However, its subsequent lifetime is the same as if it had been declared statically. Hence if the CATCH
statement in the first example below is in the main program, the variable gx_excp is global and remains
alive until the end of the program. Similarly, if the variable is declared within a modularization unit, it remains
alive for the remainder of the corresponding unit.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 1


Inline Data Declarations

DATA: gx_excp TYPE REF TO cx_sy_move_cast_error.


TRY.
go_oref2 ?= go_oref1. Before
CATCH cx_sy_move_cast_error INTO gx_excp.
ENDTRY.

TRY.
go_oref2 ?= go_oref1.
After
CATCH cx_sy_move_cast_error INTO data(gx_excp).
ENDTRY.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Inline Data Declarations – Method Parameters

Before
DATA: go_alv TYPE REF TO cl_salv_table.

cl_salv_table=>factory( IMPORTING r_salv_table = go_alv


CHANGING t_table = gt_data ).

After

cl_salv_table=>factory( IMPORTING r_salv_table = data(go_alv)


CHANGING t_table = gt_data ).

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Inline Data Declarations – Internal Tables With Work Area

LOOP AT gt_itab INTO data(gs_line).

ENDLOOP.

READ TABLE gt_itab INTO data(gs_line)


INDEX n | WITH KEY…| WITH TABLE KEY…

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Inline Data Declarations – Internal Tables With Field Symbol

LOOP AT gt_itab ASSIGNING FIELD-SYMBOL(<line>).

ENDLOOP.

READ TABLE gt_itab ASSIGNING FIELD-SYMBOL(<line>)


INDEX n | WITH KEY…| WITH TABLE KEY…

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 5

You might also like