ALV動態列內表實現Demo

2021-07-09 05:50:49 字數 2493 閱讀 8728

開發財務報表或者一些**資料的報表時,經常會有動態顯示列的情況。

這裡**貼吧上的alv動態顯示列的demo,可做學習用。

report  yiris_dynamic_alv_demo.

data: wa_layo type lvc_s_layo,

wa_fcat type lvc_s_fcat,

it_fcat type lvc_t_fcat.

data: it_scol type lvc_t_scol.

field-symbols: type standard table,

, .

data: dy_table type ref to data,

dy_line type ref to data.

data: colname(10), index(2).

parameters: col type i. "列 數

clear: it_fcat.

*1)根 據 條 件 動 態 生 成 列

do col times.

index = index + 1.

concatenate 'col' index into colname.

perform frm_add_fact using colname 'c' '描述' '100'.

enddo.

*2)根 據 it_fcat 生 成 動 態 內 表

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fcat

importing

ep_table = dy_table.

*如 果 定 義 時 沒 有 指 定 類 型 或 者 結 構 ,那 麼 ref 必 須 assign

*到 另 外 一 個 fs 裡 間 接 使 用

assign dy_table->* to .

create data dy_line like line of .

assign dy_line->* to .

*3)給 表 字 段 賦 值

clear: index.

do col times.

index = index + 1.

concatenate 'col' index into colname.

assign component colname of structure to .

= '列資料1'.

enddo.

*4)給 內 表 裝 入 第 二 條 數 據

clear: index.

do col times.

index = index + 1.

concatenate 'col' index into colname.

assign component colname of structure to .

= '列資料2'.

enddo.

clear: wa_layo.

wa_layo-zebra = 'x'.

wa_layo-cwidth_opt = 'x'.

call function 'reuse_alv_grid_display_lvc'

exporting

i_callback_program = sy-repid

is_layout_lvc = wa_layo

it_fieldcat_lvc = it_fcat

tables

t_outtab = exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

form frm_add_fact using value1 value2 value3 value4.

wa_fcat-fieldname = value1.

wa_fcat-inttype = value2.

wa_fcat-reptext = value3.

wa_fcat-intlen = value4.

clear: wa_fcat.

endform. " frm_add_fact

比如在選擇螢幕上設定顯示4個動態列

輸出效果為:

動態隱藏ALV的行和列

本例和行列例程轉換不同,內錶結構是固定的,僅僅是通過alv的fieldcat和filter來隱藏 顯示alv的行和列 列 form changefield loop at gt fieldcat into gs fieldcat gs fieldcat no out if gs fieldcat f...

ABAP實現ALV表頭動態輸出 日期

data begin of it date occurs 0,lv date like vbak vdatu,endof it date.data begin of it month occurs 0,month 8 type c,end of it month.獲取每個so的所有交貨日期 yyyy...

ABAP動態內錶

定義的動態內錶,對應內錶一行的工作區 field symbols type standard table type any.form create dynamic table data lt fcat type slis t fieldcat alv,ls fcat like line of lt ...