Sorting of Dyanmic internal table

Hi Gurus,
I am having a dynamic internal table (it_mat) having  fields matnr uname field1,field2,field3 and field4.
the field is upto fieldN.
I want my table to sorted by this manner
Sort it_mat by field4 field3 field2 field1.
Sort it_mat by fieldN field(N-1)...field1.
Please help me in to get this in dynamic manner.

You can try something like this:
  types : begin of ty_comps.
          include type abap_compdescr.
  types:  srl  type i.
  types : end   of ty_comps .
  data:  lt_comps type standard table of ty_comps,
         la_comps type ty_comps.
  data: l_sort type standard table of char30 with header line.
  loop at lt_tot_comp into la_comp.      " LT_TOT_COMP contains all my components
    move-corresponding la_comp to la_comps.
    la_comps-srl = sy-tabix.
    append la_comps to lt_comps.
    clear  la_comps.
  endloop.
  sort lt_comps by srl descending.
  loop at lt_comps into la_comps.
    l_sort = la_comps-name.
    append l_sort.
  endloop.
  sort <f_tab> by (l_sort).
You can find the entire code which I have used to create a dynamic table at: [Dynamic Internal Table Creation|http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html]
Regards,
Naimesh Patel

Similar Messages

  • Can sorting facilty in internal tables can be used on char fields?

    Can sorting facilty in internal tables can be used on char fields?

    there is no restriction to sort by any TYPE. u ve the freedom to sort on any TYPE of fields.
    sort itab by ascending / descending F1 F2 F2.
    abap doubts, i request you to try and practise your doubts befor posting here in forums. I can understand you are a buddy.Please remember, PRACTISE MAKES MAN PERFECT. Try to master on own and approch forum in worst case.
    Also award points to all helpful answers.
    All the Best
    Thanks & Best Regards
    Kiran

  • What are dyanmic internal tables and what s the exact use of forall entries

    what are dyanmic internal tables and what s the exact use of forall entries?

    hi,
    <u><b>dynamic internal table.</b></u>
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html
    http://www.sap-img.com/ab030.htm
    <u><b>
    FOR ALL ENTRIES</b></u> is an effective way of doing away with using JOIN on two tables.
    You can check the below code -
    SELECT BUKRS BELNR GJAHR AUGDT
    FROM BSEG
    INTO TABLE I_BSEG
    WHERE BUKRS = ....
    SELECT BUKRS BELNR BLART BLDAT
    FROM BKPF
    INTO TABLE I_BKPF
    FOR ALL ENTRIES IN I_BSEG
    WHERE BUKRS = I_BSEG-BUKRS
    AND BELNR = I_BSEG-BELNR
    AND BLDAT IN SO_BLDAT.
    *******************************8
    look another example
    what is the use of FOR ALL ENTRIES
    1. INNER JOIN
    DBTAB1 <----
    > DBTAB2
    It is used to JOIN two DATABASE tables
    having some COMMON fields.
    2. Whereas
    For All Entries,
    DBTAB1 <----
    > ITAB1
    is not at all related to two DATABASE tables.
    It is related to INTERNAL table.
    3. If we want to fetch data
    from some DBTABLE1
    but we want to fetch
    for only some records
    which are contained in some internal table,
    then we use for alll entries.
    1. simple example of for all entries.
    2. NOTE THAT
    In for all entries,
    it is NOT necessary to use TWO DBTABLES.
    (as against JOIN)
    3. use this program (just copy paste)
    it will fetch data
    from T001
    FOR ONLY TWO COMPANIES (as mentioned in itab)
    4
    REPORT abc.
    DATA : BEGIN OF itab OCCURS 0,
    bukrs LIKE t001-bukrs,
    END OF itab.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    itab-bukrs = '1000'.
    APPEND itab.
    itab-bukrs = '1100'.
    APPEND itab.
    SELECT * FROM t001
    INTO TABLE t001
    FOR ALL ENTRIES IN itab
    WHERE bukrs = itab-bukrs.
    LOOP AT t001.
    WRITE :/ t001-bukrs.
    ENDLOOP.
    Hope this helps!
    Regards,
    Anver

  • TOP OF PAGE printing according to SORT - ALV main internal table

    Hi guys
    I manage to solve my previous issues but 1 minor problem here
    Lets say I have an itab which has 3 records
    Sales Order | Purchase No, | Distributor
    1                  |   123               | abc
    1                  |   123               | abc
    2                  |   456               | TGIF
    I'm using FM REUSE_ALV_BLOCK_LIST_APPEND to display the ALV
    its working for the main INTERNAL TABLE but  when it comes to top of page, it doesn't follow the sort
    I want it to print
    Sales Order: 1
    Purchase No: 123
    Distributor: abc
    TABLE 1
    Sales Order: 2
    Purchase No: 456
    Distributor: TGIF
    TABLE 2
    But now its printing
    Sales Order: 1
    Purchase No: 123
    Distributor: abc
    TABLE 1
    Sales Order: 1
    Purchase No: 123
    Distributor: abc
    TABLE 2
    Sales Order: 2
    Purchase No: 456
    Distributor: TGIF
    TABLE <empty table>
    My codes was working previously but its not longer the same.
      READ TABLE it_report INTO l_report INDEX SY-tabix
      WRITE: text-003,          "Sales Order Number
            AT 22 l_report-ebeln.
      WRITE: / text-004,        "Purchase Order Number
             AT 25 l_report-purch_no.
      WRITE: / text-005,        "Distributor Number
             AT 22 l_report-kunnr.
      WRITE: / text-006,        "Ship to Name
             AT 16 l_report-wename1.
      WRITE: / text-007,        "Order Date
             AT 14 l_report-vdate.
      WRITE: / text-008,        "Delivery Date
             AT 17 i_vdatu.
    Can anyone help me out here?  How do I make it print just like the SORT for ALV?

    Refresh the work areas then it work fine

  • Regarding the sorting of the internal table

    hi,
       this is my requirement
    iam having an internal table itab and it consists of the date field s_date.
    i have to sort the internal table in the descending order of the s_date.
    please provide me the code for this.
    thanks in advance

    Hi Surya,
    U can use this code
    SORT ITAB BY S_DATE DESCENDING.
    itab----internal table
    S_date--Field name
    By default the sorting is done ascending you dont have to specify.
    Thanks
    Mohinder Singh Chauhan

  • Differences between Standard , sorted and hashed internal tables

    Can any body please tell me what are the main Differences between
    1) <b>Standard internal table</b>
    2) <b>Hashed internal table</b>
    3) <b>Sorted internal table</b>
    Please give me a clear idea about these Three.
    Thanks
    Prabhudutta<b></b>

    Hi,
    <b>Standard Internal Tables</b>
    Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
    This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command).  The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
    the number of table entries.
    <b>Sorted Internal Tables</b>
    Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition.  Standard tables and sorted tables both belong to the generic group index tables.
    This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
    table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
    <b>Hashed Internal Tables</b>
    Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
    This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
    using internal tables that are similar to database tables.
    Regards
    Sudheer

  • Sort Internal table based on another internal table

    Hello All,
    My Requirement is :
    I have two internal tables itab1 and itab2. itab1 has partner_number along with some more fields/columns. Based on the partner_numbers of the itab1 i write a query to get the values for partner_last_name and central_block_flag from the table but000 and i fill these values into a new itab2.
    Sort itab2 by partner_last_name and central_block.
    Now how do I sort itab1 based on the sorted itab2-partner_number. I need to have itab1 sorted similar to the order in the itab2.
    How do i do this?
    Please let me know if you need more details.Looking forward for your support.
    Regards,
    Harish P M

    Hello Micky,
    Thank you for your early reply.
    I have this scenario wherein i need to sort a existing internal table itab1 of type 'bapibus1006_relations' based on the 'Partner last name ' and 'Inactive/Active Flag'. These two fields are not available in this itab1 and so i need to create itab2 after a query on table but000.
    Sorting itab2 is , first sort itab2 based on the 'Active flag' and then sort this itab2 again by 'Partner last name'(ascending order).
    Finally when i get my sorted itab2 i would have to ensure that my objective of sorting itab1 is obtained.
    I guess i sound better now.
    Would be helpful if you could reply.
    Regards,
    Harish P M

  • SORT DYNAMIC INTERNAL TABLE

    Hello everybody.
    How can I sort a dynamic internal table ???
    The sentence sort <gt_table> by matnr werks doesn' t work... How can I do it ??
    Thanks a lot.
    Regards

    Here is an example:
    PARAMETERS dbtab TYPE c LENGTH 30.
    SELECT-OPTIONS columns FOR dbtab NO INTERVALS.
    DATA: otab TYPE abap_sortorder_tab,
    oline TYPE abap_sortorder,
    dref TYPE REF TO data.
    FIELD-SYMBOLS: <column> LIKE LINE OF columns,
    <itab> TYPE STANDARD TABLE.
    TRY.
    CREATE DATA dref TYPE STANDARD TABLE OF (dbtab).
    ***I have assigned the value dref to internal table as follows***
    ASSIGN dref->* TO <itab>.
    CATCH cx_sy_create_data_error.
    MESSAGE 'Wrong data type!' TYPE 'I' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
    ENDTRY.
    TRY.
    SELECT *
    FROM (dbtab)
    INTO TABLE <itab>.
    CATCH cx_sy_dynamic_osql_semantics.
    MESSAGE 'Wrong database table!' TYPE 'I' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
    ENDTRY.
    LOOP AT columns ASSIGNING <column>.
    oline-name = <column>-low.
    APPEND oline TO otab.
    ENDLOOP.
    TRY.
    SORT <itab> BY (otab).
    CATCH cx_sy_dyn_table_ill_comp_val.
    MESSAGE 'Wrong column name!' TYPE 'I' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
    ENDTRY.

  • Sorting Order for SAP Tables in DB2 database

    Dear Experts -
    ISSUE: When an ABAP program selects data from the DB into an internal
    table, it is changing the way the data is sorted. In other words, the
    internal table data is in a different sort order than what is in the
    DB. It is not working this way in all other non-production systems
    (DEV, QAS, SAX, etc).
    Temporary solution for the programs that have been identified as
    impacted: Use the ABAP Command 'sort' on the internal table.
    Permanent solution needed : Since it is impossible to identify all
    of the programs that will be impacted, we need PRD to work like DEV,
    QAS, SAX, etc. when selecting data into internal tables. The data
    should be in the same order as it is in the DB (sorted by the key).
    ADDITIONAL INFO: DB2 storage disks crashed a day before. H/W team recovered everything. We are facing this only after the recovery.
    Thanks,
    Dinesh

    can you please check in your code if the sql that is being sent has an order by clause .
    Please let us know the SQL statements that is basically used to fill up the internal table.
    When data is fetched from the database, it is not sorted always. Probably you had a clustered index on the tables and the clustering is not there now.
    Edited by: Ratnajit Dey on Dec 16, 2011 1:56 PM

  • Division of internal table records

    Dear all
    How can I observe that how many record my internal table got record and how can I divide into by lines
    for ex.
              SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
                WHERE poper EQ s_poper AND
                   kalnr = itab2-kalnr AND
                   bdatj = itab2-bdatj AND
                   curtp = itab2-curtp.
              IF sy-subrc = 0.
                APPEND sum_pvprs.
    I want to get arithmetic range of this sum_pvprs-pvprs
    Actually I want to get number of lines and their summations
    pvprs1= 10 pvprs=20 pvprs=30 and then
    after I got this results 102030 = 60 /3 =20 I need this operation.
    All the best
    Message was edited by: yusuf tunay çilesiz

    I am not sure what do you mean by arithmetic range...if you mean min and max numbers you can use the below logic.
    SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
    WHERE poper EQ s_poper AND
    kalnr = itab2-kalnr AND
    bdatj = itab2-bdatj AND
    curtp = itab2-curtp.
    IF sy-subrc = 0.
    APPEND sum_pvprs.
    1. you can simply sort the sum_pvprs internal table...on pvprs first ascending and than descending to get the min and max numbers by reading the first record of the internal table.
    REad table sum_pvprs index 1.
    2. you can have two variables lmin and lmax and initialise the same before you append statement.
    if sum_pvprs-pvprs > lmax.
      lmax  = sum_pvprs-pvprs.
    endif.
    if sum_pvprs-pvprs < lmin.
      lmin  = sum_pvprs-pvprs.
    endif.
    <u><b>Sum and Average.</b></u>
    SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
    WHERE poper EQ s_poper AND
    kalnr = itab2-kalnr AND
    bdatj = itab2-bdatj AND
    curtp = itab2-curtp.
    IF sy-subrc = 0.
    <b>l_sum = sum_pvprs-pvprs + l_sum.</b>
    APPEND sum_pvprs.
    ENDSELECT.
    <b>DESCRIBE TABLE sum_pvprs LINES lrec.
    lavg = l_sum / lrec.</b>
    Message was edited by: Anurag Bankley

  • Create dynmic deep internal table

    Dear all,
    is it possible to create a dynamic internal table which has a deep structure. The catch here is that component tables of the main internal table will determined dynamically.
    thanks a lot!!!
    Navjot

    Hi Navjot,
    Dyanmic internal table with deep structure is specially useful when we have to create an ALV with Colors or Style etc. Since we have CL_ABAP_TABLEDESCR class from RTTS, it is also possible to create a dynamic internal table with the deep structure. To create an internal table with deep structure, we need to first get the object definition of the table type. Than we have to add that as a component of our table definition and that's it.
    Try this :
    *& Report ZNP_DYNAMIC_DEEP_TABLE.
    *& Shows how to create dynamic internal table with deep strcuture
    *&   which can be used in the ALV to have Sytle table, Color table
    * 2.1 Creating the Deep strcuture field
      DATA:  lo_tab TYPE REF TO cl_abap_tabledescr.
      lo_tab ?= cl_abap_typedescr=>describe_by_name( 'LVC_T_SCOL' ).
      la_comp-name = 'COLOR_TAB'.
      la_comp-type = lo_tab.
      APPEND la_comp TO lt_tot_comp.
      CLEAR: la_comp.
    Regards
    Abhinab Mishra

  • How to find min and max of a field from sorted internal table

    Hi,
    I have sorted Internal Table by field f1.
    How do I find max and min value of f1.
    For min value of f1 I am using,
    READ TABLE IT1 INDEX 1.
    IT1-F1 = MIN.
    Is this correct? And how do I find the max value of f1 from this table.
    Thanks,
    CD

    Yes, that is right, and you can get the max like this.
    data: lv_lines type i.
    * get min
    READ TABLE IT1 INDEX 1.
    MIN  = IT1-F1.
    * get max
    lv_lines = lines( it1 ).
    read table it1 index lv_lines.
    MAX  = IT1-F1.
    Regards,
    Rich Heilman

  • Sort the internal table based on the vendor field

    hello experts,
    I am stuck with a small problem...
    I am uploading the data for partner association for vendors through lsmw BI program.
    I am collecting all the records in the end of trasaction and downloading all those records on to the apps server.
    I declared one internal table as
    TYPES: BEGIN OF type_erecord,
            mesg(1000) TYPE c,
            END OF type_erecord.
    DATA: t_precord type standard table of type_erecord initial size 0,
                w_precord type type_erecord.
    I am concatenating all the fields and moving to the internal table..
    concatenate zvendor_master-source  zvendor_master-lifnr  blf00-lifnr                   
                      zvendor_master-lname    zvendor_master-parvw
                      zvendor_master-psource  zvendor_master-pname
                      zvendor_master-lifn2        bwyt3-lifn2
                      zvendor_master-ekorg      zvendor_master-werks   
                      w_PLANT-muplant           zvendor_master-defpa
                      v_message
          into w_precord-mesg separated by c_pipe.
          append w_precord to t_precord.
    now at the end I have to sort this internal table t_precord based on blf00-lifnr
    can any one guide me how to do it
    Thanks for your anticipation
    Nitesha

    OK...
    Than you can create one more table and do the process of sorting and than put data into the final table.
    TYPES: BEGIN OF type_erecord,
    mesg(1000) TYPE c,
    END OF type_erecord.
    DATA: t_precord type standard table of type_erecord initial size 0,
    w_precord type type_erecord.
    TYPES: BEGIN OF type_erecord_1,
    mesg(1000) TYPE c,
    lifnr type blf00-lifnr ,  "<<<
    END OF type_erecord_1.
    DATA: t_precord_1 type standard table of type_erecord initial size 0,
    w_precord_1 type type_erecord.
    I am concatenating all the fields and moving to the internal table..
    concatenate zvendor_master-source zvendor_master-lifnr blf00-lifnr
    zvendor_master-lname zvendor_master-parvw
    zvendor_master-psource zvendor_master-pname
    zvendor_master-lifn2 bwyt3-lifn2
    zvendor_master-ekorg zvendor_master-werks
    w_PLANT-muplant zvendor_master-defpa
    v_message
    into w_precord_1-mesg separated by c_pipe.
    w_precord_1-lifnr = blf00-lifnr .  " <<<
    append w_precord_1 to t_precord_1.   " <<<
    SORT T_PRECORD_1 by LIFNR.  " <<
    LOOP AT T_PRECORD_1 into w_precord_1.
      move-corresponing w_precord_1 to w_precord.
      append w_precord to T_PRECORD.
      clear  w_precord .
    endloop.
    Regards,
    Naimesh Patel

  • SORT INTERNAL TABLE USING NON KEY OF THE INTERNAL TABLE

    HI,
    i have one query for the cdpos table of abap.
    What i am looking is i want the latest CHANENR of the cdpos for that
    objectid  and tabname and fname in my internal table.
    what i thought of doing was to sort my internal table with objectid changnr tabname fname in descending order
    and than use delete adjacent duplicates command
    BUt that is not sorting based on all field , its sorting on changnr only
    please let me know what can i do

    no, that is not what i am looking at,
    I am saying say i have internal table cdpos
    OBJECTCLAS      OBJECTID    CHANGENR   TABNAME                        FNAME
    RECN_RECN      |0100TEST1   0000384409|    VICN01                        |RECNEND
    RECN_RECN       0100TEST1   0000383462    VICN01                          RECNLIFNR 
    RECN_RECN       0100TEST1    0000360190   VICN01                         RECNEND
    RECN_RECN        0100TEST1   0000340630    VICN01                         RECNEND
    this is my debug output after sorting on objectid changenr tabname fname in descending
    i wanted line 2nd to be at last so when i use delete adjacent command i can get 2 line item i.e 1st and 2nd line ...

  • Date sorting in internal table

    Dear Friends
       I wish to know how i perform the date operations in internal table... I am looking for the most recent record from the internal table for that i am supposed to look at chdate and chtime fields gives me the information on most corrently changed record... if  in the case of the record which is there but not changed to determin the its most currentness i must look at the crdate and crtime..so i have the code for that which works perfectly nice without the crdate and crtime... if i insert the crdate and crtime it gives me the only those records which are most currently chnaged according to chdate and chtime...would you like to help me in  this regards, I am giving you the code here.. any suggestion or changes will be great help of mine... thanking you,,,,
    regards naim... the code:
    TYPES: BEGIN OF itab_type,
            id       TYPE i,
            idnumber TYPE i,
            chdate   LIKE sy-datum,
            chtime   LIKE sy-uzeit,
            crdate   LIKE sy-datum,
            crtime   LIKE sy-uzeit.
    TYPES: END OF itab_type.
    DATA: itab     TYPE TABLE OF itab_type WITH HEADER LINE,
          itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
          prev_rec TYPE itab_type.
    DATA: v_id TYPE i.
    START-OF-SELECTION.
      itab-id       = 1.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135312'.
      itab-crdate   = '00000000'.
      itab-crtime   = '000000'.
      APPEND itab. CLEAR itab.
      itab-id       = 2.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135900'.
      itab-crdate    = '00000000'.
      itab-crtime    = '000000'.
      APPEND itab. CLEAR itab.
      itab-id       = 3.
      itab-idnumber = 123456.
      itab-chdate   = '00000000'.
      itab-chtime   = '000000'.
      itab-crtime    = '20060622'.
      itab-crdate    = '125412'.
      APPEND itab. CLEAR itab.
      itab-id       = 4.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '140000'.
      itab-crdate    = '00000000'.
      itab-crtime    = '000000'.
      APPEND itab. CLEAR itab.
      itab-id       = 5.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '142500'.
      itab-crdate    = '00000000'.
      itab-crtime    = '000000'.
      APPEND itab. CLEAR itab.
      itab-id       = 6.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '135312'.
      itab-crdate    = '00000000'.
      itab-crtime    = '000000'.
      APPEND itab. CLEAR itab.
      itab-id       = 7.
      itab-idnumber = 123457.
      itab-chdate   = '00000000'.
      itab-chtime   = '000000'.
      itab-crdate    = '20060601'.
      itab-crtime    = '150000'.
      APPEND itab. CLEAR itab.
      itab_new[] = itab[].
      SORT itab_new BY idnumber ASCENDING
                       chdate DESCENDING
                       chtime DESCENDING
                       crdate Descending
                       crtime Descending.
      DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
    LOOP AT itab.
         WRITE:/ itab-id,
                 itab-idnumber,
                 itab-chdate,
                 itab-chtime,
                 itab-crdate,
                 itab-crtime.
      ENDLOOP.
    skip 5.
    write: '_______________________________________________________________________________________'.
      LOOP AT itab_new.
        WRITE:/ itab_new-id,
                itab_new-idnumber,
                itab_new-chdate,
                itab_new-chtime,
                itab_new-crdate,
                itab_new-crtime.
      ENDLOOP.

    Hi,
    i modifed your code now see...,Copy paste and see...
    REPORT  ZTESTT                                  .
    TYPES: BEGIN OF itab_type,
    id TYPE i,
    idnumber TYPE i,
    chdate LIKE sy-datum,
    chtime LIKE sy-uzeit,
    crdate LIKE sy-datum,
    crtime LIKE sy-uzeit.
    TYPES: END OF itab_type.
    DATA: itab TYPE TABLE OF itab_type WITH HEADER LINE,
    itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
    prev_rec TYPE itab_type.
    DATA: v_id TYPE i.
    START-OF-SELECTION.
    itab-id = 1.
    itab-idnumber = 123456.
    itab-chdate = '20060606'.
    itab-chtime = '135312'.
    itab-crdate = '00000000'.
    itab-crtime = '000000'.
    APPEND itab. CLEAR itab.
    itab-id = 2.
    itab-idnumber = 123456.
    itab-chdate = '20060606'.
    itab-chtime = '135900'.
    itab-crdate = '00000000'.
    itab-crtime = '000000'.
    APPEND itab. CLEAR itab.
    itab-id = 3.
    itab-idnumber = 123456.
    itab-chdate = '00000000'.
    itab-chtime = '000000'.
    <b>itab-crdate = '20060622'. "here you intechanged the data
    itab-crtime = '125412'.</b>
    APPEND itab. CLEAR itab.
    itab-id = 4.
    itab-idnumber = 123457.
    itab-chdate = '20060606'.
    itab-chtime = '140000'.
    itab-crdate = '00000000'.
    itab-crtime = '000000'.
    APPEND itab. CLEAR itab.
    itab-id = 5.
    itab-idnumber = 123457.
    itab-chdate = '20060606'.
    itab-chtime = '142500'.
    itab-crdate = '00000000'.
    itab-crtime = '000000'.
    APPEND itab. CLEAR itab.
    itab-id = 6.
    itab-idnumber = 123457.
    itab-chdate = '20060606'.
    itab-chtime = '135312'.
    itab-crdate = '00000000'.
    itab-crtime = '000000'.
    APPEND itab. CLEAR itab.
    itab-id = 7.
    itab-idnumber = 123457.
    itab-chdate = '00000000'.
    itab-chtime = '000000'.
    itab-crdate = '20060601'.
    itab-crtime = '150000'.
    APPEND itab. CLEAR itab.
    itab_new[] = itab[].
    SORT itab_new BY
    idnumber
    *chdate DESCENDING
    *chtime DESCENDING
    crdate Descending
    crtime Descending.
    DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber crdate
    crtime.
    *DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
    LOOP AT itab.
    WRITE:/ itab-id,
    itab-idnumber,
    itab-chdate,
    itab-chtime,
    itab-crdate,
    itab-crtime.
    ENDLOOP.
    skip 5.
    LOOP AT itab_new.
    WRITE:/ itab_new-id,
    itab_new-idnumber,
    itab_new-chdate,
    itab_new-chtime,
    itab_new-crdate,
    itab_new-crtime.
    ENDLOOP.
    Regards
    vijay

Maybe you are looking for

  • 10g RAC upgrade to 11g RAC

    How to perform 10g RAC upgrade to 11g with Dataguard in place? OS=LINUX RDBMS=10.2.0.4 DG=PHYSICAL STANDBY Below is my understanding 1)Install 11g CRS in NEW_CRS_HOME 2)Install 11g in NEW_ASM_HOME 3)Install 11g in NEW_RDBMS_HOME 4)Export the new NEW_

  • An error occurred while attempting to perform the operation.

    Hi All, I am getting an error while running the report: "An error occurred while attempting to perform the operation. Then operation did not complete successfully." Although I can see the data coming is correct, but don't know why this error is comin

  • Can I batch print PDF files with Adobe Acrobat Reader X

    can I batch print PDF files with Adobe Acrobat Reader X?  I have tried from Windows Exploer (Windows XP) and it looks like the files are opening but they do not print. Pat

  • Powerpoint won't open in keynote

    Hello, I just purchased Keynote so I could show my powerpoint on the iPad 2, but it won't let me snyc it via iTunes and I can't use iCloud. So I don't know what to do. I have Lion on my Macbook Pro. Thanks for any help. T

  • Woke computer from Sleep: USB doesn't work

    So, I woke my computer from sleep, and now all my USB ports are dead. I tried restarting, resetting the CMOS, removing the D-Bracket, which I had just installed (it didn't work either.).  Any thoughts? EDIT:  All ports get power, none get signal.