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.

TYPESBEGIN OF ls_stu,
         st_id(10)   TYPE n,
         st_name(15TYPE c,
       END OF ls_stu.

DATAlt_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.
CLEARlr_stu.

lr_stu-st_id 2.
lr_stu-st_name 'vinod'.
APPEND lr_stu TO lt_stu.
CLEARlr_stu.

cl_demo_output=>displaylt_stu ).

new syntax

TYPESBEGIN OF ls_stu,
         st_id(10)   TYPE n,
         st_name(15TYPE c,
       END OF ls_stu.

TYPESlty_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_stuVALUE lty_stust_id st_name 'ajay' st_id st_name 'vinod' ).
cl_demo_output=>displaylt_stu ).


Output


******************************Thank You***************************

Comments

Popular posts from this blog

Add custom tab to me51n at item level in ABAP

Pf status and user command in factory method - OOPS ALV in ABAP