ABAP ALV控件的使用

ALV控件的使用

ALV(SAP List Viewer)控件是SAP业务中最常用的控件之一,本章先用一个简单的例子介绍用ALV控件显示数据,再以实例方式介绍ALV的强大功能。

本章主要内容有:

(1)简单的ALV控件实例

(2)自定义输出字段的ALV控件实例

(3)在屏幕上建立ALV控件

(4)自定义ALV控件的工具条按钮

(5)处理ALV控件双击事件

(6)通过ALV控件编辑内表和数据库更新

(7)ALV Tree的使用

1、简单的ALV控件实例

以学校表(YTJAYSCHOOL)为例,使用数据字典定义结构,通过ALV控件显示数据

REPORT  YTEST20160617001.
*定义内表
DATA WA_SCHOOL LIKE TABLE OF YTJAYSCHOOL WITH HEADER LINE.
*内表赋值
SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.
*通过数据字典结构显示ALV
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    I_STRUCTURE_NAME = 'YTJAYSCHOOL'
  TABLES
    T_OUTTAB = WA_SCHOOL
  EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.

输出结果:

2、自定义输出字段的ALV控件实例

REPORT  YTEST20160617002.
*ALV使用到的类库
TYPE-POOLS:SLIS.
*一列描述
DATA WA_ALV_FIELD TYPE SLIS_FIELDCAT_ALV.
*列描述内表,列清单
DATA WA_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*定义内表
DATA WA_SCHOOL LIKE TABLE OF YTJAYSCHOOL WITH HEADER LINE.
*内表赋值
SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.

*定义第一到第四个字段
WA_ALV_FIELD-COL_POS = 1.
WA_ALV_FIELD-FIELDNAME = 'YCT_ID'.
WA_ALV_FIELD-SELTEXT_M = '城市编号'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.

WA_ALV_FIELD-COL_POS = 2.
WA_ALV_FIELD-FIELDNAME = 'YSH_ID'.
WA_ALV_FIELD-SELTEXT_M = '学校编号'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.

WA_ALV_FIELD-COL_POS = 3.
WA_ALV_FIELD-FIELDNAME = 'YSH_NAME'.
WA_ALV_FIELD-SELTEXT_M = '学校名称'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.

WA_ALV_FIELD-COL_POS = 4.
WA_ALV_FIELD-FIELDNAME = 'YSH_ADDR'.
WA_ALV_FIELD-SELTEXT_M = '学校地址'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    IT_FIELDCAT = WA_ALV_FIELDCAT
    TABLES
      T_OUTTAB = WA_SCHOOL.

输出结果:

3、在屏幕上建立ALV控件

3.1、定义SCREEN窗口

在屏幕上创建两个文本元素控件、一个退出按钮控件、一个定制控制控件

3.2、定义逻辑流

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.

PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

3.3、主程序代码

REPORT  YTEST20160620001.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
     SAVE_OK TYPE SY-UCOMM.
*定义内表,变量需要传递,不加HEADER LINE
DATA WA_SCHOOL TYPE TABLE OF YTJAYSCHOOL.
*内表赋值
SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.
*ALVDATA是屏幕100中定义控制控件的名称
DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
     ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
     WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
*直接调用窗口
CALL SCREEN 100.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
*如果窗口还没有创建ALV对象则创建它
  IF WA_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT WA_CUSTOM_CONTAINER
      EXPORTING
        CONTAINER_NAME = WA_CONTAINER.

    CREATE OBJECT ALV_GRID
      EXPORTING
        I_PARENT = WA_CUSTOM_CONTAINER.

    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'YTJAYSCHOOL'
      CHANGING
        IT_OUTTAB = WA_SCHOOL.
  ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.

输出结果:

4、自定义ALV控件的工具条按钮

在ALV的工具条上增加一个自定义的按钮,单击它弹出窗口提示选择行数据内容。执行结果如图

单击自定义按钮后输出如图

程序处理流程的说明:

定义ALV控件相关事件、接口和实现方法等,主要定义以下事件。

(1)ALV控件的工具条处理事件,定义了新按钮和功能码;

(2)ALV控件的功能码处理事件,定义用户单击按钮产生的功能码事件。

主程序代码如下:

REPORT  YTEST20160620002.

INCLUDE <ICON>.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.

DATA: OK_CODE TYPE SY-UCOMM,
      SAVE_OK TYPE SY-UCOMM.

DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.

DATA: WA_SCHOOL TYPE TABLE OF YTJAYSCHOOL,
      A_SCHOOL LIKE YTJAYSCHOOL.

SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.

DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
     ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
     WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

CALL SCREEN 100.

CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
      HANDLE_TOOLBAR
        FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
          IMPORTING E_OBJECT E_INTERACTIVE,

      HANDLE_USER_COMMAND
        FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
          IMPORTING E_UCOMM.
ENDCLASS.

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_TOOLBAR.
    DATA:LS_TOOLBAR TYPE STB_BUTTON.
    CLEAR LS_TOOLBAR-BUTN_TYPE.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR LS_TOOLBAR.

    MOVE 'SHOW_DETA' TO LS_TOOLBAR-FUNCTION.

    MOVE ICON_PPE_VNODE TO LS_TOOLBAR-ICON.
    MOVE '学校明细显示' TO LS_TOOLBAR-QUICKINFO.
    MOVE '学校明细显示' TO LS_TOOLBAR-TEXT.
    MOVE '' TO LS_TOOLBAR-DISABLED.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
  ENDMETHOD.

  METHOD HANDLE_USER_COMMAND.
    DATA:LT_ROWS TYPE LVC_T_ROW.
    CASE E_UCOMM.
      WHEN 'SHOW_DETA'.
        CALL METHOD ALV_GRID->GET_SELECTED_ROWS
          IMPORTING
            ET_INDEX_ROWS = LT_ROWS.
        CALL METHOD CL_GUI_CFW=>FLUSH.
        IF SY-SUBRC = 0.
          MESSAGE S005(YMESS) WITH '已选择行'.
          PERFORM MESSDETA TABLES LT_ROWS.
        ENDIF.
    ENDCASE.
  ENDMETHOD.
ENDCLASS.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
  IF WA_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT WA_CUSTOM_CONTAINER
      EXPORTING CONTAINER_NAME = WA_CONTAINER.
    CREATE OBJECT ALV_GRID
      EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.

    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'YTJAYSCHOOL'
      CHANGING
        IT_OUTTAB = WA_SCHOOL.

    CREATE OBJECT EVENT_RECEIVER.
    SET HANDLER EVENT_RECEIVER->HANDLE_USER_COMMAND FOR ALV_GRID.

    SET HANDLER EVENT_RECEIVER->HANDLE_TOOLBAR FOR ALV_GRID.
    CALL METHOD ALV_GRID->SET_TOOLBAR_INTERACTIVE.
   ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.

FORM MESSDETA TABLES P_ET_INDEX_ROWS STRUCTURE LVC_S_ROW.
  DATA:LS_SELECTED_LINE LIKE LVC_S_ROW,
       LF_ROW_INDEX TYPE LVC_INDEX.
  DATA:S1(200) TYPE C,
       S2(3) TYPE C.
  S2 = '-'.

  LOOP AT P_ET_INDEX_ROWS INTO LS_SELECTED_LINE.
    LF_ROW_INDEX = LS_SELECTED_LINE-INDEX.
    READ TABLE WA_SCHOOL INDEX LF_ROW_INDEX INTO A_SCHOOL.
    S1 = '选择行内容'.
    CONCATENATE S1 A_SCHOOL-YSH_NAME A_SCHOOL-YSH_ADDR
                INTO S1 SEPARATED BY S2.
    MESSAGE I005(YMESS) WITH S1.
  ENDLOOP.
ENDFORM.

5、处理ALV双击事件

主程序代码如下

REPORT  YTEST20160620003.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
     SAVE_OK TYPE SY-UCOMM.
*定义内表,变量需要传递,不加HEADER LINE
DATA WA_SCHOOL TYPE TABLE OF YTJAYSCHOOL.
*内表赋值
SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.
*定义窗口定制控件,定义ALV对象
DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
     ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
     WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
*定义事件类型
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*定义事件
DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
*直接调用窗口
CALL SCREEN 100.

CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
    HANDLE_DOUBLE_CLICK
      FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
        IMPORTING E_ROW E_COLUMN.
ENDCLASS.

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_DOUBLE_CLICK.
    DATA:LI_SCHOOL LIKE LINE OF WA_SCHOOL.
    READ TABLE WA_SCHOOL INDEX E_ROW-INDEX INTO LI_SCHOOL.
*将行列等信息合并到字符串
    DATA:S1(100) TYPE C.
*    CONCATENATE '行:' E_ROW-INDEX '列名:' E_COLUMN-FIELDNAME INTO S1.
    CONCATENATE S1 'SCHOOL NAME:' LI_SCHOOL-YSH_NAME INTO S1.
    CONCATENATE S1 'SCHOOL ADDR:' LI_SCHOOL-YSH_ADDR INTO S1.
*在状态条显示单击的行与列信息
    MESSAGE S208(00) WITH S1.
  ENDMETHOD.
ENDCLASS.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
*如果窗口还没有创建ALV对象则创建它
  IF WA_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT WA_CUSTOM_CONTAINER
      EXPORTING CONTAINER_NAME = WA_CONTAINER.
    CREATE OBJECT ALV_GRID
      EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.
    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'YTJAYSCHOOL'
      CHANGING
        IT_OUTTAB = WA_SCHOOL.
*ALV对象分配双击事件
    CREATE OBJECT EVENT_RECEIVER.
    SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK
    FOR ALV_GRID.
  ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.

输出界面如下图,双击时,注意状态条显示的信息:学校名称、学校地址的值。

6、通过ALV控件编辑内表和数据库更新

处理过程如下:

(1)设定ALV控件可以编辑;

(2)退出屏幕时将数据更新到内表;

(3)捕捉ALV控件的数据更改信息,将ALV控件的删除行信息保存到内表中;

(4)在输出时,比较删除行和最后的内表,删除重复的行;

(5)将数据更新到数据表。

主程序代码如下:

REPORT  YTEST20160620004.

DATA:OK_CODE TYPE SY-UCOMM,
     SAVE_OK TYPE SY-UCOMM.
TABLES YTJAYSCHOOL.

DATA LS_SCHOOL TYPE YTJAYSCHOOL.

DATA WA_SCHOOL TYPE TABLE OF YTJAYSCHOOL.

DATA WADEL_SCHOOL TYPE TABLE OF YTJAYSCHOOL.

SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.

DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
     ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
     WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA WA_LAYOUT TYPE LVC_S_LAYO.
WA_LAYOUT-EDIT = 'X'.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.

DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.

CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    TYPES: DEL_ROWS TYPE STANDARD TABLE OF YTJAYSCHOOL.
    DATA: DDEL_ROWS TYPE STANDARD TABLE OF YTJAYSCHOOL.

    METHODS:
    HANDLE_DATA_CHANGED
      FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
        IMPORTING ER_DATA_CHANGED.

    METHODS:
    UPDATE_DELTA_TABLES
      IMPORTING
        PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.

    METHODS:
    GET_DELETED_ROWS
    EXPORTING
      DELETED_ROWS TYPE DEL_ROWS.
ENDCLASS.

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_DATA_CHANGED.
    CALL METHOD UPDATE_DELTA_TABLES( ER_DATA_CHANGED ).
  ENDMETHOD.

  METHOD UPDATE_DELTA_TABLES.
    DATA: L_DEL_ROW  TYPE LVC_S_MOCE.

    LOOP AT PR_DATA_CHANGED->MT_DELETED_ROWS INTO L_DEL_ROW.
      READ TABLE WA_SCHOOL INTO LS_SCHOOL INDEX L_DEL_ROW-ROW_ID.
      IF SY-SUBRC NE 0.
        MESSAGE E208(00) WITH '处理错误'.
      ELSE.
        APPEND LS_SCHOOL TO DDEL_ROWS.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

  METHOD GET_DELETED_ROWS.
    DELETED_ROWS = ME->DDEL_ROWS.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  CALL SCREEN 100.
  WRITE / '---------------删除的内表记录---------------'.
  WRITE / '____________________________________________'.
  CALL METHOD EVENT_RECEIVER->GET_DELETED_ROWS
    IMPORTING
      DELETED_ROWS = WADEL_SCHOOL.

  LOOP AT WADEL_SCHOOL INTO YTJAYSCHOOL.
    WRITE:/ YTJAYSCHOOL-YSH_ID,YTJAYSCHOOL-YSH_NAME,YTJAYSCHOOL-YSH_ADDR.
  ENDLOOP.

  WRITE:/ '---------------更新后的内表记录---------------:'.
  WRITE:/ '____________________________________________'.
  LOOP AT WA_SCHOOL INTO YTJAYSCHOOL.
    WRITE:/ YTJAYSCHOOL-YSH_ID,YTJAYSCHOOL-YSH_NAME,YTJAYSCHOOL-YSH_ADDR.
  ENDLOOP.

*  WHEN 'SAVE'.
*    MODIFY YTJAYSCHOOL FROM TABLE WA_SCHOOL.
*    IF SY-SUBRC NE 0.
*      MESSAGE I005(YMESS) WITH '更新数据错误'.
*      EXIT.
*    ELSE.
*      MESSAGE I005(YMESS) WITH '更新数据OK'.
*    ENDIF.
*
*    DELETE YTJAYSCHOOL FROM TABLE DELA_SCHOOL.
*    IF SY_SUBRC NE 0.
*      MESSAGE I005(YMESS) WITH '更新数据错误'.
*    ELSE.
*      MESSAGE I005(YMESS) WITH '更新数据OK'.
*    ENDIF.

END-OF-SELECTION.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
  IF WA_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT WA_CUSTOM_CONTAINER
    EXPORTING CONTAINER_NAME = WA_CONTAINER.
    CREATE OBJECT ALV_GRID
      EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.

    CREATE OBJECT EVENT_RECEIVER.
    SET HANDLER EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR ALV_GRID.

    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'YTJAYSCHOOL'
        IS_LAYOUT = WA_LAYOUT
      CHANGING
        IT_OUTTAB = WA_SCHOOL.
    ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'CANCEL'.
      DATA L_RET VALUE 'X'.
      CALL METHOD ALV_GRID->CHECK_CHANGED_DATA
        IMPORTING
          E_VALID = L_RET.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.

输出结果:

删除最后两行数据,点击“CANCEL"按钮,结果如下:

7、ALV Tree的使用

在SAP业务系统中,大量地使用了ALV Tree对象,该对象在表格基础上对同类数据进行归类,并对各分类能进行数据汇总。如图

以学校表(YTJAYSCHOOL)为例:

(1)以城市、学校分类;

(2)在右屏输出学校名称、学校地址,并控制其输出长度。

处理过程:

(1)建立程序和屏幕,在屏幕上建立定制控制对象,定义好逻辑流;

(2)建立好PAI、PBO事件;

(3)在PAI中定义建立定制控制对象,并建立ALV Tree对象;

(4)建立ALV Tree对象的标题;

(5)建立右屏输出字段清单、字段长度等内容;

(6)建立Tree分类字段清单及输出先后顺序;

(7)显示ALV Tree对象。

主程序代码:

REPORT  YTEST20160621001.
DATA: OK_CODE TYPE SY-UCOMM,
      SAVE_OK TYPE SY-UCOMM.

DATA: GB_FIELDCAT TYPE LVC_T_FCAT.
DATA: GB_SORTFLD TYPE LVC_T_SORT.

DATA WA_SCHOOL TYPE TABLE OF YTJAYSCHOOL.

SELECT * INTO TABLE WA_SCHOOL FROM YTJAYSCHOOL.

DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
      ALV_GRID TYPE REF TO CL_GUI_ALV_TREE_SIMPLE,
      WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

CALL SCREEN 100.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
  IF WA_CUSTOM_CONTAINER IS INITIAL.
    DATA LS_LIST_COMM TYPE SLIS_T_LISTHEADER.
    DATA LS_ALIST_COMM TYPE SLIS_LISTHEADER.
    LS_ALIST_COMM-TYP = 'H'.
    LS_ALIST_COMM-INFO = 'MY ALV TREE Testing'.
    APPEND LS_ALIST_COMM TO LS_LIST_COMM.

    PERFORM BLDCAT.
    PERFORM BLDSORTFLD.

    CREATE OBJECT WA_CUSTOM_CONTAINER
      EXPORTING CONTAINER_NAME = WA_CONTAINER.

    CREATE OBJECT ALV_GRID
      EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.

    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        IT_LIST_COMMENTARY = LS_LIST_COMM
        I_STRUCTURE_NAME = 'YTJAYSCHOOL'
      CHANGING
        IT_SORT = GB_SORTFLD
        IT_FIELDCATALOG = GB_FIELDCAT
        IT_OUTTAB = WA_SCHOOL.

    CALL METHOD ALV_GRID->EXPAND_TREE
      EXPORTING
        I_LEVEL = 1.
  ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.

FORM BLDCAT.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME = 'YTJAYSCHOOL'
    CHANGING
      CT_FIELDCAT = GB_FIELDCAT.

  DATA LS_FLDCAT TYPE LVC_S_FCAT.
  LOOP AT GB_FIELDCAT INTO LS_FLDCAT.
    CASE LS_FLDCAT-FIELDNAME.
      WHEN 'YSH_NAME' OR 'YSH_ADDR'.
        LS_FLDCAT-OUTPUTLEN = 15.
      WHEN OTHERS.
        LS_FLDCAT-NO_OUT = 'X'.
    ENDCASE.

    MODIFY GB_FIELDCAT FROM LS_FLDCAT.
  ENDLOOP.
ENDFORM.

FORM BLDSORTFLD.
  DATA LS_SORTFLD TYPE LVC_S_SORT.

  LS_SORTFLD-SPOS = 1.
  LS_SORTFLD-FIELDNAME = 'YCT_ID'.
  LS_SORTFLD-UP = 'X'.
  LS_SORTFLD-SUBTOT = 'X'.
  APPEND LS_SORTFLD TO GB_SORTFLD.

  LS_SORTFLD-SPOS = 2.
  LS_SORTFLD-FIELDNAME = 'YSH_ID'.
  LS_SORTFLD-UP = 'X'.
  LS_SORTFLD-SUBTOT = 'X'.
  APPEND LS_SORTFLD TO GB_SORTFLD.

*  LS_SORTFLD-SPOS = 3.
*  LS_SORTFLD-FIELDNAME = 'YSH_NAME'.
*  LS_SORTFLD-UP = 'X'.
*  LS_SORTFLD-SUBTOT = 'X'.
*  APPEND LS_SORTFLD TO GB_SORTFLD.
*
*  LS_SORTFLD-SPOS = 4.
*  LS_SORTFLD-FIELDNAME = 'YSH_ADDR'.
*  LS_SORTFLD-UP = 'X'.
*  LS_SORTFLD-SUBTOT = 'X'.
*  APPEND LS_SORTFLD TO GB_SORTFLD.
ENDFORM.

时间: 2024-11-07 20:26:13

ABAP ALV控件的使用的相关文章

控件之应用-创建Text Editor教程

原文地址 http://www.baidusap.com/abap/dialog/1627 1, Text Editor介绍 不同于一般的屏幕字段,Text Editor可以保存多行文本,它是SAP各种凭证中常用的控件之一,比如采购订单中,凭证头和行项目中都应用到text editor控件,如下: 2, 创建text editor控件 下面介绍如何在dailog程序中创建一个text editor控件, 2.1, SE80创建dialog程序 Tcode:se80,创建一个dialog程序,并且

在DataGridView控件中实现冻结列分界线

我们在使用Office Excel的时候,有很多时候需要冻结行或者列.这时,Excel会在冻结的行列和非冻结的区域之间绘制上一条明显的黑线.如下图: (图1) WinForm下的DataGridView控件也能实现类似的冻结行或者列的功能(参见:http://msdn.microsoft.com/zh-cn/library/28e9w2e1(VS.85).aspx) ,但是呢,DataGridView控件默认不会在冻结列或者行的分界处绘制一个明显的分界线,这样的话,最终用户很难注意到当前有列或者

摆脱Login控件,自己定义登录操作

protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { //在登录过程中,程序自动使用login.aspx进行拦截 //验证用户通过后,自动返回拦截的位置 if (Membership.ValidateUser(this.TextBox1.Text, this.TextBox2.Text)) { this.Session["xh"] = this.TextBox1.Text; FormsAuth

python selenium 处理时间日期控件(十五)

测试过程中经常遇到时间控件,需要我们来选择日期,一般处理时间控件通过层级定位来操作或者通过调用js来实现. 1.首先我们看一下如何通过层级定位来操作时间控件. 通过示例图可以看到,日期控件是无法输入日期,点击后弹出日期列表供我们选择日期,自己找了一个日期控制演示一下,通过两次定位,选择了日期 #-*- coding:utf-8 -*- import time from selenium import webdriver driver = webdriver.Chrome() driver.get

Delphi XE10 dxLayoutControl 控件应用指南

http://www.cnblogs.com/Bonny.Wong/p/7440288.html DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有些控件使用起来一头雾水,不知从何下手.本节详细介绍在Delphi Xe10 Seattle中如何利用dxLayoutControl 控件来做界面布局. 1.  首先从工具箱面板中将dxLayoutControl放在Form上,设置2个关键属性如下: 属性 属性值 说明 Align alClient 一

Android自己定义控件之轮播图控件

背景 近期要做一个轮播图的效果.网上看了几篇文章.基本上都能找到实现,效果还挺不错,可是在写的时候感觉每次都要单独去又一次在Activity里写一堆代码.于是自己封装了一下.这里仅仅是做了下封装成一个控件,不必每次反复写代码了. 效果图 实现分析 轮播图的功能就是实现左右滑动的广告.图片信息展示,那我们就用ViewPager来实现,由于考虑到用户体验,我们还须要在以下加一个指示器来标示滑动到了第几张轮播图.指示器我们能够用一个线性布局来依据要展示的轮播图设置显示的View,我们要做这种一个控件没

[ ObjectListView ] - ListView的增强控件 - 前言 (翻译)

********************************************************************************** 原  标 题: A Much Easier to Use ListView 原文地址: https://www.codeproject.com/Articles/16009/A-Much-Easier-to-Use-ListView 翻       译: 于国栋 http://www.shannon.net.cn *********

MFC 加入背景图片并让控件背景透明

/*加入背景图片*/ BOOL CTOOLDlg::OnEraseBkgnd(CDC* pDC) { // TODO: 在此加入消息处理程序代码和/或调用默认值 CDialog::OnEraseBkgnd(pDC); HBITMAP   m_hBitmap; HDC           m_hBkDC; m_hBitmap   =   ::LoadBitmap(::GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP2)); m_hBkDC     =

[转] 基于C#的波形显示控件的实现

转自 基于C#的波形显示控件的实现[附完整源码下载] 编者记: 09年暑假正好在学院实验室呆了一段时间,做了个完整的上位机软件(具体实现:根据下位机的指令,实现通过串口来操纵下位机进行实验,并将采集的数据进行处理和保存,并以图形的方式显示),整个项目边学C# WinForm边设计,这个波形显示控件就是项目中的一部分,也花了自己绝大多数时间.此外,顺便将该波形显示控件当作自己毕业设计的内容,下文实际上是节选自自己的本科毕业论文,希望对大家能有所帮助.代码以及文章有疏漏.错误.不妥之处在所难免,欢迎