SAP ABAP——选择屏幕demo

简介: 本文是一个ABAP选择屏幕的demo,废话不多说直接看demo场景

本文是一个ABAP选择屏幕的demo,废话不多说直接看demo场景


Demo场景

通过选择屏幕输入检索条件,连接查询数据库表SFLIGHT、SCARR、SPFLI,输出相应航班的详细信息并且通过List表单的方式打印出来,其中选择屏幕包含了复选框,能让用户自行选择是否根据航线代码进行检索


选择屏幕样式

  • 复选框收起

6c162e812815869c60373f16aa3f8d0.png

  • 复选框展开

ea207be69da1415f26d39547a96f066.png


数据库表SFLIGHT

PS:本demo是通过三表连接查询,但是查询的主数据表为Sflight,这里只展示它的结构和数据,并且三个表这里用的是系统的表,假如实际demo中建议参照这三个表先构建自己的test表并且自己添加测试数据,三个表sflight、scarr、spfli的结构和数据可以在T-CODE:SE11中查询找到

  • 数据库表字段

1c3bb1be9631f03bb36916e372e10fa.png

  • 数据库表数据

3d65687ec96f3f2c99a7917c3b156c1.png


总程序代码

*&---------------------------------------------------------------------*
*& 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状态栏

144bee81517d6ad47bdc4141da34174.png


本demo中的按钮基本都没有写实现代码,感兴趣的可以自己写写实现看看!

目录
相关文章
SAP ABAP 程序调用设置成后台作业模式
ABAP 程序调用设置成后台作业模式
533 0
SAP ABAP 内表排序 动态字段排序
对于动态内表排序引用ABAP_SORTORDER_TAB
311 0
|
SQL 设计模式 前端开发
【置顶】SAP ABAP开发实战——从入门到精通系列目录
本文章为SAP ABAP开发实战——从入门到精通系列的目录以及关于该教程的后续写作计划表
1681 0
【置顶】SAP ABAP开发实战——从入门到精通系列目录
|
SQL
SAP ABAP-OPENSQL-数值函数简介
S4中针对OPENSQL新提供一些函数
147 0
|
SQL
SAP ABAP-OPENSQL-字符串函数介绍
S4中SQL新语法字符串函数
226 0
|
SQL
SAP ABAP-OPENSQL-日期/时间戳函数
S4提供针对OPENSQL一些新的SQL函数调用,本文展示相关函数的使用
707 0
|
BI
SAP ALV报表选择屏幕筛选字段动态文本
SAP ALV报表选择屏幕筛选字段动态文本
254 0
SAP ABAP-删除工序示例代码
ABAP-删除工序示例代码
178 0
SAP ABAP 检查事务码权限
检查用户是否有自开发事务码的权限
165 0
|
BI
SAP ABAP在线预览文档对象的开发实现
应用场景:有些定制化开发(报表/功能增强等)完成之后,客户需要将其操作手册或者相关文档放在某个报表的初始画面,供实际操作者在线查阅,当然这个功能也同样类似于模板的下载,这里就以在线预览(直接打开)为例进行说明。
234 0