本文是一个ABAP选择屏幕的demo,废话不多说直接看demo场景
Demo场景
通过选择屏幕输入检索条件,连接查询数据库表SFLIGHT、SCARR、SPFLI,输出相应航班的详细信息并且通过List表单的方式打印出来,其中选择屏幕包含了复选框,能让用户自行选择是否根据航线代码进行检索
选择屏幕样式
- 复选框收起
- 复选框展开
数据库表SFLIGHT
PS:本demo是通过三表连接查询,但是查询的主数据表为Sflight,这里只展示它的结构和数据,并且三个表这里用的是系统的表,假如实际demo中建议参照这三个表先构建自己的test表并且自己添加测试数据,三个表sflight、scarr、spfli的结构和数据可以在T-CODE:SE11中查询找到
- 数据库表字段
- 数据库表数据
总程序代码
*&---------------------------------------------------------------------* *& Report ZWYZTEST_01 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT ZWYZTEST_01 MESSAGE-ID FILAM. TABLES:SFLIGHT. TABLES:SPFLI. TABLES:SCARR. INCLUDE ZWYZTEST_01_TOP. INCLUDE ZWYZTEST_01_FORM. AT SELECTION-SCREEN OUTPUT. PERFORM MODIFY_SCREEN_PBO. AT SELECTION-SCREEN . PERFORM SELECTION_SCREEN_PAI. START-OF-SELECTION. PERFORM GET_DATA. END-OF-SELECTION. PERFORM DISPLAY_DATA. TOP-OF-PAGE. PERFORM ZWYZTEST_01_TOP_OF_PAGE. AT LINE-SELECTION. PERFORM ZWYZTEST_01_LINE_SELECTION. AT USER-COMMAND. PERFORM ZWYZTEST_01_USER_COMMAND.
子程序代码
ZWYZTEST_01_TOP
*&---------------------------------------------------------------------* *& 包含 ZWYZTEST_01_TOP *&---------------------------------------------------------------------* TYPES:BEGIN OF GTY_SFLIGHT, CARRID TYPE S_CARR_ID, CONNID TYPE S_CONN_ID, FLDATE TYPE S_DATE, PLANETYPE TYPE S_PLANETYE, END OF GTY_SFLIGHT. TYPES:BEGIN OF GTY_SPFLI, CARRID TYPE S_CARR_ID, CONNID TYPE S_CONN_ID, CITYFROM TYPE S_FROM_CIT, CITYTO TYPE S_TO_CITY, END OF GTY_SPFLI. TYPES: BEGIN OF GTY_TOTAL, CARRID TYPE S_CARR_ID, CONNID TYPE S_CONN_ID, FLDATE TYPE S_DATE, PLANETYPE TYPE S_PLANETYE, CITYFROM TYPE S_FROM_CIT, CITYTO TYPE S_TO_CITY, END OF GTY_TOTAL. DATA:GT_SFLIGHT TYPE TABLE OF GTY_SFLIGHT. DATA:GT_SPFLI TYPE TABLE OF GTY_SPFLI. DATA:GT_TOTAL TYPE TABLE OF GTY_TOTAL. DATA:GT_SCARR TYPE TABLE OF SCARR. DATA:GS_SFLIGHT TYPE GTY_SFLIGHT. DATA:GS_SPFLI TYPE GTY_SPFLI. DATA:GS_TOTAL TYPE GTY_TOTAL. DATA:GS_SCARR TYPE SCARR. SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001. SELECT-OPTIONS S_PLANE FOR GS_SFLIGHT-PLANETYPE NO-EXTENSION NO INTERVALS. SELECT-OPTIONS S_CONNID FOR GS_SFLIGHT-CONNID. SELECT-OPTIONS S_FLDATE FOR GS_SFLIGHT-FLDATE. SELECTION-SCREEN END OF BLOCK BK1. SELECTION-SCREEN SKIP 3. PARAMETERS P_CHECK TYPE CHAR1 AS CHECKBOX USER-COMMAND HIDE. SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE TEXT-002. PARAMETERS P_1 RADIOBUTTON GROUP GP1 MODIF ID DEP. PARAMETERS P_2 RADIOBUTTON GROUP GP1 MODIF ID DEP. PARAMETERS P_3 RADIOBUTTON GROUP GP1 MODIF ID DEP. PARAMETERS P_4 RADIOBUTTON GROUP GP1 MODIF ID DEP. SELECTION-SCREEN END OF BLOCK BK2 .
ZWYZTEST_01_FORM
*&---------------------------------------------------------------------* *& 包含 ZWYZTEST_01_FORM *&---------------------------------------------------------------------* FORM GET_DATA. RANGES R_CARRID FOR GS_SFLIGHT-CARRID. CLEAR: R_CARRID , R_CARRID[]. IF P_1 = 'X'. R_CARRID-SIGN = 'I'. R_CARRID-OPTION = 'EQ'. R_CARRID-LOW = 'AC'. APPEND R_CARRID. ELSEIF P_2 = 'X'. R_CARRID-SIGN = 'I'. R_CARRID-OPTION = 'EQ'. R_CARRID-LOW = 'AF'. APPEND R_CARRID. ELSEIF P_3 = 'X'. R_CARRID-SIGN = 'I'. R_CARRID-OPTION = 'EQ'. R_CARRID-LOW = 'LH'. APPEND R_CARRID. ELSEIF P_4 = 'X'. R_CARRID-SIGN = 'I'. R_CARRID-OPTION = 'EQ'. R_CARRID-LOW = 'SQ'. APPEND R_CARRID. ENDIF. SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE GT_SFLIGHT WHERE PLANETYPE IN S_PLANE AND CONNID IN S_CONNID AND FLDATE IN S_FLDATE AND CARRID IN R_CARRID. IF GT_SFLIGHT IS NOT INITIAL. SELECT CARRID CONNID CITYFROM CITYTO FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE GT_SPFLI FOR ALL ENTRIES IN GT_SFLIGHT WHERE CARRID = GT_SFLIGHT-CARRID AND CONNID = GT_SFLIGHT-CONNID. SORT GT_SPFLI BY CARRID CONNID. ENDIF. LOOP AT GT_SFLIGHT INTO GS_SFLIGHT. CLEAR GS_TOTAL. MOVE-CORRESPONDING GS_SFLIGHT TO GS_TOTAL . READ TABLE GT_SPFLI INTO GS_SPFLI WITH KEY CARRID = GS_TOTAL-CARRID CONNID = GS_TOTAL-CONNID BINARY SEARCH. IF SY-SUBRC = 0 . GS_TOTAL-CITYFROM = GS_SPFLI-CITYFROM . GS_TOTAL-CITYTO = GS_SPFLI-CITYTO. ELSE. CONTINUE. ENDIF. APPEND GS_TOTAL TO GT_TOTAL. ENDLOOP. ENDFORM. FORM DISPLAY_DATA. SET PF-STATUS 'STANDARD'. SET TITLEBAR 'TITLE' WITH'航班'. LOOP AT GT_TOTAL INTO GS_TOTAL. WRITE:/1 SY-VLINE NO-GAP, (20) GS_TOTAL-PLANETYPE NO-GAP CENTERED, SY-VLINE NO-GAP, (20) GS_TOTAL-CONNID NO-GAP CENTERED, SY-VLINE NO-GAP, (20) GS_TOTAL-FLDATE NO-GAP CENTERED, SY-VLINE NO-GAP, (20) GS_TOTAL-CARRID NO-GAP CENTERED, SY-VLINE NO-GAP, (20) GS_TOTAL-CITYFROM NO-GAP CENTERED, SY-VLINE NO-GAP, (20) GS_TOTAL-CITYTO NO-GAP CENTERED, SY-VLINE NO-GAP. WRITE:/1(127) SY-ULINE. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form MODIFY_SCREEN *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM MODIFY_SCREEN_PBO . LOOP AT SCREEN. IF P_CHECK = ''. IF SCREEN-GROUP1 ='DEP'. SCREEN-ACTIVE = 0. MODIFY SCREEN. ENDIF. ENDIF. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form SELECTION_SCREEN_PAI *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM SELECTION_SCREEN_PAI . SELECT SINGLE * FROM SFLIGHT INTO CORRESPONDING FIELDS OF GS_SFLIGHT WHERE PLANETYPE = S_PLANE. IF SY-SUBRC = 0. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form ZWYZTEST_01_TOP_OF_PAGE *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM ZWYZTEST_01_TOP_OF_PAGE . FORMAT COLOR 3 ON. WRITE:/1(127) '航班详细信息表' CENTERED. FORMAT COLOR 3 OFF. WRITE:/1(127) SY-ULINE. FORMAT COLOR 6 INVERSE ON. WRITE:/1 SY-VLINE NO-GAP, (20) '航班类型' NO-GAP CENTERED, SY-VLINE NO-GAP, (20) '航班连接编号' NO-GAP CENTERED, SY-VLINE NO-GAP, (20) '航班日期' NO-GAP CENTERED, SY-VLINE NO-GAP, (20) '航线代码' NO-GAP CENTERED, SY-VLINE NO-GAP, (20) '起飞城市' NO-GAP CENTERED, SY-VLINE NO-GAP, (20) '到达城市' NO-GAP CENTERED, SY-VLINE . WRITE:/1(127) SY-ULINE. FORMAT COLOR 6 INVERSE OFF. ENDFORM. *&---------------------------------------------------------------------* *& Form ZWYZTEST_01_LINE_SELECTION *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM ZWYZTEST_01_LINE_SELECTION . DATA:GV_FIELD(30). DATA:GV_VALUE(30). GET CURSOR FIELD GV_FIELD VALUE GV_VALUE. CHECK GV_FIELD = 'GS_TOTAL-CARRID'. SELECT SINGLE * FROM SPFLI WHERE CARRID = GV_FIELD . IF SY-SUBRC = 0 . WRITE:/'国家地区代码',SPFLI-COUNTRYFR. ELSE. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form ZWYZTEST_01_USER_COMMAND *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM ZWYZTEST_01_USER_COMMAND . CASE SY-UCOMM. WHEN 'SAVE'. MESSAGE S001 WITH'保存功能暂未定义' DISPLAY LIKE 'E'. WHEN 'SORTUP'. MESSAGE S001 WITH'升序功能暂未定义' DISPLAY LIKE'E'. WHEN 'SORTDOWN'. MESSAGE S001 WITH'降序功能暂未定义' DISPLAY LIKE'E'. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN 'EXIT' OR 'CANCEL'. LEAVE PROGRAM. WHEN OTHERS. ENDCASE. ENDFORM.
GUI状态栏
本demo中的按钮基本都没有写实现代码,感兴趣的可以自己写写实现看看!