REPORT YHELLOA.
DATA:FORINPUT(20) TYPE C VALUE '初始值',
FORCODE(20) TYPE C.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*直接调用窗口
CALL SCREEN 100.
*输出返回变量
WRITE:FORINPUT,/ FORCODE.
MODULE STATUS_0100 OUTPUT.
*定义状态条、包括菜单、工具条按钮、系统按钮等
SET PF-STATUS 'TESTSTA1'.
*将变量值输出至屏幕字段
FORCODE = SAVE_OK.
ENDMODULE.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
*分析功能码,如果是工具条上的第二个按钮,泽退出当前屏幕
CASE SAVE_OK.
WHEN 'BIN2'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
使用YTDSCHOOL学校表,在屏幕上定义相关该表字段,并根据输入的主关键字检索其他字段的信息,并显示到输入输出字段.
REPORT YHELLOB.
*功能码返回值
DATA:OK_CODE TYPE C,
SAVE_OK TYPE C.
*使用学校表
TABLES YTDSCHOOL.
*直接调用窗口
CALL SCREEN 100.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE STATUS_O100 OUTPUT.
SET PF-STATUS 'STATUS1'.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
*将SELECT数据赋给SCHOOL记录,SCHOOL记录关联屏幕字段
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF YTDSCHOOL
FROM YTDSCHOOL
WHERE YSH_ID = YTDSCHOOL-YSH_ID.
IF SY-SUBRC NE 0.
CLEAR YTDSCHOOL.
ENDIF.
ENDMODULE.
发布消息。
*功能码返回值
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 100.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
ENDMODULE.
MODULE USER_COMMAND_0100 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.
MODULE CHECK1 INPUT.
*当输入FLD1 = 'FLD1'时提示错误,而且不执行PAI
IF FLD1 = 'FLD1'.
MESSAGE E004(YMESS) WITH 'FLD1 ERROR'.
ENDIF.
*当输入FLD1 = 'FLD11'时弹出窗口提示,执行PAI
IF FLD1 = 'FLD11'.
MESSAGE I004(YMESS) WITH 'FLD1 WARNING'.
ENDIF.
*当输入FLD1 = 'FLD111'时输出成功信息,执行PAI
IF FLD1 = 'FLD111'.
MESSAGE S004(YMESS) WITH 'FLD1 OK'.
ENDIF.
ENDMODULE.
MODULE CHECK2 INPUT.
IF FLD3 = 'FLD3'.
MESSAGE E004(YMESS) WITH 'FLD3 ERROR'.
ENDIF.
IF FLD3 = 'FLD33'.
MESSAGE I004(YMESS) WITH 'FLD3 WARNING'.
ENDIF.
IF FLD3 = 'FLD333'.
MESSAGE S004(YMESS) WITH 'FLD3 OK'.
ENDIF.
ENDMODULE.
MODULE CHECK3 INPUT.
MESSAGE I004(YMESS) WITH 'FLD2 * WARNING'.
ENDMODULE.
*功能码返回值
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 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
*加两条记录
FNAME = 'FLD1'.
LVVA-KEY = '广州'.
APPEND LVVA TO VVA.
FNAME = 'FLD1'.
LVVA-KEY = '上海'.
APPEND LVVA TO VVA.
FNAME = 'FLD1'.
LVVA-KEY = '北京'.
APPEND LVVA TO VVA.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = FNAME
VALUES = VVA
* EXCEPTIONS
* ID_ILLEGAL_NAME = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
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.先创建一个自定义控件P1。
2.CODE码:SMW0 ,上传图片ZTESTWPIC
3.程序代码:
REPORT YHELLOA.
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 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
*如果还未创建定制对象
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 = 'ZTESTWPIC'.
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.
如上例中在屏幕编辑器里添加自定义控件P1。
REPORT YHELLOA.
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 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTSTA1'.
*如果还未创建定制对象
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 YHELLOA.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM,
CITYID(20) TYPE C.
TABLES YTDSCHOOL.
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 YTDSCHOOL WHERE YCT_ID = CITYID.
WRITE: / YTDSCHOOL-YCT_ID, YTDSCHOOL-YSH_ID,
YTDSCHOOL-YSH_NAME, YTDSCHOOL-YSH_ADDR.
ENDSELECT.
ENDIF.
WRITE:/ 'DONE'.
ENDMODULE.
REPORT YHELLOA.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM,
CITYID(20) TYPE C.
TABLES YTDSCHOOL.
START-OF-SELECTION.
SELECT * FROM YTDSCHOOL.
WRITE:/ YTDSCHOOL-YCT_ID,(15) YTDSCHOOL-YSH_ID,
(15) YTDSCHOOL-YSH_NAME, (15) YTDSCHOOL-YSH_ADDR.
HIDE:YTDSCHOOL-YCT_ID, YTDSCHOOL-YSH_ID,
YTDSCHOOL-YSH_NAME, YTDSCHOOL-YSH_ADDR.
ENDSELECT.
AT LINE-SELECTION.
CHECK NOT YTDSCHOOL-YSH_ID IS INITIAL.
CALL SCREEN 100.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_I100 OUTPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
单击某一行时显示下面信息: