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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP ABAP 動態內表實現 ALV橫向按月份動態顯示資料
- jqgrid動態顯示,隱藏指定列
- 【轉載】ALV的Excel方式顯示缺少模板Excel
- 數碼管動態顯示
- element-plus el-table 動態設定列顯示隱藏
- 靜態數碼管顯示、動態數碼管顯示、矩陣按鍵矩陣
- SAP ALV小數點後面如果為0不顯示
- 如何在 SAP ABAP ALV 報表裡以交通燈的方式顯示某一列的值
- javaScript動態顯示當前時間JavaScript
- win10狀態列網速工具如何顯示_win10狀態列實時顯示網速怎麼設定Win10
- Android 顯示、隱藏狀態列和導航欄Android
- 如何在 SAPGUI 的同一個螢幕顯示兩個 ALV listGUI
- vue中:is的用法,動態顯示需要的元件Vue元件
- PowerDesigner顯示註釋列
- win10狀態列怎麼新增cpu溫度顯示_win10工作列新增cpu溫度顯示的步驟Win10
- 在 Laravel 中動態 隱藏 / 顯示 API 欄位LaravelAPI
- 動態的新增ImageView到LinearLayout中並居中顯示View
- 中斷與數碼管動態顯示程式碼
- Cell 動態行高文字顯示不全問題探索
- Git差異並列顯示Git
- 基於DataTables實現根據每個使用者動態顯示隱藏列,可排序排序
- FBL5N、FBL3N、 FBL1N ALV新增欄位顯示
- layui 輪播圖動態資料不顯示問題UI
- win10qq圖示怎樣在工作列顯示_win10qq圖示在工作列顯示的方法Win10
- WIN10動態磁貼不顯示內容怎麼設定 WIN10設定動態磁貼不顯示內容方法Win10
- 靜態動態陣列陣列
- Win11工作列怎麼靠左顯示?Win11工作列靠左顯示的方法教程
- RDLC 動態列
- 動態陣列陣列
- elementui 如果變數為1 顯示 開啟,2顯示關閉。表格怎麼根據狀態碼顯示狀態值UI變數
- win10工作列圖示不顯示怎麼辦 修復工作列顯示不正常的辦法Win10
- win10 選擇圖示怎麼顯示工作列_win10選擇快速操作圖示如何顯示在工作列Win10
- 手把手教你完成數字動態變化顯示效果
- Element 利用Tooltip提示框實現動態顯示文字提示
- 動態顯示:文字框字數(輸入還剩多少字)
- 【資料】靜態/動態顯示LCD液晶驅動晶片VKS232,116SEG*2COM晶片
- win10狀態列看不到微信怎麼辦_win10如何讓工作列顯示微信圖示Win10
- 表格顯示滾動條
- 動態控制C4C UI元素的顯示和隱藏UI