QUERY虚拟特性与关键值的使用
1.Se19实现一个BADI(RSR_OLAP_BADI), ZBW_RSR_OLAP_BADI
2.操作实例:
QUERY虚拟特性与关键值的使用_第1张图片
QUERY虚拟特性与关键值的使用_第2张图片
DEFINE程序代码如下:
method IF_EX_RSR_OLAP_BADI~DEFINE.
"BREAK-POINT.
DATA: l_s_chanm TYPE rrke_s_chanm,
       l_keyfnm  
TYPE rsd_kyfnm.
if FLT_VAL = 'ZHR_C09'. " 员工薪资状况
READTABLE I_TH_CHANM_USED TRANSPORTINGNOFIELDSWITHKEY table_line = 'ZHR_NEKH'."'0HAP_AR_TYP'.
IF sy-subrc = 0 .
"l_s_chanm-chanm = '0HAP_AR_TYP'.
   l_s_chanm-chanm =
'ZHR_NEKH' .
   l_s_chanm-
mode  = rrke_c_mode-chng_w_sel.
APPEND l_s_chanm to C_T_CHANM.
ENDIF .
elseif FLT_VAL = 'ZHR_C12'. " 员工花名册
READTABLE I_TH_CHANM_USED TRANSPORTINGNOFIELDSWITHKEY table_line = 'ZLTEXT10'." 毕业院校
IF sy-subrc = 0 .
"l_s_chanm-chanm = '0HAP_AR_TYP'.
     l_s_chanm-chanm =
'ZLTEXT10' .
     l_s_chanm-
mode  = rrke_c_mode-chng_w_sel.
APPEND l_s_chanm to C_T_CHANM.
ENDIF .
endif .
*  READ TABLE c_t_kyfnm TRANSPORTING NO FIELDS WITH KEY table_line = 'ZMT_V02'.*
*  IF sy-subrc <> 0.
*    l_keyfnm = 'ZMT_V02'.
*    APPEND l_keyfnm to c_t_kyfnm.
*  ENDIF.
*  READ TABLE c_t_kyfnm INTO l_keyfnm TRANSPORTING NO FIELDS.
endmethod.
INITIALIZE程序代码如下:
method IF_EX_RSR_OLAP_BADI~INITIALIZE.
"把结构字段传输到全局变量中。
DATA: field(30) TYPEC .
TYPES: BEGINOF TW_TH_SFK,
       KYFNM
TYPE  RSKYFNM,
       VALUE_RETURNNM
TYPE  RSALIAS,
ENDOF TW_TH_SFK.
TYPES: BEGINOF TW_TH_SFC,
         CHANM
TYPE  RSCHANM,
   SIDRETURNNM
TYPE  RSALIAS,
   KEYRETURNNM
TYPE  RSALIAS,
ENDOF TW_TH_SFC.
DATA: GW_SFK LIKELINEOF I_TH_SFK,
       GW_SFC
LIKELINEOF I_TH_SFC,
       GW_TH_SFK
TYPE TW_TH_SFK,
       GW_TH_SFC
TYPE TW_TH_SFC.
FIELD-SYMBOLS: TYPEANYTABLE ,
               
TYPE TW_TH_SFK.
"BREAK-POINT.
 UNASSIGN .
field = '(SAPLXRSR)GI_TH_SFK' .
ASSIGN (field) TO .
LOOPAT I_TH_SFK INTO GW_SFK.
   GW_TH_SFK-KYFNM = GW_SFK-KYFNM.
   GW_TH_SFK-VALUE_RETURNNM = GW_SFK-VALUE_RETURNNM.
INSERT GW_TH_SFK INTOTABLE .
ENDLOOP .
 UNASSIGN .
field = '(SAPLXRSR)GI_TH_SFC' .
ASSIGN (field) TO .
LOOPAT I_TH_SFC INTO GW_SFC.
*    IF GW_SFC-USER_EXIT IS NOT INITIAL.
     GW_TH_SFC-CHANM = GW_SFC-CHANM.
     GW_TH_SFC-SIDRETURNNM = GW_SFC-SIDRETURNNM.
     GW_TH_SFC-KEYRETURNNM = GW_SFC-KEYRETURNNM.
INSERT GW_TH_SFC INTOTABLE .
*    ENDIF.
ENDLOOP .
 UNASSIGN .
endmethod.
COMPUTE程序代码如下
method IF_EX_RSR_OLAP_BADI~COMPUTE .
DATA: field(30) TYPEC .
TYPES: BEGINOF TW_TH_SFK,
       KYFNM
TYPE  RSKYFNM,
       VALUE_RETURNNM
TYPE  RSALIAS,
ENDOF TW_TH_SFK.
TYPES: BEGINOF TW_TH_SFC,
         CHANM
TYPE  RSCHANM,
   SIDRETURNNM
TYPE  RSALIAS,
   KEYRETURNNM
TYPE  RSALIAS,
ENDOF TW_TH_SFC.
DATA: GW_TH_SFK TYPE TW_TH_SFK,
       GW_TH_SFC
TYPE TW_TH_SFC,
       Gw_Th_RANGE
TYPE RRRANGEEXIT.
FIELD-SYMBOLS: TYPEANYTABLE ,
               
TYPEANYTABLE ,
               
TYPEANYTABLE ,
               
TYPEANY ,
               
TYPEANY ,
               
TYPEANY ,
               
TYPEANY .
data: v_DATETO type sy-datum,
       V_0P_REPD1
type sy-datum,
       v_HAP_AR_TYP
type /BI0/OIHAP_AR_TYP.
"BREAK-POINT.
field = '(SAPLXRSR)GI_TH_SFK'. " 获取KEY
ASSIGN (field) TO .
FIELD = '(SAPLXRSR)GI_TH_SFC'. " 获取特性
ASSIGN (field) TO .
IF FLT_VAL = 'ZHR_C09' .
FIELD = '(SAPLXRSR)GI_T_RANGE'. " 获取报表输入的日期
ASSIGN (field) TO .
获取关键值
*    LOOP AT INTO GW_TH_SFK.
*      IF GW_TH_SFK-KYFNM = 'ZMT_V02'.
*        ASSIGN COMPONENT GW_TH_SFK-VALUE_RETURNNM OF STRUCTURE C_S_DATA TO .
*        EXIT.
*      ENDIF.
*    ENDLOOP.
获取特性
LOOPAT INTO GW_TH_SFC .
IF GW_TH_SFC-CHANM = '0EMPLOYEE' .
ASSIGNCOMPONENT GW_TH_SFC-SIDRETURNNM OFSTRUCTURE C_S_DATA TO .
CONTINUE .
ENDIF .
" IF GW_TH_SFC-CHANM = '0HAP_AR_TYP'.
IF GW_TH_SFC-CHANM = 'ZHR_NEKH' .
ASSIGNCOMPONENT GW_TH_SFC-KEYRETURNNM OFSTRUCTURE C_S_DATA TO .
CONTINUE .
ENDIF .
ENDLOOP .
loopat into Gw_Th_RANGE.
IF Gw_Th_RANGE-VNAM = '0P_REPD1' .
       V_0P_REPD1 = Gw_Th_RANGE-LOW .
clear :Gw_Th_RANGE.
CONTINUE .
ENDIF .
endloop .
IF ISNOTASSIGNED .
RETURN .
ELSE .
"获取员工最近一次考绩
selectmax( DATETO ) into v_DATETO
from /bic/aZHR_O1500
where EMPLOYEE =
and DATETO <= V_0P_REPD1.
selectSINGLE HAP_AR_TYP into v_HAP_AR_TYP
from /bic/aZHR_O1500
where EMPLOYEE =
and DATETO = v_DATETO .
if v_HAP_AR_TYP isnotINITIAL .
        = v_HAP_AR_TYP.
else .
        =  
'' .” 用全角空格来代替 #
endif .
    UNASSIGN: ,,,.
ENDIF .
ENDIF .
*  IF FLT_VAL = 'ZSD_MC02'.*
*    field = '(SAPLXRSR)GI_TH_SFK'.
*    ASSIGN (field) TO .*
*    FIELD = '(SAPLXRSR)GI_TH_SFC'.
*    ASSIGN (field) TO .*
*    LOOP AT INTO GW_TH_SFK.
*      IF GW_TH_SFK-KYFNM = 'ZMT_V02'.
*        ASSIGN COMPONENT GW_TH_SFK-VALUE_RETURNNM OF STRUCTURE C_S_DATA TO .
*        EXIT.
*      ENDIF.
*    ENDLOOP.*
*    LOOP AT INTO GW_TH_SFC.
*      IF GW_TH_SFC-CHANM = '0SALESORG'.
*        ASSIGN COMPONENT GW_TH_SFC-SIDRETURNNM OF STRUCTURE C_S_DATA TO .
*        CONTINUE.
*      ELSEIF GW_TH_SFC-CHANM = '0MATERIAL'.
*        ASSIGN COMPONENT GW_TH_SFC-SIDRETURNNM OF STRUCTURE C_S_DATA TO .
*      ENDIF.
*    ENDLOOP.*
*    IF IS NOT ASSIGNED or IS NOT ASSIGNED or IS NOT ASSIGNED.
*      RETURN.
*    ELSE.
*      SELECT SINGLE A~PLND_DELRY INTO FROM /BI0/MMAT_PLANT AS A
*                                   INNER JOIN /BI0/SSALESORG AS B ON A~PLANT = B~SALESORG
*                                   INNER JOIN /BI0/SMATERIAL AS C ON A~MAT_PLANT = C~MATERIAL
*                   WHERE B~SID =
*                     AND C~SID =
*                     AND A~OBJVERS   = 'A' .*
*      UNASSIGN: ,,,.
*    ENDIF.*
*  ENDIF.
endmethod.