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的更多相关文章

  1. 简单的OO ALV小示例

    OO ALV即面向对象ALV,是在屏幕上显示的一种可以自定义大小的ALV.它区别普通ALV的优点是可以多个ALV出现在同一个屏幕,也可以同其他屏幕元素同时出现在同一个屏幕. 示例展示: 1. 进入实用 ...

  2. ALV详解:OO ALV

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. ABAP alv report

    *&---------------------------------------------------------------------* *& Report  YTST_FF_ ...

  4. OO ALV事件里使用E消息,下一步会退出到系统初始界面

    在OO ALV  data_change事件时(选中行),锁定KEY值, 继续,取消选择,退出到系统初始界面 改成 pv_status = 'E'. pv_msg = '采购订单' && ...

  5. OO ALV 学习参考

      http://blog.csdn.net/sapliumeng/article/details/18653491 一.ALV介绍 The ALV Grid Control (ALV = SAPLi ...

  6. 简单的OO ALV显示ALV及下载

    REPORT OO_ALV. CLASS OO_ALV DEFINITION. PUBLIC SECTION. METHODS:GET_DATA IMPORTING AMOUNT TYPE I,&qu ...

  7. OO ALV 后台运行时错误:Control Framework: Fatal error - GUI cannot be reached

    这个错误的原因,是GUI容器依赖GUI的存在,因为它是在后台运行,没有GUI,因此控制错误. 可以通过做一些编码绕过这个. * ALV Grid DATA: R_GRID TYPE REF TO CL ...

  8. 20170314 OO ALV 出现双滚动条

    1.出现双进度条,用户改变屏幕大小操作出现问题: 解决方法:  [园童]BJ-ABAP-可乐(708925365)  16:08:55240 * 200改为240 200,然后将滚动条的步进改为1即可 ...

  9. ALV详解:OO SALV

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

随机推荐

  1. ios中的任务分段

    工作比较忙,蛮久没有写东西了,今天我要写的是ios中的任务分段.大多数的情况下,我们用不到任务分段,但是如果我们是在执行比较频繁的函数或者这个函数是比较耗时, 某一条件下,我要执行新的任务,并且取消上 ...

  2. PHP通过Thrift操作Hbase

    PHP通过Thrift操作Hbase     HBase是一个开源的NoSQL产品,它是实现了Google BigTable论文的一个开源产品,和Hadoop和HDFS一起,可用来存储和处理海量col ...

  3. cocos2dx CCLabelTTF自己定义字体的使用

    版本号:  cocos2d-x 2.1.4 平台:  iOS 1. 字体文件名称 最好用字体冊中的family name.ttf, 不然字体可能不生效. 2. 在Info.plist  Fonts P ...

  4. python2.7 串口操作方式 编译 .py为windows可运行exe文件

    一 python操作串口 首先下载安装串口模块pyserial . 代码实现: import serial ser = serial.Serial('/dev/ttyUSB2', 115200) pr ...

  5. java组装json和提取一个json的例子

    package jsonparsed; import net.sf.json.JSONException; import net.sf.json.JSONObject; import net.sf.j ...

  6. Swift - iOS中各种视图控制器(View Controller)的介绍

    在iOS中,不同的视图控制器负责不同的功能,采用不同的风格向用户呈现信息.下面对各个视图控制器做个总结: 1,标准视图控制器 - View Controller 这个控制器只是用来呈现内容.通常会用来 ...

  7. Android如何监听蓝牙耳机的按键事件

    写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的 ...

  8. 关于caffe-windows中 compute_image_mean.exe出现的问题

    这两天有兴致装了下caffe.感受下这个框架. 可是在这个过程中遇到非常多问题.我把碰到的问题和解决方式写下,便于后人高速上手. compute_image_mean.exe 编译出来后.运行数据变换 ...

  9. NHibernate -- HQL

    使用NHibernate中的HQL来查询数据. 代码: /// <summary> /// 查找事件 /// </summary> private void btn_Selec ...

  10. 分布式消息系统jafka快速起步(转)

    Jafka 是一个开源的/性能良好的分布式消息系统.在上一篇文章中有所简单介绍.下面是一篇简单的入门文档.更多详细的文档参考wiki. Step 1: 下载最新的安装包 完整的安装指南在这里.最新的发 ...