Custom Function

I am trying to create a custom function to include in the Functions, and under the Custom Function I want to have the currency format: "cdCurrencyScalerChoice" which I found in the Crystal Report sample: "Order PRocessing Efficiency"
Jack..

I use CR XI, so this answer is based on that version.
Select a formula and edit.
Now that you are in the formula workshop, you should see "Report custom Functions" near the top of the list.
You should be able to select, and copy the custom function ( be sure to note, if this is Visual Basic, or not )

Similar Messages

  • How to write the custom Function Module to trigger the Alert.

    Hi all,
    I have developed a custom alert category in Tx - alrtcatdef. Now i want to trigger it from my custom function module. what should i do or what is the procedure to trigger the alert from my custom function module.
    Arul Jothi

    hi arul,
    try this program.
    RSALERTTEST.
    check out this link...
    <a href="/people/ginger.gatling/blog/2005/12/02/innovative-ways-to-use-alerts:///people/ginger.gatling/blog/2005/12/02/innovative-ways-to-use-alerts
    regs,
    jaga

  • How to create a custom function module with the records in SAP R/3?

    Hi All,
    How to create a custom function module with the records in SAP R/3? Using RFC Adapter I have to fetch the custom function module records.
    Regards
    Sara

    Hi
    goto se37...here u need to create a function group... then u need to create a function module. inside assign import/export parameters. assign tables/exceptions. activate the same. now write ur code within the function module
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
    Look at the below SAP HELP links, These links will show you the way to create a Function Module
    http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm

  • How to bring the custom function module in WE42?

    Hi,
    I have created a custom function module to post a custom idoc.
    Process code has been created thro WE42 and WE57 is done.
    Still I am not able to see the custom function module in the list (WE42) in order to assign it to process code.
    May i know the reason for this?
    Thanks.
    Thiyagu

    What makes you think that it should be visible in WE42? There is no F4-value help for this and you haven't added it manually yet, right.
    In WE42 you can manually add entries, so that's what I would do.

  • SSRS - Pass Field Value List To Custom Function Assembly And Display Result

    I have written a SQL Server Reporting Services custom function as a C# assembly DLL and added it to my report. The purpose of the function is to search for outlier records in a collection of data. The data is represented as an array of floating point -tuplets
    (float[][]). In a medical patient database, these might be things such as blood pressure, cholesterol, hight, weight, waist measurement, etc.
    Several user input parameters are provided in the report, including numeric seed values for this particular algorithm. One multivalued parameter is a list of the numeric columns to be used as input to the algorithm because, importantly,
    the user can choose any subset of the value columns. I have a tablix that will display columns from the dataset conditionally, based on which of those columns are chosen.
    At this point, there are two issues I'm having difficulty with:
    How do I, in the course of running the report, take just the numeric columns that the user has chosen (ignoring all others in the dataset) and pass them as a float[][] to my custom function? Or is there something in the
    Microsoft.ReportingServices namespace that I should use to query an input dataset and convert it to an array in my C# code?
    How can I present the array subset returned by my custom function in a tablix in the report?
    Note: One thought that occurs to me is that outlier records tablix could be contained in a subreport, but I'm not clear on the logistics of passing dataset field results from a master report to a subreport.
    I envision a final report when run to be similar to the following:
    - Mark Z.

    Hi Mark,
    Sorry for the delay.
    From your description, you want to pass the dataset data to a custom code array, and return the subset of the array, right? In this case, you can use a custom function to add the data to array, and use the a custom function to sort the data base on your
    requirement and then use a function to get the subset of the array. Here are some sample custom code for your reference.
    Add to arryay
    Dim values As System.Collections.ArrayList=New System.Collections.ArrayList()
    Function SetText(ByVal value As Integer) As Integer
        values.Add(value)
        return value
    End Function
    Sort array
    Function Sort()
    Dim i as Integer
    Dim j as Integer
    Dim t as Integer
    Dim n as Integer=values.Count-1
    For i=n To 1 Step-1
     For j=0 To i-1
     if values(j)<values(j+1) Then
        t=values(j)
        values(j)=values(j+1)
        values(j+1)=t
     End if
     Next j
    Next i
    End Function
    Return value.
    Function Rank(ByVal value As Integer)
       return values(value)
    End Function
    Assume that you pass [Weight] field to array, you can use the expression below on the Weight column:
    =Code.SetText(Fields!Weight.Value)
    Then use the expression below to get the values.
    PatientID:=Sort() & Lookup(Code.Rank(0),Fields!Weight.Value,Fields.Patient.Value,"Dataset")
    Height:=Lookup(Code.Rank(0),Fields!Weight.Value,Fields.Height.Value,"Dataset")
    Weight:=Code.Rank(0)
    Hope this helps.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Report Template driven by custom functions

    Hello,
    I'm a newbie, and i'm trying to design a report template driven by a vw and/or stored proc to display information on a letterhead report.  Such as names that can change at any time.  I have another interface linked to the vw/sp to change that information at any time.  What i'm trying to get is the idea of how to create a template letterhead report that i don't have to go back into crystal to change whenever the administration name changes. 
    Does anybody have any ideas or examples?  I'm thinking Custom Functions are the way to go but, i just don't know how to get started with using them if that's the way to go. 
    Thanks in advance!

    Please re-post if this is still an issue

  • Unable to debug an exit in CALL CUSTOMER FUNCTION 003

    Hi Guys,
    I have an exit EXIT_SAPMV45A_003 that is called by CALL CUSTOMER FUNCTION 003. I had placed a break point at
    CALL CUSTOMER FUNCTION 003 and the debugger stops here but i am unable to debug inside this to reach into
    the code in EXIT_SAPMV45A_003 even after setting the system debugging on & Update debugging
    ON.
    Can someone help me with this?
    thanks
    Dan

    You have to include that Enhancement of that exit in the Project and Activate that project in the CMOD.
    The Enhancement for the exit EXIT_SAPMV45A_003 is V45A0003.
    Create a project in CMOD
    And inclue V45A0003 in the project.
    Activate the Project.
    Now, it will stop at break point.
    Regards,
    Naimesh Patel

  • Error in Including the Custom function in Custom schema ...

    Hi Experts ,
                   I developed a time custom Function through PE04 ,  Z_5RT and included in Custom Schema , ZM04, while executing in PT60 using the schema ZM04 an error coming . Any configuration required to include custom function in a schema .
    Thanks and regards
    Renjith MP

    You are just going to place the custom function in the 'Func' field of schema.
    Check the counry assignment, parameters & finally you have to activate the function. Check T52A0 for correct internal number.
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/96/79bc54b27911d1a5400000e83ddb11/frameset.htm
    Regards
    N Navaneethan
    Edited by: Navaneethan on Dec 15, 2008 4:30 PM

  • Could not find Model while pointing to a custom Function Group

    Hello ,
    I am on EP7.0 ERP05 NW04s and trying to modify ESS Address application  to point to a custom function group rather than the standard one . When I tried to do that by changing the mapping for the ReadInfotype I got certain compilation errors ,I fixed those and then got the following error at runtime:
    com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Couldnt find info for class com.sap.xss.hr.per.us.address.custom_model_custom.Zhrxss_Per_Read_P0006_Us_Input in model com.sap.xss.hr.per.us.address.model.HRXSS_PER_P0006_US@10c7f0a[scope=APPLICATION_SCOPE]
         at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.associatedModelClassInfo(DynamicRFCModelClass.java:220)
         at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.elementIndexForFrontendName(DynamicRFCModelClass.java:1359)
         at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.setAttributeValueAsString(DynamicRFCModelClass.java:664)
         at com.sap.xss.hr.per.us.address.custom_model_custom.Zhrxss_Per_Read_P0006_Us_Input.setInfty(Zhrxss_Per_Read_P0006_Us_Input.java:162)
         at com.sap.xss.hr.per.us.address.fc.wdp.IPublicFcPerAddressUS$IReadInfotypeElement.setInfty(IPublicFcPerAddressUS.java:11824)
         at com.sap.xss.hr.per.us.address.fc.FcPerAddressUS.readRecord(FcPerAddressUS.java:271)
         at com.sap.xss.hr.per.us.address.fc.wdp.InternalFcPerAddressUS.readRecord(InternalFcPerAddressUS.java:692)
         at com.sap.xss.hr.per.us.address.fc.FcPerAddressUSInterface.readRecord(FcPerAddressUSInterface.java:150)
         at com.sap.xss.hr.per.us.address.fc.wdp.InternalFcPerAddressUSInterface.readRecord(InternalFcPerAddressUSInterface.java:230)
         at com.sap.xss.hr.per.us.address.fc.wdp.InternalFcPerAddressUSInterface$External.readRecord(InternalFcPerAddressUSInterface.java:306)
         at com.sap.xss.hr.per.us.address.overview.VcPerAddressUSOverview.onBeforeOutput(VcPerAddressUSOverview.java:267)
         at com.sap.xss.hr.per.us.address.overview.wdp.InternalVcPerAddressUSOverview.onBeforeOutput(InternalVcPerAddressUSOverview.java:275)
         at com.sap.xss.hr.per.us.address.overview.VcPerAddressUSOverviewInterface.onBeforeOutput(VcPerAddressUSOverviewInterface.java:158)
         at com.sap.xss.hr.per.us.address.overview.wdp.InternalVcPerAddressUSOverviewInterface.onBeforeOutput(InternalVcPerAddressUSOverviewInterface.java:140)
         at com.sap.xss.hr.per.us.address.overview.wdp.InternalVcPerAddressUSOverviewInterface$External.onBeforeOutput(InternalVcPerAddressUSOverviewInterface.java:224)
         at com.sap.pcuigp.xssfpm.wd.FPMComponent.callOnBeforeOutput(FPMComponent.java:602)
         at com.sap.pcuigp.xssfpm.wd.FPMComponent.doProcessEvent(FPMComponent.java:568)
         at com.sap.pcuigp.xssfpm.wd.FPMComponent.doEventLoop(FPMComponent.java:437)
         at com.sap.pcuigp.xssfpm.wd.FPMComponent.wdDoInit(FPMComponent.java:195)
         at com.sap.pcuigp.xssfpm.wd.wdp.InternalFPMComponent.wdDoInit(InternalFPMComponent.java:110)
         at com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.doInit(DelegatingComponent.java:108)
         at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)
         at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:200)
         at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.init(ClientComponent.java:430)
         at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.init(ClientApplication.java:362)
         at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.initApplication(ApplicationSession.java:748)
         at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:283)
         at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingStandalone(ClientSession.java:759)
         at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:712)
         at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:261)
         at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:149)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:62)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doGet(DispatcherServlet.java:46)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    I wonder what's the cause of this ...
    Any help would be highly appreciated.

    Do below things.
    1. Re-import your Model.
    2. Restart your J2ee server
    3. Re-load & Rebuild your project.
    It should work now..
    Raja T
    Message was edited by:
            Armin Reichert

  • Issue with calling custom function in merge command -10g

    Hi,
    I have ran into issue while calling a custom function in merge command.
    It throws error 'Invalid identifier'. Oracle doesnt understand that it is a function and take the function name as column name.
    Since no such collumn name exists, it throws 'Invalid identifier'.
    Interestingly, merge command works fine when it has a oracle function (replace, decode).
    The oracle version is 10.2.0.3
    It is very urgent.
    Any pointers will be helpful.
    Regards,
    Ravi

    I don't have privileges to create dblink, but this is working for me.
    So, i don't think function can be a issue here.
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:01.02
    satyaki>
    satyaki>
    satyaki>create table hist_tab
      2     as
      3       select * from emp
      4       where sal between 2000 and 4000;
    Table created.
    Elapsed: 00:00:00.09
    satyaki>
    satyaki>select * from hist_tab;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7844 TURNER     SALESMAN        7698 08-SEP-81       2178          0         30 SALESMAN
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>update hist_tab
      2     set mgr = 7794;
    1 row updated.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>commit;
    Commit complete.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from hist_tab;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7844 TURNER     SALESMAN        7794 08-SEP-81       2178          0         30 SALESMAN
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>
    satyaki>
    satyaki>create table tran_tab
      2     as
      3       select * from emp
      4       where sal between 2000 and 7000;
    Table created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from tran_tab;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7844 TURNER     SALESMAN        7698 08-SEP-81       2178          0         30 SALESMAN
          7902 FORD       ANALYST         7566 03-DEC-81    5270.76                    20 ANALYST
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>ed
    Wrote file afiedt.buf
      1  create or replace function fun(c_in number)
      2     return number
      3     is
      4       c_out number(4);
      5     begin
      6       if c_in < 7900 then
      7          c_out := 0;
      8       else
      9         c_out := 1;
    10       end if;
    11       return c_out;
    12*    end;
    13  /
    Function created.
    Elapsed: 00:00:01.00
    satyaki>
    satyaki>merge into hist_tab o
      2  using (
      3     select empno,
      4            ename,
      5            job,
      6            mgr,
      7            hiredate,
      8            sal,
      9            comm,
    10            deptno,
    11            job1,
    12            dob
    13     from (
    14              select k.*,
    15                     rank() over(order by fun(k.empno)) rn
    16              from tran_tab k
    17          )
    18     where rn = 1
    19     ) n
    20  on ( o.empno = n.empno)
    21  when matched then
    22    update set o.ename = n.ename,
    23               o.job = n.job,
    24               o.mgr = n.mgr,
    25               o.hiredate = n.hiredate,
    26               o.sal = n.sal,
    27               o.comm = n.comm,
    28               o.deptno = n.deptno,
    29               o.job1 = n.job1,
    30               o.dob = n.dob
    31  when not matched then
    32    insert(
    33            o.empno,
    34            o.ename,
    35            o.job,
    36            o.mgr,
    37            o.hiredate,
    38            o.sal,
    39            o.comm,
    40            o.deptno,
    41            o.job1,
    42            o.dob
    43          )
    44    values(
    45            n.empno,
    46            n.ename,
    47            n.job,
    48            n.mgr,
    49            n.hiredate,
    50            n.sal,
    51            n.comm,
    52            n.deptno,
    53            n.job1,
    54            n.dob
    55          );
    1 row merged.
    Elapsed: 00:00:00.03
    satyaki>
    satyaki>select * from hist_tab;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO JOB1      DOB
          7844 TURNER     SALESMAN        7698 08-SEP-81       2178          0         30 SALESMAN
    Elapsed: 00:00:00.00
    satyaki>You can check the final output with old output. It is working perfectly - i guess.
    Regards.
    Satyaki De.

  • How to develope custom function modules in SAP R/3 system to maintain c...

    How to develope custom function modules in SAP R/3 system to maintain cross
    referencing tables for sales order number.

    Hi Raja,
    Steps to crate FM..
    Follow these steps..
    Go to the T: code SE37
    First You Create Function Group
    On That u specify
    Function Group Name..............
    Short Text..............................
    save...
    Go to SE 37
    Specify the Function Module Name: Eg: Z_Bapi_Materialmaster
    Short Text.......
    Save...
    Next Go to Attributes..
    Select Radio button : Remote enabled model
    Go to Parameters..
    Click Import...
    Give Parameter Type Associate type S.t
    next Click Export...
    Give Parameter Type Associate type S.t
    Next Click Tables Button..
    Specify tables..
    Next click source code button..
    Write Source code here..
    Eg : Select statements Etc..
    Finally we should be select the Radio button Enable remorely
    https://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action?pageId=39728
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/bapi%2bstep%2bby%2bstep
    Hope this information is useful to you..
    Reward points if it is usefulll....
    Thanks ,
    Satya Kumar..

  • Why is there a limitation on the number of boolean parameters in a custom function?

    We have a custom function which 'flattens' four text temporal values into a single temporal value.
    We want to do the same with boolean temporal values.
    However, OPM throws an error when  it reads the metadata for the function in extensions.xml.  It says all boolean paramaters need to be last.  We can't put them all last as there are more than one.
    This is OPM error code OPM-W00001.
    Any ideas on how I can work around this limitation?

    Taken from OPA Developer's help:
    Only one boolean parameter can be passed to a function, and it must be the last parameter.  This is due to a limitation in the rule compiler.  Any number of other parameters may be present however.
    Should you want to pass more boolean values, create a temporary/document text variable with values "True"/"False" using rule table.

  • Help on custom function...

    Hi all
    I'm having a problem with this custom function/report posted on TechNet while back for ConfigMgr 2007
    http://social.technet.microsoft.com/wiki/contents/articles/7870.sccm-2007-create-report-of-upcoming-maintenance-windows-by-client.aspx
    I've made the needed changes according to this blog post:
    https://sccmfaq.wordpress.com/2013/08/22/sccm-2012-show-next-effective-maintenance-window/
    ..but when using maintenance windows that occurs for example 1st tuesday of every 1 months, the function returns the date week ahead. For example now (on 28th of Feb) next maintenance window should be on Tuesday March 3rd, but instead the report is showing
    Tuesday March 10th.
    Any help on modifying the function would be appreciated, I saw that there comments on the original post about the recurrence type 4 (monthly by weekday as noted here https://msdn.microsoft.com/en-us/library/cc143300.aspx) not working correctly in the function.
    It seems that the function now returns the weekday of first full week of the month instead of the correct day.
    The function is this:
    CREATE FUNCTION [dbo].[SCCM_GetNextServiceWindow](@ScheduleToken AS CHAR(16), @RecurrenceType AS INT) RETURNS @NextServiceWindow TABLE (ScheduleToken CHAR(16), RecurrenceType INT, NextServiceWindow DATETIME, Duration INT, IsGMTTime BIT) AS BEGIN
    --1 Occurs on 1/1/2012 12:00 AM 00011A8500080000
    --2 Occurs every 3 day(s) effective 1/1/2012 8:00 PM 02811A8040100018
    --3 Occurs every 3 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F6000
    --3 Occurs every 1 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F2000
    --5 Occurs day 2 of every 2 month(s) effective 1/1/2012 8:00 PM 02811A8040288800
    --5 Occurs day 31 of every 1 month(s) effective 1/1/2012 8:00 PM 02811A80402FC400
    --5 Occurs the last day of every 3 months effective 1/1/2012 8:00 PM 02811A8040280C00
    --5 Occurs the last day of every 1 months effective 1/1/2012 8:00 PM 02811A8040280400
    --4 Occurs the Third Monday of every 1 month(s) effective 1/1/2012 4:00 AM 00811A9E08221600
    --4 Occurs the Last Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241000
    --4 Occurs the Fourth Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241800
    --4 Occurs the Last Monday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040221000
    --3 Occurs every 1 week(s) on Monday effective 1/1/2012 4:00 AM 00811A9E081A2000
    -- http://msdn.microsoft.com/en-us/library/cc143300.aspx [This link is external to TechNet Wiki. It will open in a new window.]
    DECLARE @RecurrenceType_NONE INT
    , @RecurrenceType_DAILY INT
    , @RecurrenceType_WEEKLY INT
    , @RecurrenceType_MONTHLYBYWEEKDAY INT
    , @RecurrenceType_MONTHLYBYDATE INT
    SELECT @RecurrenceType_NONE = 1
    , @RecurrenceType_DAILY = 2
    , @RecurrenceType_WEEKLY = 3
    , @RecurrenceType_MONTHLYBYWEEKDAY = 4
    , @RecurrenceType_MONTHLYBYDATE = 5
    -- http://msdn.microsoft.com/en-us/library/cc143505.aspx [This link is external to TechNet Wiki. It will open in a new window.]
    --DECLARE @RecurrenceType INT; SET @RecurrenceType = @RecurrenceType_WEEKLY
    --DECLARE @ScheduleToken CHAR(16); SET @ScheduleToken = '00811A9E081A2000'
    DECLARE @ScheduleStartTime INT; SET @ScheduleStartTime = CAST(CONVERT(BINARY(4), LEFT(@ScheduleToken, 8), 2) AS INT)
    DECLARE @ScheduleDuration INT; SET @ScheduleDuration = CAST(CONVERT(BINARY(4), RIGHT(@ScheduleToken, 8), 2) AS INT)
    -- Duration is in minutes
    DECLARE @Duration INT; SET @Duration = @ScheduleStartTime % POWER(2, 6)
    -- Calculate the start time
    DECLARE @StartTime DATETIME; SET @StartTime = CONVERT(DATETIME, '01/01/1970 00:00:00')
    SET @StartTime = DATEADD(YEAR, (@ScheduleStartTime / POWER(2,6)) % POWER(2, 6), @StartTime)
    SET @StartTime = DATEADD(MONTH, ((@ScheduleStartTime / POWER(2,12)) % POWER(2, 4)) - 1, @StartTime)
    SET @StartTime = DATEADD(DAY, ((@ScheduleStartTime / POWER(2,16)) % POWER(2, 5)) - 1, @StartTime)
    SET @StartTime = DATEADD(HOUR, (@ScheduleStartTime / POWER(2,21)) % POWER(2, 5), @StartTime)
    SET @StartTime = DATEADD(MINUTE, (@ScheduleStartTime / POWER(2,26)) % POWER(2, 5), @StartTime)
    -- Determinte UTC and Flags
    DECLARE @IsGMTTime BIT; SET @IsGMTTime = CAST(@ScheduleDuration % POWER(2, 1) AS BIT)
    DECLARE @Flags INT; SET @Flags = (@ScheduleDuration / POWER(2,19)) % POWER(2, 3)
    -- Calculate the total duration in minutes
    SET @Duration = @Duration + ((@ScheduleDuration / POWER(2,22)) % POWER(2, 5)) * 24 * 60 -- DAYS
    SET @Duration = @Duration + ((@ScheduleDuration / POWER(2,27)) % POWER(2, 5)) * 60 -- HOURS
    DECLARE @Now DATETIME
    IF @IsGMTTime = 1 BEGIN
    SET @Now = GETUTCDATE()
    END ELSE BEGIN
    SET @Now = GETDATE()
    END
    DECLARE @NextMaintenanceWindow DATETIME
    IF @RecurrenceType = @RecurrenceType_NONE BEGIN
    IF DATEADD(MINUTE, @Duration, @StartTime) > @Now BEGIN
    SET @NextMaintenanceWindow = @StartTime
    END
    END ELSE IF @RecurrenceType = @RecurrenceType_DAILY BEGIN
    IF DATEADD(MINUTE, @Duration, @StartTime) > @Now BEGIN
    SET @NextMaintenanceWindow = @StartTime
    END ELSE BEGIN
    -- Calculate the daily interval in minutes
    DECLARE @DailyInterval INT
    SET @DailyInterval = ((@ScheduleDuration / POWER(2,3)) % POWER(2, 5)) * 24 * 60
    SET @DailyInterval = @DailyInterval + ((@ScheduleDuration / POWER(2,8)) % POWER(2, 5)) * 60
    SET @DailyInterval = @DailyInterval + (@ScheduleDuration / POWER(2,13)) % POWER(2, 6)
    -- Calculate the total number of completed intervals
    DECLARE @DailyNumberOfCompletedIntervals INT; SET @DailyNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MINUTE, @StartTime, @Now) AS DECIMAL) / @DailyInterval, 0, 0)
    -- Calculate the next interval
    DECLARE @DailyNextInterval DATETIME; SET @DailyNextInterval = DATEADD(MINUTE, @DailyNumberOfCompletedIntervals * @DailyInterval, @StartTime)
    -- Recalc the next interval if the next interval plus the expected duration is in the past
    IF DATEADD(MINUTE, @Duration, @DailyNextInterval) < @Now BEGIN
    SET @DailyNextInterval = DATEADD(MINUTE, (@DailyNumberOfCompletedIntervals + 1) * @DailyInterval, @StartTime)
    END
    SET @NextMaintenanceWindow = @DailyNextInterval
    END
    END ELSE IF @RecurrenceType = @RecurrenceType_WEEKLY BEGIN
    DECLARE @WeeklyInterval INT; SET @WeeklyInterval = (@ScheduleDuration / POWER(2,13)) % POWER(2, 3)
    DECLARE @WeeklyDoW INT; SET @WeeklyDoW = (@ScheduleDuration / POWER(2,16)) % POWER(2, 3)
    -- Adjust the start time to match the next day of week that matches the interval
    DECLARE @WeeklyStartTime DATETIME; SET @WeeklyStartTime = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @StartTime) + @WeeklyDoW % 7), @StartTime)
    IF DATEADD(MINUTE, @Duration, @WeeklyStartTime) > @Now BEGIN
    SET @NextMaintenanceWindow = @WeeklyStartTime
    END ELSE BEGIN
    -- Calculate the total number of completed intervals
    DECLARE @WeeklyNumberOfCompletedIntervals INT; SET @WeeklyNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(WEEK, @WeeklyStartTime, @Now) AS DECIMAL) / @WeeklyInterval, 0, 0)
    -- Calculate the next interval
    DECLARE @WeeklyNextInterval DATETIME; SET @WeeklyNextInterval = DATEADD(WEEK, @WeeklyNumberOfCompletedIntervals * @WeeklyInterval, @WeeklyStartTime)
    -- Recalc the next interval if the next interval plus the expected duration is in the past
    IF DATEADD(MINUTE, @Duration, @WeeklyNextInterval) < @Now BEGIN
    SET @WeeklyNextInterval = DATEADD(WEEK, (@WeeklyNumberOfCompletedIntervals + 1) * @WeeklyInterval, @WeeklyStartTime)
    END
    SET @NextMaintenanceWindow = @WeeklyNextInterval
    END
    END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYWEEKDAY BEGIN
    DECLARE @MonthlyBWWeek INT; SET @MonthlyBWWeek = (@ScheduleDuration / POWER(2,9)) % POWER(2, 3)
    DECLARE @MontlhyBWInterval INT; SET @MontlhyBWInterval = (@ScheduleDuration / POWER(2,12)) % POWER(2, 4)
    DECLARE @MonthlyBWDoW INT; SET @MonthlyBWDoW = (@ScheduleDuration / POWER(2,16)) % POWER(2, 3)
    -- Calculate the total number of completed intervals
    DECLARE @MonthlyBWNumberOfCompletedIntervals INT; SET @MonthlyBWNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @StartTime, @Now) AS DECIMAL) / @MontlhyBWInterval, 0, 0)
    IF @MonthlyBWWeek = 0 BEGIN
    -- Calculate the next interval
    DECLARE @MonthlyBWLDOMNextInterval DATETIME; SET @MonthlyBWLDOMNextInterval = DATEADD(MONTH, @MonthlyBWNumberOfCompletedIntervals * @MontlhyBWInterval, @StartTime)
    -- Calculate last day of month
    SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBWLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBWLDOMNextInterval) + 1, 0))), @MonthlyBWLDOMNextInterval)
    -- Calculate the last day of the week for the month
    SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, -(7 - DATEPART(WEEKDAY, @MonthlyBWLDOMNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWLDOMNextInterval)
    IF DATEADD(MINUTE, @Duration, @MonthlyBWLDOMNextInterval) < @Now BEGIN
    -- Recalc for the next month interval
    SET @MonthlyBWLDOMNextInterval = DATEADD(MONTH, (@MonthlyBWNumberOfCompletedIntervals + 1) * @MontlhyBWInterval, @StartTime)
    -- Calculate last day of month
    SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBWLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBWLDOMNextInterval) + 1, 0))), @MonthlyBWLDOMNextInterval)
    -- Calculate the last day of the week for the month
    SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, -(7 - DATEPART(WEEKDAY, @MonthlyBWLDOMNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWLDOMNextInterval)
    END
    SET @NextMaintenanceWindow = @MonthlyBWLDOMNextInterval
    END ELSE BEGIN
    -- Calculate the next interval
    DECLARE @MonthlyBWNextInterval DATETIME; SET @MonthlyBWNextInterval = DATEADD(MONTH, @MonthlyBWNumberOfCompletedIntervals * @MontlhyBWInterval, @StartTime)
    -- Set the date to the first day of the month
    SET @MonthlyBWNextInterval = DATEADD(DAY, -(DAY(@MonthlyBWNextInterval) - 1), @MonthlyBWNextInterval)
    -- Set the date to the first day of week in the month
    SET @MonthlyBWNextInterval = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @MonthlyBWNextInterval) + @MonthlyBWDoW) % 7, @MonthlyBWNextInterval)
    -- Calculate date based on the week number to add
    SET @MonthlyBWNextInterval = DATEADD(WEEK, @MonthlyBWWeek-1, @MonthlyBWNextInterval)
    IF DATEADD(MINUTE, @Duration, @MonthlyBWNextInterval) < @Now BEGIN
    -- Recalc for the next month interval
    SET @MonthlyBWNextInterval = DATEADD(MONTH, (@MonthlyBWNumberOfCompletedIntervals + 1) * @MontlhyBWInterval, @StartTime)
    -- Set the date to the first day of the month
    SET @MonthlyBWNextInterval = DATEADD(DAY, -(DAY(@MonthlyBWNextInterval) - 1), @MonthlyBWNextInterval)
    -- Set the date to the first day of week in the month
    SET @MonthlyBWNextInterval = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @MonthlyBWNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWNextInterval)
    -- Calculate date based on the week number to add
    SET @MonthlyBWNextInterval = DATEADD(WEEK, @MonthlyBWWeek-1, @MonthlyBWNextInterval)
    END
    SET @NextMaintenanceWindow = @MonthlyBWNextInterval
    END
    END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYDATE BEGIN
    DECLARE @MontlhyBDInterval INT; SET @MontlhyBDInterval = (@ScheduleDuration / POWER(2,10)) % POWER(2, 4)
    DECLARE @MonthlyBDDoM INT; SET @MonthlyBDDoM = (@ScheduleDuration / POWER(2,14)) % POWER(2, 5)
    IF @MonthlyBDDoM = 0 BEGIN
    /* This is the last day of month logic */
    -- Calculate the total number of completed intervals
    DECLARE @MonthlyBDLDOMNumberOfCompletedIntervals INT; SET @MonthlyBDLDOMNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @StartTime, @Now) AS DECIMAL) / @MontlhyBDInterval, 0, 0)
    -- Calculate the next interval
    DECLARE @MonthlyBDLDOMNextInterval DATETIME; SET @MonthlyBDLDOMNextInterval = DATEADD(MONTH, @MonthlyBDLDOMNumberOfCompletedIntervals * @MontlhyBDInterval, @StartTime)
    -- Calculate last day of month
    SET @MonthlyBDLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBDLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBDLDOMNextInterval) + 1, 0))), @MonthlyBDLDOMNextInterval)
    -- Recalc the next interval if the next interval plus the expected duration is in the past
    IF DATEADD(MINUTE, @Duration, @MonthlyBDLDOMNextInterval) < @Now BEGIN
    SET @MonthlyBDLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBDLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, DATEADD(MONTH, (@MonthlyBDLDOMNumberOfCompletedIntervals + 1) * @MontlhyBDInterval, @StartTime)) + 1, 0))), @MonthlyBDLDOMNextInterval)
    END
    SET @NextMaintenanceWindow = @MonthlyBDLDOMNextInterval
    END ELSE BEGIN
    -- Check to make sure we won't loop forever if more than 31 days some how ends up in the token
    IF @MonthlyBDDoM > 31 SET @MonthlyBDDoM = 31
    -- Adjust the start time to match the next day of month that matches the interval
    DECLARE @MonthlyBDStartTime DATETIME; SET @MonthlyBDStartTime = DATEADD(DAY, (31 - DATEPART(DAY, @StartTime) + @MonthlyBDDoM % 31), @StartTime)
    -- This loop is used multiple times to search for the next valid date that falls on the desired day of month
    WHILE(DATEPART(DAY, @MonthlyBDStartTime) <> @MonthlyBDDoM) BEGIN
    SET @MonthlyBDStartTime = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDStartTime) + @MonthlyBDDoM) % 31, @MonthlyBDStartTime)
    END
    IF DATEADD(MINUTE, @Duration, @MonthlyBDStartTime) > @Now BEGIN
    SET @NextMaintenanceWindow = @MonthlyBDStartTime
    END ELSE BEGIN
    -- Calculate the total number of completed intervals
    DECLARE @MonthlyBDNumberOfCompletedIntervals INT; SET @MonthlyBDNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @MonthlyBDStartTime, @Now) AS DECIMAL) / @MontlhyBDInterval, 0, 0)
    -- Calculate the next interval
    DECLARE @MonthlyBDNextInterval DATETIME; SET @MonthlyBDNextInterval = DATEADD(MONTH, @MonthlyBDNumberOfCompletedIntervals * @MontlhyBDInterval, @MonthlyBDStartTime)
    WHILE(DATEPART(DAY, @MonthlyBDNextInterval) <> @MonthlyBDDoM) BEGIN
    SET @MonthlyBDNextInterval = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDNextInterval) + @MonthlyBDDoM % 31), @MonthlyBDNextInterval)
    END
    -- Recalc the next interval if the next interval plus the expected duration is in the past
    IF DATEADD(MINUTE, @Duration, @MonthlyBDNextInterval) < @Now BEGIN
    SET @MonthlyBDNextInterval = DATEADD(MONTH, (@MonthlyBDNumberOfCompletedIntervals + 1) * @MontlhyBDInterval, @MonthlyBDNextInterval)
    WHILE(DATEPART(DAY, @MonthlyBDNextInterval) <> @MonthlyBDDoM) BEGIN
    SET @MonthlyBDNextInterval = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDNextInterval) + @MonthlyBDDoM % 31), @MonthlyBDNextInterval)
    END
    END
    SET @NextMaintenanceWindow = @MonthlyBDNextInterval
    END
    END
    END
    INSERT INTO @NextServiceWindow VALUES (@ScheduleToken, @RecurrenceType, @NextMaintenanceWindow, @Duration, @IsGMTTime)
    RETURN
    END
    Thanks in advance for any suggestions!

    What an ungodly amount of the code for the task!
    I tried
    SELECT * FROM SCCM_GetNextServiceWindow('00811A9E08221600', 4)
    Which is said mean "Occurs the Third Monday of every 1 month(s)" and it returned 2015-03-17. Which is a Tuesday. But it is the third Tuesday.
    Turns out that I have British settings on that instance, DATEFIRST is 1. If do SET DATEFIRST 7, I get 2015-03-23. Which is a Monday, but the wrong one.
    The current setting of DATEFIRST can be detected with @@DATEFIRST, and that would make the code even more complex.
    My gut reaction would be to start over and do it all in C#, where at least I don't have to bother about SET DATEFIRST.
    Or maybe first inspect that the ScheduleToken is correct. Maybe it is, but to me that is just an incomprehensible hex string.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Can we Call Custom function in Background? VERY URGENT

    Hi All,
    Can one one tell me can we call a custom function module in background. Is it possible or not. If yes plz tell how.
    In the custom function module I am updating a data base table using UPDATE statement. Can help me on this issue.
    Thanks
    Yathish

    Hi,
    1)
    Yes..You can call a customer function module in BACKGROUND ...
    Steps
    1 Make the custom FM as remote enabled..
    2 CALL FUNCTION 'ZFUNC' IN BACKGROUNG TASK
    2) Yes..You can write UPDATE statement..
    Thanks,
    Naren

  • Cr XIR1 to create a custom function to change the timestamp of a field

    Post Author: palm
    CA Forum: Crystal Reports
    Hi,
    I am trying to create a custom function to change the timezone of a field in the report depending on the timezone selected by the user in the prompt
    I wrote a SQL Expression to do this , but i ended up creating a bunch of expressions for each time zone ,
    So i am thinking of custom fuction some thing like
    TimeZoneConvertor:
    Fuction(TimeStampField ,  Timezone)
    Returns: Timestamp field with newtimezone as selected by user
    Hope you get this and please give me some kind of ideas to acheive this
    Thanks in Advance!!!!!!!!

    Hi
    goto se37...here u need to create a function group... then u need to create a function module. inside assign import/export parameters. assign tables/exceptions. activate the same. now write ur code within the function module
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
    Look at the below SAP HELP links, These links will show you the way to create a Function Module
    http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm

  • Inconsistent Errors when processing  IDocs using custom Function Module

    I am encountering a most perplexing error. Here is the situation.
    We have a custom function module to update data in the EH&S system. We are having a bizarre error occurring. This is the basic processing of the function module:
    1. IDoc data is read and loaded into an internal table.
    2. Data is run through a series of checks to determine if the data is valid for entry into the system.
    3. After validation we use function module  C1F2_SUBSTANCES_READ_WITH_REF to read  characteristic data for the  substance. This data is used to validate whether current data exists to allow for loading of the IDoc data. (This is the step where the IDoc is receiving an error even if the data is valid. This only occurs if we are processing a large amount of Idocs and one IDoc contains valid data and another invalid data for the same substance. It occurs even if the Idocs are not processed in sequence.  If individually processed or reprocessed after initial failure they pass. This is what is so confusing!) If it exists, a flag is set and  the data is loaded using function module BAPI_BUS1077_CHANGE to modify the data.
    4. If the flag is set to allow further processing, the function module C1F2_SUBSTANCES_READ_WITH_REF is used again to select different characteristic data for the substance. A similar validation process occurs and if it passes, data is loaded using BAPI_BUS1077_CHANGE to update and BAPI_BUS1077_CREATE to create new data.
    Here is the situation:
    When processing one valid record for one substance, the record loads successfully.  When processing multiple valid records (all are valid) for one substance, they all load successfully.  The problem occurs when attempting to load valid and invalid records for the same substance.  Some times the program successfully loads the valid data (as expected).  Other times, it will not load any records.  It is not consistent!
    The order of IDoc processing does not have an impact on the success of the load.  Whether the valid or invalid record processes first does not have an impact on the success of the valid substance load.
    Does anyone have ANY Idea of what is going on? I am clearing all fields in the function module before processing occurs. I cannot find what is causing the error to occur.
    HELP!
    Jim Hardy

    I have some further information. It seems that if data for a substance is sent in two separate Idocs, one with valid and one with invalid data, As long as the two IDocs are processed consecutively, they process correctly. If they are separated by IDocs containing other substance information, they fail.
    thanks
    Jim

Maybe you are looking for