cancel
Showing results for 
Search instead for 
Did you mean: 

Customer exit variable fiscal year

Former Member
0 Kudos

Hi All,

I have this requirement where, when user enters a date, he should get values for that whole fiscal year. Means if user enters 2015.25.01, he should get the values from starting of the fiscal year i.e April 1st 2014  to 2015.25.01. I know this is a standard requirement, but i am new to ABAP, so can anyone give me a pseudo code please? It would be really helpful.!!

Thanks,

Karthik

Accepted Solutions (0)

Answers (2)

Answers (2)

Loed
Active Contributor
0 Kudos

Hi Krishna,

Why is it if user enters January 25, 2015, the range should be April 1,2014 to January 25, 2015?

Why is it April 1, 2014 is the start of the fiscal year?

Regards,

Loed

Former Member
0 Kudos

Hi Loed,

Why is it if user enters January 25, 2015, the range should be April 1,2014 to January 25, 2015?


Yeah


Why is it April 1, 2014 is the start of the fiscal year?


Yeah


I just need a pseuodo code...can u provide pls...


Thanks,


Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

My question is not answerable by yes or no..=)

I want to know WHY is it like that? I want to know the logic behind so that I can make a code for you..;-)

Regards,

Loed

Former Member
0 Kudos

Hi Loed,

The financial year is from April 1st to 31st march in my company. Can u write  a sample code as per this?

Thanks,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

Let's say the name of your entry date is ZVAR_DATE..

Create another variable, let's call it ZVAR_RANGE_DATE..Under the GENERAL tab, choose CUSTOMER EXIT in the PROCESSING BY..In the DETAILS tab,choose INTERVAL in the VARIABLE REPRESENTS..

Do this in tcode CMOD (just ask your teammates how to go in the coding section of CMOD):

DATA:

date_temp like sy-datum,

date_start like sy-datum,

year_temp type i length 4.

WHEN 'ZVAR_RANGE_DATE'.             "this is the new variable you have created

LOOP AT I_T_VAR_RANGE INTO FISC_VAR_RANGE WHERE VNAM = 'ZVAR_DATE'.    "for example, I entered 2015.25.01

CONCATENATE FISC_VAR_RANGE-LOW(4) '0401' into date_temp.

IF FISC_VAR_RANGE-LOW < date_temp.

year_temp = FISC_VAR_RANGE-LOW(4) - 1.

CONCATENATE year_temp '0401' into date_start.

L_S_RANGE-LOW      = date_start.                           "start date result will be 2014.01.04

L_S_RANGE-HIGH      = FISC_VAR_RANGE-LOW.     "end date result will be 2015.25.01

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'BT'.

ELSE.

L_S_RANGE-LOW      = date_temp.

L_S_RANGE-HIGH      = FISC_VAR_RANGE-LOW.

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'BT'.

ENDIf.

APPEND L_S_RANGE TO E_T_RANGE.

EXIT.

ENDLOOP.

Just post here if you have questions..

Regards,

Loed

Former Member
0 Kudos

Hi Loed,

Thanks for the great explanation. I am indeed greateful. I ow you a treat

With the help of your previous explanation, i tried to write a code for another requirement also. Please see the below code and correct me if i am wrong.

Requirement: If user enters a date, he should get data of a month earlier (Month - 1)  and month later (Month +1).

If he enters feb 15th 2014, he should get data for Jan and march also.

Data: Month type sy-datum

         month1 type sy-datum

  LT_VAR_PRE  type i

  LT_VAR_NEXT type i

  When IT_VAR_MONTH "Our variable on month"

      If I_STEP = 2

    Loop at I_T_VAR_RANGE into I_S_VAR_RANGE where VNAME = ZVAR1_DAT "HERE I HAVE ENTERED DATE"

     Month = I_S_VAR_RANGE + 4(2)

    Month = Month -1 " Here Jan data would come"

    Month1 = Month + 1 "Here March data would come"

Concatenate I_S_VAR_RANGE +0(4) MONTH INTO LT_VAR_PRE " For previous month i.e jan"

Concatenate I_s_VAR_RANGE + 0(4) MONTH1 Into LT_VAR_NEXT " For next month i.e march"

L_S_RANGE-LOW = LT_VAR_PRE

L_S_RANGE-SIGN =  'I'.

L_S_RANGE-OPT  = 'BT'.

L_S_RANGE - High = I_S_VAR_RANGE

"By doing the above statement it will get current and previous month data"

L_S_RANGE-LOW = I_S_VAR_RANGE "Current month"

L_S_RANGE-SIGN =  'I'.

L_S_RANGE-OPT  = 'BT'.

L_S_RANGE - High =LT_VAR_NEXT    " Next month"

"By doing the above statement it will get current and next month data"

APPEND L_S_RANGE TO E_T_RANGE.

Thanks,

Karthik.

Former Member
0 Kudos

Hi Karthik,

try the below to suffice your requirement

when 'exit_variable'.

if i_step = 2.

data : fdate type 0calday,

         ldate type 0calday,

    wa1 like line of i_t_var_range,

     wa2 like line of e_t_range.

read table i_t_var_range into wa1 with key vnam = 'userentry_var'.

fdate = wa1-low.

fdate = fdate - 35.

fdate+6(1) = '01'.

ldate = wa1-low.

ldate = ldate+65.

ldate+6(1) = '01'.

ldate = ldate - 1.

wa2-low = fdate.

wa2-high = ldate.

wa2-sgn = 'I'.

wa2-opt = 'BT'.

append wa2 to e_t_range.

endif.

Loed
Active Contributor
0 Kudos

Hi Krishna,

Are you going to create two (2) codes? one (1) code for previous month and another code for next month?

By the way, I found some glitch on your code which may give you an incorrect result..

Regards,

Loed

Former Member
0 Kudos

Hi Loed,

Can you tell me the mistake in this code? I will correct it while implementing.

Thanks,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

The problem lies when the entered date is January or December since subtracting or adding 1 will give you 0 and 12, respectively.

What code do you want to do? Do you need two (2) codes; one (1) code for previous month and another code for next month? I want to know so that I can edit well your code above.


Regards,

Loed

Former Member
0 Kudos

Hi Karthik,

Have you try to execute your code which you have mentioned.

Month = I_S_VAR_RANGE + 4(2)

    Month = Month -1 " Here Jan data would come"

    Month1 = Month + 1 "Here March data would come"

The work area I_S_VAR_RANGE doesn't pass month value to the Month variable.

Month1 = Month + 1 the variable value will be passed to next day, since month1 type is sy-datum.

Instead of using sy-datum as a type, you would have used data element of calday.

Try to execute your code in debug mode. If you want Rolling quarters as a output give a try on the code which i have mentioned.

Former Member
0 Kudos

Hi Loed,

That's the problem, when the user enters jan it would roll to previous year dec and Feb of next year. That's why i am confused.

As per my requirement like when user enters a date, he should get data of a month earlier and a month later in total 3rows ( earlier month, current, next month). If u got my requirement...Can u give a sample code pls like the one u gave earlier, it was very informative...

Thanks,

Karthik

Former Member
0 Kudos

Hi Sunil,

So by just changing the datatype as D wil be enough? the rest of the code was okay?

Thanks,

Karthik

Former Member
0 Kudos

Hi Karthik,

Instead of using type for the Month variable, you can use of calmonth as type.

then by reading the user entry into the internal table, you can assign like below

Month = wa1-low+4(2)

that means month variable will hold Fed month of that particular year, then by minus 1

will roll back to JAN, similarly

Month1 = wa1-low+4(2) will hold Feb value by Adding 1 then you will match data.

or else you can use date values to get those roll  back values which i have mentioned in my earlier reply. Try to replicate the code which i have mentioned.

Hope this may help you.

Loed
Active Contributor
0 Kudos

Hi Krishna,

There are two (2) ways to achieve your requirement:

I assume that your ZVAR1_DAT variable is the variable for your 0CALDAY and it is a SINGLE VALUE:

1. Create a "HIDDEN" selection with any keyfigure on it and CALDAY with variable ZVAR1_DAT..

2. Create a new variable in CALMONTH, let's call it ZVAR_MONTH..

3. Under the GENERAL tab, choose REPLACEMENT PATH in the PROCESSING BY..

4. In the REPLACEMENT PATH tab, choose VARIABLE in the REPLACE VARIABLE WITH section..

5. In the same tab, type ZVAR1_DAT in the VARIABLE section and choose KEY in the REPLACE WITH section..

6. In the same tab also, choose FROM VALUE in the CHOOSE INTERVAL section and type 6 in the OFFSET LENGTH (just leave OFFSET START blank)..

7. Create your three (3) SELECTIONS (the earlier month, current month, and next month)..

8. Just put the CALMONTH field on those SELECTIONS and filter them with ZVAR_MONTH having an OFFSET value of -1 for earlier month, 0 for current month, and +1 for next month..

The second method is by using the CMOD, by getting the CALMONTH of the entered date and just repeat some steps above..

1. Create a "HIDDEN" selection with any keyfigure on it and CALDAY with variable ZVAR1_DAT..

2. Create a new variable in CALMONTH, let's call it also ZVAR_MONTH..

3. Under the GENERAL tab, choose CUSTOMER EXIT in the PROCESSING BY..In the DETAILS tab,choose SINGLE in the VARIABLE REPRESENTS..

Do this in CMOD:

WHEN 'ZVAR_MONTH'.            "the new variable we have created

IF i_step = 2. "After input of 0CALDAY

LOOP AT I_T_VAR_RANGE INTO FISC_VAR_RANGE WHERE VNAM = 'ZVAR1_DAT'.   "sample day entered: 20140215

L_S_RANGE-LOW      = FISC_VAR_RANGE-LOW(6).    "final result will be the CALMONTH of entered date which is 201402

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'EQ'.

APPEND L_S_RANGE TO E_T_RANGE.

EXIT.

ENDLOOP.

ENDIF.

4. Create your three (3) SELECTIONS (the earlier month, current month, and next month)..

5. Just put the CALMONTH field on those SELECTIONS and filter them with ZVAR_MONTH having an OFFSET value of -1 for earlier month, 0 for current month, and +1 for next month..

***just use the 2nd method if you are comfortable with CMOD..


Just post here if you have questions..


Regards,

Loed

Former Member
0 Kudos

Hi Sunil,

So u mean to say use month as type Means

Data: Month type /BIC/OOCALMONTH

        Month1 type /BIC/OOCALMONTH

       Month 3 type /BIC/OOCALMONTH

When DATE_VAR

If I_STEP =2

Loop at I_T_VAR_RANGE to I_S_VAR_RANGE where VNAME = DATE_VAR (USER ENTRY DATE VARIABLE)

Month = I_S_VAR_RANGE - LOW + 4(2)

Month1 = Month  - 1 (For previous month)

Month3 = Month + 1 (For next month)

Concatenate I_S_VAR_RANGE - LOW MONTH into LV_CURRMONTH

Concatenate I_S_VAR_RANGE - LOW MONTH1 into LV_PREMONTH

Concatenate I_S_VAR_RANGE -LOW Month 3 Into LV_NEXT

L_S_RANGE - LOW = LV_PREMONTH

L_S_RANGE - SIGN = I

L_S_RANGE -OPT = BT

L_S_RANGE - HIGH = LV_CURRMONTH


L_S_RANGE - LOW = LV_CURRMONTH

L_S_RANGE - SIGN = I

L_S_RANGE -OPT = BT

L_S_RANGE - HIGH = LV_NEXT


Append L_S_RANGE to E_T_DATA

Loed
Active Contributor
0 Kudos

Hi Krishna,

I can revise this code for you mate..Do you want to use your code instead of mine?


May I have a glimpse of your query designer? So that I will know what's the best solution for you..


Regards,

Loed

Former Member
0 Kudos

Hi Loed,

I am so sorry i cant put the screen shots of designer. It could be prob for me. In case u want to see how data should look like:

                          Supply chain1    Supply chain2       S C 3

Previous month     12000                    90000                  47000

Current month        4000                     78900                  9000

Next month           50000                    56700                  6000

All the values here are quantities.

After looking at the above data can u correct the code i have written?

Thanks,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

Did you see my reply above? It will solve your requirement..

REPOSTING:

There are two (2) ways to achieve your requirement:

I assume that your ZVAR1_DAT variable is the variable for your 0CALDAY and it is a SINGLE VALUE:

1. Create a "HIDDEN" selection with any keyfigure on it and CALDAY with variable ZVAR1_DAT..

2. Create a new variable in CALMONTH, let's call it ZVAR_MONTH..

3. Under the GENERAL tab, choose REPLACEMENT PATH in the PROCESSING BY..

4. In the REPLACEMENT PATH tab, choose VARIABLE in the REPLACE VARIABLE WITH section..

5. In the same tab, type ZVAR1_DAT in the VARIABLE section and choose KEY in the REPLACE WITH section..

6. In the same tab also, choose FROM VALUE in the CHOOSE INTERVAL section and type 6 in the OFFSET LENGTH (just leave OFFSET START blank)..

7. Create your three (3) SELECTIONS (the earlier month, current month, and next month)..

8. Just put the CALMONTH field on those SELECTIONS and filter them with ZVAR_MONTH having an OFFSET value of -1 for earlier month, 0 for current month, and +1 for next month..

The second method is by using the CMOD, by getting the CALMONTH of the entered date and just repeat some steps above..

1. Create a "HIDDEN" selection with any keyfigure on it and CALDAY with variable ZVAR1_DAT..

2. Create a new variable in CALMONTH, let's call it also ZVAR_MONTH..

3. Under the GENERAL tab, choose CUSTOMER EXIT in the PROCESSING BY..In the DETAILS tab,choose SINGLE in the VARIABLE REPRESENTS..

Do this in CMOD:

WHEN 'ZVAR_MONTH'.            "the new variable we have created

IF i_step = 2. "After input of 0CALDAY

LOOP AT I_T_VAR_RANGE INTO FISC_VAR_RANGE WHERE VNAM = 'ZVAR1_DAT'.   "sample day entered: 20140215

L_S_RANGE-LOW      = FISC_VAR_RANGE-LOW(6).    "final result will be the CALMONTH of entered date which is 201402

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'EQ'.

APPEND L_S_RANGE TO E_T_RANGE.

EXIT.

ENDLOOP.

ENDIF.

4. Create your three (3) SELECTIONS (the earlier month, current month, and next month)..

5. Just put the CALMONTH field on those SELECTIONS and filter them with ZVAR_MONTH having an OFFSET value of -1 for earlier month, 0 for current month, and +1 for next month..

***just use the 2nd method if you are comfortable with CMOD..


Just post here if you have questions..





Regards,

Loed

Former Member
0 Kudos

Hi Karthik,

how  your report should look like from JAN to FEB and then FEB to MARCH

or else from JAN to MAR. Here in your code you have mentioned like

L_S_RANGE-LOW = LV_PREMONTH which contains value as JAN and

as L_S_RANGE_HIGH = LV_CURRMONTH which has the value FEB

If the user entry value is in the month of FEB. And in the next statement in your code is

L_S_RANGE-LOW = LV_CURRMONTH which has the value of FEB i.e means workarea - low has been overwrite with FEB previously it was JAN. So now the data appended to the E_T_DATA Table will from FEB to MARCH.

As said by Leo you can also do it in Bex by using the selections if you want your month data to be in 3 Different columns.See the last reply of LEO .

OR else give a try the code which i have given.

Hope this may help you.

Loed
Active Contributor
0 Kudos

I opted not to change your code since I think one the two (2) solutions I have posted can handle your requirement..;-)

Just use the 2nd method mate..

Regards,

Loed

Former Member
0 Kudos

Hi Loed,

Thanks a ton. 2nd method was more better. I think my problem wil be solved. So finally  apart from code, i just have to create 3 selections in rows 

1st selction: Add quantity, calmonth and filter them with ZVAR_MONTH and offset with -1

2nd section:   Add quantity, calmonth and filter them with ZVAR_MONTH and offset

same with 3rd selection too. Is this correct?

Thanks,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

Yeah, just do the 3 selections having the OFFSET value of -1, 0, and +1 for the 3 months, respectively.

Regards,

Loed

Former Member
0 Kudos

Thanks Loed,

You saved my day and sorry that i marked it as a discussion as i am kinda new here and i couldn't award u points for your effort

Thanks Bud,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,

It's ok mate..Glad that I have helped you..

Regards,

Loed

Former Member
0 Kudos

Hi Karthik,

You may close your thread with Correct Answer and helpful answers if you achieved the requirement.

Former Member
0 Kudos

Hi Sunil,

I marked it as a discussion by mistake, that's what i was telling Loed. Anywaz thanks for help

Thanks,

Karthik

Former Member
0 Kudos

Hi Loed,

Sorry to getting back to my 1st  question on fiscal year . You said year_temp = FISC_VAR_RANGE-LOW(4) - 1.


Means if it is 2015 this will make it previous year. But as i said my fiscal year is on April 1st say if user enters the report on 2015 jan that year_temp = FISC_VAR_RANGE-LOW(4) - 1 gets desired output as it substracts an year from now and concatenates it with 0401 but say if user enters on july 5th 2014 then that year - 1 gives  a wrong result right as it goes to previous year i.e 2013 ?

Thanks,

Karthik

Loed
Active Contributor
0 Kudos

Hi Krishna,


DATA:

date_temp like sy-datum,

date_start like sy-datum,

year_temp type i length 4.

WHEN 'ZVAR_RANGE_DATE'.    

IF i_step = 2.


LOOP AT I_T_VAR_RANGE INTO FISC_VAR_RANGE WHERE VNAM = 'ZVAR_DATE'.    "for example, you entered 2014.05.07

CONCATENATE FISC_VAR_RANGE-LOW(4) '0401' into date_temp.   "date_temp will be 2014.01.04

IF FISC_VAR_RANGE-LOW < date_temp.    "if 2014.05.07 < 2014.01.04 is TRUE, proceed below

year_temp = FISC_VAR_RANGE-LOW(4) - 1.

CONCATENATE year_temp '0401' into date_start.

L_S_RANGE-LOW      = date_start.                  

L_S_RANGE-HIGH      = FISC_VAR_RANGE-LOW.   

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'BT'.

ELSE.   "if the condition above is FALSE, proceed below, since 2014.05.07 is greater than 201.01.04, the program will go here instead

L_S_RANGE-LOW      = date_temp.   "2014.01.04

L_S_RANGE-HIGH      = FISC_VAR_RANGE-LOW.    "2014.05.07

L_S_RANGE-SIGN        = 'I'.

L_S_RANGE-OPT         = 'BT'.

ENDIf.

APPEND L_S_RANGE TO E_T_RANGE.

EXIT.

ENDLOOP.


ENDIF.



The YEAR_TEMP will only be done if the date entered is less than APRIL 1 of the year entered..

Just post here if you have clarifications..



Regards,

Loed

anshu_lilhori
Active Contributor
0 Kudos

You can make use of FM DATE_TO_PERIOD_CONVERT

Pass the date entered by user and the variant which you are using then this give the fiscal year.

Based on that further you can do the calculations.

Regards,

AL

Former Member
0 Kudos

Thanks again Loed for taking time to explain again. Now i understood it fully. Have a great time cheers.

Loed
Active Contributor
0 Kudos

You are very welcome mate!

Regards,

Loed

ccc_ccc
Active Contributor
0 Kudos

Hi Krishna,

Please below link how to write customer exit for similar requirement.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a002f796-be78-2e10-5485-c19b0a637...

Thank you,

Nanda

Former Member
0 Kudos

Hi Nanda,

Thanks for the link. In that the user entry variable is fiscal year period only. But as per my req the user input is date and as per date, it should get data related to that whole fiscal year. Can u provide any psuodo code pls?

Thanks,

Karthik

ccc_ccc
Active Contributor
0 Kudos

Hi Krishna,

Please uses below function module convert date to fiscperiod.

DATE_TO_PERIOD_CONVERT

Thank you,

Nanda

Former Member
0 Kudos

Hey Nanda,

Thanks for the FM. I know i can use it. Can u give me  a sample code pls. It would help.

Thanks,

Karthik