Questions about user-defined functions

Hello all,
I've got some questions about user-defined function in a message mapping:
1) How can I get the current date/time in format yyyy-mm-dd hh:mm:ss ? What is the java code for this?
2) I want to use the StreamTransformation constant TIME_SENT, only this is not in the right time-zone.
It is GMT and it should be CET (1 hour difference). How can I convert this in Java?
Can somebody help me with this?
Thanks in advance.
Kind regards,
Marco van Iersel

Hi Marco,
If the date format is fixed as you have mentioned,please use this:
                                String test = "2009-03-27 23:15:30";
          String test1 = test.substring(11,13);
          if(!test1.equals("23"))
          int a = Integer.parseInt(test1);
          int b = a+1;
          System.out.println("b"+b);
          String c = Integer.toString(b);
                                test = test.substring(0,10)+" " + c + test.substring(13,19);
                                return test;
          if(test1.equals("23"))
          test = test.substring(0,10)+ " 00" + test.substring(13,19);
          return test;
                                else return "";
Kindly let me know if this works.
Thanks.
Regards.
Shweta

Similar Messages

  • Question in User Defined Functions....

    Hi,
    Can I develop new User Defined functions in ABAP programming language rather than in Java? If Yes, how and if not why?
    Sorry, if this is a petty question as I am in the process of learning XI.
    Thanks,
    Monica

    Hi,
    yes it's a stantard function module
    which you can call from abap mapping
    there's no possibility to create user defined function
    that you could use in graphical mapping in abap
    take a look at this document on how to do abap mapping:
    https://websmp103.sap-ag.de/~sapdownload/011000358700001795162005E/HowToIDocXMLToFlat.pdf
    Regards,
    michal
    Message was edited by: Michal Krawczyk

  • Multi mapping question using user defined function

    Hi,
    I have a message with multiple occuring nodes (i.e. one message with multiple orders (header + detail)) that I need to map to a idoc. I need to filter out of the source based on order type (in header) from creating an idoc.. How do I do it using user defined function + message mappping ?
    mad

    All - Thanks much.. Here is my requirement that is no solved by regular mapping
    <Root>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
      </Recordset>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
    </Recordset>
    <Root>
    As you see above, each recordset has order transaction. One Root message can contain multiple of these. So, when I map to the IDOC, I want to filter out any ord_type <> XX.
    If I use regular graphical map, it only looks at first recordset and accepts all or rejects all.
    I need to use UDF. In the UDF, what comes in as input ? Resultset is output -correct ? Now how do I usse graphical mapping with UDF to generate the correct target info

  • About user defined function in user defined rule

    Hi,
    I am wondering if I can use a user defined function in a user defined rule in oracle sem.. I've seen examples of user defined function used in sparql query filter clause in that dev. guide. However, I don't know if I can define a function in oracle sem. database and use it in the rule body or head. For example, I want to define a duration function that calculate the date difference between two dates.  Then, I want to define a rule like this: event1 :has_start_date d1 and event1: has_end_date d2 and duration (24, d1,d2) then event1:date_satisfiable "yes". Does oracle support this kind of rule? Thank you very much.
    Hong

    Hi Hong,
    The user defined rules are quite similar to a CONSTRUCT SPARQL query, where the FILTER clause is implemented in SQL.
    I think we have already written rules like you want :
    You have to write a PL/SQL FUNCTION that returns a NUMBER (not a BOOLEAN, think you are in SQL) :
    FUNCTION DURATION(HOURS INTEGER, D1 VARCHAR2, D2 VARCHAR2) RETURN INTEGER
    IS
    BEGIN
         IF(.................)
            THEN RETURN 1;
            ELSE RETURN 0;
         END IF;
    END;
    Maybe you will have to GRANT EXECUTE ON DURATION TO MDSYS.
    Then include the following in the FILTER clause of the Rulebase "[owner].duration (24, TO_CHAR(d1),TO_CHAR(d2)) = 1"
    Hope this helps.

  • About User defined Functions

    Hi,
    Do anyone know what are user defined functions .. and what's the procedure to create a user defined function in sql or pl/sql ??
    Regards

    Is this Seshu or someone else asking with his login? The reason for this is earlier there was a post from some Param Reddy from Kurnool asking with his login.
    If it is Seshu himself, I've seen you using the word 'function' a couple of time earlier.
    Re: Comma separation
    and
    Re: Data Hiding
    If you go and see in SQL Reference, you find two types of functions. SQL built-in and User-defined.
    Cheers
    Sarma.

  • Regarding sqlserver user defined functions

    Hi,
      How to write user defined functions dynamically?
    Please help me in any situation

    Hi Bellam,
    You post same question 2 times. Please avoid this practice on Forum, I 
    have merged the same thread  into this thread.
    As other post, dynamic SQL is not allowed in user defined functions (UDF), however, you can execute dynamic SQL store procedure with parameter. A user-defined function takes zero or more input parameters and returns either a scalar value or a table. There
     is different between user-defined stored procedures and
    user-defined function. User-defined functions do not support output parameters.
    For more information, you can review the article about User-Defined Functions(UDF).
    http://technet.microsoft.com/en-us/library/ms191007.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • How can I use Seeburger java functions on SAP XI's user defined functions?

    Hi All,
    As my title implies; how can I use Seeburger java functions on SAP XI's user defined functions?  I've tried searching over the net in tutorials regarding this topic but I failed to find one; can someone provide me information regarding my question? thanks very much.
    best regards,
    Mike

    Hi Mike !
    You should check your documentation about which java classes you need to reference in the "import" section of your UDF. And also deploy the java classes into the java stack or include them as a imported archive in integration repository...it should be stated in the seeburger documentation.
    What kind of functions are you trying to use?
    Regards,
    Matias.

  • Java class within user defined function

    Hi all,
    in order to have a JDBC-lookup java function "globally" in XI i created a java class and imported it to XI as an imported Archive (i have to do the lookup within a mapping). I then can include the class to a user defined function. However the problem is now that this works fine within one Software Component Version but when i want to use it in several SWCV i have to import the jar to every SWCV. My question is therefore if anybody has already had this problem and if there is another possible solution - maybe deploying the class to XI using SDM?
    Thank you for your thoughts.
    Mathias

    hi Markus,
    >>>>My question is therefore if anybody has already had this problem and if there is another possible solution - maybe deploying the class to XI using SDM?
    if you do that then you'll have to remember about it
    every time you import a new SP or upgreade your XI
    this is not standard so SAP may always overwrite it
    and your interfaces will stop working
    consider importing it for every SWCV  
    Regards,
    michal

  • User define Function at Mapping Time

    Hello Everyone,
    My requirement is I input the one value to the user define function (at mapping time). That function calls the RFC to R/3 system and return the 3 output values. Now my question is how can I return 3-output value from the user define function.
    What is the other possibility to solve this type of problem?
    Where we have one input parameter and more than one output parameter.
    If any one did this kind of job. Please give me the idea how can I solve this.
    Regards,
    Gaurav Jain

    Hello Richard,
    Are you talking about <b>copy head to line</b> example given in MappingFunctionality.pdf.
    In my scenario:
    Input - NULL
    Output - OP1, OP2, RESULT
    And I write my Advance user define function as
    import com.sap.mw.jco.*;
    public void Lookupfunction(ResultList result, Container container){
    JCO.Repository mRepository;
    // Change the logon information to your own system/user
    JCO.Client mConnection = JCO.createClient(
        "100", // SAP client
        "user", // userid
        "pass", // password
        "EN", // language
        "hostid", // host name
        "00" ); // system number
    // connect to SAP
    mConnection.connect();
    // create repository
    mRepository = new JCO.Repository( "SAPLookup", mConnection );
    // Create function
    JCO.Function function = null;
    IFunctionTemplate ft = mRepository.getFunctionTemplate("ZTEST2");
    function = ft.getFunction();
    mConnection.execute( function );
    result.addValue( function.getExportParameterList().getString( "OP1" ) );
    result.addValue(function.getExportParameterList().getString( "OP2" ) );
    result.addValue(function.getExportParameterList().getString( "RESULT" ) );
    mConnection.disconnect();
    But it shows me only one field as output in mapping icon.
    so as per the mapping document i attach splitbyvalue over that but in the example only one field at the output side where i have three field.
    How can i solve the problem?
    Even i check in XI 2.0 System it doesn't show output at all.
    Thanks & Regards,
    Gaurav Jain
    Message was edited by: Gaurav Jain

  • User Defined Function (Part 2)

    Hi,
    István Korös has finally solved my problem on User Defined Function.
    See
    My objective was to write a simple UDF to represent the following formula which Gordon Du gave me:
    (DATEADD (s, -1, 
             DATEADD (mm, (DATEDIFF (m,0,@refdtzz ) + @mthnumber),  0)))
    However, the solution proposed by István, although it works perfectly, leaves me scratching my head. Let's see why?
    The only difference between my solution and that proposed by István is that István enclosed the UDF name between .
    I wonder how this can make the vital difference between a (simple query!) that works well and one that gets blocked.
    I tried several combinations of and am in for a few surprises, listed below. Can anybody explain what's going on?
    Solution proposed by István:
    CREATE FUNCTION [dbo].[udf_EndOfMonth]
    and executed as:
    select  [dbo].udf_EndOfMonth (@refdt1 , 1)
    Remarks: works perfectly
    If I execute the UDF with exaclly the same name as in CREATE, it does not work
    CREATE FUNCTION [dbo].[udf_EndOfMonth]
    and executed as:
    select  [dbo].[udf_EndOfMonth] (@refdt1 , 1)
    Error Msg: Must specify table to select from
    If I don't put the , the function is created, but the execution of the calling query returns error
    CREATE FUNCTION dbo.udf_EndOfMonth
    Remarks : Creation OK
    and executed as:
    select  dbo.udf_EndOfMonth (@refdt1 , 1)
    Error Msg: Must specify table to select from
    It seems that the only combination that works is that provided by István.
    This is surely a simple UDF.
    I don't know what to do if I attack a more complicated UDF.
    Grateful if anybody could help light my way.
    Thanks
    Leon Lai

    Hi Leon,
    As István has already pointed out, there is no documentation for those small differences to make the SQL work or not. He must be tested quite a few times to find the actual working code. This question can only be answered by the developer who made this part for B1.
    Thanks,
    Gordon

  • User-defined function in FILTER clause

    hi,
    can i create the user-defined functions and use them in the FILTER clause in the sem_match function? there are some built-in functions for the FILTER clasue. however, only one function (DATATYPE(literal)) support for date/time in the built-in functions. i want to implement some user-defined funcitons in the FILTER clause which can check time intervals in ontology. there are some functions about valid time in the WorkSpace Manager such as WM_OVERLAPS, WM_CONTAINS,WM_MEETS, etc. so, can i write some functions using the these valid time functions in WM and use them in the FILTER clause? thanks a lot in advance.
    hong

    Hi Hong,
    You don't need user-defined functions to do time interval comparisons. You can directly compare xsd:dateTime values with the built-in comparison operators: <, >, =, !=, <=, >=
    For example, the query pattern below could find events that happened during event1 if we have data such as:
    :event1 :startTime "2013-01-01T03:15:00Z"^^xsd:dateTime .
    :event1 :endTime "2013-02-01T02:15:00Z"^^xsd:dateTime .
    :event2 :startTime "2013-01-11T14:15:00Z"^^xsd:dateTime .
    :event2 :startTime "2013-01-14T12:15:00Z"^^xsd:dateTime .
    SELECT ?e2
    WHERE
    { :event1 :startTime ?e1_st; :endTime ?e1_et .
    ?e2 :startTime ?e2_st; endTime ?e2_et .
    FILTER (?e1_st < ?e2_st && ?e2_et < ?e1_et) }
    In general, it is trivial to convert interval relations such as meets and overlaps to conditions on start and end times.
    Hope this helps.
    - Matt

  • Error in User defined function for dynamic file naming

    Hi,
    While creating User Defined function with this following code for dynamic fieldname
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return ourSourceFileName;
    which options should i select for cache Value, Context, Queue
    for Augument , what name shd i mention.
    Regards,
    Varun

    Hi Varun,
    I guess I have answered a similar question just a few minutes before on very similar post from you. Just pasting the same here .................
    Are you trying to access the ASMA values from the SOAP header of the XI message for the source file name?
    First of all you need to Set the Sender File Adapter for Set ASMA and then file name. So it will work fine when you actually run the scenario end to end.
    But in the mapping tool when you test the mapping - there is not message header updated with the actual source filename - and whenever you try to read the FileName attribute in the message header from the UDF - it cannot find the object and returns a NullPointerException.
    I would suuggest for your mapping tool testing to be successful, have a check in the java code for null values,
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    If (ourSourceFileName != null)
       Return ourSourceFileName;
    Return "NoFileName.txt";
    Let us know if this works.
    Regards,
    Suddha

  • XI 7.0 Advnaced User Defined Function  how to check Cache Entire Queue ?

    Hi Friends ,
                       We are using XI 7.0 (PI)   . There is no Selection For Advanecd UserDefinedFunction .  I think in this version Both will perfom in the User DefinedFunction Itself .
               There is option for Context and Queue While we are creating Function . If we select Queue is it eqivalent to Check box of Cache Entire Queue ? Is My assuption is correct  ?
              I want to cache the Entire Queue  ? Can you please tell me about this.
              My environment is like
    Session Information
    Application:
    Design: Integration Builder
    User:
    Test
    Logon Language:
    English
    Server:
    xidev_XID
    Server Node:
    server0
    Runtime Environment
    Java version:
    1.4.2_13
    Java vendor:
    Sun Microsystems Inc.
    Version
    Service pack:
    10
    Release:
    645_VAL_REL
    Best Regards .,
    V.Rangarajan

    you advanced user defined functions are now known as 
    Enhanced Functions (Cache = Context or Cache = Queue)
    From Help -
    +Features
    Depending on which values are available in the cache for a user-defined function, different functions are available:
    ·        Simple Functions (Cache = Value)
    This function type can process individual input values of a field for each function call. Therefore, simple functions expect strings as input values and return a string.
    ·        Enhanced Functions (Cache = Context or Cache = Queue)
    This function type can process multiple input values of a field for each function call. Before you call the function, you can either import all the field values of a context or the whole queue for the field in an array.+
    Have this link as your reference - http://help.sap.com/saphelp_nw04s/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm

  • User defined function to find difference between dates

    format of dtActivityStartDate/dtActivityFinishDate: 2010-09-17 14:50:51.150
    usdFuncTimeCalc (vcActivityName,dtActivityStartDate, dtActivityFinishDate) -- user defined function
    i need to calculate time elapsed for that type of activity following are the rules:
    (If Process Request is the activity)
    Working Days: Monday through Saturday
    Hours of Operation: 9AM – 5PM
    only working hours of day need to the counted like for example if it is sep 15 11 Am is dtActivityStartDate & Sep 17 is dtActivityFinishDate is 10 Am. then time elapsed is 11am to 5pm on sep 15 , 9 to 5 on sep 16 & 9 to 10 on sep 17 so total should be
    6+ 8 + 1 = 15 hours + minutes.
    format of date time: 2010-09-17 14:50:51.150
    vcActivityName = Process Request
    Don't worry about process request...

    I hv modified the code to make it more generic inorder to suit any timings (customizable) from Monday - Saturday.
    declare
      -- ** b u s i n e s s _ h o u r s **
      -- business_hours returns the number of work houts (9 am through 5 pm,
      -- Monday through Saturday) between in_start_dt and in_end_dt.
      -- If in_start_dt > in_end_dt, the results will be <= 0.
      -- Holidays are not considered.
      in_start_dt DATE := to_date('15-SEP-2010 11:00:00','DD-MON-RRRR HH24:MI:SS');
      in_end_dt   DATE := to_date('17-SEP-2010 10:00:00','DD-MON-RRRR HH24:MI:SS');
      d          NUMBER; -- Hours of either start_dt or end_dt after midnight
      end_dt     DATE := GREATEST(in_start_dt, in_end_dt); -- In case dates were in wrong order
      return_val NUMBER; -- Total number of working hours
      start_dt   DATE := LEAST(in_start_dt, in_end_dt); -- In case dates were in wrong order
      start_time number := 9;
      end_time   number := 17;
    BEGIN
      WITH all_days AS(
        SELECT start_dt + LEVEL - 1 AS a_dt
          FROM dual
        CONNECT BY LEVEL <= 1 + TRUNC(end_dt) - TRUNC(start_dt))
          --SELECT SUM(12)
           SELECT SUM(end_time-start_time)
            INTO return_val
            FROM all_days
           WHERE TO_CHAR(a_dt,'Dy','NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun');
      dbms_output.put_line('Return_Val_1 : '||return_val);
      -- Adjust hours from start_dt, if necessary
      IF TO_CHAR(start_dt, 'Dy', 'NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun') THEN
         -- Calculate nbr of hours passed from midnight
         d := 24 * (start_dt - TRUNC(start_dt));
         dbms_output.put_line('d:'||d);
         IF d >= end_time THEN -- d has passed 5 PM (end_time)
            -- Don't count start_dt if it has passed the closing hours
            return_val := return_val - (end_time-start_time);
            dbms_output.put_line('if-d:'||return_val);
         ELSIF d > start_time and d < end_time THEN -- d has passed 9 AM but less than 5 PM
            -- Don't count the part of start_dt which has passed the opening hours
            return_val := return_val - (d - start_time);
            dbms_output.put_line('else-d:'||return_val);
         END IF;
      END IF;
      dbms_output.put_line('');
      dbms_output.put_line('Return_Val_2 : '||return_val);
      -- Adjust hours from end_dt, if necessary
      IF TO_CHAR(end_dt, 'Dy', 'NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun') THEN
         d := 24 * (end_dt - TRUNC(end_dt));
         dbms_output.put_line('d:'||d);
        IF d <= 9 THEN -- d < 9 AM
           -- Don't count end_dt itself
           return_val := return_val - (end_time-start_time);
           dbms_output.put_line('if-d:'||return_val);
        ELSIF d > start_time and d < end_time THEN -- d > 5 PM
          -- Don't count part of end_dt
          return_val := return_val - (end_time - d);
          dbms_output.put_line('else-d:'||return_val);
        END IF;
      END IF;
      dbms_output.put_line('');
      dbms_output.put_line('Return_Val_3 : '||return_val);
      IF in_start_dt > in_end_dt THEN
          return_val := -return_val;
      END IF;
      dbms_output.put_line('');
      dbms_output.put_line('Return_Val_4 : '||return_val);
    END;Plz note the following points of the code :
    1) You'll need to convert it a function, I just made it a declare..begin..end; block.
    2) I hv used the same timings for start & end as you hv mentioned.
    3) The 2 variables "start_time" and "end_time" take the opening & closing business hours respectively in a 24 hour format.
    4) You might want to remove the DBMS_OUTPUT ... stmts which I had added for debugging.
    It was an interesting code block to analyze ... :-)

  • User-defined function(java)

    hi expects,
    how to write user defined finction in javain meesage mapping.please help me.

    Hi Rohit,
    In order to create UDFs, you need to have a basic idea about using Core Java. Also, based on the kind of functonality of the code, you will need to know if you require any extra jar files.
    To create a UDF, all you need to do is click on LHS icon in the graphical mapping editor. Also, keep in min that the input and otput of a udf is always in strings.
    To test your functions, you can either use the test tab present in the mapping editor or you can even use the following editor(blog by Sravya):-
    /people/sravya.talanki2/blog/2006/07/24/integrating-java-editor-in-xi-integration-stack
    I think info will be enough for you to start off with creating and using UDFs:)
    This link for User Defined Functions,
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm
    Writing use defrined functions in XI is quite simple. Create a simple UDF, give the import parameters and then just go ahead with the logic coding and then return the output from the UDF.
    Just remember that all inputs and outputs to an UDF are always Strings.
    Cheers...
    Vasu
    <b>** REward Points if found useful **</b>

Maybe you are looking for

  • Turbo K7 Limited & XP 1800+ issue

    All,  I have the K7T Turbo limited edition board with bios upgraded to the latest version (3.6) and AMD 1.4GHz. I would like to upgrade the CPU to XP 1800+ but the system will not boot, it hung before POST. Would some kind souls give me a pointer how

  • Nano isn't recognised by Windows XP on US, 2 other ipods in family are.

    Recently replaced under warrantee, 4 Gig Nano isn't seen by Windows or Itunes. I've tried Itunes diagnostics help, none of it solved the issue, also the rest of the apple online help stuff. The strange thing is my wifes nano (brought 6 months ago) an

  • My usb is not working

    My last 4 days one of my usb port in MAc book air is not functioning. i reformatted the system still the same error persists. need help to troubleshoot the problem

  • Refresh Two selectOneChoice  on run time ADF rich client

    HI... i have two selectOneChoice .. the first from master table and the second from detail table i have create view link between the two VO . in the page.jspx i display the allies in the selectonechoice for bothe now.. first* i need to refresh the se

  • Unattend files and Server 2012 R2 RDS

    Hi I have a vdi implementation (managed, pooled vm's) , which is working fine as long as i don't create a custom unattend file. for exmaple, my desktops need to run some powershell scripts upon first logon, which i use to be able to do in Microsoft-W