ALV相关汇总

使用函数显示ALV格式报表
1)定义ALV
type-pools slis. "调用类型组
data: myrepid like sy-repid. "程序为当前程序
data: i_layout type slis_layout_alv. "ALV显示格式内表
data: allfields type slis_t_fieldcat_alv. " ALV显示字段内表
data: i_fieldcat type line of slis_t_fieldcat_alv. "ALV字段信息结构
data: e_status type slis_formname value 'STANDARD_ER01'. "ALV自定义非标准按钮
myrepid = sy-repid.
2)ALV 显示属性
i_layout-colwidth_optimize = 'X'. "自动调整列宽
i_layout-zebra = 'X'. "变换行颜色
2)ALV写法,有两种:
(1)法一,写成块形式
data: pos type i.
define alv_append_field. "定义模块
i_fieldcat-col_pos = pos. "列标志
i_fieldcat-fieldname = &1. "字段名
i_fieldcat-seltext_l = &2. "字段描述
i_fieldcat-no_zero = 'X'. "不显示值为0的数据和前导0
... "其它的fieldcat属性
append i_fieldcat to allfields. "写进显示字段内表
clear i_fieldcat.
pos = pos + 1. "下一列
end-of-definition.
refresh allfields.
pos = 1.
clear i_fieldcat.
alv_append_field 'FLDNAME' 'FLDTXT' .
(2)法二:标准形式
clear i_fieldcat.
i_fieldcat-fieldname = 'FLDNAME'. "字段名
i_fieldcat-seltext_l = 'FLDTXT'. "字段描述
i_fieldcat-no_zero = 'X'.
... "其它fieldcat属性
append i_fieldcat to allfields.
... "循环同上
3)调用ALV显示函数
call function 'REUSE_ALV_GRID_DISPLAY' "statt LIST
exporting
i_callback_program = myrepid
i_callback_pf_status_set = e_status "使用非标准按钮
is_layout = i_layout
i_CALLBACK_USER_COMMAND = 'USER_COMMAND' "非标准按钮动作
it_fieldcat = allfields "显示字段的内表
i_save = 'A' "是否打开保存
tables
t_outtab = itab " 内表名
exceptions
program_error = 1
others = 2.

注:alv有两种显示格式的function:(1)REUSE_ALV_LIST_DISPLAY(和 write到屏幕一样的样式);(2)REUSE_ALV_GRID_DISPLAY(单元格样式)。

ALV2:ALV列、行、单元格颜色设置
1 )颜色含义

1 :海蓝;2:浅清;3:黄色;4:浅蓝;5:青色;6:红色;7:橙色。
(1)首位为主颜色;
(2)次位为辅助颜色;
(3)末位为0时,表示首位数字表为表格的底色;
末位为1时,则表示以1为底色,首位数字则表为表格字体的颜色;
末位为其它颜色时,则表示底色为ALV的默认颜色;
以上三条是本人大概总结出来的规律,本人发现的现象基本如上,但也不一定全部正确。
其中C200与系统标准ALV底色比较相似;C410与系统标准关键字颜色比较相似。
2 )列颜色:
设置ALV字 段 fieldcat属性:i_fieldcat-emphasize = &3. " 颜色
把 fieldcat属性写入属性内表 allfields:alv_append_field 'WERKS' ' 工厂 ' 'C110'.
C110 :为颜色代码;
3 )行颜色:
(1)在内表itab定义一个字段 line_color来存储颜色;loop内表itab,在需要显示颜色的行其值赋为颜色'C110';
(2)在定义alv显示格式定义:
设置ALV显示layout属性:i_layout-info_fieldname = 'LINE_COLOR',line_color为内表定义的存储颜色的列名。
4)单元格颜色
单元格颜色属性:LVC_S_SCOL,该属性为一结构,含三个字段:FNAME(30)、COLOR(颜色结构,含三个字段:col(10)、int(3)、inv(10))、 NOKEYCOL(1)(覆盖码颜色)
ALV 列属性:coltab_fieldname
exa :
定义内表itab含字段FLDNAME type LVC_S_SCOL;
定义单元格颜色结构cellcolor type LVC_S_SCOL;
循环内表,当要设置单元格颜色所在的列字段 colname要设置颜色时
fldname-FNAME = ‘ COLNAME ’
fldname-COLOR-col = ‘ 2 ’ (颜色代码)
fldname-COLOR-int = ‘ 1 ’
fldname-COLOR-inv = ‘ 0 ’ 。

ALV3:ALV的html表头
在ALV的function的exporting里添加属性:

I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE
定义form响应上述ALV属性
form html_top_of_page using document type ref to cl_dd_document.
DATA: text TYPE SDYDO_TEXT_ELEMENT.
 text = titlname
 CALL METHOD DOCUMENT->ADD_TEXT
    EXPORTING
      TEXT      = text
      SAP_STYLE = 'HEADING'.
 "换行写另一标题
 CALL METHOD DOCUMENT->NEW_LINE.
或使用空格
CALL METHOD DOCUMENT->ADD_GAP
    EXPORTING
      WIDTH = 10. "空格宽10
...
 endform.

ALV4:ALV里显示状态灯
1)在alv引用类型池定义时加入icon,如type-pools: slis, icon.

2)给显示内表itab定义一字段statu存储状态灯;

3)循环内表itab给字段statu值赋:
绿灯:itab-statu = icon_led_green.
红灯:itab-statu = icon_led_red.
4)alv的fieldcat属性i_fieldcat-icon = 'X'.
ALV5:ALV的layout属性
ALV里的显示属性可通过定义i_layout TYPE slis_layout_alv来使用不同的显示风格。可双击“slis_layout_alv”来查看类型组SLIS里的layout属性:

父类  子类  子类  主要属性(部分)  描述 
slis_layout_alv  slis_layout_main    dummy  
slis_layout_alv_spec  slis_layout_alv_spec0  no_colhead(1) type c 没有标题
zebra(1) type c 行颜色间隔改变
no_vline(1) type c 没有竖线,由空格代替
no_hline(1) type c 没有横线,由空格代替
cell_merge(1) type c 单元格复制形式
edit(1) type c 可编辑仅为grid
edit_mode(1) type c 编辑模式仅为grid
numc_sum(1) type c 数值型字段汇总
no_input(1) type c 仅输出
no_keyfix(1) type c 不固定关键字列
slis_layout_alv_spec1  Display options 显示属性  
colwidth_optimize(1) type c 自动调整列宽
no_min_linesize(1) type c line size = width of the list
min_linesize like sy-linsz if initial min_linesize = 80
max_linesize like sy-linsz, Default 250
window_titlebar like sy-title  
no_uline_hs(1) type c  
Exceptions 扩展  
lights_fieldname type slis_fieldname  
lights_tabname type slis_tabname  
lights_rollname like dfies-rollname  
lights_condense(1) type c  
Sums 合计  
no_sumchoice(1) type c 不可选择总计
no_totalline(1) type c 没有合计行
no_subchoice(1) type c 不可选择小计
no_subtotals(1) type c 没有小计
no_unit_splitting type c  
totals_before_items type c 在明细前显示合计
totals_only(1) type c 只显示合计
totals_text(60) type c 合计第一列文本行
subtotals_text(60) type c 小计第一列文本行
Interaction 继承  
box_fieldname type slis_fieldname  
box_tabname type slis_tabname  
box_rollname like dd03p-rollname  
key_hotspot(1) type c keys as hotspot
flexible_key(1) type c key columns movable
group_buttons(1) type c buttons for COL1 - COL5
get_selinfos(1) type c read selection screen
group_change_edit(1) type c Settings by user for new group
no_scrolling(1) type c no scrolling
Detailed screen 屏幕详细  
detail_popup(1) type c 弹出显示明细
detail_initial_lines(1) type c 显示初始行
detail_titlebar like sy-title 详细标题栏
Display variants 显示变量  
header_text(20) type c 标题按钮文本
default_item(1) type c 默认明细
colour 颜色  
info_fieldname type slis_fieldname  
coltab_fieldname type slis_fieldname  
others 其它(略)  

ALV6:ALV的fieldcat属性
ALV里的字段属性可通过定义i_fieldcat TYPE slis_t_fieldcat_alv来使用字段的属性。可双击“slis_t_fieldcat_alv”来查看类型组SLIS里的fieldcat 属性,slis_t_fieldcat_alv 来自类slis_fieldcat_alv,该类主要包含两个类:slis_fieldcat_main、 slis_fieldcat_alv_spec,主要有以下属性: 

父类  子类  子类  主要属性(部分)  描述 
Slis_fieldcat_alv  slis_fieldcat_main  slis_fieldcat_main0  row_pos 输出行
col_pos 列位置
fieldname  
tabname 标签名称
currency(5) 货币单位
cfieldname field with currency unit
ctabname Table with currency unit
ifieldname initial column
quantity(3) 计量单位
qfieldname 参考计量单位的字段名称
qtabname Table with quantity unit
round ROUND 值
exponent(3) 流动表示的指数
key(1) 关键字段
icon(1) 作为图标输出
symbol(1) 输出作为符号
checkbox(1) 作为复选框输出
just(1) 对齐
lzero(1) 输出前导零
no_sign(1) 输出抑制符号
no_zero(1) 为输出隐藏零
no_convext(1)  
edit_mask 为输出编辑掩码
emphasize(4) 带有颜色的高亮列
fix_column(1) 固定列
do_sum(1) 总计列值
no_out(1) 列没有输出
tech(1) 技术字段
outputlen 列的字符宽度
offset offset
seltext_l 长文本
seltext_m 中文本
seltext_s 短文本
slis_fieldcat_main1  ref_fieldname  
ref_tabname  
roundfieldname  
roundtabname  
decimalsfieldn  
decimalstabnam  
decimals_out(6) 控制小数点的位数
text_fieldname  
reptext_ddic  
ddic_outputlen  
slis_fieldcat_alv_spec     key_sel(1) field not obligatory
no_sum(1) do not sum up
sp_group(4) group specification
reprep(1) selection for rep/rep
input(1) input
edit(1) internal use only
hotspot(1) hotspot

ALV7:ALV式的弹出窗口
在系统标准程序下,有不少屏幕在检查或过帐时会弹出一个小型的ALV窗口,上面记录着错误信息,这种ALV弹出式窗口可通过以下方法做成:
(1)定义ALVBOX
data:box_container type ref to cl_gui_dialogbox_container,
     box_alv type ref to cl_gui_alv_grid.
class lcl_event_handler definition.
 public section.
 class-methods:
on_close for event close of cl_gui_dialogbox_container importing sender.
endclass.
class lcl_event_handler implementation.
 method on_close.
   call method sender->free.
    free: box_container, box_alv .
 endmethod.
endclass.
data: ls_fcat type lvc_s_fcat., "ALV的fieldcat属性行
lt_fieldcat type lvc_t_fcat. "ALV的fieldcat属性内表
data: ls_layout type lvc_s_layo. " ALV的layout属性内表
可双击父类lvc_t_fcat、lvc_s_layo来查看所包含的属性
(2)建立ALV对象
    create object box_container
      exporting
        width   = 600      " 窗口大小
        height = 200
        top     = 120
        left    = 120
        caption = ' 提示信息' "弹出窗口标题
      exceptions
        others = 1.
set handler lcl_event_handler=>on_close for box_container.
 create object box_alv
    exporting
      i_parent          = box_container
    exceptions
      others           = 1.
(3)输出ALV的fieldcat属性和layout属性
call function 'LVC_FIELDCATALOG_MERGE'
 exporting
   i_structure_name          = 'ZSTAB'   " 输出格式对应的结构
 changing
   ct_fieldcat                = lt_fieldcat "ALV 的fieldcat属性内表
 exceptions
   inconsistent_interface       = 1
   program_error             = 2
   others                    = 3.
注:要事先在se11创建一个和ALV 输出字段一致的结构ZSTAB;
      " 写入fieldcat的属性
loop at lt_fieldcat into ls_fcat.
 ls_fcat-icon = 'X '.
 ...
  modify lt_fieldcat from ls_fcat.
endloop.
"写入layout属性
ls_layout-cwidth_opt = 'X '.
...
(4)调用方法显示ALV窗口
call method box_alv->set_table_for_first_display
 exporting
   i_structure_name              = 'ZBGER' " 输出格式对应的结构
   is_layout                   = ls_layout "layout 属性
   i_default                   = 'X'
 changing
   it_outtab                   = itab " 内表
   it_fieldcatalog               = lt_fieldcat "fieldcat 属性
 exceptions
   others                        = 1.
弹出式窗口另外做法:可使用write到屏幕的办法,如下:

(1)在程序中创建一个screen type 为“方式对话框”的屏幕;
(2)在屏幕输出前,write要输出的数据:
process before output.
 modiule frm_write_out.
(3)在module里写输出到屏幕的代码
module frm_write_out output.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
NEW-PAGE NO-TITLE.
write ...
LEAVE SCREEN.
endmodule.

posted @ 2010-08-30 15:08  elegant  阅读(2780)  评论(0编辑  收藏  举报