cancel
Showing results for 
Search instead for 
Did you mean: 

Variable Exit

Former Member
0 Kudos

Hi Gurus,

I need variable exit to calculate last year till date with current year date. For Example

If it is current months is March then I need in my report like

cumulative of Jan-2008, Feb-2008, Mar-2008 cumulative of Jan-2009, Feb-2009, Mar-2009

If it is current month then Jan feb march april may 2008 and same for 2009

I getting for 2009 but how can I achieve previous year. If your user execute report

Current month = 003/2009 then I need to get last year 3 months and current year 3 months.

Please some give me a code. Thanks in advance.

Thanks

Robert Courtney

Accepted Solutions (1)

Accepted Solutions (1)

former_member181964
Active Contributor
0 Kudos

Hi,

Here I'm giving solution for your problem. ..

I'm assuming that you have 0CALMONTH in your cube and this will work based on SY-DATUM. It will takes SY-DATUM and tehn calculates YTD and PTYD.

Eg: Today date = 21-02-2009

So for Current Year it will take Jan 2009 and Feb 2009 cumulatively gives the values

For Previous Year it will take Jan 2008 and Feb 2008 cumulatively gives the values

Steps:

1.Create a Customer Exit Variable on 0CALMONTH i.e. ZYTM1

Properties:

Variable Name = ZYTM1

Process By = Customer Exit

Charateristic = Calender Year/Month

Variable Represents = Interval

Variable Entry = Mandatory

Uncheck Ready for Input

2.Create a Customer Exit Variable on 0CALMONTH i.e. ZPYM1 with same properties of above variable.

And write the code in CMOD in BW.

3. Drag and drop Keyfigure or create new selection in columns and then restrict Keyfigure with ZPYM1 for Previous year and in the same way restrict the keyfigure with ZYTM1 and execute the report.

Note: Don't drag and drop any date/calmonth in report. If you want to any user Input variable for calday or calmonth then you need to include...

LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZMNTH'.

Code

ENDLOOP

*************YTD*********************************

 WHEN 'ZYTM1'.

    DATA: SDT TYPE SY-DATUM,
          ST_YR(4) TYPE N,
          ST_MM(2) TYPE N,
          ED_YR(4) TYPE N,
          ED_MM(2) TYPE N,
          SM TYPE /BI0/OICALMONTH,
          EM TYPE /BI0/OICALMONTH.

          SDT = SY-DATUM.

          ST_MM = '01'.
          ST_YR = SDT+0(4).

          CONCATENATE ST_YR ST_MM INTO SM.

          ED_MM = SDT+4(2).
          ED_YR = SDT+0(4).

          CONCATENATE ED_YR ED_MM INTO EM.

          l_s_range-low = SM.
          l_s_range-high = EM.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'BT'.
          APPEND l_s_range TO e_t_range.

*************YTD*********************************

*************PYTD*********************************

 WHEN 'ZPYM1'.

    DATA:
          PSDT TYPE SY-DATUM,
          PST_YR(4) TYPE N,
          PST_MM(2) TYPE N,
          PED_YR(4) TYPE N,
          PED_MM(2) TYPE N,
          PSM TYPE /BI0/OICALMONTH,
          PEM TYPE /BI0/OICALMONTH.

          PSDT = SY-DATUM.

          PST_MM = '01'.
          PST_YR = PSDT+0(4) - 1.

          CONCATENATE PST_YR PST_MM INTO PSM.

          PED_MM = PSDT+4(2).
          PED_YR = PSDT+0(4) - 1.

          CONCATENATE PED_YR PED_MM INTO PEM.

          l_s_range-low = PSM.
          l_s_range-high = PEM.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'BT'.
          APPEND l_s_range TO e_t_range.

*************PYTD*********************************

Thanks

Reddy

Former Member
0 Kudos

Hi Surender,

Thank you so much, actually I was sick thats what I didnt responded quickly. I am using Fiscal Year Period but not calender month. Please if you could tell me same logic for Fiscal year Period.

"0FYTCFP" I tried this variable but it is not working. In my report selection I am using 0Fiscal Year Period. When user enters 002/2009. It should display cumulaltive of upto current month and last year upto same till this month.

Let me know your code will be thesame for Fiscal Year period.

Thanks

Robert Courtney.

emjay
Active Participant
0 Kudos

Create a variable under 0FISCPER for last year eg. Z_LASTYR. This code is assuming that you use the single entry for selecting the FISCAL PERIOD (0P_FPER).


Data: year(4) type i.

when 'Z_LASTYR'.

    if i_step eq 3.
      loop at i_t_var_range into intern_range.
        if intern_range-vnam = '0P_FPER'.
          clear l_s_range.
          year = intern_range-low(4).
          year = year - 1.
          month = intern_range-low+5(2).
          l_s_range-low(4) = year.
          l_s_range-low+5(2) = '01'.
          l_s_range-high(4) = year.
          l_s_range-high+5(2) = month.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'BT'.
          append l_s_range to e_t_range.
       endif.
    endloop.
  endif.

Former Member
0 Kudos

Hi,

I written the code for cummulative of current fiscal year period.

WHEN 'ZCYTD_CFY'.

IF I_STEP = 2.

LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE

WHERE VNAM = 'ZUSM_FYP'.

CLEAR L_S_RANGE.

L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(7).

L_S_RANGE-LOW+4(3) = '001' .

L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(4) + '001'.

L_S_RANGE-HIGH = LOC_VAR_RANGE-HIGH(7).

ENDLOOP.

ENDIF.

Please some help me to what need to be modified to get the cumulated upto current fiscal year period (User Input : 2009003).

Thanks

Robert.

emjay
Active Participant
0 Kudos

WHEN 'ZCYTD_CFY'.

IF I_STEP = 2.

LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE

WHERE VNAM = 'ZUSM_FYP'.

CLEAR L_S_RANGE.

L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(7).

L_S_RANGE-LOW+5(2) = '01' .

L_S_RANGE-HIGH = LOC_VAR_RANGE-HIGH(7).

APPEND L_S_RANGE TO E_T_RANGE.

ENDLOOP.

ENDIF.

former_member399569
Participant
0 Kudos

Hi,

same issue but i manage to create the variable exit.

the problem now, when i put the 0CALMONTH to the row, then my brought forward figure same as created figure.

row: 0CALMONTH (period and year)

column: brought forward, created, closed, carry forward

formula:

A. brought forward = opened data that created previous period

B. created = data created this period (follow the row)

C. closed = opened data from A + B and status CLOSED

D. carry forward = A + B - C

below is the logic for my variable:

loop at i_t_var_range into loc_var_range

where vnam = '0CALDAY'.

clear l_s_range.

year = loc_var_range-low(4).

month = loc_var_range-low+4(2).

month = month - 1.

l_s_range-low(4) = year.

l_s_range-low+4(2) = '01'.

l_s_range-high(4) = year.

l_s_range-high+4(2) = month.

l_s_range-sign = 'I'.

l_s_range-opt = 'BT'.

append l_s_range to e_t_range.

endloop.

Former Member
0 Kudos

Problem resolved

Answers (2)

Answers (2)

Former Member
0 Kudos

HI,

Just Drag N drop the Cal Month above key Structure. Restrict it to the already Defined Variable Interval or create new through Replecment path & select Interval.

now wht so ever range you give it show cumulative for eact month.

there is no need to write customer or variable exit as it leeds to decrese the performance of query. also try n avoide calculated key figure & restricted key figure as it also dicrese the query performance.

regards,

sandeep

former_member212742
Active Participant
0 Kudos

Hi Robert,

You can use this variable to achieve the same.

0CYTCM - gives the range of calmonth from the first month of the year to the current month.

create two restricted KF. one for current year and then another for previous year.

in the first KF restrict calmonth with this variable.

in the second restrict calmonth with this variable - 12.

guess this will solve ur issues.

Regards.

Shafi.