Retrieve last records in GRPO table.

Hello All,
I have a doubt in the query where i want to retrive last six records of GRPO No. for particular item no. from SAP business table, if i pass parameter 1 then it should display last one record, if i pass parameter 2 then last two records.
Sap business table = OPDN, OPOR
Please suggest me.
Thanks,
Avijit

HEllo frnds, thanks for the reply.
But i want to display report dynamically from the selection paramter.
Please see the below code, currently its displaying all the GPRO#, Date, Quantity and Rate based upon the Item(those items which have PO status open).
I want to restrict it up to 6 GRPO Nos....
SELECT  OPDN.[DocNum]AS GRPONO, CONVERT(NVARCHAR,OPDN.[DocDate],103) AS GRPODATE,
SUM(PDN1.[Quantity]) AS GRPOQUANTITY, PDN1.[PriceBefDi]AS GRPORATE,
T0.[DocNum]AS PONO,T1.[Dscription]AS POITEMDESCRIPTION,
SUM(T1.[Quantity]) AS POQUANTITY, T1.[PriceBefDi] AS PORATE
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT join PDN1  ON T1.ItemCode = PDN1.ItemCode
LEFT join opdn ON opdn.DocEntry = PDN1.DocEntry
WHERE T0.DocStatus = 'O' AND T1.LineStatus = 'O'
and T0.U_MStatus <> '' and T0.canceled = 'N'
and T0.DOCNUM IN (615)
GROUP BY
OPDN.[DocNum], CONVERT(NVARCHAR,OPDN.[DocDate],103),
PDN1.[Quantity], PDN1.[PriceBefDi],
T0.[DocNum],T1.[Dscription],
T1.[Quantity], T1.[PriceBefDi]
ORDER BY OPDN.[DocNum] DESC,T1.[Dscription]
This is display as :-
PO Number PO Description      Quantity Rate      GRPONo GRPODate           Quantity      Rate
615      TRANSTEL DK XXXX
                    2      41.63
                              700      07/02/2009      10           42.46
                              681      06/01/2009      10           42.463
                              649      06/11/2008      7           42.462857
                              617      18/09/2008      15           42.4626
                              562      11/07/2008      20           42.4625
                              517      07/05/2008      25           42.4628
                              285      10/03/2008      46           42.878
Look The GRPO No  its display all the records, i only want to display last six records also i want to restrict it from 01/04/2009.
I dont want to display before that.
Edited by: Chintesh Soni on Jan 25, 2010 7:06 PM

Similar Messages

  • Fetch last record from database table

    hi,
    how to fetch last record from database table.
    plz reply earliest.
    Regards,
    Jyotsna
    Moderator message - Please search before asking - post locked
    Edited by: Rob Burbank on Dec 11, 2009 9:44 AM

    abhi,
    just imagine the table to be BSEG or FAGLFLEXA... then what would be performance of the code ?
    any ways,
    jyotsna, first check if you have a pattern to follow like if the primary key field have a increasing number range or it would be great if you find a date field which stores the inserted date or some thing..
    you can select max or that field or order by descending using select single.
    or get all data.. sort in descending order.(again you need some criteria like date).
    read the first entry. using read itab index 1

  • How to find the last records of the table in adventure work db

    hi all,
    i want to find out " how to receive a last records of the table (eg:  person.emailaddress ) in sql 2008 and 2005"
    Thanks

    If you are looking for the latest record( the one which got inserted/modified last) then use this query
    select top 1 * from person.emailaddress
    Order by ModifiedDate desc
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • 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 retrieve last record entered into database

    Hi all,
    I want to retrieve the last resord entered into a database table.
    I have a MS Access database.
    This code does not return the last record but its my nearest attempt to.
    Can anyone suggest the correct SQL or Solution.
    Help is greatly appriciated.
    Thanks.
    String str = "SELECT * FROM Missions WHERE Mission = (SELECT MAX(Mission) FROM MISSIONS)";
            ResultSet rs = null;
                String f1 = null, f2 = null, f3 = null, f4 = null;
                try{   
                    rs = statement.executeQuery(str);
                    txtMissionInformation.setText("");
                    int row = 0;
                    while(rs.next()){
                        f1 = rs.getString(1);
                        f2 = rs.getString(2);
                        f3 = rs.getString(3);
                        f4 = rs.getString(4);
                        System.out.println(f1 + " " + f2 + " "+f3+" "+f4);
                        txtMissionInformation.append(f1 + ", "+ f2 + ""+","+f3+","+f4);
                    System.out.println("Query Complete !");
                } catch(Exception e){
                    e.printStackTrace();
                }

    I fixed my problem, i aded an autonumber field to my database set it as primary key and called it ID. i then used the syntax from before and it worked.

  • Delete last record in plsql table

    TYPE r_LOOPElement IS RECORD (TermID   NUMBER
    TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
    i_CustomerLoop      t_LOOPType ;
    i_CustomerLoop(1).TermID=1;
    i_CustomerLoop(2).TermID=2;
    i_CustomerLoop(3).TermID=3;based on some conditions, i need to delete the last record from i_CustomerLoop
    whichi s the best way to do it. because i will sometimes have duplicate values for TermID in this plsql table.

    Hi,
    See [Deleting Collection Elements (DELETE Method)|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]
    Regards,

  • How to fetch last record from the table to display in screen painter?

    Hi Gurus,
                  I have a requirement where i have to fetch the last record value in the table.
    I have a screen where the TEXT name is REQUEST and I/P field name is REQ and SAVE push button.
    In this I/P field automatically 1 should display when i excecute the program and when i save this, the request number should turn to 2 that is dynamically..once agin save then 3 and so on....and this 1, 2, 3 will be storeing in table.
    I have succeeded till generating the values dynamically and saving in the table like 1 is displayed and when i click save it is changeing to 2..but the problem is when i am coming out of program and logon again the request number is again displaying as 1 rather it has to start with 4 because already 3 request are there in the table.
    My code is...
    Table zsave.
    data declarations....
    data req type i.
    req = 0.
    req = zsave-req.
    PROCESS BEFORE OUTPUT
    req = 0.
    select req into table fun_st from zsave.
    req = zsave-req.
    zsave-req = req.
    req = zsave-req + 1.
    PAI
    req = zsave-req + 1.
    zsave-req = req.
    when 'save'.
    wa_funst-req = zsave-req.
    Please can you provide me with the solution....answer will be rewared.
    THKS

    Can you tell me, when updaing the ZSAVE table with the counter value are you modifying the exisiting value or inserting the value as new record?
    From the code in your first post, i see that you are extracting records into internal table but when you are moving to variable REQ, you are moving from table work area which is blank, so everytime when you execute it may be starting as 0.
    Hope below code can help you understand on handling your requirement
    Global Declaration:
    >DATA: l_req TYPE i. 
    PBO:
      SELECT MAX( req ) INTO l_req FROM zsave.
      l_req = l_req + 1.
    PAI:
      DATA: wa TYPE zsave.
      CASE ucomm.
      WHEN 'SAVE'.
        wa-req = l_req.
        INSERT zsave FROM wa.
      ENDCASE.

  • How i know when a EXECUTE_QUERY retrieved last record

    Hi...
    How i know when the EXECUTE QUERY retrieved the last record in a block ....?
    Exist a trigger after trigger POST-QUERY?
    Regards
    Hector Gabriel Ulloa Ligarius
    Santiago of Chile
    http://es.groups.yahoo.com/group/desarrolloOracle/

    Kevin, sorry
    But the :system.last_record not change the value during the execution of EXECUTE_QUERY.
    Only useful when the data was retrieved into blocks...not during..
    Other mode?
    Regards
    Hector Gabriel Ulloa Ligarius
    Santiago of Chile
    http://es.groups.yahoo.com/group/desarrolloOracle/

  • Stored pl/sql procedure retrieving similar records from different tables using

    Hi all I'm trying to retrieve the employee num and employee name if they are both a driver and mechanic
    I'm script my own procedure and it compiles with no issue but when i try to execute it. they will show me this error.
    Error starting at line 29 in command:
    EXECUTE VERIFY(1,'John Smith')
    Error report:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "CARSON.VERIFY", line 8
    ORA-06512: at line 1
    01422. 00000 -  "exact fetch returns more than requested number of rows"
    *Cause:    The number specified in exact fetch is less than the rows returned.
    *Action:   Rewrite the query or change number of rows requested
    This is how my procedure look like:
    CREATE OR REPLACE PROCEDURE VERIFY(
    enum IN NUMBER,
    ename IN VARCHAR) IS
    empnum NUMBER;
    empname VARCHAR(50);
    Fail EXCEPTION;
    BEGIN
    select employee.e#, employee.name
    into empnum, empname
    from employee join driver
    on driver.e# = employee.e#
    join mechanic
    on driver.e# = enum;
    EXCEPTION
    WHEN Fail THEN
    dbms_output.put_line('OK');
    END VERIFY;
    and this is how i execute the procedure
    EXECUTE VERIFY(1,'John Smith');
    so may i know what have gone wrong? would be glad if someone is able to enlighten me.

    No need for a loop.
    Just make sure that your query always returns at most one row. Adding a predicate like 'where rownum=1' is a way to achieve that:
    select employee.e#
    ,      employee.name
    into   empnum
    ,      empname
    from   employee join driver on driver.e# = employee.e#
                    join mechanic on driver.e# = enum
    where rownum = 1;

  • Last record retrieval

    Hi,
    I'd like to know how I can retrieve the last inserted tuple in a table with an SQL select.
    Thank you

    a rowid cannot be sorted alphabetically to retrieve last record.
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#sthref3904
    a rowid contains the object number, the datafile number, the data block number, the row in the block.
    A segment can have many datafiles, many blocks and many rows. There is no way of knowing in which file/block/position the next row will be inserted. It is an oracle internal mechanism.
    For the OP, you can either implement a kind of trigger inserting a timestamp or have a look at log miner to analyze archive logs or even implement auditting
    HTH
    Laurent

  • Accessing the very last record in a transparent table.

    Hi!
    There's any way to read the last record of a transparent table?
    My problem is:
    I have to access the very las record of a Z table because I need the maximun value of a numeric field (that is the first field of the primary key).
    I used a SELECT MAX, with no condition , but I was asked to find a more performance solution.
    There is any way to access the last record of a table? Something like we have for the internal tables with the READ TABLE INDEX N, but with a select statement?
    Thanks a lot for your help!

    Yes, that was my first thought, but I made a comparising between both options with SE30.
    Check this numbers:
    TIME:  11,377,702
    select * from t100 into table t_t100.
    sort t_t100 descending.
    read table t_t100 index 1.
    TIME: 954,218
    DATA: MAX_MSGNR type t100-msgnr.
    SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr.
    Select MAX is better...
    I don't think there is a better solucion... Maybe a big brain here has an idea...
    Vasanth, thanks for your quick reply!

  • Need to fetch the last record/row from a table

    Hi,
    I have a requirement like fetching the closing balance of the last record of the table and inserting the same into the opening balance of the immediatetly created next record.
    In simple words, I need to fetch a value from the last row of the record.
    For example, I use the below query,
    select rownum, empno, ename from emp
    where rownum = (select count(rownum) from emp);
    But, the above query does not return any of the record.
    Hence, need help on this.
    Regards,
    Shivakumar A
    Edited by: shiva on Mar 27, 2011 10:14 PM

    Rows in a table are inherently unordered. In order to introduce the concept of "first" and "last", you would need to specify how to order the rows which would require that there was one or more columns in the table that you could order by in order to determine the "last" record.
    In your closing balance example, if we assume that there is something like a BALANCE_DATE column,
    SELECT account_number, balance_amount, balance_date
      FROM (
        SELECT account_number,
               balance_amount,
               balance_date,
               rank() over (partition by account_number order by balance_date desc) rnk
          FROM table_of_balances )
    WHERE rnk = 1Justin

  • Read the last record in the database table..

    Hi..
    I am new to ABAP. So i have one condition to read the address number field in the last record from database table by using the person number where clause field.
    But the person number is same for some the records.
    So can any tell me the logic for to read the addressnumber field in the last record of selected records from database where personnumber is equal to some thing.
    Please help me..
    Thanks
    venki

    Hi Venkat ,
    u mean to say
    person number  addressnumber
    aa1            0000000000001
    aa1            0000000000002
    aa1            0000000000003
    aa1            0000000000004
    aa2            0000000000021
    aa3            0000000000110
    if i have to read the addressnumber 00000000000004
    of the person number aa1
    u can go like
    data v_address number like addressnumber.
    sort itab by personnumber addressnumber
    loop at itab .
    at end of personnumber.
    move addressnumber to v_addressnumber ..
    endat.
    endloop.
    so using control break statements i can fetch the last record of my person number if at all the same person number is having more than one address number ..
    hope this helps,
    Regards,
    Vijay
    Message was edited by: Vijay

  • Retrive last inserted  record  from database table

    Hi,
    some body inserting a record into table 'A' through some procedure/java program.i want to retrive the last inserted record from database table.records are not stored in order.Can any body help me.

    In general, unless you are storing a timestamp as part of the row or you have some sort of auditing in place, Oracle has no idea what the "first" or "last" record in a table is. Nor does it track when a row was inserted.
    - If you have the archived logs from the point in time when the row was inserted, you could use LogMiner to find the timestamp
    - If the insert happened recently (i.e. within hours), you may be able to use flashback query to get the value
    - If you're on 10g or later and the table was built with ROWDEPENDENCIES and the insert happened in the last few days and you can deal with a granularity of a few seconds and you don't need 100% accuracy, you could get the ORA_ROWSCN of the row and convert that to a timestamp.
    If this is something you contemplate needing, you need to store the data in the row or set up some sort of auditing.
    Justin

  • How to get the last record??

    Hi, I now have to get only the last record from one table
    from MS Access.
    I was looking for the useful method from API, however,
    I cannot get it.
    How to get only the last record from one table ???
    Please help, thanks.

    In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
    Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
    So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
    For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
    select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
    the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
    bRi

Maybe you are looking for

  • No sound output from dock connector or headphones but speaker is fine

    I've got a 3GS which I've had since October. Recently, there has been no sound output from the headphone socket - or rather, what does come out is very strange, sounding almost electronically distorted. I thought that maybe the headphone jack was bro

  • Try get value in input type="file". Not is full path. It's bug?

    In html: <input type="file" id="path_image"> In javascript: path_image = document.getElementById("path_image").value; Example: Select path: "/images/image.gif" This result: path_image = " image.gif"

  • Ipad 3 cases compatible with smart cover.

    Hi, im looking for a ipad 3 case that willl work with the smart cover but there is not alot online and wanted to know if anyone had and ideas. thanks

  • Order of windows services

    Hi Guys, I recently installed Oracle EBS R12.1.1 on Windows XP Pro, well i want to know in which order oracle's windows services are executed/loaded(with what parameters) at the windows start-up.......i want to make batch files to start and stop serv

  • An Error is ocurring during I try to deploy a new version of a proyect

    Hi there. I changed the ip address of my SQL Server, where databases of Engine and Dir were. Then I enter through the Administrator Workspace and change the ip address wrong for the new one. After that, I recreate the .ear files and restart my Aplica