Advanced User Defined Functions - Handling Contexts

Hi All,
Are there any blogs on Advanced User Defined functions? I would like to get some information on how the queue is accessed, manipulation of the ResultList object etc.
Many Thanks,
Sandeep

Hi,
This blog talks about context handling
/people/riyaz.sayyad/blog/2006/04/23/introduction-to-context-handling-in-message-mapping
This is will give you a clear idea and will be hwlpful for sure
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/9202d890-0201-0010-1588-adb5e89a6638
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/190eb190-0201-0010-0ab3-e69f70b6c257
Thanks
Prakash

Similar Messages

  • Advanced User Defined Function

    Dear All,
    I have a target structure as follows:
    <Item>
       <Record10>
          <RecordType>
          <BankCode>
          <AccountID>
          <Amount>
       </Record10>
       <Record50>
          <RecordType>
          <Segment1>
          <segment2>
          <segment3>
       </Record50>
    </Item>
    I want to fill the elements in the Record50 in a special way by using some logic. Sometimes I may have to create multiple Record50 structures. So I'm using an advanced user defined function to do this.
    My mapping is as follows:
    Source Structure -> myFunction()->Record50
    And in myFunction() I wrote the following piece of code:
    result.addValue("50");
    result.addValue("PayRef1");
    result.addValue("Address");
    result.addValue("Nil");
    I expect the output to be:
       <Record50>
          <RecordType>50</RecordType>
          <Segment1>PayRef1</Segment1>
          <segment2>Address</segment2>
          <segment3>Nil</segment3>
       </Record50>
    But the output is like this:
    <Record50>50</<Record50>
    <Record50>PayRef1</<Record50>
    <Record50>Address</<Record50>
    <Record50>Nil</<Record50>
    Can somebody tell me how to proceed? I tried to insert a context change in the beginning, but then the Record50 itself is not appearing.
    Thanks,
    Sandeep

    Hi,
    Advanced UDF will not create you like you expected.
    You need to do like this
    Source>myFunction1()-><RecordType>
    And in myFunction() you do code:
    result.addValue("50");
    Source>myFunction2()-><Segment1>
    And in myFunction2() you do code:
    result.addValue("PayRef1");
    so on..
    Thanks,
    Prakash

  • User-Defined Function and Context Manipulation

    Hi Mapping Gurus, I need your help.
    I have a user-defined function and one of my input parameter (c) is in a loop (EDI segment).  So one, if I execute my function I get:
    Exception:[java.lang.ArrayIndexOutOfBoundsException: 0]
    If I change the context or use the remove context node function it’s working but it’s always taking the first row in consideration since I'm using c[0] .  Here is the logic:
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[0]"'";
    So since c is an array [], I have tried different logic to get to the right row.
    1- I tried using another parameter (e) to pass a counter or an index to my function.  So each time it's looping, it's passing a new value to the function but I’m still getting the first row and I’m not to sure why?
    int G = Integer.parseInt(e[0]);  // e[] = My counter field
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    2- I tried using a parameter stored in the container:
    String Num;
    Num = (String)getParameter(“counter”);
    if (Num == null)  G = 0;
    else
    G = Integer.parseInt(Num);
    G = G + 1;
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    Num = "" + G;
    setParameter(e[0], Num);
    and I’m still getting the first one, look like it’s using a different container each time it’s looping so the Value is always the same?
    4- I created a new user-defined function with the container logic, then it’s working but I’m back to the same problem in my main function, it’s only looking at e[0] for my counter all the time.
    5- I tried using the Seeburger Java Variables and guess what in the main fonction, as new UDF,... and guess what, same result!
    So anybody out there that was able to get UDF's working into a multiple context scenario?
    Am I missing something?
    I will reward points and beer for any help!

    This is one of the text with passing a counter to the function to try to go to the right row in the array since I'm doing a remove context and I'm getting all the d_234's:
    public void ReadTable(String[] a,String[] b,String[] c,String[] d,String[] e,ResultList result,Container container){
    int G = Integer.parseInt(e[0]); // My counter
    String var;
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    Now this one was with the internal container logic:
    int G;
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String Num;
    Num = (String)getParameter(e[0]);
    if (Num == null)  G = 0;
    else
    G = Integer.parseInt(Num);
    G = G + 1;
    Num = "" + G;
    setParameter(e[0], Num);
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    And now with the Seeburger Variables:
    int G;
    try {
    VariableBean be=VariableFactory.getVariableInstance("");
    G = Integer.parseInt(String.valueOf(be.getStringVariable("yves")));
    } catch (Exception f) {
    throw new RuntimeException(f);
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    try {
    G = G + 1;
    Num = "" + G;
    VariableBean be=VariableFactory.getVariableInstance("");
    be.setStringVariable("yves",Num);
    catch (Exception f) {
    throw new RuntimeException(f);
    All 3 logics were returning always the first row or a counter of 1 if the logic is in the main ReadTable function.

  • 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

  • How to check empty idoc fields in user defined function

    Dear All,
    I am working on an IDOC to file scenario. In my user defined function, I want to check whether a particular field of the idoc is populated. I can perform this test in message mapping by comparing the field with an empty constant.
    How can I do the same test in an advanced user defined function? I have tried all the following, but none has worked so far
    If (a.length == 0) ….
    If (a[0].length == 0) …
    If (a[0] == “”) …
    If (a[0] == “ “)…
    Am I doing something wrong?
    Thx/Farshad

    To check whether an element is not available:
    if (a.length == 0)
    but you have to set cache to context. If you set cache to queue, it will not work, as in this case the context changes are part of the array a.
    To check whether an element is empty:
    if (a[0].equals(""))
    Regards
    Stefan
    Message was edited by: Stefan Grube
    Message was edited by: Stefan Grube

  • How many types of user defined functions are there?

    how many types of user defined functions are there?

    Hi Ramakrishna,
    A user-defined function is only visible in the message mapping in which you created it. You can insert the function in the data-flow editor as a standard function by using the User-Defined function category.
    You can use the following user-defined functions:
    1.Simple functions, which can process individual field input values for each function call. Simple functions therefore expect strings as input values and return a string.
    2.Advanced functions, which can process several field input values for each function call. You can import either all field values of a context or the whole queue for the field in an array before calling the function. For more information, see Advanced User-Defined Functions.
        go through :
    http://help.sap.com/saphelp_erp2004/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
         Advanced user-defined functions, which can process more than just individual field values.Instead, you can import a complete context or an entire queue for a field as an array before your function is called
        go through :
    http://help.sap.com/saphelp_erp2004/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/content.htm
    *Pls: Reward points if helpful*
    Regards,
    Jyoti

  • 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

  • How to resolve the error while using user defined function.

    EPN Assembly file
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
    xmlns:jdbc="http://www.oracle.com/ns/ocep/jdbc"
    xmlns:spatial="http://www.oracle.com/ns/ocep/spatial"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/osgi
    http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.bea.com/ns/wlevs/spring
    http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd
    http://www.oracle.com/ns/ocep/jdbc
    http://www.oracle.com/ns/ocep/jdbc/ocep-jdbc.xsd
    http://www.oracle.com/ns/ocep/spatial
    http://www.oracle.com/ns/ocep/spatial/ocep-spatial.xsd">
         <wlevs:event-type-repository>
              <wlevs:event-type type-name="TestEvent">
                   <wlevs:class>com.bea.wlevs.event.example.FunctionCEP.TestEvent</wlevs:class>
              </wlevs:event-type>
         </wlevs:event-type-repository>
         <wlevs:adapter id="InputAdapter"
              class="com.bea.wlevs.adapter.example.FunctionCEP.InputAdapter">
              <wlevs:listener ref="inputStream" />
         </wlevs:adapter>
         <wlevs:channel id="inputStream" event-type="TestEvent">
              <wlevs:listener ref="processor" />
         </wlevs:channel>
         <wlevs:processor id="processor">
              <wlevs:listener ref="outputStream" />
              <wlevs:function function-name="sum_fxn" exec-method="execute">
              <bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
              </wlevs:function>
         </wlevs:processor>
         <wlevs:channel id="outputStream" event-type="TestEvent">
              <wlevs:listener ref="bean" />
         </wlevs:channel>
         <bean id="bean" class="com.bea.wlevs.example.FunctionCEP.OutputBean">
         </bean>
    </beans>
    Event class
    package com.bea.wlevs.event.example.FunctionCEP;
    public class TestEvent {
         private int num_1;
         private int num_2;
         private int sum_num;
         public int getSum_num() {
              return sum_num;
         public void setSum_num(int sumNum) {
              sum_num = sumNum;
         public int getNum_1() {
              return num_1;
         public void setNum_1(int num_1) {
              this.num_1 = num_1;
         public int getNum_2() {
              return num_2;
         public void setNum_2(int num_2) {
              this.num_2 = num_2;
    Adapter class
    package com.bea.wlevs.adapter.example.FunctionCEP;
    import com.bea.wlevs.ede.api.RunnableBean;
    import com.bea.wlevs.ede.api.StreamSender;
    import com.bea.wlevs.ede.api.StreamSource;
    import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
    public class InputAdapter implements RunnableBean, StreamSource {
    private StreamSender eventSender;
    public InputAdapter() {
    super();
    public void run() {
         generateMessage();
    private void generateMessage() {
         TestEvent event = new TestEvent();
         event.setNum_1(10);
         event.setNum_2(20);
         eventSender.sendInsertEvent(event);
    public void setEventSender(StreamSender sender) {
    eventSender = sender;
    public synchronized void suspend() {
    Output Bean class
    package com.bea.wlevs.example.FunctionCEP;
    import com.bea.wlevs.ede.api.StreamSink;
    import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
    import com.bea.wlevs.util.Service;
    public class OutputBean implements StreamSink {
         public void onInsertEvent(Object event) {
              System.out.println("In Output Bean");
              TestEvent event1 = new TestEvent();
              System.out.println("Num_1 is :: " + event1.getNum_1());
              System.out.println("Num_2 is :: " +event1.getNum_2());
              System.out.println("Sum of the numbers is :: " +event1.getSum_num());
    Function Class
    package com.bea.wlevs.example.FunctionCEP;
    public class TestFunction {
         public Object execute(int num_1, int num_2)
              return (num_1 + num_2);
    config.xml file
    <?xml version="1.0" encoding="UTF-8"?>
    <wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
    xmlns:jdbc="http://www.oracle.com/ns/ocep/config/jdbc">
         <processor>
              <name>processor</name>
                   <rules>
                   <view id="v1" schema="num_1 num_2">
                        <![CDATA[
                             select num_1, num_2 from inputStream     
                        ]]>
                   </view>
                   <view id="v2" schema="num_1 num_2">
                   <![CDATA[
                   select sum_fxn(num_1,num_2), num_2 from inputStream // I am getting error when i am trying to call this function
                   ]]>
                   </view>
                   <query id="q1">
                        <![CDATA[
                             select from v2[now] as num_2*     // Showing error while accessing the view also               ]]>
                   </query>
              </rules>
         </processor>
    </wlevs:config>
    Error I am getting is :
    Invalid statement: "select >>sum_fxn<<(num_1,num_2),age from inputStream"
    Description: Invalid call to function or constructor: sum_fxn
    Cause: Probable causes are: Function name sum_fxn(int,int) provided is invalid, or arguments are of
    the wrong type., or Error while handling member access to complex type. Constructor sum_fxn of type
    sum_fxn not found. or Probable causes are: Function name sum_fxn(int,int) provided is invalid, or
    arguments are of the wrong type., or Error while handling member access to complex type.
    Constructor sum_fxn of type sum_fxn not found.
    Action: Verify function or constructor for complex type exists, is not ambiguous, and has the correct
    number of parameters.
    I have made a user defined function in a java class and configured this function in the EPN assembly file under the processor tag.
    But when i am trying to access the function in the config.xml file , it is giving me an error in the query.
    Please provide urgent help that how to write the exact query.

    Hi,
    In the EPN Assembly file use
    <bean class="com.bea.wlevs.example.FunctionCEP.TestFunction"/>
    instead of
    <bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
    Best Regards,
    Sandeep

  • User Defined Function VS join - Performance....

    Hi All,
    while linking the mulitple table and getting the values ....which one is the best ?
    Joining or User defined function.....
    single row function
    select a.name , get_salary(empid) from emp a;
    Note : get_salary function will return the salary from salary tables.
    Using joins
    select a.name ,b.salary from emp a, salary b
    where a.empid=b.empid;
    which is the performancewise best ?
    also if you give any related document also fine.
    Thanks in advance.
    Edited by: BASKAR NATARAJAN on Jan 6, 2011 10:09 PM

    Don't use such functions for joins. The function itself has to query the salary table. It will run the query against the salary table separately for each row that it reads from the emp table. You will end up with multiple recursive calls and possibly inconsistency in the output. (Imagine what would happen if the salary table were updated and commited while this query was running -- some rows would have been read with the pre-update values and others with the updated values).
    Specifying the join in the query ensures that a single SQL call is executed and provides read consistency across all the rows it reads. And it is much faster, being one single parse and execute.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • Error when use User-Defined Function

    I just create User defined function "getfilename" and I put there:
    "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; ".
    But In test mapping I have worning:
    "Runtime exception during processing target field mapping /ns1:Z_KBFI_INPUT_FILE/IS_IFILE/FILE_NAME. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._KBFIMsgMapping_ method get_fname$[com.sap.aii.mappingtool.tf3.rt.Context@37d4662c] com.sap.aii.mappingtool.tf3.MessageMappingException: Runtime exception during processing target field mapping /ns1:Z_KBFI_INPUT_FILE/IS_IFILE/FILE_NAME. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._KBFIMsgMapping_ method get_fname$[com.sap.aii.mappingtool.tf3.rt.Context@37d4662c] at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:284) at com.sap.aii.mappingtool.tf3.AMappingProgram.processNode(AMappingProgram.java:238)...."
    And in RWB in Communication Channel Monitoring I can not see file name in the payload.
    Maby I do something wrong, please tell me.

    my source file 200610.txt is like this:
    HR 0610 061030 061021
    DR 03 C 0610 820114 00010111 0000015000 PLN descr...
    DR 03 D 0610 403201 00010111 0000015000 PLN descr..
    TR 0000000002
    Then in sxmb_moni in inbound message (payload) I have:
    <?xml version="1.0" encoding="utf-8" ?>
    - <ns:KBFIMsgTypeSource xmlns:ns="http://p4.org/xi/KBFI/Interface">
    - <FIRecordset>
    - <HeaderLine>
      <LineKey>HR</LineKey>
      <PostingPeriod>0610</PostingPeriod>
      <PostingEndDate>061030</PostingEndDate>
      <PostingDate>061021</PostingDate>
      </HeaderLine>
    - <PostingLine>
      <LineKey>DR</LineKey>
      <ServerID>03</ServerID>
      <DCFlag>C</DCFlag>
      <PostingPeriod>0610</PostingPeriod>
      <GLAccount>820114</GLAccount>
      <SubAccount>00010111</SubAccount>
      <NetValue>0000015000</NetValue>
      <Currency>PLN</Currency>
      <Description>descr...</Description>
      </PostingLine>
    - <PostingLine>
      <LineKey>DR</LineKey>
      <ServerID>03</ServerID>
      <DCFlag>D</DCFlag>
      <PostingPeriod>0610</PostingPeriod>
      <GLAccount>403201</GLAccount>
      <SubAccount>00010111</SubAccount>
      <NetValue>0000015000</NetValue>
      <Currency>PLN</Currency>
      <Description>descr..</Description>
      </PostingLine>
      </FIRecordset>
      </ns:KBFIMsgTypeSource>
    But I don't have payload for Response (black and white flag).
    In DynamicConfiguration i have:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Response
      -->
    - <SAP:DynamicConfiguration xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileSize">141</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileType">txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileTimestamp">20061212T121622Z</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileEncoding">ISO646-US</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileName">200610.txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="Directory">/usr/sap/PXD/put/archive</SAP:Record>
      </SAP:DynamicConfiguration>

  • User Defined Function is not recognizing java class in IR.

    Hi All,
    i have written one normal java class, and i imported that java class into IR using imported Archive as a .jar file,
    it will add just two values .
    now in message mapping i created one user defined function in that
    iam trying to call this java class. while testing it is showing error as cannot resolve symbol java class name
    so experts please help me in this or it would be appreciate if any one will provide
    step by step process of one java class and one USD just to add two numbers.
    thanks in advance,
    jasmine .

    Hi,
    The steps are as follows:
    1) Create a java file with .java extension.
    2)Compile it to create a .class file.
    3) Create a zip file for this .class file using any compressed archive program(ex-winrar)
    4) Upload this zip file as an imported archive ,save and activate.
    When you go to this archive,below , you can see your .class file with the older path,for below ex:
    ObjRecord.class     jxl/biff/drawing/
    you have to give following entry in imports section:
    jxl.biff.drawing.ObjRecord;
    Please try this and let us know if this works.
    Thanks.
    Regards,
    Shweta

  • Using a User Defined Function as a constraint within a temporary table.

    Hello, 
    I am trying to create a temp table that uses a UDF in a constraint. I'm getting the following error message 
    Msg 4121, Level 16, State 1, Line 1
    Cannot find either column "dbo" or the user-defined function or aggregate "dbo.CK_LoseTeamSportExists", or the name is ambiguous.
    I've tested the function and it works in other contexts. Any idea? All code below:  
    Thanks, 
    - Bryon
    create function dbo.CK_LoseTeamSportExists (@loseteam int, @sportid int)
    returns bit
    as
    begin
    declare @return bit
    if exists 
    select TeamID, sportid from Link_TeamSport
    where 
    TeamID = @loseteam 
    and
    SportID = @sportid
    set @return = 1
    else set @return = 0
    return @return
    end
    go
    create table #check
    SportID int
    ,WinTeamID int
    ,LoseTeamID int
    ,check 
    (dbo.CK_LoseTeamSportExists(LoseTeamID,SportID) = 1)

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I am trying to create a temp table that uses a UDF in a constraint. <<
    You do not understand how SQL or any declarative language works! 
    We do not use UDFs (procedural programming)
    We do not use bit flags (assembly language).
    We do not use temp tables (mag tape files).
    We do not use integer as identifiers (what math do you do on them?)
    Your silly “Link_TeamSport” implies a pointer chain; we have no links in SQL. Where is the DDL? 
    Constraints are always predicates in any declarative language. 
    Do you know why you have to create a local variable to pass the non-relational flag back to the calling environment? FORTRAN I and II! These early languages has to use hardware registers in the first IBM computers to return results. In your ignorance, you mimic
    them! 
    We do not use if-then-else control flow in any declarative language. We have CASE expressions that we put where you have a local variable getting an assignment. 
    I see you also put the comma at the start of the line. We did that with punch cards, so we could re-use them 50 years ago. 
    In SQL, we would use REFERENCES to assure a team reference exists. We use names for teams because they are entities, not quantities: 
    CREATE TABLE Game_Results
    (sport_name CHAR(10) NOT NULL PRIMARY KEY,
     win_team_name CHAR(12) NOT NULL
      REFERENCES Teams(team_name)
       ON DELETE CASCADE,
     lose_team_name CHAR(12) NOT NULL
      REFERENCES Teams(team_name)
       ON DELETE CASCADE,
     CHECK (win_team_name <> lose_team_name)); 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • User Defined Function Missing In EF 6?

    I'm using Entity Framework 6 and I have imported several user-defined functions like the one shown below, but it doesn't
    appear when I try to select the function in intellisense and the model doesn't recognize this function as a method on the EF context.  How do I call this function in EF 6?
    <Function Name="getCycleDate" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" ReturnType="date" />
    MCSD .NET developer in Dallas, Texas

    Hello DallasSteve,
    >> I have imported several user-defined functions like the one shown below,
    What is your UDF? If it is a TVF, starting from EF5, it is supported already:
    https://msdn.microsoft.com/en-us/data/hh859577.aspx
    However, it is a scalar function, unfortunately, as far as I know, even entity framework 6 doesn't suport generating calls for scalar functions by default. The workaround is to write a custom method like this inside your DbContext class, for example, there
    is scalar function as:
    CREATE FUNCTION [dbo].[Function20150410]
    @param1 int,
    @param2 int
    RETURNS INT
    AS
    BEGIN
    RETURN @param1 + @param2
    END
    When we imported it to the model, it would generate code in SSDL as:
    <Function Name="Function20150410" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" ReturnType="int">
    <Parameter Name="param1" Type="int" Mode="In" />
    <Parameter Name="param2" Type="int" Mode="In" />
    </Function>
    While, it will not generate a call method as a store produce, for a workaround, we could write a custom function as:
    [DbFunction("DFDBModel.Store", "Function20150410")]
    public ObjectResult<int> GetContentByIdAndCul(int id, int culture)
    var objectContext = ((IObjectContextAdapter)this).ObjectContext;
    var parameters = new List<ObjectParameter>();
    parameters.Add(new ObjectParameter("Id", id));
    parameters.Add(new ObjectParameter("Culture", culture));
    return objectContext.CreateQuery<int>("DFDBModel.Store.Function20150410(@Id, @Culture)", parameters.ToArray()).Execute(MergeOption.NoTracking);
    I suggest that you write this custom method a separate cs file since if we update the model, the original context call would be reset.
    Calling it as:
    using (DFDBEntities db=new DFDBEntities())
    var result = db.GetContentByIdAndCul(1, 1).FirstOrDefault();
    }s
    Regards.
    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.
    Click
    HERE to participate the survey.

  • 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

Maybe you are looking for