REPORT Z_ABAP_23_MULTIPLE_SELECTION.
TABLES: KNA1.
DATA: OK_CODE LIKE sy-ucomm.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (40) W_BUT1 USER-COMMAND BUT1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF SCREEN 0900 AS SUBSCREEN.
SELECT-OPTIONS: s_kunnrs FOR kna1-kunnr NO INTERVALS.
SELECTION-SCREEN END OF SCREEN 0900.
INITIALIZATION.
W_BUT1 = 'PUSHBUTTON'.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'BUT1'.
CLEAR sy-ucomm.
CALL SCREEN 1100.
ENDCASE.
START-OF-SELECTION.
CALL SCREEN 1100.
END-OF-SELECTION.
MODULE STATUS_1100 OUTPUT.
SET PF-STATUS 'S1100'.
ENDMODULE. " STATUS_1100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1100 INPUT.
CASE OK_CODE.
WHEN 'CANC' OR 'BACK' OR 'EXIT'.
CLEAR OK_CODE.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_1100 INPUT
此程式需要自行建立 SCREEN 1000,並加入下面 Flow logic,Screen 0900 在上面 Sample Code。
注意 : CALL SUBSCREEN: SUB1 一般是放在 MODULE USER_COMMAND_1100. 前,但如果先 CALL SUBSCREEN: SUB1 會先觸發 AT SELECTION-SCREEN 結果又 CALL SCREEN 1100,在此只是短解讓 User 按下 BACK/CANC/EXIT 可優先執行,無特殊意義可依自己的習慣撰寫即可,或是參考 SOLUTION II 裡 AT SELECTION-SCREEN 加入 IF sy-dynnr NE 1100 AND sy-dynnr NE 900. 即可
How to triggering start of selection after pressing pushbutton from report 可透過之前寫的 Blog 進行 Enhance,即在按了 PUSHBUTTON 後強制進入 START-OF-SELECTION,其實主要解決 CALL SCREEN 不要在 AT SELCTION-SCREEN 即可,當在 START-OF-SELECTION 即可讓呼叫的 SUB SCREEN 的 MULTI-SELECTION
*&---------------------------------------------------------------------*
*& Report Z_ABAP_22_PBTN_MTLSLTION
*&---------------------------------------------------------------------*
*& 使用 Pushbutton Call Screen
*&
*&---------------------------------------------------------------------*
REPORT Z_ABAP_23_MULTIPLE_SELECTION.
TABLES: KNA1.
TABLES sscrfields.
DATA: OK_CODE LIKE sy-ucomm.
DATA: G_FROM_PUSHBUTTON TYPE C VALUE 'X'.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (40) W_BUT1 USER-COMMAND BUT1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF SCREEN 0900 AS SUBSCREEN.
SELECT-OPTIONS: s_kunnrs FOR kna1-kunnr NO INTERVALS.
SELECTION-SCREEN END OF SCREEN 0900.
INITIALIZATION.
W_BUT1 = 'PUSHBUTTON'.
AT SELECTION-SCREEN.
CLEAR G_FROM_PUSHBUTTON.
CASE sy-ucomm.
WHEN 'BUT1'.
G_FROM_PUSHBUTTON = 'X'.
sy-ucomm = 'ONLI'.
sscrfields-ucomm = 'ONLI'.
"CALL SCREEN 1100. "不在此呼叫
ENDCASE.
START-OF-SELECTION.
IF G_FROM_PUSHBUTTON = 'X'.
CLEAR G_FROM_PUSHBUTTON.
CALL SCREEN 1100.
MESSAGE 'PRESS PUSHBUTTON' TYPE 'I'.
ELSE.
"DO OTHER THING
MESSAGE 'PRESS EXECUTE BUTTON' TYPE 'I'.
ENDIF.
END-OF-SELECTION.
MODULE STATUS_1100 OUTPUT.
SET PF-STATUS 'S1100'.
ENDMODULE. " STATUS_1100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1100 INPUT.
CASE OK_CODE.
WHEN 'CANC' OR 'BACK' OR 'EXIT'.
CLEAR OK_CODE.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_1100 INPUT
SOLUTION II : FM : COMPLEX_SELECTIONS_DIALOG
針對原本程式先進行以下調整
SCREEN 1100 把 CALL SUBSCREEN: SUB1 拉到 MODLUE USER_COMAND_1100. 之上,避勉因為在 USER_COMMAND_1100 中將 Multi Selection 的值填入 s_kunnrs[] 後,因 Call Subscreen: SUB1 該 Range 的值又被變動
REPORT Z_ABAP_23_MULTIPLE_SELECTION.
TABLES: KNA1.
DATA: OK_CODE LIKE sy-ucomm.
DATA: g_tab_and_field LIKE rstabfield.
RANGES: gr_kunnr FOR kna1-kunnr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (40) W_BUT1 USER-COMMAND BUT1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF SCREEN 0900 AS SUBSCREEN.
SELECT-OPTIONS: s_kunnrs FOR kna1-kunnr NO INTERVALS.
SELECTION-SCREEN END OF SCREEN 0900.
INITIALIZATION.
W_BUT1 = 'PUSHBUTTON'.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'BUT1'.
CLEAR sy-ucomm.
IF sy-dynnr NE 1100 AND sy-dynnr NE 900.
CALL SCREEN 1100.
ENDIF.
ENDCASE.
START-OF-SELECTION.
CALL SCREEN 1100.
END-OF-SELECTION.
MODULE STATUS_1100 OUTPUT.
SET PF-STATUS 'S1100'.
ENDMODULE. " STATUS_1100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1100 INPUT.
CASE OK_CODE.
WHEN 'CANC' OR 'BACK' OR 'EXIT'.
CLEAR OK_CODE.
LEAVE TO SCREEN 0.
WHEN '109000000041059'. "上面 debug 取得 Multiple Selectoin 的 Button user command
CLEAR: gr_kunnr, gr_kunnr[], g_tab_and_field.
g_tab_and_field-fieldname = 'KUNNR'.
g_tab_and_field-tablename = 'KNA1'.
gr_kunnr[] = s_kunnrs[].
CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
EXPORTING
TITLE = 'MULTIPLE SELECTION FOR S_KUNNR'
TEXT = 'Customer'
TAB_AND_FIELD = g_tab_and_field
TABLES
RANGE = gr_kunnr
EXCEPTIONS
NO_RANGE_TAB = 1
CANCELLED = 2
INTERNAL_ERROR = 3
INVALID_FIELDNAME = 4
OTHERS = 5.
IF SY-SUBRC <> 0 AND SY-SUBRC <> 2.
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
STOP.
ELSEIF SY-SUBRC = 2. "When user press cancel don't do any thing
ELSE.
CLEAR: s_kunnrs, s_kunnrs[].
s_kunnrs[] = gr_kunnr[].
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_1100 INPUT
沒有留言:
張貼留言