Register Login

How to Retrieve Last Record from Table

Updated May 18, 2018

SAP ABAP Select Last Record

Hi All,

We are on SAP 4.7R3 ext 200. Oracle 9.2 and Solaris 5.9

I upgraded my SAP Support packages, since then my SAP is running slow

In stack 30 I upgraded:

  • ABA_PLUS 16 to 20 PI patch 8 to 15
  • PI_BASIS 2004_1_620 to 2005_1_620 patch 16
  • SAP_ABA 55 TO 64
  • SAP_APPL 25 to 30
  • SAP_BASIS 55 TO 64

my SP Manager was 6.20/32 and kernel was 221

After applying above stack I run SGEN and generate only above. I ignore others like SAP_HR,EA_APPL etc.

Is that OK or I should generate all in my SAP

Any suggestion in this regard.

Thanks in Advance!


Comments

  • 11 Apr 2009 12:16 pm Manoj Helpful Answer
    Use types in data declaration.

    try this.
    Types:begin of ty_zbt_bonus,
    man(3) type c,
    poz(3) type c,
    tel(6) type c,
    name(25) type c,
    surname(35) type c,
    novi(1) type c,
    dat type dats,
    usnam(12) type c,
    end of ty_bonus.

    DATA: WA_ZBT_BONUS TYPE TY_ZBT_BONUS,
    IT_ZBT_BONUS TYPE STANDARD TABLE OF TY_ZBT_BONUS.

    select * from
    zbt_bonus
    into table IT_ZBT_BONUS.

    SORT it_zbt_bonus BY dat descending.

    read table IT_ZBT_BONUS INTO WA_ZBT_BONUS index 1.

    WRITE: / WA_ZBT_BONUS- poz,
    WA_ZBT_BONUS- tel,
    WA_ZBT_BONUS- name,
    WA_ZBT_BONUS- surname.

    Because we are descending by date, we make sure that while inserting records, system date is used and last record is with latest date always in inserting ..then it will work out.

    Hope it clarifies,,
  • 11 Apr 2009 12:17 pm Manoj Helpful Answer
    hi try this = D

    data: begin of itab occurs 0,
    man(3) type c,
    poz(3) type c,
    tel(6) type c,
    name(25) type c,
    surname(35) type c,
    novi(1) type c,
    dat type dats,
    usnam(12) type c,
    end of itab. ' the same structure like zbt_bonus table
    data cant type i.

    select * from zbt_bonus into table itab.
    describe table itab.
    cant = sy-tfill.

    read table itab index cant.
    WRITE: / itab-poz, itab-tel, itab-name, itab-surname.

    good luck.
  • 11 Apr 2009 12:18 pm Shalesh Singh Visen Helpful Answer
    Hi, you can use the field dbcnt of the sy variable to know how many record retrieve the select statement, such like this

    data v_cant like sy-dbcnt.

    select * from zbt_bonus into table itab.

    v_cant = sy-dbcnt.

    read table itab index cant.

    good luck.
  • 12 Apr 2009 1:39 am Shalesh Singh Visen Helpful Answer
    step 1. I insert record manually (SE16N) and run report. it gives me last record.

    step2. when I insert record using screen control (small example in se51) then report doesn't return me that last recurd. it returns me record from step 1.
  • 11 Apr 2009 11:49 am Manoj
    Sort the table descending and based on that read the table index 1, so that u can retrieve ur last record
  • 11 Apr 2009 11:50 am Manoj
    SORT ITAB BY zbt_bonus-pozivni DESCENDING.
    READ TABLE ITAB INDEX 1.
    WRITE:/ ITAB-zbt_bonus- pozivni

    1. what if 2 more fileds are primary keys??
    2. zbt_bonus-pozivni is char- not numeric??
  • 11 Apr 2009 11:51 am Manoj
    Code this as

    SORT ITTAB DESCENDING BY zbt_bonus-pozivni.

    If 2 r more fields as primary key,you can specify that separated by comma.

    If if the field is non numeric it will be sorted accordingly.
  • 11 Apr 2009 11:53 am rekha
    But these primary keys are char, for ex:

    123456
    234567
    765432 etc...
    and it refers to phone number. if I sort them like you said
    it means that last record will be considered?

    Maybe it is better to do this sorting by system date or time??

    What do you think?
  • 11 Apr 2009 11:53 am Manoj
    try this:

    data: v_lines type sy-tabix.
    select * from zbt_bonus into table itab.
    if sy-subrc eq 0.
    describe itab lines v_lines
    read table itab index v_lines into
    endif.
  • 11 Apr 2009 11:53 am rekha
    I have no wa_area defined., should I define one?
  • 11 Apr 2009 11:54 am rekha
    Obviously..

    or you declare like this

    data: wa_area like line of itab.
  • 11 Apr 2009 12:15 pm Manoj
    hi, I tried like this

    data: begin of itab occurs 0,
    man(3) type c,
    poz(3) type c,
    tel(6) type c,
    name(25) type c,
    surname(35) type c,
    novi(1) type c,
    dat type dats,
    usnam(12) type c,
    end of itab. ' the same structure like zbt_bonus table

    select * from zbt_bonus into table itab.
    SORT itab BY dat descending.
    read table itab index 1.
    WRITE: / itab-poz, itab-tel, itab-name, itab-surname.

    but I dont get last inserted record (in zbt_bonus) :((

    Any idea?
  • 11 Apr 2009 12:17 pm Shalesh Singh Visen
    how are the entries in table ZBT_BONUS created? Is the date field when it was inserted into the table? Is the poz field a sequential field?
  • 12 Apr 2009 1:56 am Shalesh Singh Visen
    Date should be mandatory when entering data on screen.
  • 04 May 2009 7:23 am Guest
    select * from zbt_bonus into table itab.
    data: int_line type i.

    describe table zbt_bonus lines int_line .

    read table zbt_bonus index int_line.

    this will give u the last record.

    Nafran
  • 02 Aug 2010 5:44 am Guest
    SELECT __ FROM TABLE INTO CORRESPONDING FIELDS OF TABLE ITAB
    WHERE__ ORDER BY __ DESCENDING.
    IF SY-SUBRC EQ 0.
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING_.
    ENDIF.
  • 07 Apr 2016 10:25 am vamsilakshman.p

    Hi ,

    Sort the Table with Descending order...

    Read Table with index 1....It will fetch Last Record of the Table...

     

     

    Thanks  & Regards

    Vamsi


×