自己寫的ALV程式
*&---------------------------------------------------------------------*
*& Report ZTEST_TRAIN *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZTEST_TRAIN_01 NO STANDARD PAGE HEADING
LINE-SIZE 183
LINE-COUNT 60.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:
SPFLI.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
TYPES: BEGIN OF TYP_OUTPUT,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
COUNTRYFR TYPE SPFLI-COUNTRYFR,
CITYFROM TYPE SPFLI-CITYFROM,
AIRPFROM TYPE SPFLI-AIRPFROM,
COUNTRYTO TYPE SPFLI-COUNTRYTO,
CITYTO TYPE SPFLI-CITYTO,
AIRPTO TYPE SPFLI-AIRPTO,
FLTIME TYPE SPFLI-FLTIME,
DEPTIME TYPE SPFLI-DEPTIME,
ARRTIME TYPE SPFLI-ARRTIME,
DISTANCE TYPE SPFLI-DISTANCE,
END OF TYP_OUTPUT.
*----------------------------------------------------------------------*
* DATA
*----------------------------------------------------------------------*
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GH_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: GW_LAYOUT TYPE SLIS_LAYOUT_ALV,
GW_EXIT_CAUSED_BY_CALLER TYPE C,
GW_EXIT_CAUSED_BY_USER TYPE SLIS_EXIT_BY_USER,
GW_REPID TYPE SY-REPID.
DATA: GT_EVENTS TYPE SLIS_T_EVENT,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GW_STATUS_SET TYPE SLIS_FORMNAME VALUE 'PF_STATUS_SET',
GW_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND',
GW_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
GW_TOP_OF_LIST TYPE SLIS_FORMNAME VALUE 'TOP_OF_LIST',
GW_END_OF_LIST TYPE SLIS_FORMNAME VALUE 'END_OF_LIST'.
DATA: GW_VARIANT TYPE DISVARIANT,
GW_SAVE TYPE C.
DATA: GW_COUNT TYPE N.
* STRUCTURE
DATA GH_OUTPUT TYPE TYP_OUTPUT.
* INNER TABLE
DATA GT_OUTPUT TYPE STANDARD TABLE OF TYP_OUTPUT.
CONSTANTS:
C_TEXT001(12) TYPE C VALUE 'Airline Code',
C_TEXT002(25) TYPE C VALUE 'Flight Connection Number',
C_TEXT003(12) TYPE C VALUE 'Country From',
C_TEXT004(14) TYPE C VALUE 'Departure City',
C_TEXT005(17) TYPE C VALUE 'Departure Airport',
C_TEXT006(10) TYPE C VALUE 'Country To',
C_TEXT007(12) TYPE C VALUE 'Arrival city',
C_TEXT008(19) TYPE C VALUE 'Destination airport',
C_TEXT009(12) TYPE C VALUE 'Flight time',
C_TEXT010(14) TYPE C VALUE 'Departure time',
C_TEXT011(12) TYPE C VALUE 'Arrival time',
C_TEXT012(8) TYPE C VALUE 'Distance'.
*----------------SELECTION SCREEN DEFINATION---------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE BLK1_TIL.
*PARAMETERS:
* P_CARRID LIKE SPFLI-CARRID.
SELECT-OPTIONS:
S_CONNID FOR SPFLI-CONNID.
SELECTION-SCREEN END OF BLOCK BLK1.
*----------------OUTPUT SCREEN DEFINATION------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE BLK2_TIL.
PARAMETERS:
P_LIST RADIOBUTTON GROUP GRP1,
P_ALV RADIOBUTTON GROUP GRP1.
SELECTION-SCREEN END OF BLOCK BLK2.
*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
* INITIAL SELECTION SCREEN
PERFORM INITIAL_SCREEN.
*----------------------------------------------------------------------*
* TOP-OF-PAGE
*----------------------------------------------------------------------*
TOP-OF-PAGE.
IF P_LIST = 'X'.
PERFORM WRITE_LIST_HEADER.
ENDIF.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* GET SELECT DATA
PERFORM SELECT_DATA.
*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* OUTPUT RESULT
PERFORM OUTPUT_RESULT.
*----------------------------------------------------------------------*
* FORMS
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form INITIAL_SCREEN
*&---------------------------------------------------------------------*
* INITIAL SELECTION SCREEN
*----------------------------------------------------------------------*
FORM INITIAL_SCREEN.
%_S_CONNID_%_APP_%-TEXT = 'Flight Connection Number'.
* %_P_CARRID_%_APP_%-TEXT = 'Airline Code'.
BLK1_TIL = 'Select Option'.
%_P_LIST_%_APP_%-TEXT = 'List output'.
%_P_ALV_%_APP_%-TEXT = 'ALV output'.
BLK2_TIL = 'Output'.
ENDFORM. " INITIAL_SCREEN
*&---------------------------------------------------------------------*
*& Form SELECT_DATA
*&---------------------------------------------------------------------*
* GET SELECT DATA
*----------------------------------------------------------------------*
FORM SELECT_DATA.
SELECT CARRID
CONNID
COUNTRYFR
CITYFROM
AIRPFROM
COUNTRYTO
CITYTO
AIRPTO
FLTIME
DEPTIME
ARRTIME
DISTANCE
INTO TABLE GT_OUTPUT
FROM SPFLI
WHERE CONNID IN S_CONNID.
* AND CARRID = P_CARRID.
IF SY-SUBRC <> 0.
REFRESH GT_OUTPUT.
ENDIF.
ENDFORM. " SELECT_DATA
*&---------------------------------------------------------------------*
*& Form WRITE_LIST_HEADER
*&---------------------------------------------------------------------*
* WRITE LIST TITLE
*----------------------------------------------------------------------*
FORM WRITE_LIST_HEADER.
WRITE: / 'PLEAN FOR THE AIRPLANE'.
WRITE: / SY-ULINE.
WRITE: /1(1) '|',
2(12) C_TEXT001 CENTERED,
15(1) '|',
16(25) C_TEXT002 CENTERED,
32(1) '|',
33(12) C_TEXT003 CENTERED,
46(1) '|',
47(14) C_TEXT004 CENTERED,
62(1) '|',
63(17) C_TEXT005 CENTERED,
81(1) '|',
82(10) C_TEXT006 CENTERED,
93(1) '|',
94(12) C_TEXT007 CENTERED,
107(1) '|',
108(19) C_TEXT008 CENTERED,
128(1) '|',
129(12) C_TEXT009 CENTERED,
142(1) '|',
143(14) C_TEXT010 CENTERED,
158(1) '|',
159(12) C_TEXT011 CENTERED,
172(1) '|',
173(8) C_TEXT012 CENTERED,
182(1) '|'.
ULINE.
ENDFORM. " WRITE_LIST_HEADER
*&---------------------------------------------------------------------*
*& Form OUTPUT_RESULT
*&---------------------------------------------------------------------*
* OUTPUT RESULT
*----------------------------------------------------------------------*
FORM OUTPUT_RESULT.
IF P_LIST = 'X'.
PERFORM OUTPUT_BY_LIST.
ELSE.
PERFORM COMMENT_BUILD USING GT_LIST_TOP_OF_PAGE[].
PERFORM OUTPUT_BY_ALV.
ENDIF.
ENDFORM. " OUTPUT_RESULT
*&---------------------------------------------------------------------*
*& Form OUTPUT_BY_LIST
*&---------------------------------------------------------------------*
* OUTPUT BY LST
*----------------------------------------------------------------------*
FORM OUTPUT_BY_LIST.
DESCRIBE TABLE GT_OUTPUT LINES GW_COUNT.
IF GW_COUNT <> 0.
LOOP AT GT_OUTPUT INTO GH_OUTPUT.
WRITE: /1(1) '|',
2(12) GH_OUTPUT-CARRID CENTERED,
15(1) '|',
16(10) GH_OUTPUT-CONNID CENTERED,
32(1) '|',
33(12) GH_OUTPUT-COUNTRYFR CENTERED,
46(1) '|',
47(14) GH_OUTPUT-CITYFROM CENTERED,
62(1) '|',
63(17) GH_OUTPUT-AIRPFROM CENTERED,
81(1) '|',
82(10) GH_OUTPUT-COUNTRYTO CENTERED,
93(1) '|',
94(12) GH_OUTPUT-CITYTO CENTERED,
107(1) '|',
108(19) GH_OUTPUT-AIRPTO CENTERED,
128(1) '|',
129(12) GH_OUTPUT-FLTIME CENTERED,
142(1) '|',
143(14) GH_OUTPUT-DEPTIME CENTERED,
158(1) '|',
159(12) GH_OUTPUT-ARRTIME CENTERED,
172(1) '|',
173(8) GH_OUTPUT-DISTANCE CENTERED,
182(1) '|'.
ENDLOOP.
WRITE: / SY-ULINE.
ENDIF.
WRITE: 'The number of flights is: ',
GW_COUNT.
ENDFORM. " OUTPUT_BY_LIST
*&---------------------------------------------------------------------*
*& Form OUTPUT_BY_ALV
*&---------------------------------------------------------------------*
* ALV OUTPUT
*----------------------------------------------------------------------*
FORM OUTPUT_BY_ALV.
* INITIAL ALV
PERFORM INITIAL_ALV.
PERFORM SET_ALV_FIELDCAT.
PERFORM OUTPUT_ALV.
ENDFORM. " OUTPUT_BY_ALV
*&---------------------------------------------------------------------*
*& Form SET_ALV_FIELDCAT
*&---------------------------------------------------------------------*
* SET ALV FIELDCAT
*----------------------------------------------------------------------*
FORM SET_ALV_FIELDCAT .
* FIRST
GH_FIELDCAT-FIELDNAME = 'CARRID'.
GH_FIELDCAT-SELTEXT_M = C_TEXT001.
GH_FIELDCAT-OUTPUTLEN = 12.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* SECOND
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'CONNID'.
GH_FIELDCAT-SELTEXT_M = C_TEXT002.
GH_FIELDCAT-OUTPUTLEN = 25.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* THIRD
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'COUNTRYFR'.
GH_FIELDCAT-SELTEXT_M = C_TEXT003.
GH_FIELDCAT-OUTPUTLEN = 12.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* FOUTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'CITYFROM'.
GH_FIELDCAT-SELTEXT_M = C_TEXT004.
GH_FIELDCAT-OUTPUTLEN = 14.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* FIFTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'AIRPFROM'.
GH_FIELDCAT-SELTEXT_M = C_TEXT005.
GH_FIELDCAT-OUTPUTLEN = 30.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* SIXTH COUNTRYTO
GH_FIELDCAT-FIELDNAME = 'COUNTRYTO'.
GH_FIELDCAT-SELTEXT_M = C_TEXT006.
GH_FIELDCAT-OUTPUTLEN = 10.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* SEVENTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'CITYTO'.
GH_FIELDCAT-SELTEXT_M = C_TEXT007.
GH_FIELDCAT-OUTPUTLEN = 12.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* EIGHTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'AIRPTO'.
GH_FIELDCAT-SELTEXT_M = C_TEXT008.
GH_FIELDCAT-OUTPUTLEN = 19.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* NINTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'FLTIME'.
GH_FIELDCAT-SELTEXT_M = C_TEXT009.
GH_FIELDCAT-OUTPUTLEN = 12.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* TENTH
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'DEPTIME'.
GH_FIELDCAT-SELTEXT_M = C_TEXT010.
GH_FIELDCAT-OUTPUTLEN = 14.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
CLEAR GH_FIELDCAT.
* ELEVEN
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'ARRTIME'.
GH_FIELDCAT-SELTEXT_M = C_TEXT011.
GH_FIELDCAT-OUTPUTLEN = 12.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
* TLWALV
CLEAR GH_FIELDCAT.
GH_FIELDCAT-FIELDNAME = 'DISTANCE'.
GH_FIELDCAT-SELTEXT_M = C_TEXT012.
GH_FIELDCAT-OUTPUTLEN = 8.
APPEND GH_FIELDCAT TO GT_FIELDCAT.
CLEAR GH_FIELDCAT.
ENDFORM. " SET_ALV_FIELDCAT
*&---------------------------------------------------------------------*
*& Form OUTPUT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM OUTPUT_ALV.
DATA: LW_TITLE TYPE LVC_TITLE.
LW_TITLE = 'Show The Information Of The Plan For Airplane'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = 'X'
I_CALLBACK_PROGRAM = GW_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = GW_TOP_OF_PAGE
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
I_BACKGROUND_ID = 'ALV_BACKGROUND'
I_GRID_TITLE = LW_TITLE
* I_GRID_SETTINGS =
IS_LAYOUT = GW_LAYOUT
IT_FIELDCAT = GT_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = GW_SAVE
IS_VARIANT = GW_VARIANT
IT_EVENTS = GT_EVENTS[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER = GW_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER = GW_EXIT_CAUSED_BY_USER
TABLES
T_OUTTAB = GT_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC = 0.
IF GW_EXIT_CAUSED_BY_CALLER = 'X'.
*" Forced Exit by calling program
*"
ELSE.
*" User left list via F3, F12 or F15
IF GW_EXIT_CAUSED_BY_USER-BACK = 'X'. "F3
PERFORM WRITE_LIST_HEADER.
PERFORM OUTPUT_BY_LIST.
ELSE.
IF GW_EXIT_CAUSED_BY_USER-EXIT = 'X'. "F15
*"
ELSE.
IF GW_EXIT_CAUSED_BY_USER-CANCEL = 'X'. "F12
*"
ELSE.
*" should not occur!
*"
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ELSE.
*"Fatal error callin ALV
* MESSAGE AXXX(XY) WITH ...
ENDIF.
ENDFORM. " OUTPUT_ALV
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_EVENTS text
*----------------------------------------------------------------------*
FORM EVENTTAB_BUILD USING P_GT_EVENTS TYPE SLIS_T_EVENT.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = P_GT_EVENTS
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
READ TABLE P_GT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE GW_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO P_GT_EVENTS.
ENDIF.
ENDFORM. " EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form INITIAL_ALV
*&---------------------------------------------------------------------*
* INITIAL ALV
*----------------------------------------------------------------------*
FORM INITIAL_ALV.
GW_REPID = SY-REPID.
GW_VARIANT-REPORT = GW_REPID.
GW_SAVE = 'A'.
GW_LAYOUT-DETAIL_POPUP = 'X'.
GW_LAYOUT-F2CODE = '&ETA'.
PERFORM EVENTTAB_BUILD USING GT_EVENTS.
ENDFORM. " INITIAL_ALV
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
* BUILD TITLE COMMENT
*----------------------------------------------------------------------*
* -->LT_LIST_TOP_OF_PAGE[] text
*----------------------------------------------------------------------*
FORM COMMENT_BUILD USING LT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
*
* LIST HEADING LINE: TYPE H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
LS_LINE-INFO = 'ALV Show The Information Of Airplane'.
APPEND LS_LINE TO LT_LIST_TOP_OF_PAGE.
* STATUS LINE: TYPE S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'The Last Date:'.
LS_LINE-INFO = SY-DATUM.
APPEND LS_LINE TO LT_LIST_TOP_OF_PAGE.
LS_LINE-KEY = 'Airport:'.
LS_LINE-INFO = 'Frankfurt'.
APPEND LS_LINE TO LT_LIST_TOP_OF_PAGE.
* ACTION LINE: TYPE A
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
LS_LINE-INFO = 'Informations'.
APPEND LS_LINE TO LT_LIST_TOP_OF_PAGE.
ENDFORM. " COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* EVENT: TOP_OF_PAGE
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE
* I_LOGO =
* I_END_OF_LIST_GRID =
.
ENDFORM. "TOP_OF_PAGE
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-933128/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何看待自己寫的爛程式碼
- 自己寫的部分實用的程式碼
- 寫給程式設計師:當自己的上帝程式設計師
- 自己寫的面試題,自己想的答案面試題
- 寫一個《扎金花》程式自己玩。
- 寫最少的程式碼,避免給自己找麻煩
- 寫最少的程式碼 避免給自己找麻煩
- 自己寫的一個洗撲克牌的java程式Java
- 自己寫的加密方式加密
- 自己編寫安裝製作程式 (轉)
- 編寫自己的 TypeScript CLITypeScript
- 自己寫的fabric指令碼指令碼
- 程式設計練習-自己寫一個strcpy程式設計
- 程式設計師看不懂自己寫的程式碼 是不可饒恕的程式設計師
- 自己寫的和收藏的一寫php函式PHP函式
- function ALV 獲取OO ALV event IDFunction
- ALV LAYOUT的設定
- 如果你想寫自己的Benchmark框架框架
- 寫給自己看的Typescript起步TypeScript
- 手寫一個自己的PromisePromise
- 手寫自己的MyBatis框架-SqlSessionMyBatis框架SQLSession
- 來學著寫自己的“jQuery”jQuery
- 編寫自己的Webpack LoaderWeb
- 使用kotlin寫自己的dslKotlin
- 編寫自己的程式碼庫:CSS3 常用動畫的實現CSSS3動畫
- 編寫自己的程式碼庫(css3常用動畫的實現)CSSS3動畫
- 寫給.NET程式設計師:不要困在自己建造的盒子裡程式設計師
- Android編譯期插樁,讓程式自己寫程式碼(一)Android編譯
- Android編譯期插樁,讓程式自己寫程式碼(二)Android編譯
- 寫給自己看的 Git 命令指北Git
- 寫給自己看的面試題整理面試題
- 寫給自己看的 Flex 佈局Flex
- 編寫你自己的Python模組Python
- 編寫自己的Babel外掛(一)Babel
- 自己手寫的JS小工具JS
- 寫給自己的python基礎Python
- 自己學習寫的觸發器觸發器
- 自己動手寫PromisePromise