2011年3月30日 星期三

[Code] Search Help For KSCHL

Customizing KSCHL search help with your request in report.

Defination:
DATA: BEGIN OF gt_t685 OCCURS 0,
kschl LIKE t685-kschl,
vtext LIKE t685t-vtext,
END OF gt_t685 .

DATA gw_dfies LIKE dfies .

DATA BEGIN OF gt_dfies OCCURS 0.
INCLUDE STRUCTURE dfies .
DATA END OF gt_dfies .

DATA BEGIN OF gt_dfies2 OCCURS 0.
INCLUDE STRUCTURE dfies .
DATA END OF gt_dfies2 .

DATA gv_repid LIKE sy-repid .
INITIALIZATION:
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_t685
FROM t685t
WHERE spras = sy-langu
AND kvewe = 'A'
AND kappl = 'V'
AND kschl IN gr_kschl.

gv_repid = sy-repid .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T685T'
fieldname = 'KSCHL'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies INTO gw_dfies .
gw_dfies-position = 1 .
gw_dfies-offset = 0 .
APPEND gw_dfies TO gt_dfies2 .
ENDLOOP .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T685T'
fieldname = 'VTEXT'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies INTO gw_dfies .
gw_dfies-position = 2 .
gw_dfies-offset = 4 .
APPEND gw_dfies TO gt_dfies2 .
ENDLOOP .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kschl-low:
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'KSCHL'
dynpprog = gv_repid
dynpnr = '1000'
dynprofield = 'S_KSCHL-LOW'
value_org = 'S'
TABLES
value_tab = gt_t685[]
field_tab = gt_dfies2[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kschl-high:
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'KSCHL'
dynpprog = gv_repid
dynpnr = '1000'
dynprofield = 'S_KSCHL-HIGH'
value_org = 'S'
TABLES
value_tab = gt_t685[]
field_tab = gt_dfies2[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.



Multi-Selection Search Help:
DATA: gt_return LIKE ddshretval OCCURS 0 WITH HEADER LINE,
gt_dfies LIKE dfies OCCURS 0 WITH HEADER LINE,
gt_dfies2 LIKE dfies OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF gt_brsch OCCURS 0,
brsch LIKE t016t-brsch,
brtxt LIKE t016t-brtxt,
kunnr LIKE komg-kunnr,
END OF gt_brsch.

DEFINE append_brsch.
clear: gt_brsch.
gt_brsch-brsch = &1.
gt_brsch-brtxt = &2.
gt_brsch-kunnr = &3.
append: gt_brsch.
END-OF-DEFINITION.



SELECT-OPTIONS:
s_brsch FOR komg-brsch NO INTERVALS.



*----------------
* INITIALIZATION
*----------------
INITIALIZATION.
gv_vrm_id = 'P_BRSCH'.
append_brsch 'K001' '中華' 'C1'.
append_brsch 'K002' '台哥大' 'C2'.
append_brsch 'K003' '遠傳' 'C3'.

* 設定產業碼 F4
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T016T'
fieldname = 'BRSCH'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies.
gt_dfies-position = 1 . " 第一個欄位
gt_dfies-offset = 0 .
APPEND gt_dfies TO gt_dfies2 .
ENDLOOP .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T016T'
fieldname = 'BRTXT'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies.
gt_dfies-position = 2 . " 第二個欄位
gt_dfies-offset = 4 . " 位置
APPEND gt_dfies TO gt_dfies2 .
ENDLOOP .


*--------------------
* AT SELECTION-SCREEN
*--------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_brsch-low.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BRSCH'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_BRSCH'
value_org = 'S'
multiple_choice = 'X' " 多重選取
TABLES
value_tab = gt_brsch
field_tab = gt_dfies2
return_tab = gt_return.
READ TABLE gt_return INDEX 1.
IF sy-subrc = 0.
CLEAR: s_brsch, s_brsch[].
s_brsch-sign = 'I'.
s_brsch-option = 'EQ'.
SORT gt_return DESCENDING.
LOOP AT gt_return.
s_brsch-low = gt_return-fieldval.
APPEND s_brsch.
ENDLOOP.
SORT s_brsch.
ENDIF.

沒有留言:

張貼留言