Skip to Content

deleting records from internal table

hi, i have a small requirment ,i dont know if it is really tough.

requirment is to display records which were craeted at last for a paticular field value.

ex:

these are the records of the internal table out of these records i would like to display

last created entry for each drvr.

internal table entries :

plant dutycard no drvr drnm crdt

2001 17 d0001 ram 20131010

2001 19 d0001 ram 20140101

2001 21 d0001 ram 20131004

2001 22 d0002 raju 20130112

and the expected output is

output :

2001 19 d0001 ram 20140101

2001 22 d0002 raju 20130112

can anyone help out by providing logic.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2014 at 04:27 PM

    There is another simple option :

    SORT table BY drvr ASCENDING credt DESCENDING.

    DELETE ADJACENT DUPLICATES FROM table COMPARING drvr.


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2014 at 11:49 AM

    hi,

    sort the internal table by descending order by keeping date field as a reference the syntax is as follows.

    just see this link.

    Sorting Internal Tables (SAP Library - ABAP Programming (BC-ABA))

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2014 at 02:17 PM

    Hi Prakash,

    check the code!

    TYPES: BEGIN OF ty_temp,
    plant(4),
    dutycardno(2),
    drnm(10),
    dats TYPE sy-datum,
    drvr(5),
    END OF ty_temp.

    DATA: itab TYPE STANDARD TABLE OF ty_temp WITH HEADER LINE,
    itab1 TYPE STANDARD TABLE OF ty_temp WITH HEADER LINE.



    itab-plant = '2001'.
    itab-dutycardno = '17'.
    itab-drvr = 'd0001'.
    itab-drnm = 'ram'.
    itab-dats = '20131010'.
    APPEND itab.

    CLEAR itab.

    itab-plant = '2001'.
    itab-dutycardno = '19'.
    itab-drvr = 'd0001'.
    itab-drnm = 'ram'.
    itab-dats = '20140101'.
    APPEND itab.
    CLEAR itab.


    itab-plant = '2001'.
    itab-dutycardno = '21'.
    itab-drvr = 'd0001'.
    itab-drnm = 'ram'.
    itab-dats = '20131004'.
    APPEND itab.
    CLEAR itab.

    itab-plant = '2001'.
    itab-dutycardno = '21'.
    itab-drvr = 'd0002'.
    itab-drnm = 'ram'.
    itab-dats = '20130112'.
    APPEND itab.
    CLEAR itab.

    itab-plant = '2001'.
    itab-dutycardno = '21'.
    itab-drvr = 'd0002'.
    itab-drnm = 'ram'.
    itab-dats = '20150112'.
    APPEND itab.
    CLEAR itab.

    SORT itab[] STABLE DESCENDING BY drvr dats.



    LOOP AT itab.

    ON CHANGE OF itab-drvr.
    MOVE itab TO itab1.
    APPEND itab1.
    ENDON.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2014 at 02:31 PM

    Hello,

    What is combination of your output need to be display?

    Thanks and Regards,

    I.Muthukumar.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 02, 2014 at 04:57 AM

    Hi,

    I think on change of is Obsolete Syntax .It is better to avoid that statement.

    Try like this,

    SORT itab[] by drvr ASCENDING dats DESCENDING.

    delete ADJACENT DUPLICATES FROM itab[] COMPARING drvr.

    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.