用到COND、LINE_EXISTS()和MODIFY FROM VALUE,可以省去重复READ内表的麻烦,很快的将需要的字段写入内表,接下来不废话直接展示:
"修改内表
LOOP AT gt_alv INTO gs_alv.
MODIFY gt_alv FROM VALUE ty_data(
txt01 = COND #( WHEN line_exists( lt_skat[ hkont = gs_alv-hkont ] )
THEN lt_skat[ hkont = gs_alv-hkont ]-txt01 )
txt02 = COND #( WHEN line_exists( lt_t053s[ bukrs = gs_alv-bukrs rstgr = gs_alv-rstgr ] )
THEN lt_t053s[ bukrs = gs_alv-bukrs rstgr = gs_alv-rstgr ]-txt02 )
ktxt1 = COND #( WHEN line_exists( lt_cskt[ kostl = gs_alv-kostl ] )
THEN lt_cskt[ kostl = gs_alv-kostl ]-ktxt1 )
ktxt2 = COND #( WHEN line_exists( lt_cepct[ prctr = gs_alv-prctr ] )
THEN lt_cepct[ prctr = gs_alv-prctr ]-ktxt2 )
txt03 = COND #( WHEN line_exists( lt_anla[ bukrs = gs_alv-bukrs anln1 = gs_alv-anln1 ] )
THEN lt_anla[ bukrs = gs_alv-bukrs anln1 = gs_alv-anln1 ]-txt03 )
name1 = COND #( WHEN line_exists( lt_name1[ kunnr = gs_alv-kunnr ] )
THEN lt_name1[ kunnr = gs_alv-kunnr ]-name1 )
user1 = COND #( WHEN line_exists( lt_user1[ usnam = gs_alv-usnam ] )
THEN lt_user1[ usnam = gs_alv-usnam ]-user1 )
user2 = COND #( WHEN line_exists( lt_user2[ ppnam = gs_alv-ppnam ] )
THEN lt_user2[ ppnam = gs_alv-ppnam ]-user2 ) )
TRANSPORTING txt01 txt02 txt03 ktxt1 ktxt2 name1 user1 user2 .
ENDLOOP.
原创不易,给个赞呗😙