ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 一個完整的測試程式

一個完整的測試程式

原创 Linux操作系统 作者:chouer523 时间:2019-04-04 15:00:07 0 删除 编辑

*******************************

**MSN: njchouer@hotmail.com

********************************

对ALV中的某一列进行分类的完成测试程序。


REPORT ZTEST .



DATA:BEGIN OF IT1 OCCURS 5,
MATNR LIKE MARA-MATNR,
PSMNG LIKE AFPO-PSMNG,
END OF IT1 .


TYPE-POOLS: SLIS.
DATA:L_EVENTS TYPE SLIS_T_EVENT,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
eventcat TYPE slis_t_event WITH HEADER LINE.
DATA IT_SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA: l_variant TYPE TABLE OF disvariant WITH HEADER LINE,
prg LIKE sy-repid.


START-OF-SELECTION.

CLEAR IT1.
IT1-MATNR = 'AA'.
IT1-PSMNG = 10.
APPEND IT1.
CLEAR IT1.
IT1-MATNR = 'AA'.
IT1-PSMNG = 20.
APPEND IT1.
CLEAR IT1.
IT1-MATNR = 'BB'.
IT1-PSMNG = 30.
APPEND IT1.
CLEAR IT1.
IT1-MATNR = 'BB'.
IT1-PSMNG = 40.
APPEND IT1.
CLEAR IT1.
IT1-MATNR = 'BB'.
IT1-PSMNG = 50.
APPEND IT1.
CLEAR IT1.
IT1-MATNR = 'CC'.
IT1-PSMNG = 80.
APPEND IT1.

END-OF-SELECTION.

PERFORM PREPARE_LIST_VAL.
PERFORM DISPLAY_VAL.
*&---------------------------------------------------------------------*
*& Form PREPARE_LIST_VAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PREPARE_LIST_VAL.
prg = sy-repid.
L_variant-report = sy-repid.
PERFORM EVENTTAB_BUILD CHANGING L_EVENTS.
PERFORM COMMENT_BUILD CHANGING GT_LIST_TOP_OF_PAGE.
PERFORM SET_LAYOUT.
ENDFORM. " PREPARE_LIST_VAL
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_EVENTS text
*----------------------------------------------------------------------*
FORM EVENTTAB_BUILD CHANGING P_EVENTS TYPE SLIS_T_EVENT.

ENDFORM. " EVENTTAB_BUILD


*---------------------------------------------------------------------*
* FORM COMMENT_BUILD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> GT_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

ENDFORM. " COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SET_LAYOUT.
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-F2CODE = '&ETA'.
GS_LAYOUT-DETAIL_POPUP = 'X'.
GS_LAYOUT-get_selinfos = 'X'.
ENDFORM. " SET_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_VAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_VAL.
PERFORM GET_FIELDCAT.
PERFORM GET_EVENTCAT.
PERFORM GET_IT_SORT.
PERFORM START_LIST_VAL.
ENDFORM. " DISPLAY_VAL
*&---------------------------------------------------------------------*
*& Form GET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = PRG
I_INTERNAL_TABNAME = 'IT1'
I_INCLNAME = PRG
CHANGING
CT_FIELDCAT = FIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.

LOOP AT FIELDCAT.
CASE fieldcat-fieldname.
WHEN 'MATNR'.
fieldcat-tabname = 'IT1'.
fieldcat-key = 'X'. " Key Column
fieldcat-col_pos = 1. " Position on screen
fieldcat-hotspot = ''. " Hotspot column
fieldcat-seltext_s = '物料號'.
fieldcat-ddictxt = 'S'.
fieldcat-outputlen = 18.
WHEN 'PSMNG'.
fieldcat-tabname = 'IT1'.
fieldcat-key = ' '. " Key Column
fieldcat-col_pos = 2. " Position on screen
fieldcat-hotspot = ' '. " Hotspot column
fieldcat-seltext_s = '數量'.
fieldcat-ddictxt = 'S'.
fieldcat-outputlen = 15.
fieldcat-no_zero = 'X'.
fieldcat-DO_SUM = 'X'. "SUM UPON DISPLAY
ENDCASE.
MODIFY FIELDCAT.
ENDLOOP.
ENDFORM. " GET_FIELDCAT
*&---------------------------------------------------------------------*
*& Form GET_EVENTCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_EVENTCAT.
ENDFORM. " GET_EVENTCAT
*&---------------------------------------------------------------------*
*& Form GET_IT_SORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_IT_SORT.

CLEAR IT_SORT.
IT_SORT-FIELDNAME = 'MATNR'.
IT_SORT-SPOS = 1.
IT_SORT-UP = 'X'.
IT_SORT-SUBTOT = 'X'.
APPEND IT_SORT .

* CLEAR IT_SORT.
* IT_SORT-FIELDNAME = 'AUFNR'.
* IT_SORT-SPOS = 2.
* IT_SORT-UP = 'X'.
* IT_SORT-SUBTOT = ''.
* APPEND IT_SORT .

ENDFORM. " GET_IT_SORT
*&---------------------------------------------------------------------*
*& Form START_LIST_VAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM START_LIST_VAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = prg
IS_LAYOUT = GS_LAYOUT
IS_VARIANT = l_variant
IT_FIELDCAT = fieldcat[]
IT_SORT = IT_SORT[]
I_SAVE = 'A'
IT_EVENTS = eventcat[]
TABLES
T_OUTTAB = IT1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

ENDFORM. " START_LIST_VAL

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/332542/viewspace-53618/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 用户出口(转)
请登录后发表评论 登录
全部评论

注册时间:2019-03-28

  • 博文量
    27
  • 访问量
    20438