alv動態顯示列
report z_zxp_test05.
tables: sflight.
data: t_sflight like table of sflight with header line.
data: begin of t_connid occurs 0,
connid like sflight-connid,
end of t_connid.
data: i_fieldcat like table of lvc_s_fcat,
w_fieldcat like line of i_fieldcat.
field-symbols: type standard table.
parameters: p_carrid like sflight-carrid.
start-of-selection.
perform. sub_calc_column.
perform. sub_generate_itab.
perform. sub_display.
*&---------------------------------------------------------------------*
*& Form sub_calc_column
*&---------------------------------------------------------------------*
* 1、取數並計算動態列
*----------------------------------------------------------------------*
form. sub_calc_column .
select *
from sflight
into corresponding fields of table t_sflight
where carrid = p_carrid.
loop at t_sflight.
t_connid-connid = t_sflight-connid.
collect t_connid.
endloop.
endform. " sub_calc_column
*&---------------------------------------------------------------------*
*& Form sub_generate_itab
*&---------------------------------------------------------------------*
* 2、生成動態列表,並填充資料
*----------------------------------------------------------------------*
form. sub_generate_itab .
data: ep_table type ref to data,
w_table type ref to data,
p_connid(4).
field-symbols: type any,
.
define append_fieldcat.
w_fieldcat-fieldname = &1.
w_fieldcat-datatype = &2.
w_fieldcat-intlen = &3.
w_fieldcat-decimals = &4.
w_fieldcat-just = &5.
append w_fieldcat to i_fieldcat.
clear: w_fieldcat.
end-of-definition.
append_fieldcat 'CARRID' 'CHAR' '3' '' 'L'.
loop at t_connid.
append_fieldcat t_connid-connid 'CURR' '13' '2' 'R'.
endloop.
* 注:這裡的EXPORTING、IMPORTING相對於程式來說,it_fieldcatalog是程式的輸出引數,ep_table是程式得到的引數;
* 對於類方法來說it_fieldcatalog是輸入引數,ep_table是輸出引數(進到方法裡可以看到it_fieldcatalog是EXPORTING
* 引數,ep_table是IMPORTING引數)
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = i_fieldcat
importing
ep_table = ep_table.
assign ep_table->* to.
create data w_table like line of.
assign w_table->* to.
loop at t_sflight.
move-corresponding t_sflight to.
read table t_connid with key connid = t_sflight-connid.
* 把結構的欄位名為“t_sflight-connid的值”的資料參考變數賦值給欄位符號(Field sysmbol,指標)
* 通過訪問指標來訪問資料參考變數的值,同理,也可以改變指標的值來修改資料參考變數的值。
* 注:ASSIGN COMPONENT + fieldname 中,fieldname欄位型別必須為字元型。
p_connid = t_sflight-connid.
assign component p_connid of structure to .
= t_sflight-price.
at end of carrid.
append to .
clear:.
endat.
endloop.
endform. " sub_generate_itab
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
* 3、顯示動態列表的資料
*----------------------------------------------------------------------*
form. sub_display .
type-pools: slis.
data: g_variant like disvariant. "(不知道用途,有待研究)
data: g_layout type slis_layout_alv. "優化設定
data: i_fieldcat type slis_t_fieldcat_alv with header line. "輸出欄位情況(必輸項)
data: git_event_exit type slis_t_event_exit,
gw_event_exit like line of git_event_exit. "Events for Callback(需瞭解的功能)
data: p_mdvname like m_crama-ktext,
p_connid(4).
define add_it_alv.
i_fieldcat-fieldname = &1.
i_fieldcat-seltext_l = &2.
i_fieldcat-outputlen = &3. "控制輸出的寬度(在設定g_layout-colwidth_optimize = 'X'後,失效。)
i_fieldcat-fix_column = &4.
i_fieldcat-key = &5.
i_fieldcat-just = &6.
i_fieldcat-decimals_out = &7. "控制小數位
i_fieldcat-round = &8.
i_fieldcat-no_zero = &9. "控制是否輸出“0”
append i_fieldcat.
clear i_fieldcat.
end-of-definition.
refresh i_fieldcat.
add_it_alv 'CARRID' '公司程式碼' '10' 'X' 'X' 'L' '' '' 'X'.
loop at t_connid.
concatenate '航班' t_connid-connid '價格' into p_mdvname.
p_connid = t_connid-connid.
add_it_alv p_connid p_mdvname '20' 'X' 'X' 'R' '2' '0' 'X'.
endloop.
g_layout-colwidth_optimize = 'X'.
gw_event_exit-ucomm = 'SUNTEST'.
gw_event_exit-before = 'X'.
gw_event_exit-ucomm = '&IC1'. "標準功能CODE:DOUBLE CLICK
gw_event_exit-before = 'X'. "標準功能前執行USER COMMAND
append gw_event_exit to git_event_exit.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
it_fieldcat = i_fieldcat[] "必輸項
is_variant = g_variant
i_save = 'X'
is_layout = g_layout
i_grid_title = 'Sun Test Assign的動態用法'
it_event_exit = git_event_exit
i_callback_user_command = 'FRM_UCOMM' "注:FRM_UCOMM是子程式的名稱
tables
t_outtab = "必輸項
exceptions
program_error = 1
others = 2.
endform. " sub_display
*&---------------------------------------------------------------------*
*& Form FRM_UCOMM
*&---------------------------------------------------------------------*
* 4、自定義ALV的雙擊事件(i_callback_user_command = 'FRM_UCOMM')
*----------------------------------------------------------------------*
form. frm_ucomm using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when 'SUNTEST'. "雙擊
when '&IC1'.
if rs_selfield-fieldname eq 'MAKTX'.
else.
r_ucomm = '&ETA'. "強行將雙擊事件關聯到F2,及介面上的檢視按鈕
endif.
endcase.
endform. "FRM_UCOMM
tables: sflight.
data: t_sflight like table of sflight with header line.
data: begin of t_connid occurs 0,
connid like sflight-connid,
end of t_connid.
data: i_fieldcat like table of lvc_s_fcat,
w_fieldcat like line of i_fieldcat.
field-symbols:
parameters: p_carrid like sflight-carrid.
start-of-selection.
perform. sub_calc_column.
perform. sub_generate_itab.
perform. sub_display.
*&---------------------------------------------------------------------*
*& Form sub_calc_column
*&---------------------------------------------------------------------*
* 1、取數並計算動態列
*----------------------------------------------------------------------*
form. sub_calc_column .
select *
from sflight
into corresponding fields of table t_sflight
where carrid = p_carrid.
loop at t_sflight.
t_connid-connid = t_sflight-connid.
collect t_connid.
endloop.
endform. " sub_calc_column
*&---------------------------------------------------------------------*
*& Form sub_generate_itab
*&---------------------------------------------------------------------*
* 2、生成動態列表,並填充資料
*----------------------------------------------------------------------*
form. sub_generate_itab .
data: ep_table type ref to data,
w_table type ref to data,
p_connid(4).
field-symbols:
define append_fieldcat.
w_fieldcat-fieldname = &1.
w_fieldcat-datatype = &2.
w_fieldcat-intlen = &3.
w_fieldcat-decimals = &4.
w_fieldcat-just = &5.
append w_fieldcat to i_fieldcat.
clear: w_fieldcat.
end-of-definition.
append_fieldcat 'CARRID' 'CHAR' '3' '' 'L'.
loop at t_connid.
append_fieldcat t_connid-connid 'CURR' '13' '2' 'R'.
endloop.
* 注:這裡的EXPORTING、IMPORTING相對於程式來說,it_fieldcatalog是程式的輸出引數,ep_table是程式得到的引數;
* 對於類方法來說it_fieldcatalog是輸入引數,ep_table是輸出引數(進到方法裡可以看到it_fieldcatalog是EXPORTING
* 引數,ep_table是IMPORTING引數)
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = i_fieldcat
importing
ep_table = ep_table.
assign ep_table->* to
create data w_table like line of
assign w_table->* to
loop at t_sflight.
move-corresponding t_sflight to
read table t_connid with key connid = t_sflight-connid.
* 把結構
* 通過訪問指標
* 注:ASSIGN COMPONENT + fieldname 中,fieldname欄位型別必須為字元型。
p_connid = t_sflight-connid.
assign component p_connid of structure
at end of carrid.
append
clear:
endat.
endloop.
endform. " sub_generate_itab
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
* 3、顯示動態列表的資料
*----------------------------------------------------------------------*
form. sub_display .
type-pools: slis.
data: g_variant like disvariant. "(不知道用途,有待研究)
data: g_layout type slis_layout_alv. "優化設定
data: i_fieldcat type slis_t_fieldcat_alv with header line. "輸出欄位情況(必輸項)
data: git_event_exit type slis_t_event_exit,
gw_event_exit like line of git_event_exit. "Events for Callback(需瞭解的功能)
data: p_mdvname like m_crama-ktext,
p_connid(4).
define add_it_alv.
i_fieldcat-fieldname = &1.
i_fieldcat-seltext_l = &2.
i_fieldcat-outputlen = &3. "控制輸出的寬度(在設定g_layout-colwidth_optimize = 'X'後,失效。)
i_fieldcat-fix_column = &4.
i_fieldcat-key = &5.
i_fieldcat-just = &6.
i_fieldcat-decimals_out = &7. "控制小數位
i_fieldcat-round = &8.
i_fieldcat-no_zero = &9. "控制是否輸出“0”
append i_fieldcat.
clear i_fieldcat.
end-of-definition.
refresh i_fieldcat.
add_it_alv 'CARRID' '公司程式碼' '10' 'X' 'X' 'L' '' '' 'X'.
loop at t_connid.
concatenate '航班' t_connid-connid '價格' into p_mdvname.
p_connid = t_connid-connid.
add_it_alv p_connid p_mdvname '20' 'X' 'X' 'R' '2' '0' 'X'.
endloop.
g_layout-colwidth_optimize = 'X'.
gw_event_exit-ucomm = 'SUNTEST'.
gw_event_exit-before = 'X'.
gw_event_exit-ucomm = '&IC1'. "標準功能CODE:DOUBLE CLICK
gw_event_exit-before = 'X'. "標準功能前執行USER COMMAND
append gw_event_exit to git_event_exit.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
it_fieldcat = i_fieldcat[] "必輸項
is_variant = g_variant
i_save = 'X'
is_layout = g_layout
i_grid_title = 'Sun Test Assign的動態用法'
it_event_exit = git_event_exit
i_callback_user_command = 'FRM_UCOMM' "注:FRM_UCOMM是子程式的名稱
tables
t_outtab =
exceptions
program_error = 1
others = 2.
endform. " sub_display
*&---------------------------------------------------------------------*
*& Form FRM_UCOMM
*&---------------------------------------------------------------------*
* 4、自定義ALV的雙擊事件(i_callback_user_command = 'FRM_UCOMM')
*----------------------------------------------------------------------*
form. frm_ucomm using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when 'SUNTEST'. "雙擊
when '&IC1'.
if rs_selfield-fieldname eq 'MAKTX'.
else.
r_ucomm = '&ETA'. "強行將雙擊事件關聯到F2,及介面上的檢視按鈕
endif.
endcase.
endform. "FRM_UCOMM
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16794144/viewspace-700139/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 動態內表及動態ALV顯示(轉)
- 動態的實現任意表的ALV顯示02
- 動態的實現任意表的ALV顯示01
- SAP ABAP 動態內表實現 ALV橫向按月份動態顯示資料
- jqgrid動態顯示,隱藏指定列
- ALV顯示OO實現(摘)
- ALV1:使用函式顯示ALV格式報表函式
- jQuery 動態數字顯示jQuery
- Tree動態顯示Icon
- 數碼管動態顯示
- 【轉載】ALV的Excel方式顯示缺少模板Excel
- 八、Qt Creator實現狀態列顯示QT
- element-plus el-table 動態設定列顯示隱藏
- 靜態數碼管顯示、動態數碼管顯示、矩陣按鍵矩陣
- javaScript動態顯示當前時間JavaScript
- 數碼管顯示動態資料
- 動態顯示資料庫圖片資料庫
- function模式設定ALV用彈出視窗顯示Function模式
- ALV報表不能正確顯示資料問題
- win10狀態列網速工具如何顯示_win10狀態列實時顯示網速怎麼設定Win10
- 動態隱藏/顯示選擇螢幕
- javascript動態隱藏顯示技術(轉)JavaScript
- SAP ALV小數點後面如果為0不顯示
- Android 顯示、隱藏狀態列和導航欄Android
- vue中:is的用法,動態顯示需要的元件Vue元件
- 8位數碼管動態掃描顯示
- QT實現動態顯示系統時間QT
- JavaScript操作下拉框動態顯示內容JavaScript
- Android動態生成控制元件居中顯示Android控制元件
- 控制檯中動態顯示系統時間
- 如何控制手機網站控制狀態列顯示樣式網站
- 在alv grid中的列中設定icon圖示
- win10狀態列怎麼新增cpu溫度顯示_win10工作列新增cpu溫度顯示的步驟Win10
- Cell 動態行高文字顯示不全問題探索
- 在 Laravel 中動態 隱藏 / 顯示 API 欄位LaravelAPI
- javascript動態設定div的顯示和隱藏JavaScript
- js動態控制表單的顯示和隱藏JS
- 中斷與數碼管動態顯示程式碼