OO alv report
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid ,"ALV对象
gt_fieldcat TYPE lvc_t_fcat , "ALV字段控制
gs_layout TYPE lvc_s_layo , "ALV布局控制
gs_variant TYPE disvariant, "当前程序
alv_container TYPE scrfname VALUE 'T_COL', "屏幕元素名称,ALV展示数据存放在此容器中
alv_custom_container TYPE REF TO cl_gui_custom_container,ALV容器对象 *定义一个类
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
handle_double_click "方法handle_double_click用于处理cl_gui_alv_grid类中的双击事件double_click
FOR EVENT double_click of cl_gui_alv_grid
IMPORTING e_row e_column.
PRIVATE SECTION.
ENDCLASS *方法的实现
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_double_click.
PERFORM handle_double_click USING e_row e_column es_row_no. "定义处理双击事件方法, 如果双机alv某一行时,需要弹出子窗口中的alv的话这边,可以在此方法中获取需要显示的数据,还要类似于CALL SCREEN STARTING AT ENDING AT .call出子屏幕
ENDMETHOD. "handle_double_click
ENDCLASS. DATA: gr_event_handler TYPE REF TO lcl_event_handler. "定义对象引用,用于双击事件 *alv实现
gs_variant-report = sy-repid. IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_alvgrid "创建gr_alvgrid对象
EXPORTING
i_parent = cl_gui_container=>screen0. CREATE OBJECT gr_event_handler. 创建gr_event_handler对象
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid. "注册处理双机事件的方法
PERFORM display_alv. "ALV实现
ELSE.
call METHOD gr_alvgrid->refresh_table_display. 刷新alv报表
ENDIF. FORM DISPLAY_ALV . "调用ALV的实现方法 CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_variant = gs_variant "当前程序
i_save = 'A'
is_layout = gs_layout "ALV布局
CHANGING
it_outtab = gt_zc_main[] "内表
it_fieldcatalog = gt_fieldcat "需要输出的字段
EXCEPTIONS
invalid_parameter_combination =
program_error =
too_many_lines =
OTHERS = .
IF sy-subrc <> . ENDIF. ENDFORM
这边还要补充一些:
e_row TYPE lvc_s_row, "alv的行,如果要读取alv内表指定行时,可以read table 内表 index e_row-index.这样写
e_column TYPE lvc_s_col, "alv的列
es_row_no TYPE lvc_s_roid.
alv对象的析构函数free,也是类cl_gui_alv_grid中的,释放各实例化对象的内存,一般用在退出程序时,比如GUI界面点击 退出按钮时候
CALL METHOD SUB_GR_ALVGRID->FREE
EXCEPTIONS
CNTL_ERROR =
CNTL_SYSTEM_ERROR =
others =
.
IF SY-SUBRC <> .
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. CLEAR: sub_gr_alvgrid, sub_gs_layout,sub_gs_variant,sub_gt_fieldcat.
LEAVE TO SCREEN .
还有排除不必要的按钮操作:下面有个维护表排除不必要按钮部分的 实例
gt_exclude TYPE ui_functions,"存放排除按钮的内表
***排除不要的按钮
PERFORM exclude_tb_functions USING gt_exclude.
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions. DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_current_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_load_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_views.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_filter.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude. IF p_insert <> 'X' . ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude. ELSE. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ENDIF. ENDFORM. ALV 展示的时候传入排除不必要按钮的参数
***展示数据
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = gt_exclude "排除不必的按钮
CHANGING
it_outtab = gt_data
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination =
program_error =
too_many_lines =
OTHERS = .
对于alv中的布局定义:
示例1:维护表中的示例
PERFORM prepare_layout CHANGING gs_layout ."设置layout
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo. ps_layout-zebra = 'X' . "可选颜色
ps_layout-smalltitle = 'X' . "标题大小
ps_layout-no_toolbar = ' '. "显示工具栏
IF p_disp = 'X' OR p_modify = 'X'.
ps_layout-no_rowmark = 'X'. "禁用行选择
ENDIF.
ENDFORM.
示例2:
PERFORM prepare_layout CHANGING gs_layout.
FORM PREPARE_LAYOUT CHANGING P_GS_LAYOUT TYPE lvc_s_layo.
p_gs_layout-zebra = ' ' .
p_gs_layout-grid_title = text- . "ALV 控制: 标题栏文本
p_gs_layout-smalltitle = 'X' . "可选颜色
p_gs_layout-no_toolbar = ' '. "显示工具栏
p_gs_layout-no_rowmark = 'X'. "禁用行选择
p_gs_layout-cwidth_opt = 'X'. "优化列宽 ENDFORM.
字段控制: 示例1:
gt_fieldcat TYPE lvc_t_fcat,"需要显示的字段
PERFORM prepare_field_catalog CHANGING gt_fieldcat. "gt_fieldcat
FORM PREPARE_FIELD_CATALOG CHANGING PT_FIELDCAT TYPE lvc_t_fcat.
CLEAR: PT_FIELDCAT.
PERFORM fill_field_catalog USING pt_fieldcat 'VKORG' '' '销售组织'. "销售组织
ENDFORM. FORM fill_field_catalog USING pt_fieldcat TYPE lvc_t_fcat
col_pos fieldname datatype coltext .
DATA ls_fieldcat TYPE lvc_s_fcat.
CLEAR ls_fieldcat .
ls_fieldcat-fieldname = fieldname . "字段名称
ls_fieldcat-coltext = coltext. "ALV 控制: 列标
ls_fieldcat-datatype = datatype. "ABAP 字典中的数据类型
ls_fieldcat-col_pos = col_pos. "ALV 控制: 输出列
IF ls_fieldcat-fieldname = 'KUNNR'.
ls_fieldcat-REF_FIELD = 'KUNNR'. "ALV 控制: 内部表字段的参考字段名称
ls_fieldcat-REF_TABLE = 'KNA1'. "ALV 控制: 内部表字段的参考表名称
ENDIF.
APPEND ls_fieldcat TO pt_fieldcat .
ENDFORM.
示例2:可以通过函数实现:
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = g_tabname "表结构
i_client_never_display = 'X'
CHANGING
ct_fieldcat = pt_fieldcat "字段控制表
EXCEPTIONS
inconsistent_interface =
program_error =
OTHERS = .
IF sy-subrc <> .
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
可以循环pt_fieldcat,在赋值,
*UserExit,用于自定义Field Catalog
PERFORM userexit_fieldcat CHANGING pt_fieldcat.
FORM userexit_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA: ls_fieldcat TYPE lvc_s_fcat.
LOOP AT pt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'BUKRS'.
ls_fieldcat-coltext = '分公司' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'ORGTYPE'.
ls_fieldcat-coltext = '部门类型' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'ORGID'.
ls_fieldcat-coltext = '部门编码' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'LVORM'.
ls_fieldcat-coltext = '删除标记' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'BUNO'.
ls_fieldcat-coltext = '创建人员' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'BUDAT'.
ls_fieldcat-coltext = '创建日期' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'BUTIME'.
ls_fieldcat-coltext = '创建时间' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'UPNO'.
ls_fieldcat-coltext = '修改人员' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'UPDAT'.
ls_fieldcat-coltext = '修改日期' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
WHEN 'UPTIME'.
ls_fieldcat-coltext = '修改时间' .
ls_fieldcat-col_pos = .
ls_fieldcat-outputlen = .
ENDCASE.
IF p_insert = 'X'.
IF ls_fieldcat-fieldname = 'BUKRS' OR
ls_fieldcat-fieldname = 'ORGTYPE' OR
ls_fieldcat-fieldname = 'ORGID'.
ls_fieldcat-edit = 'X'.
ENDIF. " IF ls_fieldcat-fieldname = 'LVORM'.
" ls_fieldcat-no_out = c_flg_on.
" ENDIF. ELSEIF p_modify = 'X'.
IF ls_fieldcat-fieldname = 'ORGID' OR
ls_fieldcat-fieldname = 'LVORM'.
ls_fieldcat-edit = 'X'.
ENDIF.
ENDIF. MODIFY pt_fieldcat FROM ls_fieldcat.
ENDLOOP. ENDFORM.
"特殊的要显示的可以额外添加
OO alv report的更多相关文章
- 简单的OO ALV小示例
OO ALV即面向对象ALV,是在屏幕上显示的一种可以自定义大小的ALV.它区别普通ALV的优点是可以多个ALV出现在同一个屏幕,也可以同其他屏幕元素同时出现在同一个屏幕. 示例展示: 1. 进入实用 ...
- ALV详解:OO ALV
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- ABAP alv report
*&---------------------------------------------------------------------* *& Report YTST_FF_ ...
- OO ALV事件里使用E消息,下一步会退出到系统初始界面
在OO ALV data_change事件时(选中行),锁定KEY值, 继续,取消选择,退出到系统初始界面 改成 pv_status = 'E'. pv_msg = '采购订单' && ...
- OO ALV 学习参考
http://blog.csdn.net/sapliumeng/article/details/18653491 一.ALV介绍 The ALV Grid Control (ALV = SAPLi ...
- 简单的OO ALV显示ALV及下载
REPORT OO_ALV. CLASS OO_ALV DEFINITION. PUBLIC SECTION. METHODS:GET_DATA IMPORTING AMOUNT TYPE I,&qu ...
- OO ALV 后台运行时错误:Control Framework: Fatal error - GUI cannot be reached
这个错误的原因,是GUI容器依赖GUI的存在,因为它是在后台运行,没有GUI,因此控制错误. 可以通过做一些编码绕过这个. * ALV Grid DATA: R_GRID TYPE REF TO CL ...
- 20170314 OO ALV 出现双滚动条
1.出现双进度条,用户改变屏幕大小操作出现问题: 解决方法: [园童]BJ-ABAP-可乐(708925365) 16:08:55240 * 200改为240 200,然后将滚动条的步进改为1即可 ...
- ALV详解:OO SALV
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
随机推荐
- php 原生或curl获取 http headers
有一个函数: array get_headers ( string $url [, int $format = 0 ] ) Parameters url The target URL. format ...
- hdu1540之线段树单点更新+区间合并
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- jQuery推断复选框是否勾选
今天要实现一功能就是:复选框勾选时给input表单赋值,复选框取消时将表单值清除. 效果如图: 实现源代码:cyfID为复选框的id $("#cyfID").click(funct ...
- 边框圆角化方式(原文链接http://www.cnblogs.com/SJP666/p/4678730.html)
第一种方法:如果是CSS2.2的话,可以简单写一个制作圆角矩形,分上中下裁成三张图 <title>CSS3实现圆角</title> <style type="t ...
- 使用java对执行命令行 或 执行bat文件
public class Hellotianhao { public static void main(String[] args) throws Exception{ System.out.prin ...
- 修改linux文件权限命令:chmod 【转载】
Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. chmod 命令可以改变所有子目录的权限,下面有2种方法 改变一个文件的权限: chmod ...
- 【译】在Asp.Net中操作PDF - iTextSharp - 利用列进行排版
原文 [译]在Asp.Net中操作PDF - iTextSharp - 利用列进行排版 在使用iTextSharp通过ASP.Net生成PDF的系列文章中,前面的文章已经讲述了iTextSharp所涵 ...
- 项目优化经验分享(六)SVN冲突和处理
上一篇博客我们分享了新增需求的确定思想<站在全局看问题>.今天我们来分享项目开发中SVN冲突的解决经验:SVN冲突和处理! 引言 开发过项目的人都知道,公司开发一个项目都会使用到版本号控制 ...
- Mybatis 示例之 复杂(complex)属性(property)
Mybatis示例专栏:http://blog.csdn.net/column/details/mybatis-sample.html Mybatis的复杂属性,Mybatis的这个特点很少被提及,但 ...
- perl 继承 @ISA
12.5 类继承 对Perl的对象剩下的内容而言,从一个类继承另外一个类并不需要给这门语法增加特殊的语法,当你调用一个方法的时候, 如果Perl在调用者的包里找不到这个字过程,那么他就检查@ISA数组 ...