2011年3月24日 星期四

[Code] Modify Selection Screen


Example code for for modifying Selection screen from within ABAP code
一定要放在 Event: AT SELECTION-SCREEN OUTPUT 底下:
*  
* AT SELECTION-SCREEN OUTPUT  
*  
AT SELECTION-SCREEN OUTPUT.
  LOOP AT screen.
    IF screen-name = '%_S_AUART_%_APP_%-TEXT'  OR
      screen-name = 'S_AUART-LOW'  OR
      screen-name = 'S_AUART-HIGH' OR
      screen-name = '%_S_AUART_%_APP_%-VALU_PUSH'.
      IF gv_incl = 'X'.
        screen-input = '0'.
        screen-intensified = '0'.
        screen-display_3d  = '0'.
      ELSE.
        screen-input = '1'.
        screen-intensified = '1'.
        screen-display_3d  = '1'.
      ENDIF.
      MODIFY screen.
    ENDIF.
  ENDLOOP.
另外可以在定義 SELECT-OPTIONS 用 MODIF ID 來設定 screen-group1 ,可以比較方便的來判斷一整個欄位群組, 但是因為上面的例子使用了 screen-display_3d ,如果使用 screen-group1 來判斷時,執行 screen-display_3d = '1' 的時候,連同 OPTI_PUSH 欄位都會浮現出來,就不是很完美。
除了 screen-group1 之外,還可以用 screen-group3 來判斷,group3 的內容如下
BLK for SELECTION-SCREEN ... BLOCK ...: Block 
COF for SELECTION-SCREEN COMMENT ... FOR FIELD ...: Field-related comment 
COM for SELECTION-SCREEN COMMENT: Comment 
HGH for SELECTION-OPTIONS: Interval upper limit 
ISX for PARAMETERS ... AS SEARCH PATTERN: Komplex selection 
LOW for SELECTION-OPTIONS: Interval lower limit 
OPU for SELECTION-OPTIONS: Selection option icons 
PAR for PARAMETERS: Parameters 
PBU for SELECTION-SCREEN PUSHBUTTON ...: Pushbutton 
TAB for SELECTION-SCREEN TAB: Tab title 
TOT for SELECTION-OPTIONS: Text of interval upper limit 
TST for SELECTION-SCREEN ... TABBED ...: Tabstrip 
TXT for PARAMETERS, SELECT-OPTIONS: Selection text 
ULI for SELECTION-SCREEN ULINE: Horizontal Line 
VPU for SELECT-OPTIONS: Pushbutton for multiple selection

如果想在程式工具列加一個 Button 的話:
TABLES: sscrfields.

DATA: li_exclude  TYPE TABLE OF rsexfcode,
      lwa_exclude TYPE rsexfcode.

PARAMETERS: p_kunnr TYPE kunnr.

SELECTION-SCREEN FUNCTION KEY 1.

INITIALIZATION.
  MOVE 'Text' TO sscrfields-functxt_01.
  lwa_exclude-fcode = 'ONLI'.
  APPEND lwa_exclude TO li_exclude.

AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'FC01'.
** Coding here >>
ENDIF.

AT SELECTION-SCREEN OUTPUT.
  CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
    EXPORTING
      p_status  = '%_00'
      p_program = 'RSSYSTDB'
    TABLES
      p_exclude = li_exclude.

Parameters 和 select-options 的 low 欄位可以用 memory id 來記錄欄位的值,但是 select-options 的 high 欄位呢?
可以在 AT SELECTION-SCREENAT SELECTION-SCREEN OUTPUT EVENT 裡來處理:
SELECT-OPTIONS:
s_vkbur FOR vbrp-vkbur MEMORY ID vkb,
s_vtweg FOR vbrk-vtweg MEMORY ID vtw,
s_kunag FOR vbrk-kunag MEMORY ID vag.

* -------------------
* AT SELECTION-SCREEN
* -------------------
AT SELECTION-SCREEN .
SET PARAMETER ID 'VKBH'          FIELD s_vkbur-high.
SET PARAMETER ID 'VTWH'          FIELD s_vtweg-high.
SET PARAMETER ID 'VAGH'          FIELD s_kunag-high.

AT SELECTION-SCREEN OUTPUT.
* 
GET PARAMETER ID 'VKB'           FIELD s_vkbur-low.
GET PARAMETER ID 'VKBH'          FIELD s_vkbur-high.
IF s_vkbur-low NE space.
COLLECT s_vkbur.
ENDIF.
* 
GET PARAMETER ID 'VTW'           FIELD s_vtweg-low.
GET PARAMETER ID 'VTWH'          FIELD s_vtweg-high.
IF s_vtweg-low NE space.
COLLECT s_vtweg.
ENDIF.
* 
GET PARAMETER ID 'VAG'           FIELD s_kunag-low.
GET PARAMETER ID 'VAGH'          FIELD s_kunag-high.
IF s_kunag-low NE space.
COLLECT s_kunag.
ENDIF.

沒有留言:

張貼留言