收藏 分享(赏)

SAP_ALV_详细使用方法.doc

上传人:精品资料 文档编号:9232019 上传时间:2019-07-30 格式:DOC 页数:18 大小:596KB
下载 相关 举报
SAP_ALV_详细使用方法.doc_第1页
第1页 / 共18页
SAP_ALV_详细使用方法.doc_第2页
第2页 / 共18页
SAP_ALV_详细使用方法.doc_第3页
第3页 / 共18页
SAP_ALV_详细使用方法.doc_第4页
第4页 / 共18页
SAP_ALV_详细使用方法.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

1、ALV 学习资料SAP 提供一组 ALV(ABAP LIST VIEWER)功能模块,这些功能模块可以修饰报表输出。这些设置的 ALV 功能可以提高报表的可读性。首先呢,我先跟大家说一下 ALV 是什么东西?ALV=SAP LIST VIEWER,SAP 列表显示器。就目前 ALV 技术主要分 ALV GRID 和 ALV TREE。先跟大家说一下目前本人用的比较多的 ALV GRID 技术,ALV GRID 的效果见图(1.1) 。图(1.1)第一步在使用ALV 时,需要定义一个SAP标准TYPE-POOLS,具体语法为:TYPE-POOLS: SLIS.然后需要定义一个LAYOUT式样,和

2、一个FIELDCAT字段格式,具体语法为:DATA: LIT_FCAT TYPE SLIS_T_FIELDCAT_ALV,LT_LAYO TYPE SLIS_LAYOUT_ALV,GIT_EVENTS TYPE SLIS_T_EVENT, GIT_LISTHEADER TYPE SLIS_T_LISTHEADER.,LIT_EXTAB TYPE SLIS_T_EXTAB.第二步(可选)可以为需要为最初的目录显示选择参数。在这里需要使用函数REUSE_ALV_VARIANT_DEFAULT_GETSample code:CALL FUNCTION REUSE_ALV_VARIANT_DEFAUL

3、T_GETEXPORTINGi_save = variant save condition ( A=all, U = user-specific )CHANGINGcs_variant = internal table containing the program name (and the default variant-optional )EXCEPTIONSnot_found = 2.使用者也可以使用现有的变量中选择,使用函数REUSE_ALV_VARIANT_F4。第三步调用函数REUSE_ALV_EVENTS_GET达到分屏显示的效果Sample code:CALL FUNCTION

4、 REUSE_ALV_EVENTS_GETEXPORTINGI_LIST_TYPE = 0IMPORTINGET_EVENTS = GIT_EVENTSEXCEPTIONSLIST_TYPE_WRONG = 1OTHERS = 2.具体效果见图(3.1)图3.1也可以为GIT_EVENTS添加许多参数也可以插入图片,需要使用函数REUSE_ALV_COMMENTARY_WRITESample code:CALL FUNCTION REUSE_ALV_COMMENTARY_WRITEEXPORTINGIT_LIST_COMMENTARY = GIT_LISTHEADER 文本抬头I_LOGO =

5、 ENJOYSAP_LOGO. 图片L_LISTHEADER-TYP = H.L_LISTHEADER-INFO = TEST ALV. 文本抬头内容APPEND L_LISTHEADER TO GIT_LISTHEADER.具体效果见图(3.2)图(3.2)第四步调用函数REUSE_ALV_FIELDCATALOG_MERGE获得标准字段Sample code:CALL FUNCTION REUSE_ALV_FIELDCATALOG_MERGEEXPORTINGI_PROGRAM_NAME = SY-REPIDI_STRUCTURE_NAME = MSEG 表名CHANGINGCT_FIEL

6、DCAT = LIT_FCAT 字段格式EXCEPTIONSINCONSISTENT_INTERFACE = 1PROGRAM_ERROR = 2OTHERS = 3CLEAR PS_FCAT.PS_FCAT-FIELDNAME = MATNR. 表中字段名PS_FCAT-REF_TABNAME = MSEG. 表名PS_FCAT-KEY = X 水平移动时固定该列PS_FCAT-COL_POS = 1. 列的位数APPEND PS_FCAT TO LIT_FCAT.具体效果见图(4.1)图(4.1)在这里我们也可以使用自定义字段Sample code:PS_FCAT-FIELDNAME =

7、TEXT.“ 字段名,一定要大写PS_FCAT-INTTYPE = P. 字段类型PS_FCAT-OUTPUTLEN = 20 . 输出长度PS_FCAT-COL_POS = 7. 列的位数PS_FCAT-SELTEXT_L = ADD BY Jacky_L. 列的抬头文本PS_FCAT-SELTEXT_M = ADD BY Jacky_M. 列的抬头文本PS_FCAT-SELTEXT_S = ADD BY Jacky_S. 列的抬头文本PS_FCAT-DDICTXT = M. 选择M抬头PS_FCAT-EDIT = X. 该列可编辑APPEND PS_FCAT TO LIT_FCAT.具体效

8、果见图(4.2)图(4.2)在这里我们也可以自己设定输出的格式Sample code:CLEAR PS_FCAT.PS_FCAT-FIELDNAME = BWART. 字段名,一定要大写PS_FCAT-REF_TABNAME = MSEG 表名.PS_FCAT-OUTPUTLEN = 20. 字段输出长度PS_FCAT-JUST = C. 字段输出居中PS_FCAT-COL_POS = 9. 列的位置PS_FCAT-EMPHASIZE = X.“ 颜色,也可以是CXYZ如C501.PS_FCAT-HOTSPOT = X. 激活热点APPEND PS_FCAT TO LIT_FCAT.具体效果见

9、图(4.3)图(4.3)还可以把输出的字段变成图标:首先呢,在数据取入内表之后,循环这个内表,把要改变的那个字段进行操作Sample code:LOOP AT LIT_OUTTAB.LIT_OUTTAB-WERKS = 06. 图标的名字MODIFY LIT_OUTTAB.ENDLOOP.然后在定义字段格式的时候PS_FCAT-FIELDNAME = WERKS.PS_FCAT-REF_TABNAME = MSEG.PS_FCAT-COL_POS = 10.PS_FCAT-ICON = X. 激活图标APPEND PS_FCAT TO LIT_FCAT.具体效果见图(4.4)图(4.4)第五步

10、当你把字段格式都设定完了之后,那么接下来你就需要设定LAYOUT输出的格式了。在LAYOUT中有几个参数是比较重要和比较常用到的:LAYOUT-COLWIDTH_OPTIMIZE:当你把这个参数的值设为X时,ALV中的字段就会自动缩近,也就是说当你把一个字段设为100位长时,而你输入的那个值只有10位长,这个参数就会把字段的长度自动缩进为10位长:Sample code:LT_LAYO-COLWIDTH_OPTIMIZE = X. 自动缩进效果见图(5.1)。图(5.1)LAYOUT-ZEBRA:当你把这个参数的值设为 X时,ALV显示时会隔行颜色相同,Sample code:LT_LAYO-

11、COLWIDTH_OPTIMIZE = X. 自动缩进效果见图(5.2)。图(5.2)LAYOUT-F2CODE :当你把这个参数设为&ETA时,你双击字段时会触发FUNCTION CODESample code:LT_LAYO-F2CODE = &ETA 双击触发效果见图(5.3)。图(5.3)LAYOUT-EDIT:当你把这个参数的值设定为X 之后,就表示输出的时候ALV所有的列都可以修改,Sample code:LT_LAYO-EDIT = X 所有列都可以修改效果见图(5.4)。图(5.4)第六步当你把字段格式和LAYOUT格式都设置的差不多了,那么接下来就需要把你要显示的字段和内容取

12、入你的内表,这个我就不多说了,每个人都每个人的需求。第七步那么在你做好以上那6个步骤之后,就可以把ALV显示出来了,这里需要调用函数REUSE_ALV_GRID_DISPLAYSample code:CALL FUNCTION REUSE_ALV_GRID_DISPLAYEXPORTINGI_CALLBACK_PROGRAM = L_REPID 返回程序IS_LAYOUT = LT_LAYO 输出格式IT_FIELDCAT = LIT_FCAT 字段输出格式IT_EVENTS = GIT_EVENTS 分屏显示I_GRID_TITLE = 物料凭证 ALV抬头I_CALLBACK_USER_C

13、OMMAND = FRM_UCOMMTABLEST_OUTTAB = LIT_OUTTAB 输出的内表EXCEPTIONSPROGRAM_ERROR = 1OTHERS = 2.例子程序:*&-*& Report Z_TEST_ALV_ZJY *& *&-*& *& *&-*REPORT Z_TEST_ALV_ZJY .TABLES: MSEG.TYPE-POOLS: SLIS.DATA: LIT_FCAT TYPE SLIS_T_FIELDCAT_ALV,LT_LAYO TYPE SLIS_LAYOUT_ALV.DATA BEGIN OF LIT_OUTTAB OCCURS 0.INCLUD

14、E STRUCTURE MSEG.DATA: TEXT TYPE P DECIMALS 2,ROW_COLOR(4),END OF LIT_OUTTAB.DATA: GIT_EVENTS TYPE SLIS_T_EVENT, “,RUNTIME“ERRORGIT_LISTHEADER TYPE SLIS_T_LISTHEADER.“,RUNTIME“ERRORDATA LIT_EXTAB TYPE SLIS_T_EXTAB.*&-* Start of Selection*&-*START-OF-SELECTION.PERFORM FRM_GET_EVENTS.PERFORM FRM_COMME

15、NT_BUILD.PERFORM FRM_FLDCAT.PERFORM FRM_LAYOUT.PERFORM FRM_ADD_DATA.PERFORM FRM_EXCLUDING.PERFORM FRM_OUTPUT.*&-*& Form FRM_FLDCAT*&-* text*-*FORM FRM_FLDCAT .DATA LS_FCAT TYPE SLIS_FIELDCAT_ALV.* CLEAR LIT_FCAT.PERFORM FRM_GET_ALL_FIELD USING LS_FCAT.* REF PERFORM FRM_REF_FIELD USING LS_FCAT.* PERF

16、ORM FRM_REDEFINE_FIELD USING LS_FCAT.* * PERFORM FRM_SUM_FIELD USING LS_FCAT.* HOTSPOTPERFORM FRM_COLOR_HOTSPOT USING LS_FCAT.* PERFORM FRM_FORMAT_FIELD USING LS_FCAT.ENDFORM. “ FRM_FLDCAT*&-*& Form FRM_ADD_DATA*&-* text*-*FORM FRM_ADD_DATA .SELECT * UP TO 10 ROWSINTO CORRESPONDING FIELDS OF TABLE L

17、IT_OUTTABFROM MSEG.* ICONLOOP AT LIT_OUTTAB.LIT_OUTTAB-WERKS = 06.LIT_OUTTAB-TEXT = 0.1.LIT_OUTTAB-ROW_COLOR = 5.MODIFY LIT_OUTTAB.ENDLOOP.ENDFORM. “ FRM_ADD_DATA*&-*& Form FRM_LAYOUT*&-* text*-*FORM FRM_LAYOUT .LT_LAYO-COLWIDTH_OPTIMIZE = X.LT_LAYO-ZEBRA = X. “*LT_LAYO-EDIT = X. “ALV,*“LT_LAYO-INFO

18、_FIELDNAME = ROW_COLOR. “OUTTABLT_LAYO-F2CODE = &ETA. “FUNCTION CODE* LT_LAYO-TOTALS_ONLY = X.* LT_LAYO-DETAIL_POPUP = X.ENDFORM. “ FRM_LAYOUT*&-*& Form FRM_OUTPUT*&-* text*-*FORM FRM_OUTPUT .DATA L_REPID LIKE SY-REPID VALUE SY-REPID.CALL FUNCTION REUSE_ALV_GRID_DISPLAYEXPORTINGI_CALLBACK_PROGRAM =

19、L_REPID “SAPSY-REPIDIS_LAYOUT = LT_LAYOIT_FIELDCAT = LIT_FCATIT_EVENTS = GIT_EVENTSI_SAVE = XI_GRID_TITLE = I_CALLBACK_USER_COMMAND = FRM_UCOMMIT_EXCLUDING = LIT_EXTAB “SHIFT+F3“SAPALV STATUS“SAPLSALV* I_STRUCTURE_NAME = MSEG “MSEGTABLEST_OUTTAB = LIT_OUTTABEXCEPTIONSPROGRAM_ERROR = 1OTHERS = 2.IF S

20、Y-SUBRC p1 text* 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.LOOP AT LIT_FCAT INTO PS_FCAT.IF SY-TABIX 4.DELETE LIT_FCAT.ENDIF.ENDLOOP.ENDFORM. “ FRM_GET_ALL_FIELD*&-*& Form FRM_REF_FIELD*&-* text*-*FORM FRM_REF_FIELD USING PS_FCAT TYPE SLIS_FIEL

21、DCAT_ALV.CLEAR PS_FCAT.PS_FCAT-FIELDNAME = MATNR.PS_FCAT-REF_TABNAME = MSEG.PS_FCAT-COL_POS = 1.PS_FCAT-KEY = X. “APPEND PS_FCAT TO LIT_FCAT.ENDFORM. “ FRM_REF_FIELD*&-*& Form FRM_REDEFINE_FIELD*&-* text*-*FORM FRM_REDEFINE_FIELD USING PS_FCAT TYPE SLIS_FIELDCAT_ALV.* CLEAR PS_FCAT.PS_FCAT-FIELDNAME

22、 = TEXT. “PS_FCAT-INTTYPE = P.“PS_FCAT-DATATYPE = P.PS_FCAT-OUTPUTLEN = 20.PS_FCAT-COL_POS = 7.* LIT_FCAT-CHECKBOX = X.PS_FCAT-SELTEXT_L = ADD BY Jacky_L.PS_FCAT-SELTEXT_M = ADD BY Jacky_M.PS_FCAT-SELTEXT_S = ADD BY Jacky_S.PS_FCAT-DDICTXT = M. “SELTEXT_SPS_FCAT-EDIT = X. “APPEND PS_FCAT TO LIT_FCAT

23、.ENDFORM. “ FRM_REDEFINE_FIELD*&-*& Form FRM_SUM_FIELD*&-* text*-*FORM FRM_SUM_FIELD USING PS_FCAT TYPE SLIS_FIELDCAT_ALV.* CLEAR PS_FCAT.PS_FCAT-FIELDNAME = MENGE.PS_FCAT-REF_TABNAME = MSEG.PS_FCAT-COL_POS = 8.PS_FCAT-DO_SUM = X. “I,F,PAPPEND PS_FCAT TO LIT_FCAT.ENDFORM. “ FRM_SUM_FIELD*&-*& Form F

24、RM_COLOR*&-* text*-* p1 text* p1 text* 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.*(NAME)“TOP_OF_PAGE“FORM(FORM)*“FRM_TOP_OF_PAGE,PERFORM FRM_TOP_OF_PAGE.CLEAR L_EVENTS.READ TABLE GIT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE INTOL_EVENTS.IF SY

25、-SUBRC = 0.MOVE FORMNAME_TOP_OF_PAGE TO L_EVENTS-FORM.MODIFY GIT_EVENTS FROM L_EVENTS INDEX SY-TABIX.ELSE.L_EVENTS-FORM = FORMNAME_TOP_OF_PAGE.L_EVENTS-NAME = FORMNAME_TOP_OF_PAGE.APPEND L_EVENTS TO GIT_EVENTS.ENDIF.ENDFORM. “ FRM_GET_EVENTS*&-*& Form FRM_TOP_OF_PAGE*&-* *-*Form FRM_TOP_OF_PAGE.CALL

26、 FUNCTION REUSE_ALV_COMMENTARY_WRITEEXPORTINGIT_LIST_COMMENTARY = GIT_LISTHEADERI_LOGO = ENJOYSAP_LOGO. “ENJOYSAP_LOGO*TCODE:OAOR,CLASS NAME:PICTURES,*CLASS TYPE :OT,PICTUREENDFORM.*&-*& Form FRM_COMMENT_BUILD*&-* text*-*FORM FRM_COMMENT_BUILD.DATA L_LISTHEADER TYPE SLIS_LISTHEADER.CLEAR: GIT_LISTHE

27、ADER, L_LISTHEADER.L_LISTHEADER-TYP = H.L_LISTHEADER-INFO = TEST ALV.APPEND L_LISTHEADER TO GIT_LISTHEADER.CLEAR L_LISTHEADER.L_LISTHEADER-TYP = S.L_LISTHEADER-KEY = :.L_LISTHEADER-INFO = SY-UNAME.APPEND L_LISTHEADER TO GIT_LISTHEADER.CLEAR L_LISTHEADER.L_LISTHEADER-TYP = ABC.L_LISTHEADER-INFO = SY-

28、DATUM.APPEND L_LISTHEADER TO GIT_LISTHEADER.ENDFORM. “ FRM_COMMENT_BUILD*&-*& Form FRM_EXCLUDING*&-* FUNCTION CODE*-*FORM FRM_EXCLUDING.DATA LS_EXTAB TYPE SLIS_EXTAB.CLEAR: LS_EXTAB, LIT_EXTAB.LS_EXTAB-FCODE = &F15.APPEND LS_EXTAB TO LIT_EXTAB.ENDFORM.*&-*& Form FRM_UCOMM*&-* ALV*-*FORM FRM_UCOMM US

29、ING R_UCOMM LIKE SY-UCOMMRS_SELFIELD TYPE SLIS_SELFIELD.READ TABLE LIT_OUTTAB INDEX RS_SELFIELD-TABINDEX.IF SY-SUBRC = 0.IF RS_SELFIELD-FIELDNAME = MBLNR.SET PARAMETER ID MBN FIELD LIT_OUTTAB-MBLNR.CALL TRANSACTION MB03 AND SKIP FIRST SCREEN.ELSEIF RS_SELFIELD-FIELDNAME = MATNR.SET PARAMETER ID MAT FIELD LIT_OUTTAB-MATNR.CALL TRANSACTION MM03 AND SKIP FIRST SCREEN.ENDIF.ENDIF.ENDFORM.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报