on 01-27-2015 2:28 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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.
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
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.
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
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.
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
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
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
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
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.
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
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
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
Hi Krishna,
Please below link how to write customer exit for similar requirement.
Thank you,
Nanda
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.