Skip to Content
avatar image
Former Member

How to get the only the last raw of the table

Hello All,

While fetching a table into internal table, how to get only the last record of the table.?

Thanks and Regards, Pradeep

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • avatar image
    Former Member
    Oct 10, 2007 at 05:19 AM

    First get the number of rows in table by using DESCRIBE command

    DESCRIBE <> into a variable v_index

    then use READ stmt as

    READ table <tab> index v_index.

    This will work out

    Reward if helpful

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 05:20 AM

    Hi,

    Get the number of rows using the DESCRIBE statement and then use READ TABLE ..INDEX..

    Ex..

    DESCRIBE TABLE ITAB.

    READ TABLE ITAB INDEX sy-tfill.

    Thanks

    Naren

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member
       
      SELECT COUNT(*)
        FROM DBTAB
        INTO v_index.
       
      SELECT *
        FROM DBTAB
        INTO TABLE itab.
       
      READ TABLE itab INTO x_tab INDEX V_INDEX.
  • Oct 10, 2007 at 05:26 AM

    hi Pradeep..

    Try this way.

    SELECT <FIELDS> FROM dbtable INTO table ITAB.

    DESCRIBE TABLE ITAB.

    read table itab INDEX sy-tfill. "Last record

    REWARD IF HELPFUL.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 05:30 AM

    Hi Pradeep,

    Use this..

    DESCRIBE TABLE ITAB.

    READ TABLE ITAB INDEX sy-tfill.

    Reward if Useful.

    Regards,

    Chitra

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 05:32 AM

    hi,

    use this...

    <b>DESCRIBE TABLE ITAB.

    READ TABLE ITAB INDEX sy-tfill.</b>

    With RGds,

    S.Barani

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I hope following code will solve your problem.

      DATA : it_bseg TYPE TABLE OF bseg,

      x_bseg TYPE bseg,

      v_index TYPE i.

      SELECT COUNT(*)

      FROM bseg

      INTO v_index.

      SELECT *

      FROM bseg

      INTO TABLE it_bseg.

      READ TABLE it_bseg INTO x_bseg INDEX V_INDEX.

      First SELECT will give you the number of rows in a table in v_index. Second SELECT will fetch all table data and then READ will give you the last record of the table in a structure x_bseg.

      Reward points if the answer is helpful.

  • avatar image
    Former Member
    Oct 10, 2007 at 07:00 AM

    Hi Pradeep,

    Suppose your table is T549A.

    <b>check the below code.</b>

    data wa like t549a.

    data itab like t549a occurs 0 with header line.

    select * from t549a into wa.

    move-corresponding wa to itab.

    endselect.

    append itab.

    *So itab contains the last record of the given selections.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 07:04 AM

    select * from <table>

    into wa_tab

    upto 1 rows order descending by <key field>.

    this will give u the last record.

    *reward if solved*

    Add comment
    10|10000 characters needed characters exceeded