User Exit Formula Variable - to calculate #days of any month

Hello Team,
I need a column in my report layout which shows the #days of any month entered by the user. User entry 01.2014 to 03.2014 report should have 31 28 & 31 according to the Calendar month in the rows.
To achieve this I'm using a user exit formula variable in my local calculation. An Optional Interval User Entry variable on CALMONTH is also put in at the filter section.
I created a CLASS with 2 methods CONSTRUCTOR( vNam = 'ZC2C_DSONWDAYS') & GET_VALUES. We may also use FM /OSP/GET_DAYS_IN_MONTH but i need the code because I failed terribly.
GET_VALUES method code:
if i_step = 2.
   DATA: wa like line of i_t_var_range[].
   DATA: L_V_INDICATOR TYPE SCAL-INDICATOR.
   data: begin of ccrange ,
           iobjnm(30) type c,
             sign(1),
              opt(2),
              low(7) type c,
             high(7) type c,
         end of ccrange.
  data: l_s_range type rrrangesid,
        no_of_wrkdays type i value 0,
        startdate     type d,
        enddate       type d,
        startmth(2)   type c,
        endmth(2)     type c,
        startyr(4)    type c,
        endyr(4)      type c,
        endday(2)     type c,
        leapyear      type i value 0,
        dayofmth      type syst-datum.
DATA:  day           type SCAL-INDICATOR.
  loop at i_t_var_range into wa.
    if wa-iobjnm = '0CALMONTH'.
       ccrange-sign = wa-sign.
       ccrange-opt = wa-opt.
       ccrange-low = wa-low.
       ccrange-high = wa-high.
       exit.
    endif.
  endloop.
  startyr  = ccrange-low+0(4).
  startmth = ccrange-low+4(2).
  endyr    = ccrange-high+0(4).
  endmth   = ccrange-high+4(2).
  concatenate startyr startmth '01' into startdate.
* determine last day of the end month
  if endmth = '02'.
     leapyear = endyr mod 4.
     if leapyear = 0.
        endday = '29'.
     else.
        endday = '28'.
     endif.
  elseif ( endmth = '04' or endmth = '06' or endmth = '09' or endmth = '11' ).
       endday = '30'.
  else.
       endday = '31'.
  endif.
  concatenate endyr endmth endday into enddate.
  dayofmth = startdate.
IF startmth <= endmth.
   startmth = startmth+1.
ENDIF.
* do it for all days in space of time
   WHILE dayofmth <= enddate.     "to date
     CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
     EXPORTING
       input = startmth
     IMPORTING
       output = no_of_wrkdays.
       CLEAR l_s_range.
       l_s_range-sign = 'I'.
       l_s_range-opt = 'EQ'.
       l_s_range-low = no_of_wrkdays.
   append l_s_range to e_t_range.
       startmth = startmth + 1.
       CONCATENATE startyr startmth '01' into dayofmth.
    ENDWHILE.
endif.
endmethod.

Hi Vasavi,
1)  Create a FV to calculate no.of days  like below, with calmonth in ref characteristics :
2. If you see number of days is an attribute of calmonth. Please enter that as below :
3. Create a formula with above variable and make sure calmonth is added in the row.
Its giving output like this :
I hope this will help you.
Thanks,

Similar Messages

  • Funtion Module for user exits for variables used in BEx Queries.

    Hi,
    This is for BW Query customer exit variable (zvar2) for include ZXRSRU01 and exit :EXIT_SAPLRRS0_001.
    Can anyone please suggest the function modules that can be used to do the following.
    1)Read value of zvar1 from selection screen whatever
    user enters at run time.
    2)How to define the zvar2 in the include. zvar2 is the
    variable created in BEx to be populated from this
    customer exit.
    3)How to use case statment where once the value for zvar1
    is determined then,
    Case zvar1.
    when zvar1 = 0 , then zvar2 = 10
    when zvar1 = 1 , then zvar2 = 20
    3) Assign zvar2 value as computed in the case statement.
    Can anyone please help with the code to achieve this.
    Any information regarding function modules that can help write user exits for variable reading and input will be greatly helpful.
    Thanks
    Sarah.

    Hi Sarah,
    You don't need any FM for your issue.
    Please try thie sample code :
    DATA: VAR_INPIUT LIKE RRRANGEEXIT.
    CASE I_VNAM.
      WHEN 'ZVAR2'.
       CLEAR L_S_RANGE.
       IF I_STEP = 2."PROCESSED AFTER VARIABLE INPUT
    *Reading value of ZVAR1
        LOOP AT I_T_VAR_RANGE INTO VAR_INPIUT
          WHERE VNAM = 'ZVAR1'.
          CASE VAR_INPIUT-LOW.
    *FILLING ZVAR2
           WHEN 0.
              L_S_RANGE-LOW     = 10.
           WHEN 1.
              L_S_RANGE-LOW     = 20.
          ENDCASE.
          L_S_RANGE-SIGN     = 'I'.
          L_S_RANGE-OPT      = 'EQ'.
          APPEND L_S_RANGE TO E_T_RANGE.
          EXIT.
        ENDLOOP.
      ENDIF.
    ENDCASE.
    Hope this helps
    Joe

  • Regarding User Exits in VARIABLES

    can any one let me know,
    1>  wen can we go for user exits in variables ?
    2>  any suitable examples for that ?
    3>  and can u people provide CODE for better Xplaination.?
    Thanks and Regards,
    Hawkin.

    Read this article, it will clear your concepts.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f1a7e790-0201-0010-0a8d-f08a4662562d

  • User input formula variable with greater than/less than operators for KFG

    Hello all,
    I have used a formula in my query that is a difference of two key figures .For e.g:
    Difference = tax from system A  -  tax from system B.
    Now when the users run the report they should be prompted for the 'Difference' threshold for seeing the report say where difference is greater 100 or equal to 10 and so on.Currrently I have created a formula variable with 'user input' and created a 'condition' to display 'Difference' greater than the user entered value.
    However,it is required to have various selection options for setting the threshold of difference.For e.g User should be able to set say 'equal to'/'greater than/less than/not equal to operator for 'difference' in the initial selection screen of the report.
    With the current user-input formula variable I am not getting these 'greater than' etc operators.Any ideas on how to achieve this?

    Ya know, that's all well and good ... BUT ... WHAT IF you do want to sort text type columns with Greater Than and Less Than operatiors??
    SQL does it just Fine ... so WHY does APEX have the limit??? This is an Oracle BUG ... it SHOULD NOT limit the operators ... I realize "they" may be trying to be helpful with proper constraints to field searches ... but ... if SQL can do it, then ... no need for a limit.
    EG ...
    Show the records where
    the "Begin_Year-Wk" data is less than or equal to "2009-09" AND
    the "End_Year-Wk" data is greater than or equal to "2009-04"
    ... to give everything that was running in that 5 week period whether or not it starts within that time frame
    I can run this query perfectly fine via SQL ... but not in APEX ... unless I reconvert a lot of strings back to numbers, and for sorting / formatting / explain-to-user purposes, I really don't want them to be numbers.
    So ... there's gotta be a hidden tweak for operators somewhere ...

  • User Exits: Global Variables

    Please help me in how to create User Exits: Global Variables
    if there is step by step doc pls send it to my mail id
    [email protected]

    I guess by default (if text is maintained) F4 for calmonth should show you key, short description and long description.
    refer: Variable - Name of month instead of Number
    Edited by: sam hennry on Mar 17, 2008 11:00 AM

  • How to use formula variable to calculate the days for a document.

    Hi expert.
    I have a question, I need to calculate how many days it cost for a document, therefore , it should be like this,
    cost days = clearing date - creation date..
    how can I implement this calculated key figure by formula variable..
    Here cost days should be a key figure, but the clearing date and creation date are the characteristics in the document.
    it seems that formula variable by replacement path can not be used, do I have to use the customer exit for this variable ??
    any other good ways to calculate the cost days (beside during the data loading or by virtual key figure).
    I just want to implement this in the query designer..
    Please give a detailed steps if you could,  thanks a lot.

    Hi,
    These steps below are for the query designer in BI 7.0:
    1. First create a Formula in the Columns.
    2. Edit the formula, in the "Available Operands" see for the "Formula Variable".
    3. Right Click on the "Formula Variable" folder and then create a new variable.
    4. Edi the Formula Variable in the edit screen provide the Description and Technical name; select the processing by as Replacement path.
    5. In the reference characteristic select your characteristic "Creation Date".
    6. Save the variable.
    7. Select the variable into the formula and name the formula as Creation Date.
    Repeat the Same steps for the "Clearing Date".
    Then create another formula for the Cost days in which you mention as Clearing date (Formula) - Creation Date (Formula).
    Hope your issue is solved...
    Regards,
    Ravi Kanth

  • FORMULA VARIABLE "NO OF DAYS"

    Hi
    my report is based on infoset(ISARGL) and need one field (No of days)
    No of  days = 0CALDAY - POSTING DATE.
    BEFORE I WAS NOT HAVING 0CALDAY IN INFOSET(ISARGL)  AND ODS, BUT I ADDED IN BOTH ODS THIS 0CALDAY.
    POSTING DATE I HAVE IN INFOSET.
    for No of Days i am creating CKF based on formula variable.
    here i used replacement path, KEY, DATE.
    Formula variable FISFV_CD IS MADE FOR 0CALDAY.
    GETTING SYSTEM ERROR.
    Formula variable FISFV_CD is used in formula element No of Days and is
    to be replaced from characteristic 0CALDAY or from an attribute of
    0CALDAY. However, 0CALDAY is not contained in InfoProvider ISARGL.
    Neither does it reference any ISARGL characteristic to No of Days and
    0CALDAY is not a basic characteristic.

    variable FISFV_CD having  (current date)
    processing by  -          replacement path
    replace variable with -  attribute value
    attribute  -                  charac. reference (constant 1)
    dimension id -              number
    character.   -                calander day
    variable FISFV_PD having  (posting date)
    processing by  -          replacement path
    replace variable with -  attribute value
    attribute  -                  charac. reference (constant 1)
    dimension id -              number
    character.   -                posting date
    My selection screen is coming for calender date .
    now i am abele to see report but no of records coming 0.0000
    plz provide me solution

  • User exit for display of first day in report

    Hello friens,
    I have to design a query in which my user want to see following way
    Billed Packs----
    Week1   Week 2...................week 52
    packA
    packB
    Now user want to see the aggregated bill packs for each week.
    And user does not want to see Week numbers , for e.g.
    Billed Packs----
    01/20xx  02/20xx 03/20xx  ....................
    packA
    packB
    User want to see the Start date of that week which means Date of Monday for each week instead.
    Now it is not defined, for how much weeks user want to see , so i created a interval range variable for Week selection.
    Now from previous posts i learnt that to display Start date of Monday for each week I HAVE TO CREATE A USER EXIT.
    And also create text variable which then i will be using in Description to do the same.
    Can you please send me STEP BY STEP for same.
    Can all of you please send me Code for creating user exit
    Can you please send me some sample codes and sample documents for the same.
    My email id is [email protected]
    Points will be awarded.

    As you said "<i>Now it is not defined, for how much weeks user want to see , so i created a interval range variable for Week selection</i>.", how can you decide about the number of KFs in the structures?? (Because u'll have to create as many text variables as the no. of weeks)
    <b>But if that is not the case, following are the steps -
    1. Go to cmod to create customize project.
    2. Click on Enhancement Assignment & key in 'RSR00001'
    3. Click on Components & double click on the function exit EXIT_SAPLRRS0_001.
    4. Here you write the above code before the "Endcase" statement.
    5. Repeat the above code for rest of the text variables with slight modification as follows...
    insert modification between function module call & filling l_s_range9  --</b>i.e.
    <i>CALL FUNCTION 'WEEK_GET_FIRST_DAY'
      EXPORTING
        WEEK               = wa9-low
    IMPORTING
       DATE               =  l_fst_day
    EXCEPTIONS
      WEEK_INVALID       = 1
      OTHERS             = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.</i>
    <b>data: n_fst_day type sy-datum.
    clear n_fst_day.
    n_fst_day = l_fst_day + 8.
    l_s_range9-low =  n_fst_day.</b>
    <i>l_s_range9-sign   = 'I'.</i>
    Please assign the points if this is useful.

  • User exit for pricing to calculate net sales value and tax at billing level

    Hi,
    Can anyone give the solution for below thing.
    I have written the code for to calculate the net sale a value and tax value based on condition types YTN1 & YTN2 and with pricing procedure "ZXTNIC"  under   user exit "userexit_field_modification"  in include program LV69AFZZ
    Calculation as per below
    FD:
    The user exit will run on the values of the line item and the header of the pricing conditions
    The user exit will subtract the current net value from the value of the conditions YTN1 & YTN2, also the Tax value will be added to the value of the conditions YTN1 & YTN2.
    Need the Net value = 8,032 and not 8,882  " here 8832 value is before calculation
    This value will be calculated as follows = Current Net u2013 YTN1 u2013 YTN2 = 8,882 u2013 0,773 u2013 0,077 = 8,032
    Need the Tax value = 2,395 and not 1,545  " here 1545 value is before calculation.
    This value will be calculated as follows = Current Tax + YTN1 + YTN2 =     1,545 + 0,773 + 0, 077 = 2,395
    When i will execute the VF01 transaction there in initial screen values are not updating automatically.Once we will select item line and  then clicking on " item pricing condition" icon i.e., item level , then only the values are updating both in item level and header level.
    But when we will execute the VF02 and VF03 the values are updating automatically as per condition.
    So please suggest me is there any exit for this requirement.
    Regards,
    Jayaram

    Hi,
    You should implement your logic in VOFM Copying routine for billing document.
    Regards
    Prasenjit

  • Get hierarchy name in user-exit from variable

    Hi everybody
    I have a WebTemplate with different queris. The user can select the costcenter in the beginning. In a further query of the template I show all the orders regarding that costcenter. But with this concept I block all the orders with one user executing the template.
    So now I want to select the orders that belong to the selected costcenter in a user exit (with a variable). This works fine when the user selects a costcenter.
    But it is also possible that the user selects a higher node of the costcenter hierarchy. How can I get all the orders that are connected to a costcenter node?
    So far I thought that I have to get all costcenter nodes that have the selected node as a parent (etc..) in the hierarchy table. But how do I find out which hierarchy is used by the query? I get the Variable name loc_var_range-vnam. And I know which table the hierarchy is in. But how do I find the correct HIEID?
    or does anybody have a better suggestion to solve my problem?
    Thanks in advance.
    Christophe

    Hi Christophe,
    I've written a code for finding the name of hierarchy using the node.
    It's little bit big code, if send ur email id i can pass it to you.
    hope that helps you.
    regards
    rajesh

  • Query with user-exit hierarchy variable and input ready hierarchy node var.

    Hello everyone.
    we are using several hierarchies (2005, 2006 and 2007) of the same info object 0FUNDS_CTR (one for each fiscal year). We would like to be able to use same reports regardless of chosen fiscal year (selected hierarchy) and ever more, to select node inside proper hierarchy. At the moment reports use 3 parameters:
    1) fiscal period from - fiscal period to
    2) hierarchy name
    3) hierarchy node
    Our goal is to get report with only 2 parameters:
    1) fiscal period from - fiscal period to
    2) hierarchy node
    since hierarchy name could be derived (user exit) from fiscal period.
    When user selects hierarchy node he is being asked to select hierarchy name (despite of user exit for hierarchy name) and key date (populated with current date).
    We would like to avoid step of user selecting hierarchy. Is it possible?
    Any other approaches to problem would be appreciated.
    Kind regards,
    Josko.

    Hi Jörg,
    As mentioned, I_STEP = 3 is  processed once per query, not once per varaiable.
    If this statement is placed within case-endcase for I_VNAM it never will be processed.
    Please take a look on this, it might be helpful..
    Regards
    Joe

  • Is there any standard variable to calculate previous and current month

    hi,
    Is there any standar variable to calculate previous month and current month which will calcualte from system date (sy-date). I found standard SAP Delivered variable - 0CMONTH to calculate current month. But i want both current month and previous month.  IF it is not avialble can you please provide me the ABAP code..
    thanks in advance.

    Hi,
    Check this thread.
    ABAP routine for loading previous months data in infopackage
    Regards.

  • Variable for last day of last month....

    Hi,
    Can somebody let me know the code to find the last day of last month from the query variable.
    Is there any standard/business content  variable available for this?
    I have found one similar variable , but its for the posting date.
    Any help is appreciated.
    Regards...

    Check this code:
    l_date_from = sy-datum.
           l_date_from+6(2) = '01'.
           l_date_from = l_date_from - 1.
           l_s_range-sign = 'I'.
           l_s_range-opt  = 'EQ'.
           l_s_range-low = l_date_from.
           l_s_range-high = space.
           APPEND l_s_range TO e_t_range.
    You can modify based on your specific requirement.
    Regards,
    Kams

  • User Exit/BADI to Lock Sales order for any changes in VA02 (Excluding Prici

    Hi All,
    I am looking for an User Exit or BADI which disallows any kind of changes in Sales Order on a particular condition.
    This can't b controlled through Authorization, so have to look for an exit. Please suggest.
    If possible, please provide the example.
    Thanks

    Hi,
    Check the user exit MV45AFZZ in this exit u will be finding the Lot of stages where we can control the VA01 or VA02 . Please find the exit with the name SAVE before. Try to check any changes For sales order in CDHDR and CDPOS and give some error message .
    Thanks and Regards,
    Srinivas.

  • User Exit for Variable which calls to a Function Module is NOT working ???

    Hi all,
        I have a created a variable 'ZNBUSDAY' with Processing Type 'Customer Exit' on 0SCL_DELDAT  (Date). The query is on 0PUR_C04 and passing 0SCL_DELDAT  to Function Module  Z_WORKDAY to get the Next Business Day by using the company Calendar(30). The following code is NOT working and what is WRONG with it, PLEASE? The FM is working FINE.
    DATA: wa_calendar(2) TYPE c value '30',
          wa_znbusday    like sy-datum,
          0scl_deldat    like sy-datum,
          p_days         TYPE i value 1.
    case i_vnam.
       when 'ZNBUSDAY'.
       CLEAR wa_znbusday.
       CALL FUNCTION 'Z_WORKDAY'
         EXPORTING
         CURR_DATE        = 0scl_deldat
         NUMBER_DAYS      = p_days
         CALENDAR         = wa_calendar
       IMPORTING
         WORK_DAY         = wa_znbusday
         l_s_range-low  = wa_znbusday.
         l_s_range-opt  = 'EQ'.
         l_s_range-sign = 'I'.
         append l_s_range to e_t_range.
    endcase.
    Thanks,
    Venkat.

    Hi Venkat,
    Looks like you're only assigning type sy-datum to 0scl_deldat but not the actual value. Try the following:
    DATA: wa_calendar(2) TYPE c value '30',
          wa_znbusday    like sy-datum,
          0scl_deldat    like sy-datum,
          p_days         TYPE i value 1.
    case i_vnam.
       when 'ZNBUSDAY'.
       CLEAR wa_znbusday.
       0scl_deldat = sy-datum.
       CALL FUNCTION 'Z_WORKDAY'
         EXPORTING
         CURR_DATE        = 0scl_deldat
         NUMBER_DAYS      = p_days
         CALENDAR         = wa_calendar
       IMPORTING
         WORK_DAY         = wa_znbusday
         l_s_range-low  = wa_znbusday.
         l_s_range-opt  = 'EQ'.
         l_s_range-sign = 'I'.
         append l_s_range to e_t_range.
    endcase.
    Kind regards,
    Alex

Maybe you are looking for

  • VPN Client and Setup for RV042

    Is there a definitive setup for a small VPN using the RV042? Situation is 2 remote users wish to get access to a non server (W7P) pc to access files. The end point doesn't have a static IP but I've put in a DYNDNS.org so it reports back the IP and I

  • How do I set up a push iCal using the Lion Server on a Mac Mini?

    I have the server set up to work as a remote server. I have added users. Now I want to set up iCal to push, what are the steps to do this?

  • CS6 timeline not redrawing properly

    I just installed the Premiere CS6 demo on my Mac Pro (Lion 10.7.3), and I've been playing with it for a couple days. So far it's worked like a dream, except for one really strange glitch: in one of my sequences, the timeline doesn't want to redraw wh

  • Reg:RG 23 A Part ii Register

    Hi Guru, Refer Enclosed word screenshot. I am testing a Import Procurement. Error has been encountered while testing RG23A Part II Register. The SHE. Cess Duty Component is getting debited (Subtracted) instead of getting Credited(Added). With referen

  • Bluetooth Device for Nano

    Does anybody know if there is a bluetooth device for the iPod Nano (like 'BlueTrip'), where I can listen to it through my CD Player? Does anybody know if these devices can be played through any CD Players? Does anybody know if you can change the song