Skip to Content
author's profile photo Former Member
Former Member

Need a last record based on conditions.

Hi,

Could anyone tell me how to select the last record, based on some certain conditions, from an internal table? There is the loop - endloop which seems to be an easy solution except for that it shows up in the Check.

Please help. Points will be awarded.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Nov 22, 2007 at 01:41 PM

    hi Prem,

    SORT the table before the READ TABLE statement.

    let's say you have your conditions field1 and field2 and you want to have the last record acc. to field3:

    SORT itab field1 field2 field3 DESCENDING.

    READ TABLE itab

    WITH KEY field1 =

    field2 =

    Now you'll get the last record (acc. to field3)

    hope this helps

    ec

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 01:24 PM

    Hi

    Describe table itab

    it gives rec count

    then

    go for sy-tabix

    with if condition and fetch the last rec with the no given in the rec count

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 01:40 PM

    Hi Prem,

    do like this

    Describe table itab lines lv_lines.
    
    Read tables itab into wa index lv_lines with key....

    Regards,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 02:04 PM

    Hi Prem,

    It is easy what you want:

    please copy this code making necessary requirement:

    Data: itabCount type i.

    Data: wa like line of itab.

    Describe table itab lines itabCount.

    read table itab index itabcount into wa.

    This will give you the last record.

    Thanks.

    Please do not forget to reward if helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 02:14 PM

    Hi..

    Use the system Field <b>Sy-tfill</b>.

    It stores the last index of the internal table..

    Eg:

    data : begin of itab occurs 0,

    Square type i,

    Cube type i,

    end of itab.

    do 10 times.

    itab-square = sy-index * 2.

    itab-cube = sy-index * 3.

    append itab.

    enddo.

    read table itab index sy-tfill.

    write : itab-square,itab-cube.

    Answer will be : 20 30 .(Because it will read the SY_TFILL value)

    Post me for furthur Queries.

    Regards.

    Bala..

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 24, 2007 at 04:04 AM

    Hi Guys,

    Thanks for your reply. As promised I have awarded points to the solution. I am unable to give out the rest as helpful answers because most of them were to find the last record in an internal table and not the last record in an internal table based on conditions.

    Cheers!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.