Getting the last record from the internal table

When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
I have a internal table like
id     type
N1      A
N1      T
N1      A
N1      6 ----> LAST RECORD
my code is
read table itab wIth key id = netobjid.
for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
How to do that?

HI
actually i have done same requirement like this ...
Take  one count variable into your internal table ..you pass the number of records into cont variable for every time  u enter the loop .
Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
Then use read statement with sy-index = 1 .
USe below logic ,............
data  :  count  type i value '0'.
LOOP at int .
count = count + 1 .
endloop.
sort int count descending .
read int  with  index = 1 .

Similar Messages

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

  • Read the last record of an internal table

    Hello All,
    I need to read the last entry of the internal table? Is it possible to achieve this without using loop - endloop?
    In the following example, I need to get the Batch '110776' and store it in a variable.
    ITAB:
    MATNR|CHARG
    010780|110770
    010780|110772
    010780|110773
    010780|110774
    010780|110775
    010780|110776
    Thanks.

    Use DESCRIBE to get the number of entires in variable last_entry
    and then use read table ....index last_entry

  • How to delete the matching records from two internal tables

    Hi ,
    I have two internal tables say A and B of the same type. If A has 10 records and B has 4 records , I want to delete the 4 records in B from A .
    loop at B into wa .
    delete A where key = wa - key .
    endloop.
    takes a long time if the table B is huge. how can I improve the performance.
    Thanks.
    Gayathri

    Hi Gayathri,
    You could try field-symbols. It reduces the data transfer from the internal table B to the work area.
    field-symbols <fs_itab_b> like line of B.
    loop at B assigning <fs_itab_b>.
      delete A where key = <fs_itab_b>?-key.
    endloop.
    Regards,
    <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=zwcc%2fwm4ups%3d">anand Mandalika</a>.

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

  • How can I search the last line in an internal table?

    How can I search the last line in an internal table?
    With a describe?? If it is , how can I do that?
    Thanks!!

    Hi shilpa,
    it seems to be you are NEW to SDN. welcome. if you want to get solutions to your Questions, you have to post a NEW thread.dont use the existing thread to post your question.
    any way i am giving you the solution for your question
    LOOP AT ITAB WHERE F1 = <SOME VALUE>
                       F2 = <SOME VALUE>.
    ENDLOOP.
    IF SY-SUBRC = 0.
      ITAB WILL HAVE THE LAST RECORD which satisfying the given criteria in WHERE clause of LOOP.
      write itab <--this ITAB will have the last record.
    ENDIF.
    regards,
    Srikanth.
    Message was edited by: Srikanth Kidambi

  • Help needed to get unique record from an internal table

    Hi Everybody,
    I have to get unique record from an internal table. i know we can use read statement with key condition .
    But the problem is i have to use some relational operators like GE or LE.
    eg
    read table itab into wa with key width GE itab-widthfrom
                                                       width LE itab-widthto
                                                       machno eq itab-machno.
    Its giving me error when I use the operators GE , LE.( I think since it can't find a unique record with those relational
    operators in the with key statement)
    Is there any other way to get unique record from internal table without using the loop?
    Thanks,
    Sunny

    Using the read statement you will need some kind of loop. For example.
    DO.
    READ TABLE......
      WITH KEY ......
                        READ = SPACE
    IF SY-SUBRC EQ 0
      TABLE-READ = 'X'.
      MODIFY TABLE
      ADD 1 TO W_FOUND.
    ELSE
      EXIT.
    ENDIF
    ENDDO.
    IF W_FOUND EQ 1.
    ...record is unique.
    ENDIF.

  • 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

  • How to get first 10 records from the database using JSP

    i want ot get first 10 records from the database and then after clicking the next button in the page,it must show the next precceding 10 records from the database.i am getting the first 10 records .but how to post to the same page to get another preceeding 10 record.

    Search the forums - this has been asked a lot. I usually recommend experimenting with tops and order bys until you're satisfied.
    Kind regards,
      Levi

  • Filtering records from one internal table based on ranges in another itab

    Hi guys,
    I have 1 internal table with set of GL accounts. I have 2nd internal table where lower interval  and upper interval of GL accounts
    How to filter out records from 1 internal table by comparing with the GL account ranges present in 2nd internal table.
    Please reply.

    Hi
    Create a RANGE for GL Accounts.
    LOOP the second Internal Table.
    And assign HIGH & LOW to ranges from second ITAB.
    And Delete the accounts which are not there in the range.
    Use the below code as reference.
    DATA: itab TYPE TABLE OF mara WITH HEADER LINE.
    DATA: r_matnr TYPE RANGE OF matnr WITH HEADER LINE.
      SELECT * FROM mara INTO TABLE itab UP TO 10 ROWS.
      r_matnr-sign = 'I'.
      r_matnr-option = 'BT'.
      r_matnr-low  = '000000000016900036'.
      r_matnr-high = '000000000016900040'.
      APPEND r_matnr.
      DELETE itab WHERE matnr NOT IN r_matnr.

  • 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.

  • Get the last query from the current user

    Is there a way to get the last query of the current user, so every query could be log with a database trigger?
    Let's just say I execute:
    DELETE xxxx;
    I tried :
    SELECT T.SQL_TEXT FROM V$SQLAREA T where ADDRESS=(SELECT prev_sql_addr FROM v$session where audsid=userenv('sessionid'));
    But the result of this query is :
    'SELECT T.SQL_TEXT FROM V$SQLAREA T where ADDRESS=(SELECT prev_sql_addr FROM v$session where audsid=userenv('sessionid'))'
    Is there a way to execute a query that would return :
    'DELETE xxxx'
    Thanks

    You could join SQL_ADDR in v$session with ADDRESS in v$sqlarea to determine the SID that executed that SQL statement last. Note that PREV_SQL_ADDR in v$session will indicate the previous SQL he executed. Though you would have to look at these tables very often to get all SQL statements issued. One note here, I think if a different user ran the SAME SQL with just bind var differences the SQL_AREA will only show the last user’s information that executed it.
    BTW - it will show deletes also...

  • 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

  • How to handle the failed records from the table when using DB Adapter

    Hi,
    I am reading some records from table using DB Adapter inside my synchronous BPEL process. Say like reading 100 records from table in between after successful reading of 90 records an error occured in 91st record due some various reasons(like DB down, Connection interrupted etc.). Then how to handle this situation, whether i have to read all the records from the begining and is there any option to continue from where it stopped reading.
    Can please anybody help me out in the regard?
    Thanks in advance
    Regards,
    Aejaz

    we had the same requirement some time ago and had two option:
    1. ask the R/3 development team add a deletion indicator in the table (and thus not actually deleting the record). this deletion indicator could then be used like for any other standard datasource
    this option was however refused, due to huge data volume after a while
    2. at the end of the load we copied the ZTABLE1 to ZTABLE2. then in the begin of the load (day after) we compare the data of table1 to table2. entries available in table2 but not in table1 are deleted, and we put a 'D'. in deletion indicator; as we only keep the deleted entries for one day, the volume of the new table is acceptable.
    M.

Maybe you are looking for

  • Error 14 when upgrading to 3.0

    Last night I tried to upgrade my 3G phone to 3.0 and had some problems. The update downloaded fine, and as the software was installing it would crash with an unknown error (14) about a minute into loading the software. The phone sits with the connect

  • How do I fix that my internet is not connecting, but the service is good

    The internet on my IMac desktop computer is not always connecting to the internet. The cable service is good because I have a PC next to it hooking up fine. Does anyone have any suggestions?

  • ITunes refuses to copy TV Shows based on episode numbers...!

    I have a lot of TV content in iTunes, some bought from the iTunes store, some I have ripped and encoded myself. Everything is tagged thoroughly and correctly with episode IDs, episode numbers, watched/unwatched flags, series and season info, even epi

  • HT1937 Play video on TV?

    Can you play video on to t.v. Using 30 pin to hdmi cable ? I have iphone 4 don't want to Spend 50 if it doesn't work? Thanks

  • Command-shift-4 is not working!

    Command-shift-4 is not working for me! I know that the deafult shortcut for taking screenshots is command-shift-3, but i want to take portion of the screen and that is command-shift-4. I have tried everything wich is; 1: Log out and restart then logi