2015年12月26日 星期六

ABAP/4 : When you use pushbutton and call screen in the event "at selection screen", the multiple selection button does not work

當使用 PUSHBUTTON 在 AT SELECTION SCREEN 時 CALL SCREEN 時,會發現系統並不會出現 SUB SCREEN 的 MULTIPLE SELECTION,造成系統無法提供 user 進行條件的篩選。

但如果把 Call Screen 寫在 START-OF-SELECTION 裡,則可以正常顯示 multiple selection

SAMPLE CODE:

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. 即可

再 SCREEN 1100 COMMAND 加入 OK_CODE (在 Sample Code 裡宣告)


拉一個 Subscreen area 並輸入名稱為 SUB1


最後設定程式的 STATUS S1100,主要是進到 SCREEN 1100,可以再回到 SCREEN 1000


SOLUTION 1 : CALL SCREEN 拉到 START-OF-SELECTION

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 的值又被變動

在透過 DEBUG Mode 取得點選 Multiple Selection 的 Command Code,用於 MODLUE USER_COMAND_1100. 裡,判斷 User 點擊的是 Multiple Selection

並修改以下紅字的 Code

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

其主要的目的是透過呼叫 COMPLEX_SELECTIONS_DIALOG 產生 Multiple Selection 的畫面再回填到目前 Report 上的 Select-option 的 Range 變數中

沒有留言:

張貼留言

How to install & specified python version or distreibtuion package version in google colab

在買了 RTX 3080 要來 挖礦...  嗯~是跑機器學習後,結果發現了 GOOGLE COLAB,其實之前在「GAN 對抗式生成網路」一書就有看到,但資訊人就是什麼都想自己安裝,在本機用 Anaconda + pyCharm 弄了 GPU 環境,結果有天從新竹回家發現家裡沒...