Beruflich Dokumente
Kultur Dokumente
Read and Modify the ITAB records without using the temporary work area or variables. It is possible with
using the ABAP Table Expressions. Lets see more about them.
Preface
Let me start with begging your apologies for not publishing any article in long time. I had to take a
pause . I would try to publish as many as I can now.
ABAP 740 has many new features. This new feature Table Expressions are also powerful and reduce the
code clutter.
For Reading the data These are known as Reader Positions. This would do the same job as
you do with the READ statement, but without using the local variables. You can access the row in
question directly by specifying the key.
For Writing the data This has same effect as the MODIFY statement on the table entry. With
using the Write Positions, you can read the data change the value directly.
DO 10 TIMES.
APPEND sy-INDEX TO t_data.
ENDDO.
*Old way
DATA: lv_data TYPE i.
DO 12 TIMES.
READ TABLE t_data INTO lv_data WITH KEY TABLE_LINE = sy-INDEX.
IF sy-subrc EQ 0.
WRITE: / lv_data.
ELSE.
WRITE: / 'Not Found', sy-INDEX.
ENDIF.
ENDDO.
* Modify
* Old Way
FIELD-SYMBOLS: <lfs_data> LIKE LINE OF t_data.
READ TABLE t_data ASSIGNING <lfs_data> WITH KEY TABLE_LINE = 10.
IF sy-subrc EQ 0.
<lfs_data> = 20.
ENDIF.
* New Way
t_data[ TABLE_LINE = 20 ] = 10.
* OLD
READ TABLE t_data ASSIGNING <lfs_data> WITH KEY TABLE_LINE = 11.
IF sy-subrc EQ 0.
<lfs_data> = 20.
ENDIF.
* New Way
TRY .
t_data[ TABLE_LINE = 11 ] = 10.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
* Multiple Components
TYPES:
BEGIN OF ty_data,
kunnr TYPE kunnr,
name1 TYPE name1,
ort01 TYPE ort01,
land1 TYPE land1,
END OF ty_data.
TYPES: tt_data TYPE STANDARD TABLE OF ty_data
WITH DEFAULT KEY.
*
DATA(itab_multi_comp) =
VALUE tt_data( ( kunnr = '123' name1 = 'ABCD' ort01 = 'LV' land1 = 'NV' )
( kunnr = '456' name1 = 'XYZ' ort01 = 'LA' land1 = 'CA' )
).
* Itab Deep
TYPES:
BEGIN OF ty_alv_data,
kunnr TYPE kunnr,
name1 TYPE name1,
ort01 TYPE ort01,
land1 TYPE land1,
t_color TYPE lvc_t_scol,
END OF ty_alv_data.
TYPES: tt_alv_data TYPE STANDARD TABLE OF ty_alv_data
WITH DEFAULT KEY.
DATA(itab_alv) =
VALUE tt_alv_data(
"First Row
( kunnr = '123' name1 = 'ABCD'
ort01 = 'LV' land1 = 'NV'
" color table
t_color = VALUE #(
" Color table - First Row
( fname = 'KUNNR'
color-col = COL_NEGATIVE
color-int = 0
color-inv = 0
)
" Color Table - 2nd Row
( fname = 'ORT01'
color-col = COL_TOTAL
color-int = 1
color-inv = 1
)
)
)
"Second row
( kunnr = '456' name1 = 'XYZ'
ort01 = 'LA' land1 = 'CA'
)
).
* Old Way
FIELD-SYMBOLS: <fs_data> LIKE LINE OF itab_alv,
<fs_col> LIKE LINE OF <fs_data>-t_color.
READ TABLE itab_alv ASSIGNING <fs_data> WITH KEY kunnr = '123'.
IF sy-subrc EQ 0.
READ TABLE <fs_data>-t_color ASSIGNING <fs_col> WITH KEY fname = 'ORT01'.
IF sy-subrc EQ 0.
<fs_col>-color-col = COL_GROUP.
<fs_col>-color-int = 0.
<fs_col>-color-inv = 1.
ENDIF.
ENDIF.
ENDTRY.
In Debug, ASSIGN statement creates the FS and assigns the values of the specific structure COLOR
from T_COLOR from ALV table direclty