Table Control 表條目控制(向導自動生成代碼 )
REPORT ytest00a.
*6.6 Table Control 表條目控制(嚮導自動生成代碼)
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM.
*默認顯示600窗口
DATA: SID1(4) TYPE N VALUE '600'.
*調用主屏幕
CALL SCREEN 510.
*&---------------------------------
*& 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.
*&SPWIZARD: FUNCTION CODES FOR TABSTRIP 'TBS'
CONSTANTS: BEGIN OF C_TBS,
TAB1 LIKE SY-UCOMM VALUE 'TBS_FC1',
TAB2 LIKE SY-UCOMM VALUE 'TBS_FC2',
END OF C_TBS.
*&SPWIZARD: DATA FOR TABSTRIP 'TBS'
CONTROLS: TBS TYPE TABSTRIP.
DATA: BEGIN OF G_TBS,
SUBSCREEN LIKE SY-DYNNR,
PROG LIKE SY-REPID VALUE 'YTEST00A',
PRESSED_TAB LIKE SY-UCOMM VALUE C_TBS-TAB1,
END OF G_TBS.
*&SPWIZARD: OUTPUT MODULE FOR TS 'TBS'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: SETS ACTIVE TAB
MODULE TBS_ACTIVE_TAB_SET OUTPUT.
TBS-ACTIVETAB = G_TBS-PRESSED_TAB.
CASE G_TBS-PRESSED_TAB.
WHEN C_TBS-TAB1.
G_TBS-SUBSCREEN = '0600'.
WHEN C_TBS-TAB2.
G_TBS-SUBSCREEN = '0700'.
WHEN OTHERS.
*&SPWIZARD: DO NOTHING
ENDCASE.
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TS 'TBS'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GETS ACTIVE TAB
MODULE TBS_ACTIVE_TAB_GET INPUT.
OK_CODE = SY-UCOMM.
CASE OK_CODE.
WHEN C_TBS-TAB1.
G_TBS-PRESSED_TAB = C_TBS-TAB1.
WHEN C_TBS-TAB2.
G_TBS-PRESSED_TAB = C_TBS-TAB2.
WHEN OTHERS.
*&SPWIZARD: DO NOTHING
ENDCASE.
ENDMODULE.
屏幕顯示圖片
*&---------------------------------------------------------------------*
*& Report YTEST00A
*&---------------------------------------------------------------------*
*&Violin 2021/3/10
*&---------------------------------------------------------------------*
REPORT ytest00a.
*第六章 實戰屏幕SCREEN設計---------------------------------------------------------------------*
*6.10圖片顯示程序
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 520.
*MODULE USER_COMMAND_0100 INPUT
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
*定義狀態條,包括菜單、工具條按鈕、系統按鈕等
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
* IMPORTING
* result =
* EXCEPTIONS
* error = 1
* others = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*標誌位已初始
init = 'X'.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form LOAD_PIC_DB
*&---------------------------------------------------------------------*
*& 獲取圖片地址通用函數
*&---------------------------------------------------------------------*
*& <-- URL
*&---------------------------------------------------------------------*
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 = 'ENJOYSAP_LOGO'.
APPEND query_table.
*讀取WWWDATA表,取得圖片對象信息
*DATA RETURN_CODE TYPE W3PARAM-RET_CODE.
*DATA CONTENT_TYPE TYPE W3PARAM-CONT_TYPE.
*DATA CONTENT_LENGTH TYPE W3PARAM-CONT_LEN.
*DATA QUERY_STRING TYPE STANDARD TABLE OF W3QUERY.
*DATA HTML TYPE STANDARD TABLE OF W3HTML.
*DATA MIME TYPE STANDARD TABLE OF W3MIME.
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 <> 0.
* Implement suitable error handling here
ENDIF.
IF SY-SUBRC EQ 0.
PIC_SIZE = CONTENT_LENGTH.
ENDIF.
* DATA TYPE TYPE C.
* DATA SUBTYPE TYPE C.
* DATA SIZE TYPE I.
* DATA DATE TYPE SY-DATUM.
* DATA TIME TYPE SY-UZEIT.
* DATA DESCRIPTION TYPE C.
* DATA LIFETIME TYPE C.
* DATA CACHEABLE TYPE C.
* DATA SEND_DATA_AS_STRING TYPE CHAR01.
* DATA FIELDS_FROM_APP TYPE CHAR01.
* DATA URL TYPE C.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'image'
subtype = CNDP_SAP_TAB_UNKNOWN
SIZE = PIC_SIZE
* DATE = DATE
* TIME = TIME
* DESCRIPTION = DESCRIPTION
LIFETIME = CNDP_LIFETIME_TRANSACTION
* CACHEABLE = CACHEABLE
* SEND_DATA_AS_STRING = SEND_DATA_AS_STRING
* FIELDS_FROM_APP = FIELDS_FROM_APP
TABLES
data = PIC_data
* FIELDS = FIELDS
* PROPERTIES = PROPERTIES
* COLUMNS_TO_STRETCH = COLUMNS_TO_STRETCH
CHANGING
url = url
EXCEPTIONS
DP_INVALID_PARAMETER = 1
DP_ERROR_PUT_TABLE = 2
DP_ERROR_GENERAL = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
![](https://i-blog.csdnimg.cn/blog_migrate/be6e78f3f2e2c913e30671764c585381.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7ac34c09f1e22cf8689fe7b0ea70791f.png)
文本編輯器程序
*&---------------------------------------------------------------------*
*& Report YTEST00A
*&---------------------------------------------------------------------*
*&Violin 2021/3/10
*&---------------------------------------------------------------------*
REPORT ytest00a.
*第六章 實戰屏幕SCREEN設計---------------------------------------------------------------------*
*6.11.2 文本編輯器程序
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 520.
REFRESH m1.
CALL METHOD editor->get_text_as_r3table
* EXPORTING
* only_when_modified = FALSE
IMPORTING
table = m1.
* is_modified =
* EXCEPTIONS
* error_dp = 1
* error_cntl_call_method = 2
* error_dp_create = 3
* potential_data_loss = 4
* others = 5
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*逐行輸出
LOOP AT m1 INTO line.
WRITE / line.
ENDLOOP.
*&Module USER_COMMAND_0100 INPUT
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
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.
* EXCEPTIONS
* error_dp = 1
* error_dp_create = 2
* others = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDMODULE.
![](https://i-blog.csdnimg.cn/blog_migrate/5eda211ff4be2318053c58951a144e2b.png)
列表和屏幕相互調用
*6.12列表和屏幕相互調用
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK TYPE SY-UCOMM,
SCARRID(20) TYPE C.
TABLES SPFLI.
CALL SCREEN 530.
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 SPFLI WHERE CARRID = SCARRID.
WRITE: / SPFLI-CARRID,SPFLI-CONNID,
SPFLI-CITYFROM,SPFLI-CITYTO.
ENDSELECT.
* WRITE: / 'DONE'.
ENDIF.
ENDMODULE.
![](https://i-blog.csdnimg.cn/blog_migrate/186d5225bbdb7fc9240dcb4aa1331741.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5b61300b087fbf3e44a98863ed5da5ad.png)
從列表調用屏幕
*&---------------------------------------------------------------------*
*& Report YTEST00A
*&---------------------------------------------------------------------*
*&Violin 2021/3/10
*&---------------------------------------------------------------------*
REPORT ytest00a.
*第六章 實戰屏幕SCREEN設計---------------------------------------------------------------------*
*6.12.2從列表調用屏幕
TABLES SPFLI.
START-OF-SELECTION.
SELECT * FROM SPFLI.
WRITE: / SPFLI-CARRID,(15) SPFLI-CONNID,(15) SPFLI-COUNTRYTO,(15) SPFLI-CITYFROM,(15) SPFLI-AIRPFROM.
HIDE:SPFLI-CARRID,SPFLI-CONNID,SPFLI-COUNTRYFR,
SPFLI-CITYFROM,SPFLI-AIRPFROM,SPFLI-COUNTRYTO,SPFLI-CITYTO,SPFLI-AIRPTO.
ENDSELECT.
AT LINE-SELECTION.
CHECK NOT SPFLI-CARRID IS INITIAL.
CALL SCREEN 540.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
![](https://i-blog.csdnimg.cn/blog_migrate/a84ec482b42e662f302fd1c880c59caa.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3e8d42feee1fc02212b8dad71f026199.png)