以下是纯顾问群~
QQ群 :SAP干货铺, 群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!
如果您觉得这篇干货文章有用,请帮忙转载、分享给更多人,谢谢~
demo内容是最常用的 Function ALV展示。
效果:
代码:
REPORT ZLM_ALV009.
DATA:LT_DATA TYPE TABLE OF SPFLI.
START-OF-SELECTION.
SELECT * FROM SPFLI INTO TABLE LT_DATA.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'SAP干货铺测试'
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
TABLES
T_OUTTAB = LT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
上面使用的是 参数是:
= 'SPFLI'
直接参考结构,有时候不需要这么多字段,可以使用参数:
IT_FIELDCAT
demo
描述显示长度好像有点问题,调整代码。
加上
-OUTPUTLEN = 10.
为了避免每个字段都输入长度,还可以使用参数:IS_LAYOUT
参考代码:
REPORT ZLM_ALV009.
DATA:GT_DATA TYPE TABLE OF SPFLI.
DATA:GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
START-OF-SELECTION.
SELECT * FROM SPFLI INTO TABLE GT_DATA.
CLEAR:GT_FIELDCAT[].
PERFORM FILL_CAT:
USING 1 'CARRID' '航线代码' ' ' ' ' CHANGING GT_FIELDCAT,
USING 2 'CONNID' '航班连接ID' ' ' ' ' CHANGING GT_FIELDCAT,
USING 3 'CITYFROM' '起飞城市' ' ' ' ' CHANGING GT_FIELDCAT,
USING 4 'CITYTO' '目标城市' ' ' ' ' CHANGING GT_FIELDCAT,
USING 5 'DISTANCE' '距离' 'SPFLI' 'DISTANCE' CHANGING GT_FIELDCAT,
USING 6 'DISTID' '距离单位 ' 'SPFLI' 'DISTID' CHANGING GT_FIELDCAT.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_STRUCTURE_NAME = 'SPFLI'
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'SAP干货铺测试'
* I_GRID_SETTINGS =
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
TABLES
T_OUTTAB = GT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
FORM FILL_CAT
USING
PV_COL
PV_FIELDNAME
PV_TEXT
PV_RF_DB
PV_RF_FEILD
CHANGING CT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV..
DATA:LS_FIELDCAT LIKE LINE OF GT_FIELDCAT.
LS_FIELDCAT-COL_POS = PV_COL.
LS_FIELDCAT-FIELDNAME = PV_FIELDNAME.
LS_FIELDCAT-SELTEXT_S = PV_TEXT.
LS_FIELDCAT-SELTEXT_M = PV_TEXT.
LS_FIELDCAT-SELTEXT_L = PV_TEXT.
LS_FIELDCAT-DDICTXT = 'L'.
LS_FIELDCAT-REF_TABNAME = PV_RF_DB.
LS_FIELDCAT-REF_FIELDNAME = PV_RF_FEILD.
* LS_FIELDCAT-OUTPUTLEN = 10.
APPEND LS_FIELDCAT TO CT_FIELDCAT.
CLEAR LS_FIELDCAT.
ENDFORM.
标签:GT,PV,REUSE,FIELDCAT,01,LS,ALV,DATA,SPFLI From: https://blog.51cto.com/u_15680210/5757793