ABAP中使用TABLE CONTROL 显示数据以及操作要点小结.docx
- 文档编号:29985715
- 上传时间:2023-08-04
- 格式:DOCX
- 页数:10
- 大小:17.54KB
ABAP中使用TABLE CONTROL 显示数据以及操作要点小结.docx
《ABAP中使用TABLE CONTROL 显示数据以及操作要点小结.docx》由会员分享,可在线阅读,更多相关《ABAP中使用TABLE CONTROL 显示数据以及操作要点小结.docx(10页珍藏版)》请在冰豆网上搜索。
ABAP中使用TABLECONTROL显示数据以及操作要点小结
TABLECONTROL操作要点小结
1.屏幕号:
100
2.在屏幕100中应用tablecontrol
*声明controlT1应用于屏幕100
CONTROLST1TYPETABLEVIEWUSINGSCREEN100.“T1代表自定义的tablecontrol的名字
3.要想给tablecontrol中自动赋值,则需把tablecontrol中的字段名定义为:
WA_SPFLI-CARRID格式。
主程序代码:
*&---------------------------------------------------------------------*
*& Report ZTABLECONTROL02_
*&---------------------------------------------------------------------*
*&CREATOR:
*&---------------------------------------------------------------------*
REPORT ZTABLECONTROL02_LIUMING.
*引入表spfli
TABLES:
SPFLI.
*定义结构体
TYPES:
BEGIN OF TY_DATA,
CARRID LIKE SPFLI-CARRID,
CONNID LIKE SPFLI-CONNID,
COUNTRYFR LIKE SPFLI-COUNTRYFR,
CITYFROM LIKE SPFLI-CITYFROM,
AIRPFROM LIKE SPFLI-AIRPFROM,
FLAG TYPE C,
END OF TY_DATA.
*定义内表和工作区
DATA:
IT_SPFLI TYPE TABLE OF TY_DATA,
WA_SPFLI LIKE LINE OF IT_SPFLI.
*获取数据
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
*定义分页所需参数
DATA:
PAGESIZE TYPE I VALUE 23, "每页条数
NUM TYPE I, "判断是否刚好是整页
COUNT TYPE I, "总条数
AFTER TYPE I, "下一页的第一条
PAGECOUNT TYPE I, "总共有几页
PAGENUM TYPE I VALUE 1. "第几页
DESCRIBE TABLE IT_SPFLI LINES COUNT.
NUM = COUNT MOD PAGESIZE.
IF NUM <> 0 .
PAGECOUNT = COUNT DIV PAGESIZE + 1.
ELSE.
PAGECOUNT = COUNT DIV PAGESIZE.
ENDIF.
*声明变量
DATA:
OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*声明control T1应用于屏幕100
CONTROLS T1 TYPE TABLEVIEW USING SCREEN 100.
*调用屏幕100
CALL SCREEN 100.
*打印数据
IF NOT IT_SPFLI IS INITIAL.
LOOP AT IT_SPFLI INTO WA_SPFLI .
WRITE:
/2 WA_SPFLI-CARRID,10 WA_SPFLI-CONNID,18 WA_SPFLI-COUNTRYFR,
26 WA_SPFLI-CITYFROM,34 WA_SPFLI-AIRPFROM .
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------
* 退出图标
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS01'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* 实现用户命令
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'ISWRITE'. "读写转换
PERFORM ISWRITE.
WHEN 'ASC'. "升序处理
SORT IT_SPFLI BY CARRID CONNID ASCENDING.
WHEN 'DES'. "降序处理
SORT IT_SPFLI BY CARRID DESCENDING CONNID DESCENDING.
WHEN 'SHOW'. "用弹出框显示选中行信息
PERFORM SHOW.
WHEN 'FIRSTPAGE'. "显示首页
PERFORM FIRSTPAGE.
WHEN 'PREVIOUS'. "上一页
PERFORM PREVIOUS.
WHEN 'NEXT'. "下一页
PERFORM NEXT.
WHEN 'LAST'. "最后一页
PERFORM LAST.
WHEN 'SELECTALL'. "选中全部
PERFORM SELECTALL.
WHEN 'SELBLOCK'. "选中光标所在行
PERFORM SELBLOCK.
WHEN 'DESELALL'. " 取消全选
PERFORM DESELALL.
WHEN 'INSERTROW'. "插入一行(内表)
PERFORM INSERTROW.
WHEN 'DELETEROW'. "删除选中行(未成功)
PERFORM DELETEROW.
WHEN 'LEAVE'. "回到初始屏幕
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ISWRITE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "读写转换
*----------------------------------------------------------------------*
FORM ISWRITE .
DATA COL LIKE LINE OF T1-COLS.
LOOP AT T1-COLS INTO COL.
IF SY-TABIX = 1 OR SY-TABIX = 2.
COL-SCREEN-INPUT = 1.
ELSE.
IF COL-SCREEN-INPUT = 0.
COL-SCREEN-INPUT = 1.
ELSE.
COL-SCREEN-INPUT = 0.
ENDIF.
ENDIF.
MODIFY T1-COLS FROM COL.
ENDLOOP.
ENDFORM. " ISWRITE
*&---------------------------------------------------------------------*
*& Form SHOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "用弹出框显示选中行信息
*----------------------------------------------------------------------*
FORM SHOW .
DATA:
C_LINE TYPE I, "定义点击的行id
C_INDEX TYPE I. "定义对应的内表中的id
GET CURSOR LINE C_LINE. "鼠标所在的行
C_INDEX = T1-TOP_LINE + C_LINE - 1."TOP_LINE对应第一条数据
READ TABLE IT_SPFLI INTO WA_SPFLI INDEX C_INDEX.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
TITEL = 'HAHA '
TEXTLINE1 = WA_SPFLI-CARRID
TEXTLINE2 = WA_SPFLI-CONNID
START_COLUMN = 25
START_ROW = 6
.
ENDFORM. " SHOW
*&---------------------------------------------------------------------*
*& Form FIRSTPAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "显示首页
*----------------------------------------------------------------------*
FORM FIRSTPAGE .
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
IF PAGENUM <> 1.
PAGENUM = 1.
ELSE.
PAGENUM = 1.
MESSAGE S000(Z001) WITH '该页为首页'.
ENDIF.
ENDFORM. " FIRSTPAGE
*&---------------------------------------------------------------------*
*& Form PREVIOUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "上一页
*----------------------------------------------------------------------*
FORM PREVIOUS .
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
IF PAGENUM > 2.
AFTER = ( PAGENUM - 2 ) * PAGESIZE. "上两页的最后一条
DELETE IT_SPFLI FROM 1 TO AFTER.
PAGENUM = PAGENUM - 1.
ELSEIF PAGENUM = 2.
PAGENUM = PAGENUM - 1.
ELSEIF PAGENUM = 1.
PAGENUM = 1.
MESSAGE S000(Z001) WITH '该页是第一页'.
ENDIF.
ENDFORM. " PREVIOUS
*&---------------------------------------------------------------------*
*& Form NEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "下一页
*----------------------------------------------------------------------*
FORM NEXT .
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
AFTER = PAGENUM * PAGESIZE. "该页的最后一条
DATA AFTER1 TYPE I.
AFTER1 = ( PAGENUM - 1 ) * PAGESIZE.
IF PAGENUM = 1.
DELETE IT_SPFLI FROM 1 TO PAGESIZE.
ELSEIF PAGENUM = PAGECOUNT.
PAGENUM = PAGENUM.
DELETE IT_SPFLI FROM 1 TO AFTER1.
MESSAGE S000(Z001) WITH '该页为最后一页'.
ELSE.
PAGENUM = PAGENUM + 1.
DELETE IT_SPFLI FROM 1 TO AFTER.
IF PAGENUM = PAGECOUNT.
PAGENUM = PAGENUM.
ELSE.
PAGENUM = PAGENUM + 1.
ENDIF.
ENDIF.
ENDFORM. " NEXT
*&---------------------------------------------------------------------*
*& Form LAST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "最后一页
*----------------------------------------------------------------------*
FORM LAST .SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI.
DATA P TYPE I.
P = PAGECOUNT - 1.
AFTER = P * PAGESIZE.
IF PAGENUM = PAGECOUNT.
DATA AFTER1 TYPE I.
AFTER1 = ( PAGENUM - 1 ) * PAGESIZE.
DELETE IT_SPFLI FROM 1 TO AFTER1.
PAGENUM = PAGENUM.
MESSAGE S000(Z001) WITH '该页为最后一页'.
ELSE.
DELETE IT_SPFLI FROM 1 TO AFTER.
PAGENUM = PAGECOUNT.
ENDIF.
ENDFORM. " LAST
*&---------------------------------------------------------------------*
*& Form SELECTALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> "选中全部
*----------------------------------------------------------------------*
FORM SELECTALL .
LOOP AT IT_SPFLI INTO WA_SPFLI.
IF WA_SPFLI-FLAG = ''.
WA_SPFLI-FLAG = 'X'.
MODIFY IT_SPFLI FROM WA_SPFLI.
ENDIF.
ENDLOOP.
ENDFORM. " SELECTALL
*&----------------------------------------------------------
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ABAP中使用TABLE CONTROL 显示数据以及操作要点小结 ABAP 使用 TABLE 显示 数据 以及 操作 要点 小结
![提示](https://static.bdocx.com/images/bang_tan.gif)