Query 变量增强
Enhancement : RSR00001
EXIT_SAPLRRS0_001 INCLUDE ZXRSRU01 .
增强代码如下:
ATA: L_S_RANGE TYPE RSR_S_RANGESID. DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT.
CASE I_VNAM."变量名称 WHEN 'ZVPRENYU'. IF I_STEP = 1.输入前(QUERY里定义的变量为"用户出口" "单一值" "强制输入" "准备输入-否")重要 DATA: zcurmon(2), zpremon(2),zyear(4). CLEAR: L_S_RANGE, zcurmon, zpremon, zyear.
zcurMon = sy-datum+4(2). IF zcurMon = '01'. zpreMon = '12'. zyear = sy-datum+0(4) - 1. CONCATENATE zyear zpremon INTO L_S_RANGE-LOW. ELSE. zpremon = zcurmon - 1. IF zpremon < 10. CONCATENATE sy-datum+0(4) '0' zpremon INTO L_S_RANGE-LOW. ELSE. CONCATENATE sy-datum+0(4) zpremon INTO L_S_RANGE-LOW. ENDIF. ENDIF. CONDENSE L_S_RANGE-LOW NO-GAPS. L_S_RANGE-SIGN = 'I'. L_S_RANGE-OPT = 'EQ'. APPEND L_S_RANGE TO E_T_RANGE. CLEAR L_S_RANGE. ENDIF.
WHEN 'ZV1MONU'. IF I_STEP = 2.
"变量输入以后,根据输入的变量'ZVPRENYU',来取得ZV1MONU的值,一般QUERY有特殊的需求时用,重要 LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE WHERE VNAM = 'ZVPRENYU'. CLEAR: L_S_RANGE. L_S_RANGE-LOW = LOC_VAR_RANGE-LOW. L_S_RANGE-LOW+4(2) = '01'. CONDENSE L_S_RANGE-LOW NO-GAPS. L_S_RANGE-SIGN = 'I'. L_S_RANGE-OPT = 'EQ'. APPEND L_S_RANGE TO E_T_RANGE. ENDLOOP. CLEAR LOC_VAR_RANGE. ENDIF. ****20090223增强日期增强出口 WHEN 'ZXGDAY01'. IF I_STEP = 1. DATA:PDATE type sy-datum. CLEAR: L_S_RANGE. PDATE = sy-datum - 1. MOVE PDATE TO L_S_RANGE-LOW. CONDENSE L_S_RANGE-LOW NO-GAPS. L_S_RANGE-SIGN = 'I'. L_S_RANGE-OPT = 'EQ'. APPEND L_S_RANGE TO E_T_RANGE. CLEAR L_S_RANGE. ENDIF.
WHEN 'ZXGDAY02'. IF I_STEP = 2. LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE WHERE VNAM = 'ZXGDAY01'. CLEAR: L_S_RANGE. L_S_RANGE-LOW = LOC_VAR_RANGE-LOW. L_S_RANGE-LOW+6(2) = '01'. CONDENSE L_S_RANGE-LOW NO-GAPS. L_S_RANGE-SIGN = 'I'. L_S_RANGE-OPT = 'EQ'. APPEND L_S_RANGE TO E_T_RANGE. ENDLOOP. CLEAR LOC_VAR_RANGE. ENDIF. WHEN 'OTHERS'.
ENDCASE.
代码绿色部分为增强日历年月的例子,兰色部分为增强日历天的例子,需求都相对比较简单,容易实现. WHEN 'ZVPRENYU'.功能为取当前日期前一个月的值,比如20090223那么得到的值为200901.
WHEN 'ZV1MONU'. 功能为如果ZVPRENYU值已经输入,比如输入值为200905,那么取得是日历年月为200905的第一个月做为定值,即"200901".
WHEN 'ZXGDAY01'.功能为取当前日期前一天的值,比如20090223那么得到的值为20090222.
WHEN 'ZXGDAY02'.功能为如果ZXGDAY01值已经输入,比如输入值为20090523,那么取得是日历天为20090523月份的第一天做为定值,即"20090501".