其他分享
首页 > 其他分享> > ABAP学习(10):ALV显示之function alv

ABAP学习(10):ALV显示之function alv

作者:互联网

ABAP的ALV

1、Function ALV

    调用function,传入要显示的内表,显示样式等参数,显示alv。

    可以调用REUSE_ALV_GRID_DISPLAY这个function,也可以调用REUSE_ALV_GRID_DISPLAY_LVC这个function,输入的参数一致,但是一些细节传入参数类型不同。

REUSE_ALV_GRID_DISPLAY调用示例:

"调用function,显示alv

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

* EXPORTING

*   I_INTERFACE_CHECK                 = ' '

*   I_BYPASSING_BUFFER                = ' '

*   I_BUFFER_ACTIVE                   = ' '

*   I_CALLBACK_PROGRAM                = ' '

*   I_CALLBACK_PF_STATUS_SET          = ' '

*   I_CALLBACK_USER_COMMAND           = ' '

*   I_CALLBACK_TOP_OF_PAGE            = ' '

*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '

*   I_CALLBACK_HTML_END_OF_LIST       = ' '

*   I_STRUCTURE_NAME                  =

*   I_BACKGROUND_ID                   = ' '

*   I_GRID_TITLE                      =

*   I_GRID_SETTINGS                   =

*   IS_LAYOUT                         =

*   IT_FIELDCAT                       =

*   IT_EXCLUDING                      =

*   IT_SPECIAL_GROUPS                 =

*   IT_SORT                           =

*   IT_FILTER                         =

*   IS_SEL_HIDE                       =

*   I_DEFAULT                         = 'X'

*   I_SAVE                            = ' '

*   IS_VARIANT                        =

*   IT_EVENTS                         =

*   IT_EVENT_EXIT                     =

*   IS_PRINT                          =

*   IS_REPREP_ID                      =

*   I_SCREEN_START_COLUMN             = 0

*   I_SCREEN_START_LINE               = 0

*   I_SCREEN_END_COLUMN               = 0

*   I_SCREEN_END_LINE                 = 0

*   I_HTML_HEIGHT_TOP                 = 0

*   I_HTML_HEIGHT_END                 = 0

*   IT_ALV_GRAPHICS                   =

*   IT_HYPERLINK                      =

*   IT_ADD_FIELDCAT                   =

*   IT_EXCEPT_QINFO                   =

*   IR_SALV_FULLSCREEN_ADAPTER        =

* IMPORTING

*   E_EXIT_CAUSED_BY_CALLER           =

*   ES_EXIT_CAUSED_BY_USER            =

  TABLES

    T_OUTTAB                          = t_outtab

  EXCEPTIONS

   PROGRAM_ERROR                     = 1

   OTHERS                            = 2.
View Code

 REUSE_ALV_GRID_DISPLAY_LVC调用示例:

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

* EXPORTING

*   I_INTERFACE_CHECK                 = ' '

*   I_BYPASSING_BUFFER                =

*   I_BUFFER_ACTIVE                   =

*   I_CALLBACK_PROGRAM                = ' '

*   I_CALLBACK_PF_STATUS_SET          = ' '

*   I_CALLBACK_USER_COMMAND           = ' '

*   I_CALLBACK_TOP_OF_PAGE            = ' '

*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '

*   I_CALLBACK_HTML_END_OF_LIST       = ' '

*   I_STRUCTURE_NAME                  =

*   I_BACKGROUND_ID                   = ' '

*   I_GRID_TITLE                      =

*   I_GRID_SETTINGS                   =

*   IS_LAYOUT_LVC                     =

*   IT_FIELDCAT_LVC                   =

*   IT_EXCLUDING                      =

*   IT_SPECIAL_GROUPS_LVC             =

*   IT_SORT_LVC                       =

*   IT_FILTER_LVC                     =

*   IT_HYPERLINK                      =

*   IS_SEL_HIDE                       =

*   I_DEFAULT                         = 'X'

*   I_SAVE                            = ' '

*   IS_VARIANT                        =

*   IT_EVENTS                         =

*   IT_EVENT_EXIT                     =

*   IS_PRINT_LVC                      =

*   IS_REPREP_ID_LVC                  =

*   I_SCREEN_START_COLUMN             = 0

*   I_SCREEN_START_LINE               = 0

*   I_SCREEN_END_COLUMN               = 0

*   I_SCREEN_END_LINE                 = 0

*   I_HTML_HEIGHT_TOP                 =

*   I_HTML_HEIGHT_END                 =

*   IT_ALV_GRAPHICS                   =

*   IT_EXCEPT_QINFO_LVC               =

*   IR_SALV_FULLSCREEN_ADAPTER        =

*   I_YCBN                            =

* IMPORTING

*   E_EXIT_CAUSED_BY_CALLER           =

*   ES_EXIT_CAUSED_BY_USER            =

  TABLES

    T_OUTTAB                          = t_outtab

  EXCEPTIONS

    PROGRAM_ERROR                     = 1

    OTHERS                            = 2.
View Code

 

1.1、Function参数解析

I_INTERFACE_CHECK:检查接口一致性,默认Space;

I_BYPASSING_BUFFER:是否使用缓存buffer,类型:字符型1;

I_BUFFER_ACTIVE:是否激活缓存;

 

I_CALLBACK_PROGRAM:调用alv程序名,一般就是当前程序,sy-repid,类型:sy-repid,默认Space;

I_CALLBACK_PF_STATUS_SET:ALV工具栏Subroutine, ALV屏幕菜单,此参数允许报表展现用户自定义的屏幕菜单,类型:SLIS_FORMNAME,默认Space,

I_CALLBACK_USER_COMMAND:ALV user Command Subroutine(子程序),类型:SLIS_FORMNAME,默认Space;

I_CALLBACK_TOP_OF_PAGE:ALV抬头内容信息,类型:SLIS_FORMNAME,默认Space;

I_CALLBACK_HTML_TOP_OF_PAGE:ALV HTML格式抬头内容信息,类型:SLIS_FORMNAME,默认Space;

I_CALLBACK_HTML_END_OF_LIST:ALV HTML格式页脚内容信息,类型:SLIS_FORMNAME,默认Space;

 

I_STRUCTURE_NAME:为输出表数据结构的命名,类型:DD02L-TABNAME;

I_BACKGROUND_ID:ALV背景图片Object ID,类型:SDYDO_KEY,默认Space;

I_GRID_TITLE: ALV 标题,类型:LVC_TITLE;

I_GRID_SETTINGS:GRID设置信息,类型:LVC_S_GLAY;

IS_LAYOUT_LVC:ALV输出布局样式,类型:LVC_S_LAYO;

IT_FIELDCAT_LVC:设定显示的栏位名称及输出设定,类型:LVC_T_FCAT;

IT_EXCLUDING:隐藏设置的ALV工具栏,未激活的功能码,类型:SLIS_T_EXTAB;

IT_SPECIAL_GROUPS_LVC:若内表中一些字段通过SP_GROUP被分组在一起,必须为这些组传递组文本内表,类型:LVC_T_SGRP;

IT_SORT_LVC:ALV排序,类型:LVC_T_SORT;

IT_FILTER_LVC:ALV过滤器,类型:LVC_T_FILT;

IT_HYPERLINK:超链接,类型:LVC_T_HYPE;

IS_SEL_HIDE:替换或修改屏幕中select-option的值,类型:SLIS_SEL_HIDE_ALV;

 

I_DEFAULT:用户是否可以定义默认布局,Space-不可以定义默认布局 (默认:X);

I_SAVE: 保存表格布局,’X'-只能保存全局变式;’U'-只能保存特定变式;’A'-都可以保存;Space-不能保存变式 (默认:space);

IS_VARIANT:表格布局变式,类型:DISVARIANT;

 

IT_EVENTS:设置事件,类型为slis_t_event的内表(name:事件名称,form:事件的FORM),类型:SLIS_T_EVENT;

IT_EVENT_EXIT:设置回调的方法的执行行为,表明用户所写的代码是在执行标准执行之前还是之后,类型:SLIS_T_EVENT_EXIT;

 

IS_PRINT_LVC:打印信息,类型:LVC_S_PRNT;

IS_REPREP_ID_LVC:re/re接口初始化信息,类型:LVC_S_RPRP;

 

I_SCREEN_START_COLUMN:对话框形式显示开始列,默认:0;

I_SCREEN_START_LINE:对话框形式显示开始行,默认:0;

I_SCREEN_END_COLUMN:对话框形式显示结束列,默认:0;

I_SCREEN_END_LINE:对话框形式显示结束行,默认:0;

 

I_HTML_HEIGHT_TOP:HTML抬头的高度,类型:I;

I_HTML_HEIGHT_END: HTML页脚的高度,类型:I;

 

IT_ALV_GRAPHICS:是否可以在图表中显示ALV,类型:DTC_T_TC;

IT_EXCEPT_QINFO_LVC:Exception的信息,类型:SLIS_T_QINFO_ALV;

IR_SALV_FULLSCREEN_ADAPTER:类型:CL_SALV_FULLSCREEN_ADAPTER;

I_YCBN:类型:char1;

 

1.2、自定义屏幕菜单

    使用I_CALLBACK_PF_STATUS_SET参数,可以设置自定义屏幕菜单。

设置步骤:

1.创建自定义status。

 

2.设置自定义菜单的子程序form

示例:

"自定义屏幕菜单

form my_pf_status USING p_extab TYPE slis_t_extab.

  set PF-STATUS 'ALV_STATUS'.

endform.

 

3.设置function输入参数I_CALLBACK_PF_STATUS_SET等于子程序名,form的名字必须大写,不然识别不了。

示例:

 I_CALLBACK_PF_STATUS_SET  = 'MY_PF_STATUS'

 

标准菜单栏

1、没有自定义按钮时候,显示ALV标准的工具栏;

2、当我们使用自定义按钮后,ALV自带的标准按钮,则会失效,这时需要将一些必要的按钮在工具条补上;

3、其中 “分隔符” 的插入方法为:选择菜单:Edit->Insert-> Separator line 即可插入分隔符;

4、可以快速拷贝标准程序的菜单栏,再进行修改、筛选;

通过se80,Repository Information System -> Program Library -> Program Subobjects->GUI Status;

查找Program Name:SAPLKKBL;

 

查找STANDARD 或 STANDARD_FULLSCREEN;

 

 

 

也可以直接通过Repository Browser查找Function Group :KKBL,GUI Status:Standard

 

选择Standard,右键copy,要copy到的Program,Status名字。

标准Toolbar:

 

 

 

 

1.3、用户操作响应

    当用户点击菜单栏,点击自定义按钮等操作,响应这些操作。

使用参数I_CALLBACK_USER_COMMAND,设置用户操作响应的子程序。

    双击显示明细:使用REUSE_ALV_GRID_DISPLAY_LVC 时,会发现使用 REUSE_ALV_GRID_DISPLAY 时的双击显示行明细功能没有了,这是SAP标准程序决定的,REUSE_ALV_GRID_DISPLAY_LVC 已经取消了双击显示行明细功能。我们可以监听双击的function code:‘&IC1’,执行标准的显示明细function code。

示例:

I_CALLBACK_USER_COMMAND           = 'MY_USER_COMMAND'

对应的Form子程序:

"用户操作响应,R_UCOMM 用户操作,RS_SELFIELD 选择或点击的行列信息

form my_user_command USING R_UCOMM LIKE SY-UCOMM

               RS_SELFIELD TYPE SLIS_SELFIELD.

  "将ALV显示数据更新进输出内表中  

DATA: LR_GRID TYPE  REF TO CL_GUI_ALV_GRID.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

    IMPORTING

      E_GRID = LR_GRID.

  CALL METHOD LR_GRID->CHECK_CHANGED_DATA.

  RS_SELFIELD-REFRESH = 'X'.    " REFESH ALV

  "用户操作

  CASE R_UCOMM.

     WHEN '&IC1'.  "双击显示明细

      R_UCOMM = '&ETA'.  "调用系统功能,查看明细

  ENDCASE.
endform.

1.4、alv抬头标题信息

    I_CALLBACK_TOP_OF_PAGE 与 I_CALLBACK_HTML_TOP_OF_PAGE 参数属性都用于书写 ALV抬头标题信息,只是区别在于后者支持 HTML格式;

    参数类型:SLIS_FORMNAME,也与 I_CALLBACK_PF_STATUS_SET 参数一样,为定义的子FORM,不显式调用。

    I_CALLBACK_HTML_TOP_OF_PAGE ,需要配合CL_DD_DOCUMENT(动态文本类)来显示HTML格式。

    I_CALLBACK_TOP_OF_PAGE ,需要配合REUSE_ALV_COMMENTARY_WRITE函数输出抬头或页脚信息。

     使用REUSE_ALV_COMMENTARY_WRITE函数的参数I_LOGO可以设置表头显示图片,通过Tcode:OAER,Class name:PICTURES,Class Type:OT,Object key:图片id,通过这个id可以访问到这张图片,I_LOGO = object key。

 

 

 

 选择Screen,双击,出现文件选择弹窗,选择要上传图片,点击确认。

 

 

 

 

示例:

I_CALLBACK_TOP_OF_PAGE            = 'MY_TOP_OF_PAGE' 

I_CALLBACK_HTML_TOP_OF_PAGE       = 'MY_HTML_TOP_OF_PAGE'

 

 对应设置alv抬头的Form子程序:

"使用I_CALLBACK_TOP_OF_PAGE,alv抬头信息

form my_top_of_page.

  "保存表头显示信息

  DATA:header TYPE SLIS_T_LISTHEADER.

  DATA:wa_header LIKE LINE OF header.

 
  wa_header-typ = 'H'.   " H = Header, S = Selection, A = Action

  wa_header-info = '这是头'.

  APPEND wa_header TO header.

  clear wa_header.

 
  "参数IT_LIST_COMMENTARY,显示文字内容

  "参数I_LOGO ,显示图片id,使用OAER上传图片

  "参数I_END_OF_LIST_GRID,页脚信息

  "参数I_ALV_FORM,是否用于alv form中

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

      IT_LIST_COMMENTARY       = header

*     I_LOGO                   =               "图片id,

*     I_END_OF_LIST_GRID       =

*     I_ALV_FORM               =

      .
endform.

 

对应设置alv抬头的Form子程序:

"使用I_CALLBACK_HTML_TOP_OF_PAGE,alv抬头信息

form my_html_top_of_page USING p_cl_dd_document TYPE REF TO cl_dd_document.

 DATA:pos TYPE I.

 "html_insert,这个方法显示弃用

 CALL METHOD p_cl_dd_document->html_insert

    EXPORTING

      contents = '这是头'

   CHANGING

      position = pos.

endform.

 

1.5、I_GRID_TITLE小标题

    使用I_GRID_TITLE参数可以设置alv的小标题,这个表题显示在alv表头之下。

示例:

"小标题

DATA:my_grid_titile TYPE lvc_title VALUE '小标题'.

I_GRID_TITLE = my_grid_titile

 

1.6、I_GRID_SETTINGS参数

    I_GRID_SETTINGS这个参数用来设置GRID相关配置,单元格编辑回调。参数数据类型:LVC_S_GLAY。

    LVC_S_GLAY是内表结构类型,

COLL_TOP_P:最小TOP_OF_PAGE;

COLL_END_L:最小END_OF_LIST;

TOP_P_ONLY:仅打印TOP_OF_PAGE;

EOL_P_ONLY:仅打印END_OF_LIST;

NO_COLWOPT:打印时不优化列宽;

EDT_CLL_CB:是否退出当前编辑单元格时回调,是等于‘X’;

示例:

"GRID配置

DATA:my_grid_settings TYPE LVC_S_GLAY.

"响应输入enter回调函数

my_grid_settings-EDT_CLL_CB = 'X'. "允许回调ALV control: Callback when leaving an edited cell

 

1.7、Layout设置

LS_LAYOUT_LVC参数设置layout,alv输出格式,可以设置也可不设值。

Function REUSE_ALV_GRID_DISPLAY_LVC 使用的就是LS_LAYOUT_LVC这个参数,参数类型:lvc_s_layo。

Function REUSE_ALV_GRID_DISPLAY 使用的是IS_LAYOUT这个参数,数据类型为slis_layout_alv。

示例:

"alv的layout设置,REUSE_ALV_GRID_DISPLAY使用

DATA:my_layout TYPE slis_layout_alv.

"alv的layout设置,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_layout_lvc TYPE lvc_s_layo.

LVC_S_LAYO属性:

ZEBRA:是否使用间隔条纹颜色显示alv,是‘X’,否为space;

EDIT:是否可编辑,是‘X’,否为Space,单元格编辑控制字段STYLEFNAME需要EDIT字段配合才能实现每个单元格编辑控制;

EDIT_MODE:编辑模式,数据类型:Char1;

NO_KEYFIX:是否关键词不固定,随着滚动条滚动,是‘X’,否为Space;

CWIDTH_OPT:是否自动优化列宽,是为‘X’,否为Space;

FRONTEND: ALV控件:Excel,Crystal或ALV,数据类型:Char1;

LANGUAGE:语言标志,数据类型:LANG

NO_HGRIDLN:是否隐藏水平线是为‘X’,否为space;

NO_VGRIDLN:是否隐藏垂直线是为‘X’,否为space;

NO_HEADERS:是否隐藏列抬头是为‘X’,否为space;

NO_MERGING:单元格合并禁止,数据类型:char1;

TOTALS_BEF:在单项记录前总计输出,数据类型:char1;

NO_TOTARR:汇总行前显示箭头表示汇总,数据类型char1;

NO_TOTEXP:只显示小计,不显示总计,数据类型char1;

NO_F4:屏蔽F4帮助,数据类型char1;

COUNTFNAME:内表内部显示字段;

STYLEFNAME:内表内部显示字段,单元格编辑控制字段;

NO_ROWMARK:是否禁用行选择是为‘X’,否为space;

NO_TOOLBAR:是否隐藏工具栏是为‘X’,否为space;

GRID_TITLE:标题栏文本;

SEL_MODE:选择模式,‘A’选择按钮,Space空白;

BOX_FNAME:内表内部显示字段;

SGL_CLK_HD:第一次点击列头,升序;第二次点击降序;

NO_TOTLINE:不输出总计行,数据类型:char1;

NUMC_TOTAL:是否禁止NUMC数据类型总计,是为‘X’,否为space;

NO_UTSPLIT:是否不按单元拆分总计行,是为‘X’,否为space;

 

EXCP_FNAME:异常字段编码;

EXCP_ROLLN:异常文档的数据元素;

EXCP_CONDS:是否异常汇总,数据类型char1;

EXCP_LED:是否异常LED显示,数据类型char1;

EXCP_GROUP:异常分组,数据类型char1;

 

DETAILINIT:是否细节屏幕显示初始值,数据类型char1;

DETAILTITL:细节屏幕titlebar;

KEYHOT:关键字栏作为热点链接,数据类型char1;

NO_AUTHOR:不授权检查,数据类型char1;

XIFUNCKEY:附加功能名;

XIDIRECT:一般标记;

 

S_DRAGDROP:拖动控制,数据类型:LVC_S_DD01,

LVC_S_DD01内表结构:

CNTR_DDID:拖放对象handle,数据类型int4;

GRID_DDID: 拖放对象handle,数据类型int4;

COL_DDID: 拖放对象handle,数据类型int4;

ROW_DDID:拖放对象handle,数据类型int4;

FIELDNAME:内表内部显示字段;

 

INFO_FNAME:ALV控件:具有简单行颜色编码的字段名称

CTAB_FNAME:ALV控件:具有复杂单元格颜色编码的字段名称

 

WEBLOOK:ALV控件,WEBLOOK;

WEBSTYLE:Style;

WEBROWS:web显示行数,数据类型:INT4;

WEBXWIDTH:宽度,数据类型:INT4;

WEBXHEIGHT:高度,数据类型:INT4;

 

SLIS_LAYOUT_ALV属性

slis_layout_alv组成:slis_layout_alv_spec0和slis_layout_alv_spec1。

源码:

types: begin of slis_layout_alv_spec0,

no_colhead(1) type c,    " no headings

no_hotspot(1) type c,    " headings not as hotspot

zebra(1) type c,      " striped pattern

no_vline(1) type c,     " columns separated by space

no_hline(1) type c,     "rows separated by space B20K8A0N5D

cell_merge(1) type c,    " not suppress field replication

edit(1) type c,       " for grid only

edit_mode(1) type c,     " for grid only

numc_sum(1)  type c,  " totals for NUMC-Fields possib.

no_input(1) type c,   " only display fields

f2code like sy-ucomm, 

reprep(1) type c,   "report report interface active

no_keyfix(1) type c,   " do not fix keycolumns

expand_all(1) type c,  " Expand all positions

no_author(1) type c, " No standard authority check

*        PF-status

def_status(1) type c,  " default status  space or 'A'

item_text(20) type c,   " Text for item button

countfname type lvc_fname,

end of slis_layout_alv_spec0.

 

types: begin of 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-insz,   " 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," fieldname for exception

lights_tabname type slis_tabname, " fieldname for exception

lights_rollname like dfies-rollname," rollname f. exceptiondocu

lights_condense(1) type c,    " fieldname for exception

* Sums

no_sumchoice(1) type c,      " no choice for summing up

no_totalline(1) type c,       " no total line

no_subchoice(1) type c,       " no choice for subtotals

no_subtotals(1) type c,       " no subtotals possible

no_unit_splitting type c,   " no sep. tot.lines by inh.units

totals_before_items type c, " diplay totals before the items

totals_only(1) type c,    " show only totals

totals_text(60) type c,  " text for 1st col. in total line

subtotals_text(60) type c,  " text for 1st col. in subtotals

* Interaction

box_fieldname type slis_fieldname, " fieldname for checkbox

box_tabname type slis_tabname," tabname for checkbox

box_rollname like dd03p-rollname," rollname for checkbox

expand_fieldname type slis_fieldname, " fieldname flag 'expand'

hotspot_fieldname type slis_fieldname, " fieldname flag hotspot

confirmation_prompt,   " confirm. prompt when leaving

key_hotspot(1) type c,  " keys as hotspot " K_KEYHOT

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,  " show detail in popup

detail_initial_lines(1) type c, " show also initial lines

etail_titlebar like sy-title," Titlebar for detail

* Display variants

 header_text(20) type c,       " Text for header button

 efault_item(1) type c,       " Items as default

* colour

info_fieldname type slis_fieldname, " infofield for listoutput

coltab_fieldname type slis_fieldname, " colors

* others

list_append(1) type c,       " no call screen

xifunckey type aqs_xikey,    " eXtended interaction(SAPQuery)

xidirect type flag,      " eXtended INTeraction(SAPQuery)

dtc_layout type dtc_s_layo,  "Layout for configure the Tabstip

allow_switch_to_list(1) type c, "ACC: Switch from FullGrid to List

end of slis_layout_alv_spec1.
View Code

 

1.8、Fieldcat设置

    Fieldcat 主要用于ALV的结构定义,包括具体的栏位及名称、类型、格式等属性,为 ALV 输出的必选项。

Function REUSE_ALV_GRID_DISPLAY_LVC 使用的就是IT_FIELDCAT_LVC这个参数,参数类型:LVC_T_FCAT

Function REUSE_ALV_GRID_DISPLAY 使用的是IT_FIELDCAT这个参数,数据类型为SLIS_T_FIELDCAT_ALV。

示例:

"alv的fieldcat设置,REUSE_ALV_GRID_DISPLAY使用

DATA:my_fieldcat TYPE SLIS_T_FIELDCAT_ALV.

DATA:wa_fieldcat TYPE slis_fieldcat_alv. "工作区

 

"alv的fieldcat设置,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_fieldcat_lvc TYPE LVC_T_FCAT.

DATA:wa_fieldcat_lvc TYPE LVC_S_FCAT. "工作区

LVC_S_LAYO属性:

EDIT:当前字段列是否可输入,数据类型char1;

ROW_POS:行位置,数据类型:INT4;

COL_POS:列位置,数据类型:INT4;

FIELDNAME:内表显示字段名称;

TABNAME:内表名;

REPTEXT:列名,列表标题栏;

CURRENCY:货币单位;

CFIELDNAME:货币单位字段名称;

QUANTITY:度量单位;

QFIELDNAME:度量单位字段名称;

IFIELDNAME:内表字段名称;

ROUND:四舍五入保留位数,数据类型:INT4;

ROUNDFIELD:四舍五入字段名;

DECIMALS_O:输出小数位数,数据类型char6;

DECMLFIELD:小数字段名称;

DECIMALS:小数位数,数据类型Numc6;

EXPONENT:浮点表示指数,数据类型:char3;

KEY:是否关键字段,数据类型:char1;

KEY_SEL:是否隐藏键列,数据类型:char1;

ICON:是否输出为ICON,数据类型:char1;

SYMBOL:是否输出为Symbol,数据类型:char1;

CHECKBOX:是否输出为checkbox,数据类型:char1;

JUST:是否对齐,默认左对齐,数据类型:char1, R:Right L:Left C:Center ;

LZERO:是否输出前导0,数据类型:char1;

NO_SIGN:禁止输出正负号,数据类型char1;

NO_ZERO:禁止输出0,数据类型char1;

NO_CONVEXT:不考虑将转换退出用于输出;

EDIT_MASK:EDITMASK输出,格式化输出时间等;

EMPHASIZE:高亮颜色显示;

FIX_COLUMN:是否固定列,数据类型char1;

DO_SUM:当前列的合计值,数据类型char1;

NO_SUM:没有汇总列值,数据类型char1;

NO_OUT:列不输出,数据类型char1;

TECH:Technical字段,数据类型char1,设置为‘X’,字段不能输出,不显示;

OUTPUTLEN:输出字符长度,列宽度;

DD_OUTLEN:输出字符长度;

INTLEN:字节长度;

CONVEXIT:转换Routine;

SELTEXT:对话框function的列标识;

TOOLTIP:工具提示列标题;

ROLLNAME:F1帮助数据元素;

DATATYPE:ABAP数据字典中数据类型;

INTTYPE:ABAP基本数据类型C,D,N等;

LOWERCASE:是否允许小写,数据类型char1;

HIER_LEVEL:internal use;

REPREP:Value is selection criterion for rep./rep.intf;

DOMNAME:域名;

SP_GROUP:group key;

HOTSPOT:栏位是否有热点,数据类型char1;

DFIELDNAME:数据库中列组字段名称;

COL_ID:column id;

AUTO_VALUE:自动值copy;

CHECKTABLE:表名;

VALEXI:是否存在固定值,数据类型char1;

WEB_FIELD:内表字段名;

HREF_HNDL:Natual Number,数据类型INT4;

NO_MERGING:是否禁止合并,数据类型char1;

COL_OPT:列自动优化;

F4AVAILABL:是否有输入帮助,数据类型char1;

REF_FIELD:内表栏位参考栏位,用于f4帮助;

REF_TABLE:内表参考内表,用于f4帮助;

TXT_FIELD:内表字段名;

COLTEXT:列标题;

SCRTEXT_L:长字段标签;

SCRTEXT_M:中长字段标签;

SCRTEXT_S:短字段标签;

COLDDICTXT:DDIC文本参考,数据类型char1;

SELDDICTXT: DDIC文本参考,数据类型char1;

TIPDDICTXT: DDIC文本参考,数据类型char1;

 

SLIS_FIELDCAT_ALV属性:

Fieldcat属性结构源码:

*** Fieldcat

types: begin of slis_fieldcat_main0,

row_pos        like sy-curow, " output in row

col_pos        like sy-cucol, " position of the column

fieldname      type slis_fieldname,

tabname        type slis_tabname,

currency(5)    type c,

cfieldname  type slis_fieldname, " field with currency unit

ctabname  type slis_tabname,   " and table

ifieldname     type slis_fieldname, " initial column

quantity(3)    type c,

qfieldname type slis_fieldname, " field with quantity unit

qtabname       type slis_tabname,   " and table

round  type i,  " round in write statement

exponent(3)  type c,   " exponent for floats

key(1)   type c,    " column with key-color

icon(1)   type c,        " as icon

symbol(1)  type c,        " as symbol

checkbox(1) type c,        " as checkbox

just(1)   type c,        " (R)ight (L)eft (C)ent.

lzero(1)   type c,        " leading zero

o_sign(1)  type c,        " write no-sign

no_zero(1)  type c,        " write no-zero

no_convext(1)  type c,

edit_mask   type slis_edit_mask, 

emphasize(4)  type c,        " emphasize

fix_column(1)  type c,       " Spalte fixieren

do_sum(1)    type c,        " sum up

no_out(1)    type c,        " (O)blig.(X)no out

tech(1)    type c,        " technical field

outputlen   like dd03p-outputlen,

offset    type dd03p-outputlen,     " offset

seltext_l   like dd03p-scrtext_l, " long key word

seltext_m   like dd03p-scrtext_m, " middle key word

seltext_s   like dd03p-scrtext_s, " short key word

ddictxt(1)  type c,        " (S)hort (M)iddle (L)ong

rollname       like dd03p-rollname,

datatype       like dd03p-datatype,  

inttype        like dd03p-inttype,

intlen         like dd03p-intlen,

lowercase      like dd03p-lowercase,

decfloat_style type outputstyle,    " B20K8A2GF0

parameter0     type char30,

parameter1     type char30,

parameter2     type char30,

parameter3     type char30,

parameter4     type char30,

parameter5     type int4,        

parameter6     type int4,

parameter7     type int4,

parameter8     type int4,

parameter9     type int4,

end of slis_fieldcat_main0.

 

types: begin of slis_fieldcat_main1,

ref_fieldname  like dd03p-fieldname,

ref_tabname    like dd03p-tabname,

roundfieldname type slis_fieldname,

roundtabname   type slis_tabname,

decimalsfieldname type slis_fieldname,

decimalstabname   type slis_tabname,

decimals_out(6)   type c,   " decimals in write statement

text_fieldname type slis_fieldname,

reptext_ddic   like dd03p-reptext,   " heading (ddic)

ddic_outputlen like dd03p-outputlen,

end of slis_fieldcat_main1.

 

types: begin of slis_fieldcat_alv_spec,

key_sel(1)     type c,   " field not obligatory

no_sum(1)      type c,        " do not sum up

sp_group(4)    type c,        " group specification

reprep(1)      type c,       " selection for rep/rep

input(1)       type c,      " input

edit(1)        type c,      " internal use only

hotspot(1)     type c,        " hotspot

end of slis_fieldcat_alv_spec.
View Code

设置Fieldcat示例:使用工作区对对应属性赋值,然后将工作区加入内表。Fieldcat内表中记录就是alv中依次输出栏位。

"设置显示栏位

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'CARRID'.  "内表显示字段名

wa_fieldcat_lvc-REPTEXT = 'id'.        "字段对应描述,列名

wa_fieldcat_lvc-TABNAME = 't_outtab'.  "内表名

wa_fieldcat_lvc-col_opt = 'X'.         "单列宽优化

wa_fieldcat_lvc-just = 'R'.            "设置R右对齐,L左对齐,C居中对齐

wa_fieldcat_lvc-rollname = ''.   "F1帮助,指定数据元素

wa_fieldcat_lvc-ref_field = 'carrid'.  "F4帮助对应DDIC参考字段

wa_fieldcat_lvc-ref_table = 'spfli'.   "F4帮助对应DDIC表

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'CITYFROM'.

wa_fieldcat_lvc-REPTEXT = '出发城市'.

wa_fieldcat_lvc-TABNAME = 't_outtab'.

wa_fieldcat_lvc-OUTPUTLEN = 20.       "设置输出列宽

wa_fieldcat_lvc-EDIT = 'X'.         "设置该字段列可编辑

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'ICON_FOLDER'.

wa_fieldcat_lvc-REPTEXT = '图标'.

wa_fieldcat_lvc-icon = 'X'.          "显示图标

wa_fieldcat_lvc-hotspot = 'X'.       "使用热点点击,触发function code '&IC1'

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

1.9、IT_EXCLUDING属性设置

    IT_EXCLUDING用来将不需要的工具栏按钮FCODE隐藏掉,也可以通过这个实现动态的工具栏。

示例:

设置IT_EXCLUDING参数

IT_EXCLUDING = my_excluding
"用来隐藏fcode

DATA:my_excluding TYPE slis_t_extab.

DATA:wa_excluding TYPE slis_extab.

 
"直接将要隐藏的工具栏按钮对应Fcode加入内表,就可以隐藏掉

wa_excluding-fcode = '&UMC'.

APPEND wa_excluding to my_excluding.

 

 

1.10、IT_SORT_LVC排序

    sort主要用于ALV的字段排序。

Function REUSE_ALV_GRID_DISPLAY_LVC 使用的就是IT_SORT_LVC  这个参数,参数类型:LVC_T_SORT。

Function REUSE_ALV_GRID_DISPLAY 使用的是IT_SORT这个参数,数据类型为SLIS_T_SORTINFO_ALV。

示例:

"ALV字段排序,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_sort_lvc TYPE LVC_T_SORT.

DATA:wa_sort_lvc TYPE LVC_S_SORT.

 

"ALV字段排序,REUSE_ALV_GRID_DISPLAY使用

DATA:my_sort TYPE SLIS_T_SORTINFO_ALV.

DATA:wa_sort TYPE slis_sortinfo_alv.

 

LVC_S_SORT属性:

SPOS:排序位置;

FIELDNAME:内表显示栏位字段名;

UP:升序排列,数据类型:char1;

DOWN:降序排序,数据类型:char1;

GROUP: 控制中断:插入分页符,下划线;

SUBTOT:输出小计;

COMP:数据类型char1,标志;

EXPA:数据类型char1,标志;

SELTEXT:排序标准;

OBLIGATORY:是否必须,数据类型char1;

LEVEL:数据类型INT4;

NO_OUT:是否不输出,数据类型char1;

INTOPT: 内部优化,内部使用;

 

slis_sortinfo_alv属性:

slis_sortinfo_alv结构源码

types: begin of slis_sortinfo_alv,

*        spos(2) type n,

         spos like alvdynp-sortpos,

         fieldname type slis_fieldname,

         tabname type slis_fieldname,

*        up(1) type c,

*        down(1) type c,

*        group(2) type c,

*        subtot(1) type c,

         up like alvdynp-sortup,

         down like alvdynp-sortdown,

         group like alvdynp-grouplevel,

         subtot like alvdynp-subtotals,

         comp(1) type c,

         expa(1) type c,

         obligatory(1) type c,

       end of slis_sortinfo_alv.
View Code

 

1.11、用户ALV布局

    I_DEFAULT/ I_SAVE/ IS_VARIANT 参数,都可以操作ALV布局。

    I_DEFAULT参数用于设置用户是否可以定义默认的布局: ’X' 可以定义默认布局, SPACE 不可以定义默认布局。(默认:X)

I_SAVE 参数 保存表格布局: ’X' 只能保存全局变式 ’U' 只能保存特定变式 ’A' 都可以保存 SPACE 不能保存变式 。(默认:space)

IS_VARIANT 参数用于启用用户表格布局变式;

 

1.12、ALV事件

    IT_EVENTS 参数属性设置ALV事件处理。数据类型:SLIS_T_EVENT类型的内表,设置相应处理FORM;

示例:

"事件处理IT_EVENTS

DATA:my_events TYPE SLIS_T_EVENT.

DATA:wa_events TYPE slis_alv_event.

 

SLIS_ALV_EVENT属性:

对应类型源码:

types: begin of slis_alv_event,

        name(30),

        form(30),

      end of slis_alv_event.

通过与REUSE_ALV_EVENTS_GET函数配合使用,可自定义ALV事件。

I_LIST_TYPE获取不同类型alv的事件,0:表示获取的是通过函数REUSE_ALV_LIST_DISPLAY产生的ALV所支持的事件;4:表示获取的是通过函数REUSE_ALV_GUID_DISPLAY产生的ALV所支持的事件。

示例:

"获取alv中现有事件

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

* EXPORTING

*   I_LIST_TYPE           = 0

* IMPORTING

*   ET_EVENTS             =

* EXCEPTIONS

*   LIST_TYPE_WRONG       = 1

*   OTHERS                = 2.

 

1.13、重定义事件

    1、类lcl_event_handler,事件接收处理类;

    2、定义CL_GUI_ALV_GRID类对象;

    3、设置SLIS_T_EVENT类型内表值;

    4、指定function alv 使用的SLIS_T_EVENT;

    5、添加事件名,以及事件对应Form;

    6、设置function alv 的参数IT_EVENTS;

示例:

CLASS: lcl_event_handler DEFINITION DEFERRED.

DATA: g_event_receiver TYPE REF TO lcl_event_handler.

DATA: gr_grid TYPE  REF TO CL_GUI_ALV_GRID.

 

事件接收处理类定义:为event:data_changed_finished,单元格输入后enter事件,定义方法handle_modefy。

"事件类定义

CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    METHODS:

    handle_modify FOR EVENT data_changed_finished OF cl_gui_alv_grid

      IMPORTING e_modified et_good_cells.

ENDCLASS.

 

实现事件类中方法:

"事件类实现

CLASS lcl_event_handler IMPLEMENTATION.

  METHOD handle_modify.

DATA: ls_stbl TYPE lvc_s_stbl.

    “当单元格内容修改,enter按下逻辑代码

“稳定刷新 

ls_stbl = 'XX'.

    CALL METHOD gr_grid->refresh_table_display

      EXPORTING

        is_stable = ls_stbl.

  ENDMETHOD.                    "HANDLE_MODIFY

ENDCLASS.

 

设置SLIS_T_EVENT,function alv事件,事件名:CALLER_EXIT,触发Form名:FM_CALLER_EXIT,这个form名可以自己定义。

WA_EVENTS-name = 'CALLER_EXIT'.

WA_EVENTS-form = 'FM_CALLER_EXIT'.

APPEND WA_EVENTS TO IT_EVENTS.

 

CALLER_EXIT事件触发Form:

    1、通过GET_GLOBALS_FROM_SLVC_FULLSCR,获取alv对应CL_GUI_ALV_GRID类对象;

    2、给alv对象注册事件;

    3、将我们自己写的事件处理类对象设置给alv对象;

FORM FM_CALLER_EXIT USING ir_grid TYPE slis_data_caller_exit.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

    IMPORTING

      e_grid = gr_grid.

 

  "---注册回车事件

  CALL METHOD gr_grid->register_edit_event

    EXPORTING

      i_event_id = cl_gui_alv_grid=>mc_evt_enter

    EXCEPTIONS

      error      = 1

      OTHERS     = 2.

  CREATE OBJECT g_event_receiver.

  SET HANDLER g_event_receiver->handle_modify FOR gr_grid.

ENDFORM.

 

1.14、事件实现下拉选择框

    1、创建存储下拉选项的内表LVC_T_DROP;

示例:

"定义存储下拉列表的数据

GT_DDVAL TYPE LVC_T_DROP,

GW_DDVAL TYPE LVC_S_DROP,

    2、设置显示结构中加入下拉列DD_HANDLE

示例:

 BEGIN OF T_ALV,

    MATNR TYPE MAKT-MATNR,

    MAKTX TYPE MAKT-MAKTX,

    SPRAS TYPE MAKT-SPRAS,

    DD_HANDLE TYPE INT4,

END OF T_ALV.

 3、下拉列DD_HANDLE需要绑定具体列,在fieldcat中设置,SPRAS栏位的值是下拉列表中值;

GW_FIELDCATALOG-FIELDNAME = 'SPRAS'.

GW_FIELDCATALOG-DRDN_FIELD = 'DD_HANDLE'.

    4、下拉列表设置值;

    5、添加事件名,以及事件对应Form,这里事件名依旧是CALLER_EXIT,对应Form中需要:通过GET_GLOBALS_FROM_SLVC_FULLSCR,获取alv对应CL_GUI_ALV_GRID类对象;再通过CL_GUI_ALV_GRID 类对象调用SET_DROP_DOWN_TABLE方法,设置下拉列表。

    6、设置function alv 的参数IT_EVENTS;

示例:L_REF_ALV是CL_GUI_ALV_GRID 类对象

CALL METHOD L_REF_ALV->SET_DROP_DOWN_TABLE

    EXPORTING

      IT_DROP_DOWN = GT_DDVAL.

 

完整示例:通过事件实现下拉选择框

TYPE-POOLS: SLIS.

TYPES: BEGIN OF T_DATA,

  MATNR TYPE MAKT-MATNR,

  MAKTX TYPE MAKT-MAKTX,

  SPRAS TYPE MAKT-SPRAS,

  END OF T_DATA,

  BEGIN OF T_ALV,

    MATNR TYPE MAKT-MATNR,

    MAKTX TYPE MAKT-MAKTX,

    SPRAS TYPE MAKT-SPRAS,

    DD_HANDLE TYPE INT4,

    END OF T_ALV.

DATA: GT_FIELDCATALOG TYPE LVC_T_FCAT,

      GW_FIELDCATALOG TYPE LVC_S_FCAT,

      "定义存储下拉列表的数据

      GT_DDVAL TYPE LVC_T_DROP,

      GW_DDVAL TYPE LVC_S_DROP,

      GT_EVENTS TYPE SLIS_T_EVENT,

      GW_EVENTS TYPE SLIS_ALV_EVENT,

      GT_DATA TYPE TABLE OF T_DATA,

      GW_DATA TYPE T_DATA,

      GT_ALV TYPE TABLE OF T_ALV,

      GW_ALV TYPE T_ALV,

      G_REPID TYPE SY-REPID VALUE SY-REPID.

 

SELECT-OPTIONS: S_MATNR FOR GW_DATA-MATNR .

 

START-OF-SELECTION.

SELECT MATNR MAKTX SPRAS INTO TABLE GT_DATA UP TO 50 ROWS FROM MAKT WHERE MATNR IN S_MATNR AND SPRAS = 'EN'.

  LOOP AT GT_DATA INTO GW_DATA.

    MOVE-CORRESPONDING GW_DATA TO GW_ALV.

    APPEND GW_ALV TO GT_ALV. ENDLOOP.

    PERFORM CREAT_FIELDCAT.

    PERFORM CREAT_DROPDOWN_VALUES.

    PERFORM CREAT_EVENT_EXITS.

 

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

    EXPORTING I_CALLBACK_PROGRAM = G_REPID

      IT_FIELDCAT_LVC = GT_FIELDCATALOG

      IT_EVENTS = GT_EVENTS

      TABLES

        T_OUTTAB = GT_ALV.

 

 

* 设置输出字段的格式

FORM CREAT_FIELDCAT.

    CLEAR GW_FIELDCATALOG.

    GW_FIELDCATALOG-FIELDNAME = 'MATNR'.

    GW_FIELDCATALOG-REF_FIELD = 'MATNR'.

    GW_FIELDCATALOG-REF_TABLE = 'MAKT'.

    APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.

 

    CLEAR GW_FIELDCATALOG.

    GW_FIELDCATALOG-FIELDNAME = 'MAKTX'.

    GW_FIELDCATALOG-REF_FIELD = 'MAKTX'.

    GW_FIELDCATALOG-REF_TABLE = 'MAKT'.

    APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.

 

    CLEAR GW_FIELDCATALOG.

    GW_FIELDCATALOG-FIELDNAME = 'SPRAS'.

    GW_FIELDCATALOG-OUTPUTLEN = '7'.

    GW_FIELDCATALOG-DD_OUTLEN = '7'.

    GW_FIELDCATALOG-INTLEN = '2'.

    GW_FIELDCATALOG-INTTYPE = 'C'.

    GW_FIELDCATALOG-COLTEXT = 'Language'.

    GW_FIELDCATALOG-TOOLTIP = 'Language'.

    GW_FIELDCATALOG-SELTEXT = 'Language'.

    GW_FIELDCATALOG-DRDN_FIELD = 'DD_HANDLE'.

    GW_FIELDCATALOG-EDIT = 'X'.

    APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.

ENDFORM. " creat_fieldcat

*---------------------------------------------------------------------*

*根据物料的所有的语言生成不同的生成下拉列表

*---------------------------------------------------------------------*

FORM CREAT_DROPDOWN_VALUES.

  DATA: L_SPRAS TYPE MAKT-SPRAS,

      L_COUNT TYPE I.

  LOOP AT GT_ALV INTO GW_ALV.

    ADD 1 TO L_COUNT.

    SELECT SPRAS

       INTO L_SPRAS

    FROM MAKT

    WHERE MATNR = GW_ALV-MATNR.

      CLEAR GW_DDVAL.

      GW_DDVAL-HANDLE = L_COUNT.

      GW_DDVAL-VALUE = L_SPRAS.

      APPEND GW_DDVAL TO GT_DDVAL.

    ENDSELECT.

 

    CLEAR GW_DDVAL.

    GW_DDVAL-HANDLE = L_COUNT.

    GW_DDVAL-VALUE = ''.

    APPEND GW_DDVAL TO GT_DDVAL.

*设置对应

    GW_ALV-DD_HANDLE = L_COUNT.

    MODIFY GT_ALV FROM GW_ALV.

  ENDLOOP.

ENDFORM.                    " creat_dropdown_values

*---------------------------------------------------------------------*

* Form creat_event_exits *---------------------------------------------------------------------*

FORM CREAT_EVENT_EXITS .

  GW_EVENTS-NAME = 'CALLER_EXIT'.

  GW_EVENTS-FORM = 'CALLER_EXIT'.

  APPEND GW_EVENTS TO GT_EVENTS.

ENDFORM. " creat_event_exits

 

*---------------------------------------------------------------------*

*设置下拉列表,使Grid和内表能链接上

*---------------------------------------------------------------------*

FORM CALLER_EXIT USING LS_DATA TYPE SLIS_DATA_CALLER_EXIT.

  DATA: L_REF_ALV TYPE REF TO CL_GUI_ALV_GRID.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

    IMPORTING

      E_GRID = L_REF_ALV.

  CALL METHOD L_REF_ALV->SET_DROP_DOWN_TABLE

    EXPORTING

      IT_DROP_DOWN = GT_DDVAL.

ENDFORM.                    "CALLER_EXIT

 
1.15、实现单元格编辑控制

示例2:实现单元格的编辑控制

"单元格编辑控制

DATA: t_stylelin TYPE LVC_T_STYL. "控制单元格编辑

DATA: wa_stylelin TYPE LVC_S_STYL.  "工作区

DATA: BEGIN OF t_outtab1 OCCURS 0.

  INCLUDE STRUCTURE spfli.

  DATA:stylelin TYPE LVC_T_STYL,  "控制单元格编辑状态

      END OF t_outtab1.

 

"需要设置layout

my_layout_lvc-STYLEFNAME = 'STYLELIN'.  "设置单元格控制对应字段名

my_layout_lvc-EDIT = 'X'.  "layout设置可编辑

"将内表数据赋值

LOOP AT t_outtab.

  MOVE-CORRESPONDING t_outtab to t_outtab1.

  "设置单元格是否可编辑

  wa_stylelin-FIELDNAME = 'CARRID'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED. " 设置为可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  wa_stylelin-FIELDNAME = 'CITYFROM'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED. " 设置为不可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  wa_stylelin-FIELDNAME = 'ICON_FOLDER'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED. " 设置为不可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  "将设置的style保存到对应style属性中

  t_outtab1-stylelin[] = t_stylelin[].

  "将记录加入t_outtab1

  APPEND t_outtab1.

ENDLOOP.
View Code

 

 

1.16、添加行选择标志

1、首先在数据结构中添加行选择标志字段,

示例:

DATA: BEGIN OF t_outtab1 OCCURS 0.

  INCLUDE STRUCTURE spfli.

  DATA:stylelin TYPE LVC_T_STYL,  "控制单元格编辑状态

       sel TYPE C,          "行选择标志

      END OF t_outtab1.

2、然后,在layout声明行选择字段名,layout的BOX_FNAME属性绑定我们添加的行选择字段。

示例:

my_layout_lvc-BOX_FNAME = 'SEL'.  "指定行选择字段

3、当选择行执行alv动作时,循环alv显示内表,通过SEL选择行标志字段等于‘X’,就可以找到我们的选择行。

 

1.17、ALV的F4帮助

    ALV单元格的帮助,就是单元格后面出现一个小方块,点击方块可以显示单元格栏位建议输入值。

日期类型点击小方块,弹出一个日期选择弹窗。设置fieldcat的REF_TABLE和REF_FIELD属性,指定数据对应的数据库表和栏位;INTTYPE和DATATYPE,指定数据类型。

示例:

"设置日期栏f4帮助

  LOOP AT IT_FIELDCAT_LVC INTO WA_FIELDCAT_LVC.

    IF WA_FIELDCAT_LVC-FIELDNAME = 'DATE'.

      WA_FIELDCAT_LVC-DATATYPE = 'DATS'.

      WA_FIELDCAT_LVC-INTTYPE = 'D'.

      WA_FIELDCAT_LVC-REF_TABLE = 'LIKP'.

      WA_FIELDCAT_LVC-REF_FIELD = 'LFDAT'.

      MODIFY IT_FIELDCAT_LVC FROM WA_FIELDCAT_LVC.

    ENDIF.

  ENDLOOP.

    栏位对应Domain数据类型,点击小方块,选择domain的range值。

创建domain域,指定value range值,设置fieldcat的INTTYPE和DATATYPE对应domain名,设置REF_TABLE和REF_FIELD栏位对应表和字段名。

 

完整测试代码

"alv输出table

DATA:t_outtab LIKE TABLE OF spfli WITH HEADER LINE.

 

"查询数据

SELECT * INTO CORRESPONDING FIELDS OF TABLE t_outtab FROM spfli WHERE carrid = 'AA'.

 

"alv输出function参数

"小标题

DATA:my_grid_titile TYPE lvc_title VALUE '小标题'.

 

"GRID配置

DATA:my_grid_settings TYPE LVC_S_GLAY.

"响应输入enter回调函数

my_grid_settings-EDT_CLL_CB = 'X'. "允许回调ALV control: Callback when leaving an edited cell

 

*"alv的layout设置,REUSE_ALV_GRID_DISPLAY使用

*DATA:my_layout TYPE slis_layout_alv.

"alv的layout设置,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_layout_lvc TYPE lvc_s_layo.

 

*"alv的fieldcat设置,REUSE_ALV_GRID_DISPLAY使用

*DATA:my_fieldcat TYPE SLIS_T_FIELDCAT_ALV.

*DATA:wa_fieldcat TYPE slis_fieldcat_alv. "工作区

"alv的fieldcat设置,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_fieldcat_lvc TYPE LVC_T_FCAT.

DATA:wa_fieldcat_lvc TYPE LVC_S_FCAT. "工作区

 

"隐藏工具栏fcode

DATA:my_excluding TYPE slis_t_extab.

DATA:wa_excluding TYPE slis_extab.

"直接将要隐藏的工具栏按钮对应Fcode加入内表,就可以隐藏掉

wa_excluding-fcode = '&UMC'.

APPEND wa_excluding to my_excluding.

 

"对字段的值进行排序

"ALV字段排序,REUSE_ALV_GRID_DISPLAY_LVC使用

DATA:my_sort_lvc TYPE LVC_T_SORT.

DATA:wa_sort_lvc TYPE LVC_S_SORT.

*"ALV字段排序,REUSE_ALV_GRID_DISPLAY使用

*DATA:my_sort TYPE SLIS_T_SORTINFO_ALV.

*DATA:wa_sort TYPE slis_sortinfo_alv.

 

"事件处理IT_EVENTS

DATA:my_events TYPE SLIS_T_EVENT.

DATA:wa_events TYPE slis_alv_event.

 

"设置显示栏位

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'CARRID'.  "内表显示字段名

wa_fieldcat_lvc-REPTEXT = 'id'.     "字段对应描述,列名

wa_fieldcat_lvc-TABNAME = 't_outtab'.  "内表名

wa_fieldcat_lvc-col_opt = 'X'.         "单列宽优化

wa_fieldcat_lvc-just = 'R'.            "设置R右对齐,L左对齐,C居中对齐

wa_fieldcat_lvc-rollname = ''.   "F1帮助,指定数据元素

wa_fieldcat_lvc-ref_field = 'carrid'.  "F4帮助对应DDIC参考字段

wa_fieldcat_lvc-ref_table = 'spfli'.   "F4帮助对应DDIC表

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'CITYFROM'.

wa_fieldcat_lvc-REPTEXT = '出发城市'.

wa_fieldcat_lvc-TABNAME = 't_outtab'.

wa_fieldcat_lvc-OUTPUTLEN = 20.       "设置输出列宽

*wa_fieldcat_lvc-EDIT = 'X'.         "设置该字段列可编辑

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

clear wa_fieldcat_lvc.

wa_fieldcat_lvc-FIELDNAME = 'ICON_FOLDER'.

wa_fieldcat_lvc-REPTEXT = '图标'.

wa_fieldcat_lvc-icon = 'X'.          "显示图标

wa_fieldcat_lvc-hotspot = 'X'.       "使用热点点击,触发function code '&IC1'

APPEND wa_fieldcat_lvc to my_fieldcat_lvc.

 

"单元格编辑控制

DATA: t_stylelin TYPE LVC_T_STYL. "控制单元格编辑

DATA: wa_stylelin TYPE LVC_S_STYL.  "工作区

DATA: BEGIN OF t_outtab1 OCCURS 0.

  INCLUDE STRUCTURE spfli.

  DATA:stylelin TYPE LVC_T_STYL,  "控制单元格编辑状态

       sel TYPE C,          "行选择标志

      END OF t_outtab1.

 

"需要设置layout

my_layout_lvc-STYLEFNAME = 'STYLELIN'.  "设置单元格控制对应字段名

my_layout_lvc-EDIT = 'X'.  "layout设置可编辑

my_layout_lvc-BOX_FNAME = 'SEL'.  "指定行选择字段

 

"将内表数据赋值

LOOP AT t_outtab.

  MOVE-CORRESPONDING t_outtab to t_outtab1.

  "设置单元格是否可编辑

  wa_stylelin-FIELDNAME = 'CARRID'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED. " 设置为可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  wa_stylelin-FIELDNAME = 'CITYFROM'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED. " 设置为不可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  wa_stylelin-FIELDNAME = 'ICON_FOLDER'.

  wa_stylelin-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED. " 设置为不可编辑状态

  INSERT wa_stylelin INTO TABLE t_stylelin.     "由于LVC_T_STYL是sorted table,不能用append方式添加

  CLEAR wa_stylelin.

  "将设置的style保存到对应style属性中

  t_outtab1-stylelin[] = t_stylelin[].

  "将记录加入t_outtab1

  APPEND t_outtab1.

ENDLOOP.

 

"调用function REUSE_ALV_GRID_DISPLAY_LVC,显示alv

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

  EXPORTING

    I_CALLBACK_PROGRAM         = sy-repid

    I_CALLBACK_PF_STATUS_SET      = 'MY_PF_STATUS'

    I_CALLBACK_USER_COMMAND       = 'MY_USER_COMMAND'

    I_CALLBACK_TOP_OF_PAGE        = 'MY_TOP_OF_PAGE'

*    I_CALLBACK_HTML_TOP_OF_PAGE    = 'MY_HTML_TOP_OF_PAGE'

*   I_CALLBACK_HTML_END_OF_LIST     = ' '

    I_GRID_TITLE            = my_grid_titile

    I_GRID_SETTINGS           = my_grid_settings

    IS_LAYOUT_LVC            = my_layout_lvc

    IT_FIELDCAT_LVC           = my_fieldcat_lvc

    IT_EXCLUDING            = my_excluding

    IT_SORT_LVC              = my_sort_lvc

  TABLES

    T_OUTTAB                = t_outtab1

  EXCEPTIONS

    PROGRAM_ERROR            = 1

    OTHERS               = 2.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

 

"自定义屏幕菜单

form my_pf_status USING p_extab TYPE slis_t_extab.

  set PF-STATUS 'STANDARD_TEST_ALV'.

endform.

 

"用户操作响应,R_UCOMM 用户操作, RS_SELFIELD 选择或点击的行列信息

form my_user_command USING R_UCOMM LIKE SY-UCOMM

                           RS_SELFIELD TYPE SLIS_SELFIELD.

 

  "刷新ALV显示

  DATA: LR_GRID TYPE  REF TO CL_GUI_ALV_GRID.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

    IMPORTING

      E_GRID = LR_GRID.

  CALL METHOD LR_GRID->CHECK_CHANGED_DATA.

  RS_SELFIELD-REFRESH = 'X'.    " REFESH ALV

 

  "用户操作

  CASE R_UCOMM.

     WHEN '&IC1'.  "双击显示明细

      R_UCOMM = '&ETA'.  "调用系统功能,查看明细

  ENDCASE.

 

  message s000 with '动作回调'.

endform.

 

"使用I_CALLBACK_TOP_OF_PAGE,alv抬头信息

form my_top_of_page.

  "保存表头显示信息

  DATA:header TYPE SLIS_T_LISTHEADER.

  DATA:wa_header LIKE LINE OF header.

 

  wa_header-typ = 'H'.   " H = Header, S = Selection, A = Action

  wa_header-info = '这是头'.

  APPEND wa_header TO header.

  clear wa_header.

 

  "参数IT_LIST_COMMENTARY,显示文字内容

  "参数I_LOGO ,显示图片id,使用OAER上传图片

  "参数I_END_OF_LIST_GRID,页脚信息

  "参数I_ALV_FORM,是否用于alv form中

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

      IT_LIST_COMMENTARY   = header

      I_LOGO               = 'TEST_PIC'   "图片id,

.

endform.

 

 

*"使用I_CALLBACK_HTML_TOP_OF_PAGE,alv抬头信息

*form my_html_top_of_page USING p_cl_dd_document TYPE REF TO cl_dd_document.

* DATA:pos TYPE I.

*

* "html_insert,这个方法显示弃用

* CALL METHOD p_cl_dd_document->html_insert

*    EXPORTING

*      contents = '这是头'

*   CHANGING

*      position = pos.

*

*endform.
View Code

 

标签:function,10,lvc,wa,TYPE,alv,LVC,ALV,type
来源: https://www.cnblogs.com/tangToms/p/11870540.html