Group by on Function return value

Dear All
I'm facing a problem with when I have a group by on the return value of a function.
Following is the scenario.
Im having the following select query which executes in less than millisec for more than 20k records.
SELECT T1.FIELD1,T1.FIELD2, MY_FUNCTION(T1.FIELD2) FROM TABLE T1 ;
But when I modify the above query in the following way for the same number of records, the performance is going down to more than 4 mts.
SELECT T1.FIELD1,T1.FIELD2, MY_FUNCTION(T1.FIELD2)FIELD3 FROM TABLE T1 GROUP BY T1.FIELD1,T1.FIELD3;
can any one please suggest me whats the best solution in this regard.
Thanks in advance
Narayanan

SQL> create or replace function get_sub(a varchar2)
  2  return varchar2
  3  is
  4  begin
  5   return substr(a,1,1);
  6  end;
  7  /
Function created.
SQL> select deptno, get_sub(ename) sub from emp;
    DEPTNO S
        20 S
        30 A
        30 W
        20 J
        30 M
        30 B
        10 C
        20 S
        10 K
        30 T
        20 A
        30 J
        20 F
        10 M
14 rows selected.
SQL> select deptno, get_sub(ename) sub, count(1)
  2  from emp
  3  group by deptno, get_sub(ename)
  4  /
    DEPTNO S   COUNT(1)
        10 C          1
        10 K          1
        10 M          1
        20 A          1
        20 F          1
        20 J          1
        20 S          2
        30 A          1
        30 B          1
        30 J          1
        30 M          1
        30 T          1
        30 W          1
13 rows selected.Rgds.
Everything which is not affected by aggregate functions
should be included into GROUP BY. And GROUP BY can't use
aliases but expressions only.
You have to think what exactly do you want to get
for FIELD02 - do you want get max/min/avg/count ?
Message was edited by:
dnikiforov
(I'm asking because your query probably should look like
SELECT T1.FIELD1,T1.FIELD2, MY_FUNCTION(T1.FIELD2) FIELD3 FROM TABLE T1 GROUP BY T1.FIELD1,T1.FIELD2
Message was edited by:
dnikiforov

Similar Messages

  • Unable to see function return values in Visual Studio 2013 debugger

    Hi!
    I can't see function return values in
    Microsoft Visual Studio Ultimate 2013
    Version 12.0.31101.00 Update 4
    Microsoft .NET Framework
    Version 4.5.51650
    Installed Version: Ultimate<o:p></o:p>
    as described in  http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx
    So what can I do to get this functionality back?
    MsdnMezzo

    Hi MsdnMezzo,
    Reference:
    http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx
    If use the same sample in the above blog provided by you, how about the result? Could you debug it with the same steps? I could debug it in my side using the VS2013.
    So to make sure that whether it is your VS IDE issue, please debug it with this sample, if it works well, I doubt that we would think about your specific project and the debugging steps.
    If so, to really repro this issue, could you share us a sample with one drive? You could upload your project to one drive and share us the downloaded link in your new reply, I will download and repro this issue in my side.
    Best Regards,
    Jack
    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.

  • Function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    I want to call Stored Procedure that return records and output parameter, from CVI
    I can get output parrameter but when I want to get records stream I recieve following wrror:
    function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    in Stored procedure I create table variable and and insert into string values
    when I remove usage of table variable the error desappear

  • Data Services Designer - Function returns value, but doesnt always populate

    Within my Query Transform I call a function that I pass a old Vendor code to a sql statement and it does a few lookups and cross references it returns a new value. My issue is sometime it doesnt put the value in the field. I know it has returned a value as I had the funtion print it out for me, so I can see the value that was passed and the returning value, but when I look in my table there is no value.
    I have added the function call for you to see it is very simple takes one parameter, I have also added the print out from my function, does anyone have any ideas??
    (This is under the field Vendor Code)
    P2CMM05_Look_UP_Vendor_Code(Query.LIFNR)
    6088     4800     PRINTFN     6/28/2011 9:27:48 AM     @@@@@@@@@@@ Ret_Vendor_code @@@@@@@@@@@   MCI_719
    6088     4800     PRINTFN     6/28/2011 9:27:48 AM     @@@@@@@@@@@ $Vendor_code @@@@@@@@@@@    MUR_51

    Within my Query Transform I call a function that I pass a old Vendor code to a sql statement and it does a few lookups and cross references it returns a new value. My issue is sometime it doesnt put the value in the field. I know it has returned a value as I had the funtion print it out for me, so I can see the value that was passed and the returning value, but when I look in my table there is no value.
    I have added the function call for you to see it is very simple takes one parameter, I have also added the print out from my function, does anyone have any ideas??
    (This is under the field Vendor Code)
    P2CMM05_Look_UP_Vendor_Code(Query.LIFNR)
    6088     4800     PRINTFN     6/28/2011 9:27:48 AM     @@@@@@@@@@@ $Vendor_code @@@@@@@@@@@    MUR_51
    6088     4800     PRINTFN     6/28/2011 9:27:48 AM     @@@@@@@@@@@ Ret_Vendor_code @@@@@@@@@@@   MCI_719

  • How to get a stored function return value (which is not a cursor)?

    I want to do so with ADO inside Visual Basic. I know how to call a stored procedure, but nothing I tried could help me in calling a stored function and getting its return code. Note that the function has no cursors within its argument or return code.
    Your quick response would be appreciated
    Eyal

    Eyal,
    A stored function returns a value. You need to have the first parameter (of correct data type) for the returned value. The parameter binding is pretty much the same as you would do with stored procedures.
    e.g. "begin :1= proc(....); end;"
    Sinclair

  • How can i pass function return values in to varray

    Hi
    create procedure name(parameters list)
    here ---i am calling a function
    varname := function name
    returns 4 values
    My doudt is how can i pass these return values in to varray..
    Type varray vname[5] date type
    Begin
    statements
    end prodedure name;
    pls clarify me its urgent

    This may give u a start
    sql>
    create or replace package test_array_pack as
    type ar1 is varray(10) of number;
    end;
    Package created.
    sql>
    create or replace function test_array return test_array_pack.ar1 is
      v_ar1 test_array_pack.ar1;
    begin
    v_ar1 := test_array_pack.ar1(1,2,3,4);
    return v_ar1;
    end;
    Function created.
    sql>
    declare
    v_ar2 test_array_pack.ar1;
    begin
    v_ar2 := test_array;
    end;
    PL/SQL procedure successfully completed
    Message was edited by:
            jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • ExtendScript function return values

    As far as I can tell, it's only possible to run ExtendScript functions from a CS Extension. I don't see any (straight-forward) way get the return value of an ExtendScript function.
    CSXSInterface.getInstance().evalScript() does not seem to return any useful information. Am I missing something, or should I make a feature request?
    Harbs

    I must be doing something wrong, because it's still not working...
    Here's my ExtendScript:
    function test1(){
    alert(1);
    return "bla bla";
    function test2(){
    alert(2);
        return{
            text:"bla bla",
            number:1
    function test3(){
    alert(3);
        return
            <bla>
                <ble/>
                <ble>
                    <blu/>
                </ble>
            </bla>
    Here's my ActionScript:
                var result1:SyncRequestResult = CSXSInterface.getInstance().evalScript("test1");
                var result2:SyncRequestResult = CSXSInterface.getInstance().evalScript("test2");
                var result3:SyncRequestResult = CSXSInterface.getInstance().evalScript("test3");
    and here's what I'm seeing in the debugger:
    I am getting all three alerts, so I know that the functions are being run...
    Harbs

  • FDM Lookup function returning value not = the current POV

    Is anyone having problems returning values for periods other than current POV.
    "The FDM Lookup function is used to return the value of any source account that resides in FDM.
    The function can be used within a logic function or a logic expression."
    Presently I can only return value in current POV.
    If anyone can return a source account value from a period other than the current POV let me know.
    Tom Peera
    Syntax
    | , , 02/28/2011 , 1535-000-000 |

    Here is the dirty fix, I'm heading off to sleep.
    If the function CurrentAdId doesn't return a number, then
    this will ensure it returns 0 (prevents your error, may not display
    an ad):
    <CFFUNCTION
    NAME="CurrentAdId"
    ACCESS="Private"
    RETURNTYPE="numeric"
    HINT="For internal use. Returns the Id of the current ad in
    rotation.">
    <!--- Return the adId from the current row of the
    GetAdIds query --->
    <cfset var returnVal = ListGetAt(THIS.AdList,
    THIS.CurrentListPos)>
    <cfif NOT IsNumeric(returnVal)>
    <cfset returnVal = 0>
    </cfif>
    <CFRETURN returnVal>
    </CFFUNCTION>

  • REF CURSOR? FUNCTION RETURN VALUE BASED ON DYN QUERY

    Hi to all,
    i need to write a function that do the following (but have to work...):
    Note: what i really don't remember is how can i have a valid cursor based using
    a dynamic field taken from the input value PAR_NAME.
    Hope that my problem is clear reading the NOT WORKING CODE below.
    thanx a lot
    CREATE OR REPLACE
    FUNCTION FNC_RET_FLD_VAL(ID_CNT NUMBER, PAR_NAME VARCHAR2) RETURN VARCHAR2 AS
    RETVAL VARCHAR2(300);
    CURSOR FVAL IS
    SELECT PAR_NAME FROM TBCONTATTI WHERE NORECORD=ID_CNT;
    BEGIN
    FOR REC IN FVAL LOOP
    RETVAL:=REC.PAR_NAME;
    END LOOP;
    RETURN RETVAL;
    END FNC_RET_FLD_VAL;

    Like this ?
    SQL> create function get_data(colname varchar2, empno number)
      2  return varchar2
      3  is
      4   ret varchar2(4000);
      5  begin
      6   begin
      7    execute immediate 'select ' || colname || ' from emp where empno = :1' into ret using empno;
      8   exception
      9    when no_data_found then
    10     ret := null;
    11   end;
    12   return ret;
    13  end;
    14  /
    Function created.
    SQL> select get_data('ename',7369) from dual;
    GET_DATA('ENAME',7369)
    SMITH
    SQL> select get_data('job',7369) from dual;
    GET_DATA('JOB',7369)
    CLERK
    SQL> select get_data('job',-1) from dual;
    GET_DATA('JOB',-1)
    Rgds.

  • Can pipelined functions' return values be used in WHERE clause?

    If I have function MY_FUNC that returns a REFCURSOR with columns COL1, COL2, COL3
    can I use the values returned in the output cursor in my WHERE clause as well as in the SELECT clause?
    e.g.
    SELECT COL1, COL2, COL3
    FROM TABLE(MY_FUNC(param1, param2))
    WHERE COL1 = 24 AND COL2=25
    Would that be proper SQL?

    Hi,
    SQL> Create OR Replace Package Pkg_Test_ Is
      2 
      3     Type my_typ Is Table Of Number;
      4 
      5     Function fnc_test Return my_typ Pipelined;
      6 
      7  End;
      8  /
    Package created
    SQL> Create OR Replace Package Body Pkg_Test_ Is
      2 
      3     Function fnc_test Return my_typ
      4        Pipelined Is
      5        va_typ my_typ := my_typ();
      6     Begin
      7        For i IN 1 .. 10 Loop
      8           va_typ.Extend;
      9           va_typ(va_typ.Count) := i;
    10           Pipe Row(va_typ(va_typ.Count));
    11        End Loop;
    12        Return;
    13     End;
    14 
    15  End;
    16  /
    Package body created
    SQL> SELECT *
      2    FROM Table(PKG_TEST_.FNC_TEST)
      3   WHERE COLUMN_VALUE > 5
      4  /
    COLUMN_VALUE
               6
               7
               8
               9
              10Regards,
    Christian Balz

  • Problem with return value of stored function

    Hi,
    I've made a stored function that insert a new row in a table and return the primary key (see at the end of the message the function script).
    In VS 2005 with Visual basic, using the designer, I've created a dataset containing a tableAdapter to be able to use the Pl/SQL function.
    My problem is I can't get the proper return value. The VB code below works without error except that I get 0 as value.
    What's wrong?
    Cheers,
    Sebastien
    VB code
    Dim myAddSession As New ICISDataSetTableAdapters.AddSessionTableAdapter
    Dim intSessionId As Integer
    intSessionId = myAddSession.ADD_SESSION(tbxUsername.Text, _
    tempFolder.Substring(tempFolder.LastIndexOf("\") + 1), _
    "toto", Environment.GetEnvironmentVariable("COMPUTERNAME"), _
    myLevelAccess.icisUserId, myLevelAccess.levelId)
    The debugger tells me that the ADD_SESSION function return value is Object.
    add_session PL/SQL script:
    CREATE OR REPLACE FUNCTION ICISSEC.add_session (
    orausername IN icis_session.ora_user_name%TYPE,
    ctxsessionid IN icis_session.ctx_session_id%TYPE,
    ctxsessionname IN icis_session.ctx_session_name%TYPE,
    ctxservername IN icis_session.ctx_server_name%TYPE,
    icisuserid IN icis_session.icis_user_id%TYPE,
    startlevelid IN icis_session.start_lvl_id%TYPE
    RETURN icis_session.ICIS_SESSION_ID%TYPE
    IS
    tmpvar icis_session.ICIS_SESSION_ID%TYPE;
    BEGIN
    INSERT INTO icis_session
    (ora_user_name, ctx_session_id, ctx_server_name,
    icis_user_id, start_lvl_id, ctx_session_name
    VALUES (orausername, ctxsessionid, ctxservername,
    icisuserid, startlevelid, ctxsessionname
    RETURNING icis_session_id
    INTO tmpvar;
    COMMIT;
    RETURN tmpvar;
    EXCEPTION
    WHEN OTHERS
    THEN
    RAISE;
    END add_session;

    naama wrote:
    that if a value is null to convert it to 0 ? . i mean in the part of the declaration of parameter
    Nope, can't do that in the signature. You'll need to handle that by validating the passed parameters at the start of the function.
    It's simple enough. In your case you might just as well test for NULL and fail the function like this:
        FUNCTION date_post_message(
                user_lock_in IN NUMBER,
                form_type_in IN NUMBER DEFAULT 0 ,
                date_in      IN DATE)
            RETURN BOOLEAN
        IS
            v_num NUMBER(1);
        BEGIN
            dbms_output.put_line('Value of parameters : user_lock_in : '||user_lock_in || ' : form_type_in : '||form_type_in||' : date_in : '||date_in );
            IF user_lock_in = 1 THEN
                RETURN FALSE;
            END IF;
            IF form_type_in IS NULL THEN
                RETURN FALSE;
            ELSIF form_type_in NOT IN (1,2) THEN
                RETURN FALSE;
            END IF;
            RETURN TRUE;
        EXCEPTION
        WHEN NO_DATA_FOUND THEN
            RETURN FALSE;
        END;In other use cases I would declare a local variable and process it like this:
            IF form_type_in IS NULL THEN
                l_form_type := 0;
            ELSE
                 l_form_type := form_type_in;
            END IF;Obviously the code should use the local variable rather than the parameter.
    Validating the values passed in parameters at the start of a function is good practice. If you really want to go to town, read about Design By Contract.
    Cheers, APC
    Edited by: APC on Nov 9, 2011 1:36 PM
    Added example, as requested by OP

  • Execution flow doesn't wait for return values

    I have created JNI wrappers for existing dlls. However I'm getting weird behavior. My Java function calls a c function which communicates with an old mainframe. If I retrieve one row at a time its fine but if I do a loop the virtual machine crashes. Sometimes, if I add an empty loop for (30000 iterations) then its fine. Its like java is already trying to retrieve the next row while the first row is still being printed on my screen. I've tried adding synchronized in case the dlls where multi-threaded but it has not made a difference. Is there any way to control the execution flow so that it can't go to the next line until the values are truly returned from the c dll.
    thanks
    MA

    There are many function being called on the native side. Since I didn't want to modify the native side
    (because the old dlls are used by another application), I added my own dll as an intermediary between the old c dlls and the java side.
    To fix the problem I am having, I've heard of another project where the native side would write the returned values to a file and only once the file is written can the Java side continue. Is this the only way to control the execution flow?
    Right now I have about 5 empty loops which run to 100000 and things work most of the time. But I would prefer to find a way to say wait until the values are returned correctly.
    Essentially, what I'm doing is
    for (int i=1;i<10; i++){
       test.init(Integer.toString(i),Integer.toString(i),"english desc"+  Integer.toString(i),"french desc"+ Integer.toString(i));
       test.execute(test.ActionAdd);
    }This is supposed to add one row with four fields. I'm just putting junk for the test. If I call the two main lines
    test.init(Integer.toString(i),Integer.toString(i),"english desc"+  Integer.toString(i),"french desc"+ Integer.toString(i));
    test.execute(test.ActionAdd);just once it works fine but if I loop them then it crashes after a few loops. If I put a loop as shown below then it works fine. This is part of the code when I'm adding. Is it being looped 10 times from the code above.
    jsession.scanTable(table,errorlist);
                rtc = table.getRecordCount(errorlist);
                if (rtc > 0)
                publish(rtc+" records found.");
                    for(int i = 1; i <= rtc; ++i)
                        for (int j = 0; j < ElementName.size();j++)
                            publish((String)ElementName.get(j)+ ": " + table.getFieldByName((String)ElementName.get(j),i,errorlist));
                            for (int k = 0; k<100000;k++);
                else
                    publish("No records found.");
                }In the code, when the rows are added, I print them out just to make sure they were added correctly. This is where I got the idea that the Java code was not in synch with the native side because it would crash while writting out a line but it didn't happen every time at the same place.
    This is the function getFieldByName
    public String getFieldByName (String p_FieldName, int p_LineNum, ErrorList p_Errors)
              String retval = "";
              int ret;
              try
                   p_FieldName = prepareFieldName(p_FieldName);
                   retval = new String();
                   ret    = 0;
                   if (this.ptrTableView == NOT_SET)
                        p_Errors.addMessage(p_Errors.SEV_SYSTEM_ERROR(), "Table View Pointer not set");
                        throw (new Exception());
                   // allocating string buffer for value returned
                   StringBuffer m_FieldValue = new StringBuffer();
                   // determining length of value
                   int m_length[] = {0};
                   ret = gti.GetFieldLen(this.ptrTableView, p_FieldName, m_length, eb.getErrorBlockPtr());
                   if (m_length[0] == 0) m_length[0] = 100;
                   m_FieldValue = new StringBuffer(m_length[0]);
                   // get line field          
                   ret = gti.GetLineField(this.ptrTableView, p_FieldName, p_LineNum, m_FieldValue, eb.getErrorBlockPtr());           
                   if (ret != 0)
                          p_Errors.addMessage(p_Errors.SEV_ERROR(), "Error retrieving field value ("+p_FieldName+")");
                   else
                          retval = m_FieldValue.toString();
              catch (Throwable t)
                   p_Errors.addMessage(p_Errors.SEV_ERROR(), "Error retrieving field value ("+p_FieldName+")");
              return retval;
        }The main functions are
    GetFieldLen
    GetLineField
    They go to the native side through my dll which wraps the old dlls.
    Here are is one of the main functions in my dll. I also have the source for the functions they are calling but they are calling other functions which are calling other functions. There is a lot of code . Yes, they use arrays.
    JNIEXPORT jint JNICALL Java_advantagewrapperspk_GtiNative_GtiGetLineField
      (JNIEnv *env, jclass cls, jint p_tableViewPtr, jstring VIEWFIELDNAME, jint VIEWFIELDNUM, jobject VIEWFIELDVALUE, jint iErrBlockPtr)
           //printf("\n\nGtiGetLineField in C:\n");
           jint iResult = 0;
           char *temp1 = (*env)->GetStringUTFChars(env,VIEWFIELDNAME,0);
           char *temp2 = (*env)->GetStringUTFChars(env,VIEWFIELDVALUE,0);
         iResult = GtiGetLineField(p_tableViewPtr,temp1,VIEWFIELDNUM,temp2,iErrBlockPtr);
           //printf("VIEWFIELDNUM %d ",VIEWFIELDNUM);
           //printf("\ntemp1 %s ",temp1);
           //printf("\ntemp2 %s ",temp2);
         (*env)->ReleaseStringUTFChars(env,VIEWFIELDNAME,temp1);
         if (temp2 == 0)      return iResult;
        if (temp2 != NULL)
                cls = (*env)->GetObjectClass(env,VIEWFIELDVALUE);
                jmethodID mid = (*env)->GetMethodID (env,cls,"append","(Ljava/lang/String;)Ljava/lang/StringBuffer;");
                 if (mid == 0) return iResult;
                 jstring sfinal = (*env)->NewStringUTF (env, temp2);
                (*env)->CallObjectMethod(env,VIEWFIELDVALUE,mid,sfinal);
              if (VIEWFIELDVALUE != NULL) (*env)->ReleaseStringUTFChars(env,VIEWFIELDVALUE,temp2);
         //(*env)->ReleaseStringUTFChars(env,VIEWFIELDVALUE,temp2);
         return iResult;
      }This calls
    * Function Name : GtiGetLineField()
    * Description   : Retrieves the value of a line field in a table view
    * Parameters    : pTableViewPtr pTableView--the table view from which to
    *                                           retrieve the value of a line
    *                                           field
    *                 VIEWFIELDNAME szFieldName--the name of the line field
    *                                            whose value is returned
    *                 VIEWLINENUM iLineNum--number of line from which to retrieve
    *                                       field value.  Lines are numbered
    *                                       beginning with 1.
    *                 VIEWFIELDVALUE szFieldValue--returns the value of the
    *                                              line field
    *                 ErrBlockPtr sourceeb--error context info from calling
    *                                       function
    * Return values : int--returns RCT_RETURNOK, RCT_WARNCORECONNECT, or
    *                      RCT_FAILCORECONNECT
    * Modifications : REH - 05/25/93
    int GtiGetLineField ( TableViewPtr pTableView,
                          VIEWFIELDNAME szFieldName,
                          VIEWLINENUM iLineNum,
                          VIEWFIELDVALUE szFieldValue,
                          ErrBlockPtr sourceeb )
       int iRc ;      /* return code */
       ELOG_INIT( sourceeb,
                  "GtiGetLineField",
                  "retrieving the value of a line field in a table view" ) ;
       /* in Gti, we start numbering lines from 1, because that is the way a user
          sees them on the screen.  In Ldm, following C conventions, we start
          numbering lines at 0.  So in LdmSetField, we subtract 1 from iLineNum */
       iRc = LdmGetField( pTableView->pTran,
                          szFieldName,
                          szFieldValue,
                          iLineNum - 1,
                          0,                  /* map occurrence = 1 */
                          ELOG_ERRBLOCK ) ;
       /* in case Ldm returned a warning, indicate so to the calling function */
       iRc = ( iRc == LDM_RETURNOK ) ? RCT_RETURNOK : RCT_WARNCORECONNECT ;
       return( iRc ) ;
       /* if exception was raised, it was due to COREConnect */
       ELOG_END( RCT_FAILCORECONNECT ) ;
    }which calls
    /****************************** API Header *********************************\
    * API Name: LdmGetField
    * This function copies the string value of a specified FIELDNAME into a
    * buffer specified by FIELDVALUE.  The string is NULL terminated.
    * The first OCCUR determines which occurrence of the field in the map.
    * The second OCCUR determines which occurence of the map in the transaction
    * area.  Remember that occurrences are numbered like C arrays: a transaction
    * with ten occurrences of a field will have fields numbered zero through
    * nine.
    * It is assumed that FIELDVALUE has enough space to accommodate the field's
    * value.
    int LdmGetField( HTRAN       htran,
                     FIELDNAME   fieldname,
                     FIELDVALUE  fieldvalue,
                     FIELDOCCUR  fieldoccur,
                     MAPOCCUR    mapoccur,
                     ErrBlockPtr seb )
       ELOG_INIT ( seb, "LdmGetField", "getting transaction field value" ) ;
       if ( htran->Occurrence <= mapoccur ) {
          ElogFail1( LDM_FAILOCCNOTFOUND, htran->TranName ) ;
       }  /* END if. */
       /* Since 'blank' values for field or map occurrences are zero, there
          is no need to set a default. */
       LdmsGetField( htran->Map->CCMap,
                     htran->TranData,
                     fieldname,
                     fieldvalue,
                     fieldoccur,
                     mapoccur,
                     ELOG_ERRBLOCK ) ;
       return( LDM_RETURNOK ) ;
       ELOG_END ( ELOG_ERRBLOCK->Rc ) ;
    }  /* END LdmGetField. */which calls
    /****************************** API Header *********************************\
    * API Name: LdmsGetField
    * Put the value of FIELDNAME into FIELDVALUE.  The field must be an element
    * of the specified map.  The new value will be set in the specified data
    * buffer.  The occurrences refer to the occurrence of the field in the map
    * and the occurrence of the map in the data buffer.
    int LdmsGetField ( CCMapPtr    rcmap,
                       char        *dataarea,
                       FIELDNAME   fieldname,
                       FIELDVALUE  fieldvalue,
                       FIELDOCCUR  fieldoccur,
                       MAPOCCUR    mapoccur,
                       ErrBlockPtr seb )
       ElementPtr element ;
       char       *fieldoffset ;
       ELOG_INIT ( seb, "LdmsGetField", "getting a field of a map" ) ;
       /* Search the transaction definition area (map) for matching
          FIELDNAME. If found, copy FIELDVALUE to defined offset in
          transaction buffer. */
       element = LdmsFindField( rcmap, fieldname, fieldoccur, &localeb ) ;
       /* Copy the value from the transaction data area into FIELDVALUE. */
       fieldoffset = dataarea +
                     ( ( rcmap->BufferLength * mapoccur ) + element->Offset ) ;
       strncpy( fieldvalue, fieldoffset, element->Length ) ;
       fieldvalue[ element->Length ] = '\0' ;
       return( LDM_RETURNOK ) ;
       ELOG_END ( ELOG_ERRBLOCK->Rc ) ;
    }  /* END LdmsGetField. */and on it goes
    I gather from your question about arrays that they might be the source of the problem. Could it be that the pointer to the array is returned while the array is not completed? Any information would help. Thanks.

  • Authorization check on Function module return values

    Hi,
    I have a tricky situation. In our BW implementation, many of the FI infoobjects are authorization relevent. One of the objects is 0COSTCENTER.  A user has been assigned with authorization profile, in which the user is authorised for COST CENTER = A* and #.  All planning templates were working nice.
    We were on SP 12 earlier, now we upgraded to SP 20. Now came a issue, the user gets error that user is not authroised for the data. After our analysis, we found nothing wrong as such, so contacted SAP. They came back with a root cause
    In my planning function, an ABAP function module is used. The function module returns a COSTCENTER value. This return value is then assigned to a variable, this variable is of type 0COSTCENTER.
    SAP said there was a bug in their own design. The bug was, if the cost center value is directly used in planning function for other calculations, it will throw an authorization error.  But, if the COST CENTEr value is given to a variable and that variable is used for other calculations,  it works fine. Thats why it worked for us earlier.
    Now, they have removed that bug, so variables are also checked against authorizations and they said we need to either change the code or give * for the COST CENTER authorization.
    So we have a problem. It is not straight forward to give * for COSTCENTER in FI BW implementation. SAP theory is that they cannot say which value the functional module will return. So they will check against ALL the values for COSTCENTER but not the authorised values.
    Has anyone seen this issue before? is it only specific to planning function or its just ABAP concept? Any suggesations to come out this problem?

    Bindu, thanks,
    The error is coming at the program compile level itself i.e. before executing the planning group itself. As per the F1 help on forumla editor and from their support, the system reads all the reference data,  So when it sees the function module and its export parameter, it captures all the data for COST CENTER as reference data.
    Thus even I am sure that the return value will be always authorized, the reference data is checked for the full authorization. Thus its failing

  • Why does getdate() function return same time value for multiple select statements executed sequentially

    When I run the following code
    set nocount on
    declare @i table(id int identity(1,1) primary key, sDate datetime)
    while((select count(*) from @i)<10000)
    begin
    insert into @i(sDate) select getdate()
    end
    select top 5 sDate, count(id) selectCalls
    from @i
    group by sDate
    order by count(id) desc
    I get the following results. 
    sDate                   selectCalls
    2014-07-30 14:50:27.510 406
    2014-07-30 14:50:27.527 274
    2014-07-30 14:50:27.540 219
    2014-07-30 14:50:27.557 195
    2014-07-30 14:50:27.573 170
    As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value.  This started happening when we moved our applications to a faster server with four processors.  Is this correct or am I
    going crazy?
    Please let me know
    Bilal

    Observe that adding 2 ms is accurate only with datetime2.  As noted above, datetime does not have ms resolution:
    set nocount on
    declare @d datetime, @i int, @d2 datetime2
    select @d = getdate(), @i = 0, @d2 = sysdatetime()
    while(@i<10)
    begin
    select @d2, @d, current_timestamp, getdate(), sysdatetime()
    select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
    end
    2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    DATE/TIME functions:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Accessing function's return value

    Hi there. I have created several pl/sql procedures and functions that I can run as standalone programs and I have no problem integrating them into my java code also. However I cannot access the return value of any created function from my java code. The functions appear to execute correctly because when I deliberately enter an invalid select statement I get the errors I expect to get for that instance nad if I enter a valid select statement in the function the program executes correctly but I still cannot access the function's return value. My java code where I execute the pl/sql function is as follows:
    CallableStatement p = cont.conn.prepareCall("{call ? := Hellen.FUNC}");
    p.setString(1, "z006"); //hellen.FUNC = function name
    p.execute();
    How do I access the return value of my function?
    Do I need to get a ResultSet?
    My function is as follows:
    function func
    return varchar
    is tester varchar(4);
    BEGIN
    select cfcc_code into tester from hellen.test1 where test1.cfcc_code = 'A21';
    return tester;
    END;
    Any help will be gratefully received, Joe

    You need to do something like
    p.registerOutParameter(1, java.lang.String);
    p.execute();
    String result = p.getString(1);Cheers, APC

Maybe you are looking for

  • Calendar in web dynpro

    Hi all, I want to display calendar beside my input field for date. This input field will be displaying date as mm/dd/yyyy from the data taken from sql database. The user should be able to click on the calendar and change the dates to something else.

  • Need to split one large high-res video into sub-parts

    I have a very large high-res video (5760 x 3240) that I would like to split into 9 separate videos, each 1920 x 1080.  These would make up the content of a 3x3 video wall and would be 'stitched' back together by the media players driving the wall. I

  • 'Error mapping function' with external procedures

    I'm trying to create an external procedure in PL/SQL8.1 to run an operating system command from within a PL/SQL block. The C function couldn't be simpler: extern void host_command(char *command) (void)system(command); It's even ignoring the return va

  • Unique item permissions per user/group of ListItems

    Hello, i have following scenario: 1.) Sharepoint group named "(Adminstrator) Company A" <-> Has Add/Edit rights on the list 2.) Sharepoint group named "Company A" <-> Has only Add/read access to the list 3.) .....many many other groups (50+) with sam

  • Cannot Connect iPhone 5 to iMac

    Hello, I have spent the past hour reading up on common issues that can cause this I have turned off my firewall and forwarded port 7682. Both my devices are on the same network and have connected to each other in the past. Although the connection nev