(6)列表和屏幕相互调用
1-1和1-2为NO1组,2-1和2-2为NO2组。
程序代码如下
REPORT YTEST20160613002.
*功能码返回值
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 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS1'.
*根据按钮确定字段组
SGRP = ''.
IF SAVE_OK = 'BTN1'.
SGRP = 'NO1'.
ELSE.
SGRP = 'NO2'.
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.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
输出结果如下图
当选择不更改,单击设定组1按钮时,测试组1状态变为不能编辑。
主窗口设计界面:
子窗口设计界面:
同样方式定义好屏幕300
回到主屏幕100,定义逻辑流
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*SUBSCR是定义的子屏幕范围的名称
CALL SUBSCREEN: SUBSCR INCLUDING SY-REPID SID1.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
MODULE USER_COMMAND_0100.
*使子屏幕显示
CALL SUBSCREEN SUBSCR.
主程序代码如下
REPORT YTEST20160613003.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*子窗口默认用200子窗口
DATA:SID1(4) TYPE N VALUE '200'.
*直接调用窗口
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS1'.
ENDMODULE.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
*当单击第一个按钮,显示200子窗口
WHEN 'BTN1'.
SID1 = '200'.
*当单击第二个按钮,显示300子窗口
WHEN 'BTN2'.
SID1 = '300'.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
输出结果如图
图中控件显示粉红色表示其属性未设置完成。
逐页设置名称、文本、功能码属性,接着选中“子屏幕范围”按钮,在第一页创建该对象,设定好子屏幕的属性后,第一页就设置完成,不再显示粉红色,如下图中的表一
向导产生页面子屏幕编号和每页功能码,可以在此基础上调整,继续
默认调用主屏幕的主程序名称,继续
系统提示所示设定参数信息,单击“完成"按钮
打开设计界面,系统自动建立完成全部页面、逻辑流和主程序代码,如图
选择需要上传的本对图片
SAP GUI安全性弹出窗口,单击”允许“按钮
产生传输入请求,单击按钮,如图
上传成功,屏幕显示新产生的对象行,如图
REPORT YTEST20160614002.
DATA:OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*定义控制和图像对象定义
DATA CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA PICTURE TYPE REF TO CL_GUI_PICTURE.
*初始标志字段定义
DATA INIT.
CALL SCREEN 100.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS1'.
*如果还未创建定制对象
IF INIT IS INITIAL.
*图片地址字段定义
DATA URL(255).
CLEAR URL.
*创建对象
CREATE OBJECT CONTAINER
EXPORTING CONTAINER_NAME = 'P1'.
CREATE OBJECT PICTURE
EXPORTING PARENT = CONTAINER
EXCEPTIONS ERROR = 1.
IF SY-SUBRC NE 0.
ENDIF.
*定义通用函数取得图片地址
PERFORM LOAD_PIC_DB CHANGING URL.
*显示图片
CALL METHOD PICTURE->LOAD_PICTURE_FROM_URL
EXPORTING
URL = URL.
IF SY-SUBRC NE 0.
ENDIF.
*置标志位已初始
INIT = 'X'.
ENDIF.
ENDMODULE.
*获取图片地址通用函数
FORM LOAD_PIC_DB CHANGING P_URL.
DATA QUERY_TABLE LIKE W3QUERY OCCURS 1 WITH HEADER LINE.
DATA HTML_TABLE LIKE W3HTML OCCURS 1.
DATA RETURN_CODE LIKE W3PARAM-RET_CODE.
DATA CONTENT_TYPE LIKE W3PARAM-CONT_TYPE.
DATA CONTENT_LENGTH LIKE W3PARAM-CONT_LEN.
DATA PIC_DATA LIKE W3MIME OCCURS 0.
DATA PIC_SIZE TYPE I.
REFRESH QUERY_TABLE.
*查询对象数据
QUERY_TABLE-NAME = '_OBJECT_ID'.
*图片对象名称
QUERY_TABLE-VALUE = 'ZTESTPIC'.
APPEND QUERY_TABLE.
*读取WWWDATA表,取得图片对象信息
CALL FUNCTION 'WWW_GET_MIME_OBJECT'
TABLES
QUERY_STRING = QUERY_TABLE
HTML = HTML_TABLE
MIME = PIC_DATA
CHANGING
RETURN_CODE = RETURN_CODE
CONTENT_TYPE = CONTENT_TYPE
CONTENT_LENGTH = CONTENT_LENGTH
EXCEPTIONS
OBJECT_NOT_FOUND = 1
PARAMETER_NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC EQ 0.
PIC_SIZE = CONTENT_LENGTH.
ENDIF.
*创建图片URL地址
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
TYPE = 'image'
SUBTYPE = CNDP_SAP_TAB_UNKNOWN
SIZE = PIC_SIZE
LIFETIME = CNDP_LIFETIME_TRANSACTION
TABLES
DATA = PIC_DATA
CHANGING
URL = URL
EXCEPTIONS
DP_INVALID_PARAMETER = 1
DP_ERROR_PUT_TABLE = 2
DP_ERROR_GENERAL = 3
OTHERS = 4.
ENDFORM.
REPORT YTEST20160614003.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*初始标志字段定义
*定制控制和编辑对象定义
DATA: INIT,
CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
EDITOR TYPE REF TO CL_GUI_TEXTEDIT.
DATA: M1(256) TYPE C OCCURS 0,
LINE(256) TYPE C.
*输入初始值
LINE = '请输入'.
APPEND LINE TO M1.
CALL SCREEN 100.
REFRESH M1.
CALL METHOD EDITOR->GET_TEXT_AS_R3TABLE
IMPORTING
TABLE = M1.
*逐行输出
LOOP AT M1 INTO LINE.
WRITE / LINE.
ENDLOOP.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'CANCEL'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS1'.
*如果还未创建定制对象
IF INIT IS INITIAL.
INIT = 'X'.
CREATE OBJECT: CONTAINER EXPORTING CONTAINER_NAME = 'P1'.
CREATE OBJECT EDITOR
EXPORTING
PARENT = CONTAINER
WORDWRAP_MODE = CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION
WORDWRAP_POSITION = 256
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
ENDIF.
*读入初始数据
CALL METHOD EDITOR->SET_TEXT_AS_R3TABLE
EXPORTING
TABLE = M1.
ENDMODULE.
REPORT YTEST20160614004.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM,
CITYID(20) TYPE C.
TABLES YTJAYSCHOOL.
CALL SCREEN 100.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
IF SAVE_OK EQ 'BTN1'.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SUPPRESS DIALOG.
SELECT *
FROM YTJAYSCHOOL WHERE YCT_ID = CITYID.
WRITE: / YTJAYSCHOOL-YCT_ID, YTJAYSCHOOL-YSH_ID,
YTJAYSCHOOL-YSH_NAME, YTJAYSCHOOL-YSH_ADDR.
ENDSELECT.
ENDIF.
WRITE:/ 'DONE'.
ENDMODULE.
输出结果如图所示,在输入框输入条件,单击“确认”按钮
REPORT YTEST20160615001.
*功能码返回值
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
TABLES YTJAYSCHOOL.
START-OF-SELECTION.
SELECT * FROM YTJAYSCHOOL.
WRITE:/ YTJAYSCHOOL-YCT_ID, (15) YTJAYSCHOOL-YSH_ID,
(15) YTJAYSCHOOL-YSH_NAME, (15) YTJAYSCHOOL-YSH_ADDR.
HIDE: YTJAYSCHOOL-YCT_ID, YTJAYSCHOOL-YSH_ID,
YTJAYSCHOOL-YSH_NAME, YTJAYSCHOOL-YSH_ADDR.
ENDSELECT.
AT LINE-SELECTION.
CHECK NOT YTJAYSCHOOL-YSH_ID IS INITIAL.
CALL SCREEN 100.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
执行结果如图