New syntax for append- VALUE (new syntax 7.4+) in ABAP
* We use APPEND statement to insert the records at the last of the internal table.
* In SAP ABAP new syntax, we can use VALUE expression instead of APPEND statement.
* Value expression is a powerful mechanism to declare as well as initialize the internal
tables.
* It is a powerful utility where we can achieve the result with minimal coding.
* Value expression is of 2 types.
- Define the type before using it with VALUE keyword. The type defined is structure type or table type.
- Using # character for type and use it with VALUE keyword.
Report
REPORT zab_rp_append_value.
TYPES: BEGIN OF ls_stu,
st_id(10) TYPE n,
st_name(15) TYPE c,
END OF ls_stu.
DATA: lt_stu TYPE TABLE OF ls_stu,
lr_stu TYPE ls_stu.
lr_stu-st_id = 1.
lr_stu-st_name = 'ajay'.
APPEND lr_stu TO lt_stu.
CLEAR: lr_stu.
lr_stu-st_id = 2.
lr_stu-st_name = 'vinod'.
APPEND lr_stu TO lt_stu.
CLEAR: lr_stu.
cl_demo_output=>display( lt_stu ).
TYPES: BEGIN OF ls_stu,
st_id(10) TYPE n,
st_name(15) TYPE c,
END OF ls_stu.
DATA: lt_stu TYPE TABLE OF ls_stu,
lr_stu TYPE ls_stu.
lr_stu-st_id = 1.
lr_stu-st_name = 'ajay'.
APPEND lr_stu TO lt_stu.
CLEAR: lr_stu.
lr_stu-st_id = 2.
lr_stu-st_name = 'vinod'.
APPEND lr_stu TO lt_stu.
CLEAR: lr_stu.
cl_demo_output=>display( lt_stu ).
new syntax
TYPES: BEGIN OF ls_stu,
st_id(10) TYPE n,
st_name(15) TYPE c,
END OF ls_stu.
TYPES: lty_stu TYPE TABLE OF ls_stu WITH EMPTY KEY.
*********lr_stu is work area so insert only one value *******
********lt_stu is internal table so insert any number of values***
DATA(lt_stu) = VALUE lty_stu( ( st_id = 1 st_name = 'ajay' ) ( st_id = 2 st_name = 'vinod' ) ).
cl_demo_output=>display( lt_stu ).
st_id(10) TYPE n,
st_name(15) TYPE c,
END OF ls_stu.
TYPES: lty_stu TYPE TABLE OF ls_stu WITH EMPTY KEY.
*********lr_stu is work area so insert only one value *******
********lt_stu is internal table so insert any number of values***
DATA(lt_stu) = VALUE lty_stu( ( st_id = 1 st_name = 'ajay' ) ( st_id = 2 st_name = 'vinod' ) ).
cl_demo_output=>display( lt_stu ).
Output
******************************Thank You***************************
Comments
Post a Comment