一、我们创建3个引用单元,这3个单元里面分别存放定义相关,执行相关和子程序相关的内容
二、将程序中的各部分都拆分到INCLUDE文件中,DEF文件内容如下
三、INC文件内容
四、MAIN文件中写程序执行的逻辑
五、运行程序时,需要激活对应的3个文件,需要选中3个后再点对勾
六、运行程序
七、效果如下
代码如下:
*&---------------------------------------------------------------------* *& Report Z_TIANPAN_20190717_HELLO *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT Z_TIANPAN_20190717_HELLO LINE-SIZE 76. * 此程序引用其他单元 *此INCLUDE用于定义变量 INCLUDE Z_TIANPAN_20190717_DEF. *此INCLUDE用于执行 INCLUDE Z_TIANPAN_20190717_MAIN. *此INCLUDE用于各种函数 INCLUDE Z_TIANPAN_20190717_INC.
*&---------------------------------------------------------------------* *& 包含 Z_TIANPAN_20190717_DEF *&---------------------------------------------------------------------* *定义数据类型 DATA it_spfli TYPE TABLE OF spfli. DATA wa_spfli TYPE spfli. *定义选择屏幕,connid表示航班连接编号 DATA connid TYPE spfli-connid. SELECTION-SCREEN BEGIN OF BLOCK basic_select WITH FRAME TITLE text-005 . SELECT-OPTIONS so_car FOR connid. SELECTION-SCREEN END OF BLOCK basic_select. SELECTION-SCREEN BEGIN OF BLOCK other_select WITH FRAME TITLE text-006. PARAMETERS pa_int TYPE c AS CHECKBOX. SELECTION-SCREEN END OF BLOCK other_select.
*&---------------------------------------------------------------------* *& 包含 Z_TIANPAN_20190717_INC *&---------------------------------------------------------------------* FORM GET_DATA USING Apa_int Aso_car TYPE TABLE CHANGING Ait_spfli TYPE TABLE. *如果选中了,表示国内国际都显示 IF Apa_int = 'X'. * 读取数据库中的内容 SELECT * FROM spfli INTO TABLE Ait_spfli WHERE connid IN Aso_car. ELSE. SELECT * FROM spfli INTO TABLE Ait_spfli WHERE connid IN Aso_car AND spfli~countryfr = spfli~countryto. ENDIF. ENDFORM. FORM SHOW_DATA USING Ait_spfli TYPE TABLE. FORMAT RESET. LOOP AT Ait_spfli INTO wa_spfli. IF wa_spfli-countryfr = wa_spfli-countryto. WRITE: / sy-vline,AT 2(10) wa_spfli-carrid , sy-vline,AT 14(10) wa_spfli-connid , sy-vline,AT 26(20) wa_spfli-countryfr, sy-vline,AT 48(20) wa_spfli-countryto, sy-vline,AT 70(5) ICON_CHECKED AS ICON, AT 76 sy-vline. ELSE. WRITE: / sy-vline,AT 2(10) wa_spfli-carrid , sy-vline,AT 14(10) wa_spfli-connid , sy-vline,AT 26(20) wa_spfli-countryfr, sy-vline,AT 48(20) wa_spfli-countryto, sy-vline,AT 70(5) ICON_INCOMPLETE AS ICON, AT 76 sy-vline. ENDIF. ENDLOOP. *输出一条线 ULINE. ENDFORM.
*&---------------------------------------------------------------------* *& 包含 Z_TIANPAN_20190717_MAIN *&---------------------------------------------------------------------* *在选择屏幕时候判断 AT SELECTION-SCREEN. IF so_car IS INITIAL. MESSAGE w000(Z_TIANPAN_201907_MSG). ENDIF. *一个事件,程序加载时执行,相当于初始化 LOAD-OF-PROGRAM. pa_int = 'X'. *冻结第一行表头 TOP-OF-PAGE. *输出一条线 ULINE. *输出一条横线 Format表示格式化颜色,COL_HEADING颜色可以在F1中对比 FORMAT COLOR COL_HEADING . *输出数据库内容,sy-vline表示把内容当成字段来输出,左边线占用1个字符,从2开始 WRITE: / sy-vline,AT 2(10) text-001, sy-vline,AT 14(10) text-002, sy-vline,AT 26(20) text-003, sy-vline,AT 48(20) text-004, sy-vline,AT 70(5) '国际', AT 76 sy-vline. *输出一条线 ULINE. *程序执行选择屏幕时被A触发的事件 START-OF-SELECTION. *调用函数 PERFORM GET_DATA USING pa_int so_car[] CHANGING it_spfli. PERFORM SHOW_DATA USING it_spfli.