Friday, December 15, 2017

VALUE Internal Table "LINES OF" Line_spec

Example code is from documentation.

TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY. 

DATA(jtab) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ). 

DATA(itab) = VALUE t_itab( ( ) ( 1 ) ( 2 ) ( LINES OF jtab ) ). 

cl_demo_output=>display( itab ).



Some things are to be noted here.

Blank parenthesis will insert initial line.

Internal table key is empty. It means primary key will not have any key field. Commonly used way to declare internal table (data lt_vbap type standard table of vbap) results in non-unique default key. Default key means all non-numeric fields of line type. If internal table has unstructured line type, table_line would be the default key. Surprisingly, lt_vbap would mostly be read using vbeln posnr but default key would have more than 200 fields. Why maintain huge key when it is never utilized. So empty key or vbeln+posnr would be better than the default. An obvious advantage of using proper keys is that the read with table key will be preferred over sort read binary search.

Till now, I have used VALUE expression to fill empty table. Using LINES OF, we can essentially append lines without using append statement. LINES OF can also have additions like FROM TO and USING KEY.

No comments: