Function re-write

Hi,
I have a funtion. I would like to know how "p_max_date" & "p_min_date" are being calculated based on "p_qry" being passed. I need to re-write this function without using DBMS_SQL. I would like to know the business logic of this function.
FUNCTION Get_Time_Stamp(p_qry       Varchar2,
                        p_limit     Number,
                        p_min_date  In Out Varchar2,
                        p_max_date  In Out Varchar2)
RETURN BOOLEAN
IS
  v_cur    Integer := DBMS_SQL.OPEN_CURSOR;
  v_fdbk   Integer;
  id_tab   DBMS_SQL.VARCHAR2_TABLE;
  indx     Number;
  retval   Boolean := FALSE;
BEGIN
  If(p_limit > 0)
  Then
    DBMS_SQL.PARSE(v_cur,p_qry,1);
    DBMS_SQL.DEFINE_ARRAY(v_cur,1,id_tab,p_limit,1);
    v_fdbk := DBMS_SQL.EXECUTE_AND_FETCH(v_cur);
    DBMS_SQL.COLUMN_VALUE(v_cur,1,id_tab);
    If(v_fdbk > 0)
    Then
      retval := TRUE;
      indx := id_tab.FIRST;
      p_max_date := id_tab(indx);
      indx := id_tab.LAST;
      p_min_date := id_tab(indx);
    End If;
  End If;
  DBMS_SQL.CLOSE_CURSOR(v_cur);
  Return retval;
Exception
When others then
    DBMS_SQL.CLOSE_CURSOR(v_cur);
    Return FALSE;
End Get_Time_Stamp;-----------Parameters-------------
p_qry = A SQL query is being passed into the function.
p_limit = 100
p_min_date = date returned. Which min date of the SQL query??
p_max_date = date returned. Which max date of the SQL query??
Any help appreciated.
Thanks

> I need to re-write this function without using DBMS_SQL
If the function takes a piece of text as input that is a SQL query, then you cannot avoid using dynamic SQL.
However, it looks like it is dynamic, but there are several assumptions made in the code, that makes the function get_time_stamp only suitable for very specific queries:
- the query has to select only one varchar2 column, or maybe the datatype is different, but then this function would be sloppy
- the query has to be ordered by a date in descending order
The business logic is something like this:
Take a query text, execute it and fetch a maximum of 100 rows and return the first maximum date as in/out parameter p_max_date, and return the smallest or 100th date as p_min_date. The function (which should really be a procedure, by the way) returns true if p_max_date and p_min_date are not null and false if both are null.
Hope this helps.
Regards,
Rob.

Similar Messages

  • Using HS.Exp function to write data to a Consolidated Account

    Hi,
    Just wanted to know whether i can use the HS.Exp function to write data to a consolidated account?
    Thanks

    Hi Mau,
    In order to write data to a consolidated account, you can use HS.Exp function in rules which puts data into a combination of Account, ICP, and Custom1...4 members. The syntax is: HS.Exp "DestPOV = Expression"
    You might find useful the HS.Con function which puts data into the [Proportion] and [Elimination] Value dimension members and can also be used in Consolidation rules. The syntax is: Call HS.Con ("V#[Elimination]",-1*dPCon,"")
    Regards,
    Thanasis

  • How to find which function module write the relevant idoctype?

    Dear All,
    how to find which function module write the relevant idoctype?

    Hi,
    Generally the function modules of the idoc types are having a naming convention as IDOC_INPUT for inbound processing and IDOC_OUTPUT for outbound processing followed by the idoc type name
    for example : For IDOC type ORDERS
    the inbound function module will be IDOC_INPUT_ORDERS and for outbound IDOC_OUTPUT_ORDERSP
    In this way you can find the function module for a particular IDOC
    P.S: Hope this is what you have asked for
    Regards
    Sarves

  • Running function with "Write-Host" and redirect output to file does nothing.

    Hello,
    I created this function:
    function TicketSolutionInformation {
    Write-Host "User has been created." -ForegroundColor Green
    TicketSolutionInformation | Out-File -filepath ("123" + ".txt") -append
    but the file 123.txt is always empty. Why ?

    Write-Host will write text to console, not pipepeline so you'll always get nothing.
    Consider changing function to this:
    function TicketSolutionInformation {
    Param(
    [switch]$Passthru
    Write-Host "User has been created." -ForegroundColor Green
    if($Passthru){
    "User has been created."
    }TicketSolutionInformation -Passthru | Out-File -filepath ("123" + ".txt") -append

  • Huge lack of functionality - Please write about what is lacking in Photos.

    Is it just me or are we missing functionality in Photos?
    Photos cannot be used professionally as it is currently  -  As I see it, the program is only 80% finished
    Please write about what is lacking in Photos.
    1)
    Shared Albums, sort order.
    Optional sort order of "Shared Albums". It should be possible to select for example alphabetical sorting - Now is sort order creation time and this is useless.
    (This applies to OSX and IOS)
    2)
    All Photos, sort order.
    Optional sorting order of the All Photos. It must be possible to choose alphabetical sorting - Now it's random and this is useless.
    (This applies to OSX and IOS)
    3)
    Shared Smart Album
    Ability to create a Smart Album in Shared Album.
    (This applies to OSX and IOS)
    4)
    Make an Album Shared
    It should be possible to select an album and do the Shared.
    (This applies to OSX)
    5)
    Batch Rename (file rename)
    Ability to perform Batch Rename + serial number.
    (This applies to OSX)
    6)
    Geo tag
    Edit Geo tags on one or more images simultaneously - this is needed when importing images from a SLR camera without GPS.
    (This applies to OSX)
    7)
    Change Title
    Ability to edit the title of many images simultaneously.
    (This applies to OSX)
    8)
    Edit metadata
    Ability to edit all metadata of many images simultaneously.
    (This applies to OSX)
    9)
    Edit - Crop
    "Crop" must remember selected aspects. It must be possible to choose a default Aspect.
    (This applies to OSX)
    10)
    Sync, Faces
    Sync Faces to other devices – another MAC, IPhone or IPad.
    (This applies to OSX an IOS)

    Lars Coling wrote:
    Is it just me or are we missing functionality in Photos?
    Photos cannot be used professionally as it is currently  -  As I see it, the program is only 80% finished
    Please write about what is lacking in Photos.
    1)
    Shared Albums, sort order.
    Optional sort order of "Shared Albums". It should be possible to select for example alphabetical sorting - Now is sort order creation time and this is useless.
    (This applies to OSX and IOS)
    2)
    All Photos, sort order.
    Optional sorting order of the All Photos. It must be possible to choose alphabetical sorting - Now it's random and this is useless.
    (This applies to OSX and IOS)
    3)
    Shared Smart Album
    Ability to create a Smart Album in Shared Album.
    (This applies to OSX and IOS)
    4)
    Make an Album Shared
    It should be possible to select an album and do the Shared.
    (This applies to OSX)
    5)
    Batch Rename (file rename)
    Ability to perform Batch Rename + serial number.
    (This applies to OSX)
    6)
    Geo tag
    Edit Geo tags on one or more images simultaneously - this is needed when importing images from a SLR camera without GPS.
    (This applies to OSX)
    7)
    Change Title
    Ability to edit the title of many images simultaneously.
    (This applies to OSX)
    8)
    Edit metadata
    Ability to edit all metadata of many images simultaneously.
    (This applies to OSX)
    9)
    Edit - Crop
    "Crop" must remember selected aspects. It must be possible to choose a default Aspect.
    (This applies to OSX)
    10)
    Sync, Faces
    Sync Faces to other devices – another MAC, IPhone or IPad.
    (This applies to OSX an IOS)
    Send feedback here:
    https://www.apple.com/feedback/photos.html
    This link wasn't available a few days ago.

  • ORA-06521: PL/SQL: Error mapping function while writting into a text file

    Hi,
    I'm getting an errror ORA-06521: PL/SQL: Error mapping function while trying to write data into a text file.
    I'm using the following code:
    --To create a new directory
    create or replace directory temp as 'C:/temp';
    declare
                    l_str varchar2(1000);
                    output_file utl_file.file_type;
                    cursor test_write_cur is
                         select EMPNO,ENAME,JOB,SAL,HIREDATE
                           from EMP
                         where DEPTNO=30;
    begin
               output_file := utl_file.fopen('TEMP','TESTFILE.txt','w');
               for test_write_rec IN test_write_cur
               loop          
                l_str :=     test_write_rec.EMPNO||'^'||test_write_rec.ENAME||'^'||test_write_rec.JOB||'^'||
                         test_write_rec.HIREDATE||'^'||test_write_rec.SAL||chr(10);
                utl_file.put_line(output_file,l_str);
                     end loop;                                                                           
               utl_file.fclose(output_file);
    end;Please suggest me if i'm wrong.
    Thanks & Regards,
    Sanket Mishra

    Dear Sanket,
    I think you are need use TO_CHAR() function
      to_char(test_write_rec.EMPNO) ,
      to_char(test_write_rec.HIREDATE,'DD.MM.YYYY')
      to_char(test_write_rec.SAL)

  • Toshiba 55VL963 - TV to USB function reports write errors

    Hi,
    I have 55vl963 TV with lastest firmware 6.9.MD.1
    I am trying to get channel lists and other settings through Hotel clone function.
    However, it seems the TV to USB function often reports write errors (or sometimes ends successfully but generates corrupted files).
    I tried different USB media, formated in FAT16 or FAT32.
    Thanks for any help on resolving this.

    Tonny, I'm not sure about my 32RL900A, as I have not had any problem with USB recording, (and have forgotten whether it has its own "Format" function), but suggest that you look in the setup area of your menu, and see if your model has the "Format Disk" function, and if so, see if your model will format your USB stick, and then, if so, use it.
    As I said, it has been a little while since I plugged a USB stick in to ours and it has been left in and used a number of times, without any problems, so such things have a habit of being forgotten, when everything is going smoothly!!!
    donhe7

  • Allocate memory and call dll function which writes to the pointer

    Hi!
    I have a DLL wich has a function like the following example, wich i need to call from labview. In C I need to allocate some memory for the data and of course the struct. I add the pointer and the lengh of the data to the stuct and call the function with the struct. The function itself inserts some values to the stuct and to allocated memory. Has someone a working solution how this can be done with Labview?
    typedef struct Thestruct
     UINT16 val1;
     UINT8 val2;
     UINT8 val3;
     UINT16 dataLength;
     UINT8 *data;
    } T_Thestruct;
    MY_API Status MY_API_CALL udaReceive(Handle handle, T_Thestruct *args);
    I tried in labview (see picture), but I only got values inside the struct as well as the error 1097, the reserved memory inclues the same values as before.
    Solved!
    Go to Solution.
    Attachments:
    CallDll.PNG ‏21 KB

    Tobias_BSH wrote:
    OK, I found the soluton to my own Problem. The alignment on the struct must be corrected in Labview. There must be a 2Bytes dummy value between dataLength and the pointer.
    And please not that your solution only works in LabVIEW 32 bit. In LabVIEW 64 Bit your DLL has to be 64 bit compiled as well in order to be loadable and the pointer then is a 64 bit integer and is usually aligned to 64 bit addresses too. In this particular case since the pointer is already aligned to a multiple of 64 bit (when the additional 2 alignment bytes are added) you won't have to modify the alignment for the 64 bit case, but you have to define a different cluster with the 64 bit integer for the pointer anyhow.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • What's the FUNCTION to write datas an Infocube?

    Hello guys,
    I would like to upload datas in an Infocube directly by ABAP PROGRAM.
    Do you know what is the Function to upload the datas in an Infocube?
    Thanks,
    Carlos Eduardo

    Hi,
    Try to execute the below program. You will get options to enter the data directly to cube.
    CUBE_SAMPLE_CREATE
    Vivek

  • Using concatenate function to write report comments

    Hi am a high school teacher and have just got my first iPad - lovinging it!!! and am using Numbers and Pages on both my Mac at home and my iPad, but have hit a bit of a snage with using the concatenate funtion in my report generating spreadsheet.
    We use a 5 grade descriptor at our school for student outcomes (A-E for simplicities sack here) which I use as the basis for generating comments to explain the students performance at each outcome - this actually saves me hours and gives me more original reports across a whole class - the problem that I am having is that when I use the traditional bracketed IF queries to return the various strings matched to the outcomes Numbers will only let me address the outcome source cell in the first case, whenever i hit the cell again the orignal reference just "highlights"
    Any clues as to what I am doing wrong?
    Here is the start of the equation:
    =CONCATENATE(B1, " ",IF(Ranks and Grades :: Effort 'Nada '="O", Comment Phrases :: B9,(if when i get to here i go to hit Ranks and Grades :: Effort 'Nada' and it just highlights the original entry
    Help!!!!! these need to be in yesterday!!!!
    Ta
    Steve

    Thanks for the help Barry - don't try and author stuff like this on the iPad, just use it for record keeping, viewing and editing, author in the Mac, unfortunately your reply came just a little too late for me no not have laready resorted to using Excel (grumble grumble) but I will be doing the rest of my junior classes on Numbers - is just a nicer environment ot work with, especially with the descriptor cell addresses!!!!
    And yes they were typos, working on reports while not beina able to breath (asthma) and writing questions while brain tired from low O2 (yes I'm a science teacher) not a good combo
    Thanks again for the help
    Steve
    PS can you shed any light as to why numbers operates in this manner, it seems a little Byzentine...

  • How to write Boolean function (If Then Else)?

    Hi all,
    I have a logic to write in the query. It is:
    If (A = 0 and B = 0)
    Then 0
    Else
            If (A = 0 and B > 0)
            Then 100
            Else
                   A/B  (we want to show %)
    How to use boolean function to write this Netted If Else statement? Thank you in advance!

    Hi
    If (A = 0 and B = 0)
    Then 0
    Else
    If (A = 0 and B > 0)
    Then 100
    Else
    A/B (we want to show %)
    1. create a formula in the query designer. and use this formula for if - else
    ( ( (A==0) AND (B==0) ) * 0) +  ( ( a==0 ) AND (B >0 ) * 100 + (A/B*100) )
    : denotes THEN
    + : denotes ELSE
    See if this works.
    Assign points if helpfull
    From
    ManesH

  • How to write PL SQL function?

    First of all, whenever i try and put my attempted code for this in a thread it says 'sorry content not allowed'. I have attempted to make the function but i keep getting errors. I think its because my logic is wrong anyway. I am not quite sure how to do it.
    I am a student and this is the first time i have been asked to write a function, i have almost no prior knowledge so please bare with me.
    Could people give me some ideas where to start. It seems i cant even get a simple function to work at the moment! Where is it best to write and test the function? I have been using SQL commands, should i use Script creator instead?
    Any help or feedback would be great.
    Thanks in advance!
    Edited by: Jay on 08-Dec-2010 03:09

    Hi,
    Here's a simple function, and a test of it:
    CREATE OR REPLACE FUNCTION hello
    (     in_txt          IN     VARCHAR2
    RETURN     VARCHAR2
    DETERMINISTIC
    IS
         return_txt     VARCHAR2 (100);     -- Value to be returned
    BEGIN
         return_txt := 'Hello, '
                 || in_txt
                 || '!';
         RETURN     return_txt;
    END     hello
    SHOW ERRORS
    SELECT     dname
    ,     hello (dname)     AS hello_results
    FROM     scott.dept
    ;Output:
    Function created.
    No errors.
    DNAME          HELLO_RESULTS
    ACCOUNTING     Hello, ACCOUNTING!
    RESEARCH       Hello, RESEARCH!
    SALES          Hello, SALES!
    OPERATIONS     Hello, OPERATIONS!I don't know why you can't post your function. Here's how you can find out:
    First, change the subject line of your first message to something like "IN PROGRESS - Please Do Not Reply Yet".
    Copy the hello function I posted into your text editor
    Reply to this message, and post your copy of the function.
    Did you get the error again? If so, it looks like there's some security feature on your system that's keeping you from posting code.
    If you can post my function exactly as it is, then change it a little. Update your latest message, a little bit at a time, to make the function more and more like your function. For example, just change the name of the function to your actual function name. Change the message. If it posts corretly, make another small change, until you get the "content not allowed" message. If you can't figure out what's causing it, then change the subject line back to something meaningful, change the last message back to the last version that did post correctly, and describe what you changed that caused the error.
    You can use SQL*Plus to create and test the function. Write a script (that is, a text file), similar to the one I posted above. If you name the file hello.sql, then you can run the script from the "SQL> " prompt by saying
    @c:\fubar\sql\hellousing the full path name on your system where I used "c:\fubar\sql" above.
    Edited by: Frank Kulash on Dec 8, 2010 9:18 AM

  • Can i write java code in JavaScript function

    I want to call JavaBeans within JavaScript function. Can I do it?
    I have a button in JSP . When the button be clicked,the data be inputted will be checked by JavaScript function. If check is ok, then call a Bean's function to write the data to database.
    Please Help!

    well indeed u can write java code in javascript functions. But probably it will not work the way u want it to.
    when u say that u click a button, it means that some client side action is performed. Now if u wud require a java bean to be called then it means that the server needs to be contacted for the same, and if that has to be done, necessarily the form needs to be submitted.
    U can populate values from a java bean and then the same can be made available to a javascript variable / function when the page is loaded rather than, when the button is clicked.
    What u can do is on click of button u can process [display / calulate..etc ] the information which has already been got by the java bean.
    Kris

  • Difference between abap object and function

    hi all,
    i read the book on abap object of the difference between abap object and classical abap.
    i know that there is only 1 instance of a specific function group but somehow i still not so clear why subsequent vehicle cannot use the same function. i also can use the do and loop to call the function? if cannot then why?
    hope can get the advice.
    thanks
    using function *********
    function-pool vehicle.
    data speed type i value 0.
    function accelerate.
    speed = speed + 1.
    endfunction.
    function show_speed.
    write speed.
    endfunction.
    report xx.
    start-of-selection.
    *vehicle 1
    call function 'accelerate'.
    call function 'accelerate'.
    call function 'show_speed'.
    *vehicle 2
    *vehicle 3
    *****abap object*******
    report xx.
    data: ov type ref to vehicle,
             ov_tab type table of ref to vehicle.
    start-of-selection.
    do 5 times.
    create object ov.
    append ov to ov_tab.
    enddo.
    loop at ov_tab into ov.
    do sy-tabix times.
    call method ov->accelerate.
    enddo.
    call method ov->show_speed.
    endloop.

    Hi
    Now try this:
    REPORT ZTEST_VEHICLEOO .
    PARAMETERS: P_CAR   TYPE I,
                P_READ  TYPE I.
    *       CLASS vehicle DEFINITION
    CLASS VEHICLE DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: MAX_SPEED   TYPE I,
                    MAX_VEHICLE TYPE I,
                    NR_VEHICLES TYPE I.
        CLASS-METHODS CLASS_CONSTRUCTOR.
        METHODS CONSTRUCTOR.
        METHODS ACCELERATE.
        METHODS SHOW_SPEED.
        METHODS GET_SPEED EXPORTING E_SPEED TYPE I.
      PRIVATE SECTION.
        DATA: SPEED      TYPE I,
              NR_VEHICLE TYPE I..
    ENDCLASS.
    *       CLASS vehicle IMPLEMENTATION
    CLASS VEHICLE IMPLEMENTATION.
      METHOD CLASS_CONSTRUCTOR.
        NR_VEHICLES = 0.
      ENDMETHOD.
      METHOD CONSTRUCTOR.
        NR_VEHICLES = NR_VEHICLES + 1.
        NR_VEHICLE  = NR_VEHICLES.
      ENDMETHOD.
      METHOD ACCELERATE.
        SPEED = SPEED + 1.
        IF MAX_SPEED < SPEED.
          MAX_SPEED   = SPEED.
          MAX_VEHICLE = NR_VEHICLE.
        ENDIF.
      ENDMETHOD.
      METHOD SHOW_SPEED.
        WRITE: / 'Speed of vehicle nr.', NR_VEHICLE, ':', SPEED.
      ENDMETHOD.
      METHOD GET_SPEED.
        E_SPEED = SPEED.
      ENDMETHOD.
    ENDCLASS.
    DATA: OV     TYPE REF TO VEHICLE,
          OV_TAB TYPE TABLE OF REF TO VEHICLE.
    DATA: V_TIMES TYPE I,
          FL_ACTION.
    DATA: V_SPEED TYPE I.
    START-OF-SELECTION.
      DO P_CAR TIMES.
        CREATE OBJECT OV.
        APPEND OV TO OV_TAB.
      ENDDO.
      LOOP AT OV_TAB INTO OV.
        IF FL_ACTION = SPACE.
          FL_ACTION = 'X'.
          V_TIMES = SY-TABIX * 2.
        ELSE.
          FL_ACTION = SPACE.
          V_TIMES = SY-TABIX - 2.
        ENDIF.
        DO V_TIMES TIMES.
          CALL METHOD OV->ACCELERATE.
        ENDDO.
        CALL METHOD OV->SHOW_SPEED.
      ENDLOOP.
      SKIP.
      WRITE: / 'Higher speed', VEHICLE=>MAX_SPEED, 'for vehicle nr.',
                VEHICLE=>MAX_VEHICLE.
      SKIP.
      READ TABLE OV_TAB INTO OV INDEX P_READ.
      IF SY-SUBRC <> 0.
        WRITE: 'No vehicle', P_READ.
      ELSE.
        CALL METHOD OV->GET_SPEED IMPORTING E_SPEED = V_SPEED.
        WRITE: 'Speed of vehicle', P_READ, V_SPEED.
      ENDIF.
    Try to repeat this using a function group and I think you'll undestand because it'll be very hard to do it.
    By only one function group how can u read the data of a certain vehicle?
    Yes you can create in the function group an internal table where u store the data of every car: in this way u use the internal table like it was an instance, but you should consider here the example is very simple. Here we have only the speed as characteristic, but really we can have many complex characteristics.
    Max

  • SO_OBJECT_SEND function does not work without an explicit COMMIT WORK

    Hi,
    We have used this Function module (SO_OBJECT_SEND) inside a custom BAdI Implementation , which sends e-mails when some of the fields inside an infotype are modified using transaction PA30 (HR-Maintain master data).
    After the system was upgraded to BASIS version 7.0 , as per SAP note 489286 ,the calling program of the send interface must execute an explicit COMMIT WORK.But inside an update , COMMIT WORK should not be executed.
    So we did not execute explicit COMMIT WORK  inside BAdI.
    But after this upgrade, the emails are not sent out of R/3 , and the status message 672 (Still no entry in queue) is displayed on the program 'Administration of External Send Processes' - Transaction SOST.
    Can anyone suggest a solution , if you have used this Function module (SO_OBJECT_SEND) inside a BAdI during update?
    Thanks,
    Kiran

    Hi Kiran,
    create one remote enable function module, write your required logic in this remote enableD function module.
    Now call this function module in Badi as below,
    eg. suppose Remote enable function module created is 'ztest'.
    then,
    In BadI write logic,
    CALL FUNCTION 'ZTEST' SEPARATE TASK 'T'
    EXPORTING ......
    IMPORTING.......
    also inside this function module
    call function 'SO_OBJECT_SEND' separate task 'T'
    exporting....
    importing....
    committwork.
    after doing this what will happen is your mail logic will be in saperate session, so your current program will pass the data and execution of this RFC and Program having BADI, will be in two saperate sessions, so although you are using committ work standred program will not get affected.
    This will improve performance too...:)
    Please Give points if it is going to help you.

Maybe you are looking for