Moving backward -last record to first

Hi!
How can we move bachward, last to first record as cursors are forward only in oracle
Thnaks in advance
Imran

Raghu: You have :System.Cursor_Record and :System.Trigger_Record. Depending on what you are doing, one of them will equal 1 when you are at the first record in the block.
Imran:
I have used server-side stored procedure to do that. If you have a block of records the user has displayed (Example, names starting in the middle of the alphabet), and he wants to see the rows that come BEFORE the first record, this is what you do:
Call the stored procedure, passing the key value of the first record in your block. It creates a cursor with a where clause: where key_val < parameter_value, and Order by key_val desc. Then open the cursor, and fetch some number of rows -- I use about 50, then close the cursor and pass the key value of the last record fetched back to the form.
Then I set the where clause of the block to say Where key_val >= Value_From_stored_procedure. Execute_Query, then do a next_record until I find the record with the key value equal to (or greater than) the key value I passed to the stored procedure.
Then loop forward with a Next_Record loop however many records are displayed in the block minus two. This leaves the block displayed with the record with the initial key value as the second row displayed, and the immediately prior record is at the top.
I have implemented this type of process from the key-PrevRec trigger if :system.trigger_record = 1. Or you can put a small square button above the top of the scroll bar, so when clicked, it executes the same process.

Similar Messages

  • How to select last record or first record value in a formula?

    Post Author: d111
    CA Forum: General
    I am using a query in a report that in addition to other columns, has a column of month labels like:
    There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
    Jan07Feb07Mar07Apr07etc.
    I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
    I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
    I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
    Please advise and thanks.

    Post Author: bettername
    CA Forum: General
    Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
    If so, try these:
    Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
    //Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
    numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
    //...etc etc you fill in the rest!
    if left({YourTable.YourField},3) = "Dec" then the_month:=12;
    date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
    Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
    totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
    If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
    Stick this in the details section, and call it "HoldRecords" and suppress it:
    whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
    Now create another formula, and put it into the report footer:
    evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
    NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
    Hope this helps...

  • Moving the last record to 1st position

    Hi,
    I have 200 records in my internal table.I want to move the last record(200 position) to 1st position(i.e Index1). How to do it?

    Hi
    U can try something like this
    DATA: BEGIN OF ITAB OCCURS 0,
            FIELD(1) TYPE C,
          END   OF ITAB.
    DO 9 TIMES.
      MOVE SY-INDEX TO ITAB-FIELD.
      APPEND ITAB.
    ENDDO.
    * Check table
    DESCRIBE TABLE ITAB LINES SY-TABIX.
    * Read last record
    READ TABLE ITAB INDEX SY-TABIX.
    * Delete last record
    DELETE ITAB     INDEX SY-TABIX.
    * Append the last record to the top
    INSERT ITAB     INTO ITAB INDEX 1.
    LOOP AT ITAB.
      WRITE: / ITAB.
    ENDLOOP.
    Max

  • Want last record in internal table

    Hi All,
    I have two internal table. in one internal table all data are available. now i want last record on first internal table and store in second internal table.... so give me some logic or sample code......
    Thanks
    zeni

    get the latest record from an internal table.
    if you are using function module RH_READ_INFTY_1001 then <itab
     > will always contain all the records betweebn specified period (taken from selection screen), but to retrieve the latest, sort the records by ENDDA and you will get it on top, then use INDEX 1 for that record only, and store the record in a <work_area>, finally get that record from <work_area> to <itab> it self. thats way your <itab> will hold only latest record.  
    (you can store <work_area> in <work_area_2> and then pass the record in to <itab>
    or, you can store the <work_area> to a different <itab_2>).
       call function RH_READ_INFTY_1001
       tables
          i1001         = it_hrp1001
      sort  it_hrp1001 by endda descending.
      read table it_hrp1001 into wa_hrp1001 INDEX 1.
      refresh it_hrp1001.
      append wa_hrp1001 to it_hrp1001.

  • How to get the first and the last record of every month within a time range in sql

    I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
    where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
    SELECT PurOrderNum,
    OrderDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

  • Select first and last records in grouped results - Oracle 11g

    Say I have the following information in an Oracle 11g table:
    Qty
    Production order
    Date and time
    20
    00000000000000001
    12-JAN-14 00:02
    20
    00000000000000001
    12-JAN-14 00:05
    20
    00000000000000001
    12-JAN-14 00:07
    20
    00000000000000001
    13-JAN-14 00:09
    30
    00000000000000002
    12-JAN-14 00:11
    30
    00000000000000002
    12-JAN-14 00:15
    30
    00000000000000002
    12-JAN-14 00:20
    30
    00000000000000002
    14-JAN-14 00:29
    I would like to write a query that would return the following:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    13-JAN-14 00:09
    120
    00000000000000002
    12-JAN-14 00:11
    14-JAN-14 00:29
    That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order.
    I came up with a query that yielded this result:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    14-JAN-14 00:29
    120
    00000000000000002
    12-JAN-14 00:02
    14-JAN-14 00:29
    Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query
    I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank()and row_number() but my user does not have enough privileges to do so.
    Any help or hints will be greatly appreciated.

    Due to the fact that Oracle does not record the rows in any particular order, it would be wrong that the "first date" would be the first row processed by the query.
    Therefore you would have to supply some other column if you do not want to consider the table as ordered by date.
    Also, any analytical functions will need you to supply the "order by" and if its the date, then just a simple query will do:
    SQL>WITH Tab1 (Qty, Production_Order, Pdate)
      2       AS (SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:02', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      3           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:05', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      4           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:07', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      5           SELECT 20, '00000000000000001', TO_DATE ( '13-JAN-14 00:09', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      6           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:11', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      7           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:15', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      8           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:20', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      9           SELECT 30, '00000000000000002', TO_DATE ( '14-JAN-14 00:29', 'DD-MON-YY HH24:MI') FROM DUAL)
    10  SELECT   SUM ( Qty), Production_Order, MIN ( Pdate), MAX ( Pdate)
    11      FROM Tab1
    12  GROUP BY Production_Order
    13* ORDER BY Production_Order
    SQL> /
      SUM(QTY) PRODUCTION_ORDER     MIN(PDATE)                    MAX(PDATE)
            80 00000000000000001    12-Jan-2014 00:02:00          13-Jan-2014 00:09:00
           120 00000000000000002    12-Jan-2014 00:11:00          14-Jan-2014 00:29:00

  • Iphoto slideshow (9.5.1)is playing backwards.  last slide to first.

    My iphoto slideshow is playing backwards - last slide first.  How can I reverse that?

    Are you using an instant slideshow from an album? Instant slideshows cannot be manually sorted. Create a regular slideshow project with "File > New Slideshow". Then you have a better control about the arrangement of photos in the slideshow.

  • Format first and last record of result query

    Hello
    I have the following query
    <tt>select 1 seq, 'This is First record' data from dual union all
    select 2, 'Data ' || tname from tab union all
    select 3, 'This was last record Last record' from dual
    order by 1</tt>
    When i spool this statement to a listfile with col seq noprint option i get:
    This is First record
    Data MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    Data MLA_VPD_TABLES
    This was last record Last record
    But i want:
    This is First record MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    MLA_VPD_TABLES This was last record Last record
    I tried it with 1 statement with usage of lead and lag, because first and last record have to differ from the other result records. But i get ORA-30484: missing window specification for this function
    Is this possible with 1 statement or am i doomed to edit the results by myself?
    Thanks Auke

    select case row_number() over (order by tname)
    when 1 then 'This is the First record '
    end || tname ||
    case row_number() over (order by tname desc)
    when 1 then ' This was the last record'
    end
    from tab
    order by tname
    hth

  • How to take a value of the first record/occurrence and the last record?

    Hi experts
    Can anyone help me to tell me:
    How to make IP can take a value of the first record/occurrence and the last record in CSV file?
    I need to take the first and last to put StarTime of first record y StopTime of last record in the target file
    This is my Original CSV File
    20110820,220DNE0220,140.13 ,0.000 ,E01,0
    20110820,240FGC4280,103.80 ,0.000 ,E01,0
    20110821,220DNE0220,142.58 ,0.000 ,E01,0
    20110821,240FGC4280,88.70 ,0.000 ,E01,0
    20110822,220DNE0220,151.92 ,0.000 ,E01,0
    20110822,240FGC4280,91.47 ,0.000 ,E01,0
    Where:
    The firts field is date.
    I require it so my Target File
    20110820,20110822,140.13 ,0.000 ,E01,0
    20110820,20110822,103.80 ,0.000 ,E01,0
    20110820,20110822,142.58 ,0.000 ,E01,0
    20110820,20110822,88.70 ,0.000 ,E01,0
    20110820,20110822,151.92 ,0.000 ,E01,0
    20110820,20110822,91.47 ,0.000 ,E01,0
    Thaks..

    Hi lizcam,
    A. Use FCC at sender side, it will convert CSV to XML like this
    Input XML
    <documentName>
    <recordset>
    <record>
      <Time>20110820</Time>
      <ID>220DNE0220</ID>
      <Quan>140.13</Quan>
      <Volume>0.000</Volume>
      <Auc>E01</Auc>
      <No>0</No>
    </record>
    </recordset>
    </documentName>
    Create a target DT like this
    Output XML
    <recordset>
    <record>
      <StartTime>20110820</StartTime>
      <EndTime>20110822</EndTime>
      <Quan>140.13</Quan>
      <Volume>0.000</Volume>
      <Auc>E01</Auc>
      <No>0</No>
    </record>
    </recordset>
    In MM,
    1.Time -> CopyValue[0] -> StartTime
    2.Time -> below UDF -> EndTime
    3.Quan -> Quan
    4.Volume -> Volume
    5.Auc -> Auc
    6.No -> No
    UDF u2013 Execution type u2013 All values of Queue
    public void getLastTimeValue(String[] inputEndTime, ResultList result, Container container) throws StreamTransformationException{
    result.addValue(inputEndTime[inputEndTime.length-1]);
    B. At receiver use again FCC to convert XML to CSV.
    FYI. If you want to optimize more, you can use
    1.globalContainer concept OR
    2.u201CAttributes and Methodsu201D, declare are String. Store the EndTime using one UDF and write another UDF to retrieve it.
    Regards,
    Raghu_Vamsee

  • First and Last Record

    Hi everybody,
    I have problem with first and last record.How can I specified that current record is first and last record.
    it means that is any statement exist that determine :System.first_record is equal to :System.last_record.
    It's very emergancy.
    Thanks for your attention and your help.
    /Shiva

    You can try this:
    if :system.cursor_record = '1' and :system.last_record = 'TRUE' then
    -- this is the only record in block
    end if;
    Hi everybody,
    I have problem with first and last record.How can I specified that current record is first and last record.
    it means that is any statement exist that determine :System.first_record is equal to :System.last_record.
    It's very emergancy.
    Thanks for your attention and your help.
    /Shiva

  • How to "remember" data from the last or the first record printed on a page?

    I'd like to put a column value from the last record printed on the first page into a placeholder column (or whereever) to use later but I haven't found any way to do that. Trying the assignment statement with a placeholder in a format trigger causes "REP-1323: Cannot have output columns in format trigger...". Any ideas?

    Hi,
    SQL> select * from EMailNotify;
            ID TO_ADDRESS
             1 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
             2 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
             3 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
    SQL> update EMailNotify
      2  set to_address=replace(to_address,' [email protected],','');
    3 rows updated.
    SQL> select * from EMailNotify;
            ID TO_ADDRESS
             1 [email protected],[email protected], ma.ram @test.com,[email protected]
             2 [email protected],[email protected], ma.ram @test.com,[email protected]
             3 [email protected],[email protected], ma.ram @test.com,[email protected]

  • Fetch first and last record together

    Hi All,
    I want to fetch first and last records. I have done through ROWNUM, but I need some alternative ways, may be through RANK function.
    Please help on this.
    here sample data:
    WITH t AS
    (SELECT 100 sid, 'ABC' SNAME,  4 status_id, SYSDATE + 1/24 start_date FROM dual UNION ALL
    SELECT 100  sid, 'ABC' SNAME,  5 status_id ,SYSDATE + 2/24 start_date FROM dual UNION ALL
    SELECT 100  sid, 'ABC' SNAME,  6 status_id ,SYSDATE + 3/24 start_date FROM dual UNION ALL
    SELECT 100  sid, 'ABC' SNAME,  7 status_id ,SYSDATE + 3/24 start_date FROM dual UNION ALL
    SELECT 100  sid, 'ABC' SNAME,  8 status_id ,SYSDATE + 4/24 start_date FROM dual)
    SELECT * FROM t ORDER BY start_date;Thanks,

    if you want all the info on the same row.
    /* Formatted on 10/19/2011 7:06:50 AM (QP5 v5.149.1003.31008) */
    WITH t AS (SELECT 100 sid,
                      'ABC' SNAME,
                      4 status_id,
                      SYSDATE + 1 / 24 start_date
                 FROM DUAL
               UNION ALL
               SELECT 100 sid,
                      'ABC' SNAME,
                      5 status_id,
                      SYSDATE + 2 / 24 start_date
                 FROM DUAL
               UNION ALL
               SELECT 100 sid,
                      'ABC' SNAME,
                      6 status_id,
                      SYSDATE + 3 / 24 start_date
                 FROM DUAL
               UNION ALL
               SELECT 100 sid,
                      'ABC' SNAME,
                      7 status_id,
                      SYSDATE + 3 / 24 start_date
                 FROM DUAL
               UNION ALL
               SELECT 100 sid,
                      'ABC' SNAME,
                      8 status_id,
                      SYSDATE + 4 / 24 start_date
                 FROM DUAL)
      SELECT sid,
             sname,
             MIN (status_id) KEEP (DENSE_RANK FIRST ORDER BY start_date) min_status,
             MIN (start_date) min_dt,
             MAX (status_id) KEEP (DENSE_RANK FIRST ORDER BY start_date DESC)
                max_status,
             MAX (start_date) max_dt
        FROM t
    GROUP BY sid, sname
    SID     SNAME     MIN_STATUS     MIN_DT     MAX_STATUS     MAX_DT
    100     ABC     4     10/19/2011 8:05:54 AM     8     10/19/2011 11:05:54 AMEdited by: pollywog on Oct 19, 2011 7:11 AM

  • Getting first and last records of a query(on a table)

    Hello,
    i want to display the first and the last serial number(table: OBJK ) against a particulat matnr and obknr.
    how do i display only the first and only the last record of my query ?
    hope i am  comprehendedable..
    Thanks..
    Shehryar

    SELECT  min(sernr) max(sernr) into lfirst llast
    from objk
    where matnr = pmatnr
    and obknr = pobknr.
    ---Lets say you already have the data in the internal table in that case..
    SORT itab by SERNR.
    read table itab index 1.
    lfirst = itab-sernr.
    sort itab by sernr descending.
    read table itab index 1.
    llast = itab-sernr.
    Regards
    Anurag
    Message was edited by: Anurag Bankley
    Message was edited by: Anurag Bankley

  • How to get the first and last record

    Hai All
    I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
    form 13 june to 15 june data are here
    Kind Regards
    SrikkanthM

    Something like this can also indicate the first and last rows as you query...
    SQL> select empno, ename, hiredate
      2        ,case row_number() over (order by hiredate)
      3           when 1 then 'First Row'
      4           when count(*) over () then 'Last Row'
      5         end as flag
      6  from emp;
         EMPNO ENAME      HIREDATE            FLAG
          7369 SMITH      17/12/1980 00:00:00 First Row
          7499 ALLEN      20/02/1981 00:00:00
          7521 WARD       22/02/1981 00:00:00
          7566 JONES      02/04/1981 00:00:00
          7698 BLAKE      01/05/1981 00:00:00
          7782 CLARK      09/06/1981 00:00:00
          7844 TURNER     08/09/1981 00:00:00
          7654 MARTIN     28/09/1981 00:00:00
          7839 KING       17/11/1981 00:00:00
          7900 JAMES      03/12/1981 00:00:00
          7902 FORD       03/12/1981 00:00:00
          7934 MILLER     23/01/1982 00:00:00
          7788 SCOTT      19/04/1987 00:00:00
          7876 ADAMS      23/05/1987 00:00:00 Last Row
    14 rows selected.
    SQL>

Maybe you are looking for

  • Can't locate song files!!!

    So the family's iTunes account was transferred to my new laptop because the previous one was getting old and slow. Our computer genius transferred everything seamlessly and it was fine. However, as of late, we are missing over 300 songs on our librar

  • USB hard drives S

    Hi guys, My iMac only has one FireWire port (800) and this is being taken up by my audio interface (RME FF400) My question is, will a USB hard drive be fast enough to record audio? I'm recording a maximum of 6 to 10 tracks at the same time . Any info

  • PA: module-rtp-recv: Sink does not exist

    Hello Archers, I really would like to route my primary computer's sound via RTP to a remote machine (a laptop, which is used as my home server). Both machines have Pulseaudio set up and local playback on both works fine. Unfortunately on the remote m

  • Adobe Presenter Multi Language Publishing Support?

    Hi, I have a requirement where I wanted to convert the English course into the following 26 languages: Arabic   Chinese (Simplified)   Chinese (Traditional)   Croatian   Czech   Dutch   Finnish   French (Europe)   German (Germany)    Greek    Hindi  

  • Cannot play flv or swf file.

    I am using Dreamweaver 8 and Flash 8 in an attempt to play a flash video on my website. I have read the tutorials thoroughly and I still cannot get a video to show on my website. I have tried inserting swf files and I have tried inserting flv files.