從程序中調用Screen
***"*6.2.3從程序中調用Screen---------------------------------------------------------------------*\
DATA: forinput(20) TYPE c VALUE '初始值', "對應子屏幕的控件
forcode(20) TYPE c.
*功能碼返回值
DATA: ok_code TYPE sy-ucomm, "對應子屏幕的菜單、工具條按鈕、系統按鈕
save_ok TYPE sy-ucomm.
*使用航線表,聲明一個同數據庫表同名的內表(含表頭) 此處綁定了控件
tables: spfli.
*直接調用窗口
CALL SCREEN 100.
WRITE: forinput, / forcode. "子屏幕結束後調用
*------------------------------------------
*MODULE status_0100 output
*------------------------------------------
*PBO輸入前控制
*------------------------------------------
MODULE status_0100 OUTPUT.
*定義狀態條、包括菜單、工具條按鈕、系統按鈕等
SET PF-STATUS 'TESTSTA1'.
forcode = save_ok.
ENDMODULE. "STATUS_0100 OUTPUT
*------------------------------------------
*MODULE cancel INPUT
*------------------------------------------
*CANCEL MODULE與屏幕邏輯流對應
*------------------------------------------
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. "cancel INPUT
*------------------------------------------
*MODULE user_command_0100 INPUT
*------------------------------------------
*PAI輸入後控制
*------------------------------------------
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
*分析功能碼,如果是工具條上的第二個按鈕,則退出當前屏幕
CASE save_ok.
WHEN 'BIN2'.
LEAVE TO SCREEN 0.
when 'EXIT'.
leave program.
ENDCASE.
*將SELECT數據賦值給SPFLI記錄,SPFLI記錄關聯屏幕字段
select single *
into corresponding fields of spfli
from spfli
where carrid = spfli-carrid and connid = spfli-connid.
if sy-subrc ne 0.
clear spfli.
endif.
ENDMODULE. "user_command_0100 INPUT
發佈消息
***"*6.2.4發佈消息---------------------------------------------------------------------*
"功能碼返回值
data: ok_code type sy-ucomm,
save_ok type sy-ucomm.
*定義輸入字段變量
data: fld1(20) type c,
fld2(20) type c,
fld3(20) type c,
fld4(20) type c,
action(50) type c.
*直接調用窗口
call screen 200.
**------------------------------------------
**MODULE cancel INPUT
**------------------------------------------
**CANCEL MODULE與屏幕邏輯流對應
**------------------------------------------
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE. "CANCEL INPUT
**------------------------------------------
**MODULE STATUS_0100 OUTPUT
**------------------------------------------
**定義狀態條,包括菜單、工具條按鈕、系統按鈕等
**------------------------------------------
MODULE STATUS_0200 OUTPUT.
" SET PF-STATUS 'STATUS1'.
SET PF-STATUS 'TESTSTA1'.
ENDMODULE. "STATUS_0100 OUTPUT.
**------------------------------------------
**MODULE USER_COMMAND_0100 INPUT
**------------------------------------------
**如果能執行PAI,把FLD1\FLD2、FLD3、FLD4合併到ACTION字段
**------------------------------------------
MODULE USER_COMMAND_0200 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ACTION = ''.
CONCATENATE FLD1 FLD2 FLD3 FLD4 INTO ACTION.
ENDMODULE. "USER_COMMAND_0200 INPUT
**------------------------------------------
**MODULE CHECK1 INPUT
**------------------------------------------
**輸入FLD1 FLD2 時檢查
**------------------------------------------
MODULE CHECK1 INPUT.
"當輸入FLD1='FLD1'時提示錯誤,而且不執行PAI
IF FLD1 = 'FLD1'.
MESSAGE E005(YMESS) WITH 'FLD1 ERROR'.
ENDIF.
"當輸入FLD1='FLD11'時彈出窗口提示,執行PAI
IF FLD1 = 'FLD11'.
MESSAGE I005(YMESS) WITH 'FLD1 WARNING'.
ENDIF.
"當輸入FLD1='FLD111'時輸出成功信息,執行PAI
IF FLD1 = 'FLD111'.
MESSAGE S005(YMESS) WITH 'FLD1 OK'.
ENDIF.
ENDMODULE. "CHECK1 INPUT
**------------------------------------------
**MODULE CHECK2 INPUT
**------------------------------------------
**輸入FLD3 FLD4 時檢查
**------------------------------------------
MODULE CHECK2 INPUT.
IF FLD3 ='FLD3'.
MESSAGE E005(YMESS) WITH 'FLD3 ERROR'.
ENDIF.
IF FLD3 = 'FLD33'.
MESSAGE I005(YMESS) WITH 'FLD3 WARRING'.
ENDIF.
IF FLD3 = 'FLD333'.
MESSAGE S005(YMESS) WITH 'FLD3 OK'.
ENDIF.
ENDMODULE.
**------------------------------------------
**MODULE CHECK3 INPUT
**------------------------------------------
**當FLD2第一個字符是‘*’時,執行改MODULE,彈出信息提示
**------------------------------------------
MODULE CHECK3 INPUT.
MESSAGE I005(YMESS) WITH 'FLD2 * WARNING'.
ENDMODULE. "CHECK3 INPUT
LISTBOX下拉框設計
*6.3LISTBOX下拉框設計
*功能碼返回值
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
*VRM類型定義接口
TYPE-POOLS vrm.
DATA: fld1(20) TYPE c.
*內表、記錄,字段變量定義
DATA:fname TYPE vrm_id,
vva TYPE vrm_values,
lvva LIKE LINE OF vva.
*直接調用窗口
CALL SCREEN 300.
***------------------------------------------
***MODULE STATUS_0100 INPUT
***------------------------------------------
***定義狀態條,包括菜單、工具條、系統按鈕等
*直接在PBO中將值填入內表,再設定下拉框
***------------------------------------------
MODULE status_0300 OUTPUT.
* SET PF-STATUS 'STATUS1'.
SET PF-STATUS 'TESTSTA1'.
"加兩條記錄
fname ='FLD3'.
* LVVA-KEY = '1'.
lvva-key = '廣州'.
APPEND lvva TO vva.
CLEAR lvva.
fname = 'FLD3'.
lvva-key = '上海'.
APPEND lvva TO vva.
*下拉框賦值
*DATA ID TYPE VRM_ID.
*DATA VALUES TYPE VRM_VALUES.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = fname
values = vva
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDMODULE.
*&--------------------------------------------------------------------
*& Module CANCEL INPUT
*&--------------------------------------------------------------------
*&CANCEL MODULE 與屏幕邏輯流對應,退出程序
*&--------------------------------------------------------------------
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. "CANCEL INPUT
*&--------------------------------------------------------------------
*& MODULE USER_COMMAND_0100 INPUT
*&--------------------------------------------------------------------
* PAI
*---------------------------------------------------------------------
MODULE user_command_0100_input.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
修改屏幕狀態
*6.7修改屏幕狀態
*功能碼返回值
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA: sgrp(20) TYPE c,
smod(1) TYPE c.
*是否修改
DATA: canmod(1) TYPE c.
*默認可以修改
canmod = 'X'.
*直接調用窗口
CALL SCREEN 400.
*&---------------------------------------------------
*& Module STATUS_0100 OUTPT
*&---------------------------------------------------
*定義狀態條、包括菜單、工具條按鈕、系統按鈕
*----------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
*根據按鈕確定字段組
sgrp = ''.
IF save_ok = 'G1'.
sgrp = 'NA'.
ELSE.
sgrp = 'NB'.
ENDIF.
*CHECKBOX轉換
IF canmod = 'X'.
smod = '1'.
ELSE.
smod = '0'.
ENDIF.
*逐個掃描屏幕元素
LOOP AT SCREEN.
* 如果是需要修改的組,更改變量,其他組不考慮,如果正式考慮先存儲到變量.
IF screen-group1 = sgrp.
screen-input = smod.
* 更新到窗口元素變量
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMODULE. "STATUS_0100 OUTPUT
*&---------------------------------------------------
*& Module CANCEL INPUT
*&--------------------------------------------------
*CANCEL MOUDLE 與屏幕邏輯流對應,退出程序
*---------------------------------------------------
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. "CANCEL INPUT
*&--------------------------------------------------
*&MODULE USER_COMMAND_0100 INPUT
*&--------------------------------------------------
*PAI
*-------------------------------------------------
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. "USER_COMMAND_0100
![](https://i-blog.csdnimg.cn/blog_migrate/bd95d7070bcfd59d7579ba484b1a8e51.png)
子窗體
REPORT ytest00a.
*6.6子窗體
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*默認顯示600窗口
DATA: SID1(4) TYPE N VALUE '600'.
*調用主屏幕
CALL SCREEN 500.
*&---------------------------------
*& MODULE STATUS_0100 OUTPUT
*&--------------------------------
*TEXT
*---------------------------------
*顯示工具欄
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
ENDMODULE.
*&----------------------------------
*&MODULE CANCEL INPUT
*&----------------------------------
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
*&---------------------------
*&MODULE USER_COMMAND_0100 INPUT.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
*當單擊第一個按鈕,顯示600子窗口
WHEN 'BTN1'.
SID1 = '0600'.
*當單擊第二個按鈕,顯示700子窗口
WHEN 'BTN2'.
SID1 = '0700'.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
*主屏幕邏輯流
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*SUBSCR是定義的子屏幕範圍的名稱
CALL SUBSCREEN: subscr INCLUDING SY-REPID SID1.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
*使子屏幕顯示(下面這句不加貌似也不影響….)
CALL SUBSCREEN SUBSCR.
新建其他兩個“子屏幕”,編號為600、700
測試效果: