How to select set of unique data records from internal table

Hi
I am looking for a command in order to select all unique data-records from an internal table without using a loop. Does anybody know a command that could do this?
<b><u>An illustrating example:</u></b>
<i>Example:
Table content
a 1
a 2
a 3
b 1
b 2
c 1
c 2
c 3
d 1</i>
So I am looking for a command that should provide a, b, c & d for the first column or 1, 2 & 3 for the second column<b></b>

Hi,
SELECT DISTINCT  MATNR
                FROM MARA
               into table i_mara.
Best regards,
Prashant

Similar Messages

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • Inserting records from internal table to database table

    Hi all,
    i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
    1) insert one by one record from internal table
    loop at itab.
    insert ztable from wa.
    endloop.
    2) insert total records at a time
    INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or let me know if any other statement is there with high performance.
    i internal table contains nearly 40000 records.
    thanks.

    Hi,
    Insert the entire table at atime rather than a record so as to increase the performance.
    you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or
    MODIFY ZPRODUCT FROM TABLE GI_AFPO.
    Regards,
    Raj.

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • Delete records from internal table

    hi all,
    i want to delete records from intenal table which are starting with a particular starting number .
    eg internal table
    10000
    20000
    90000
    91000
    92000
    88880
    i want delete the records starting with 9 i.e. 90000 91000 92000.
    Thanks in Adv
            RAJ

    You can test this piece of code.
    DATA:
    i_tab TYPE STANDARD TABLE OF mara,
    wa_tab TYPE mara.
    wa_tab-matnr = '1000'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1002'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1003'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '2001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '3001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '4010'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

  • Processing some records from internal table.

    Hi,
    My internal table contains material in lakhs.After fetching the record from database table MARA,i process each material to find out its characteristics.As there are too much records it is taking time, resulting in time out error abap dump. If i want to process first 5000 material then remaining 5000 and so on...what logic should i apply?or can there be any alternative solution?

    Hi,
    You can also check if the read statement has BInary Serach.
    By Adding this it will improve performance.
    Read statement will occupy lots of time to read the records.
    Sort the Internal table with some key field and the use Binary Search for an internal table.
    Ex :
    SORT T_PRGEN by ATTR20A.
    READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A BINARY SEARCH.
    This should fix the issue.
    Regards,
    Kittu

  • How to fetch previous record from internal table?

    Hi,
    My final internal table (it_final) has all the data month wise year wise.(opening and closing qty)
    but if
    Material   Batch    Month   Year        opening_qty         closing_qty
    FC5431   abc        08        2008        100                       50
    FC5431   ABC       09        2009         0                          100
    Suppose I want to take PREVIOUS record(closing_qty = 50  in my 09/2009  openin_qty = 50)  how will Ido this?
    Any solution????????? BTW i m using S033 for opening an closing qt monthwise.
    Plz reply soon if anyone knows.
    Thanks and Regards,
    Archana

    Hi,
    Test the following Sample code hope will solve out your problem,
    TYPES:  BEGIN OF ty_test,
            m(3),
            open_qty TYPE i,
            close_qty TYPE i,
            END OF ty_test.
    DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE,
          wa_test LIKE LINE OF it_test,
          ctabix LIKE sy-tabix,
          ptabix LIKE sy-tabix.
    it_test-m = 'AAA'. it_test-open_qty = 100. it_test-close_qty = 50. append it_test.
    it_test-m = 'AAA'. it_test-open_qty =  0. it_test-close_qty = 100. append it_test.
    LOOP AT it_test.
      ctabix = sy-tabix.
      IF sy-tabix > 1.
        ptabix = sy-tabix - 1.
        READ TABLE it_test into wa_test INDEX ptabix.
        IF sy-subrc = 0.
          it_test-open_qty = wa_test-close_qty.
        ENDIF.
        MODIFY it_test INDEX ctabix.
      ENDIF.
    ENDLOOP.
    LOOP AT it_test.
      WRITE: it_test-m, it_test-open_qty, it_test-close_qty, /.
    ENDLOOP.
    Regards,
    Faisal

  • Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field

    Hello,
    I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
    Table structures are mentioned below:
    OP:
    Name                             Null                    Type        
    OP_NBR                    NOT NULL      NUMBER(4)    (Primary Key)
    OP_DESC                                        VARCHAR2(50)
    OP_PAYLOD_XML                           CLOB       
    GM:
    Name                          Null                   Type        
    GM_NBR                  NOT NULL       NUMBER(4)    (Primary Key)
    GM_DESC                                       VARCHAR2(40)
    OP_NBR               NOT NULL          NUMBER(4)    (Foreign Key)
    GM_PAYLOD_XML                          CLOB   
    DM:
    Name                          Null                    Type        
    DM_NBR                  NOT NULL         NUMBER(4)    (Primary Key)
    DM_DESC                                         VARCHAR2(40)
    GM_NBR                  NOT NULL         NUMBER(4)    (Foreign Key)
    DM_PAYLOD_XML                            CLOB       
    DE:
    Name                          Null                    Type        
    DE_NBR                     NOT NULL           NUMBER(4)    (Primary Key)
    DE_DESC                   NOT NULL           VARCHAR2(40)
    DM_NBR                    NOT NULL           NUMBER(4)    (Foreign Key)
    DE_PAYLOD_XML                                CLOB    
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    SELECT
    j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
    i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
    h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
    g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
    FROM
    DE g, DM h, GM i, OP j
    WHERE
    h.dm_nbr = g.dm_nbr(+) and
    i.gm_nbr = h.gm_nbr(+) and
    j.op_nbr = i.op_nbr(+)
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
    Current O/P:
    <resultSet>
         <Record1>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <DM_PAYLOD_XML1>
              <DE_PAYLOD_XML1>
         </Record1>
         <Record2>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML2>
              <DM_PAYLOD_XML2>
              <DE_PAYLOD_XML2>
         </Record2>
         <RecordN>
              <OP_PAYLOD_XMLN>
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XMLN>
         </RecordN>
    </resultSet>
    Now i want to change my SQL query so that i get following output structure:
    <resultSet>
         <Record>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <GM_PAYLOD_XML2> .......
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XML1>
              <DM_PAYLOD_XML2> .......
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XML1>
              <DE_PAYLOD_XML2> .......
              <DE_PAYLOD_XMLN>
         </Record>
         <Record>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML1'>
              <GM_PAYLOD_XML2'> .......
              <GM_PAYLOD_XMLN'>
              <DM_PAYLOD_XML1'>
              <DM_PAYLOD_XML2'> .......
              <DM_PAYLOD_XMLN'>
              <DE_PAYLOD_XML1'>
              <DE_PAYLOD_XML2'> .......
              <DE_PAYLOD_XMLN'>
         </Record>
    <resultSet>
    Appreciate your help in this regard!

    Hi,
    A few questions :
    How's your first query supposed to give you an XML output like you show ?
    Is there something you're not telling us?
    What's the content of, for example, <OP_PAYLOD_XML1> ?
    I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
    What's the db version BTW?

  • How to get multiple records from internal table through BDC

    PERFORM DYNPRO USING:
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_OKCODE'  '=NEWC',
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_CURSOR'  'PLPTU-PLWRK(01)',
      ' '  'BDC_OKCODE'  '=TAKE',
      ' '  'PLPTU-PLWRK(01)' '2531'. (2531 is a plant)
    This is the recording used to get plant via BDC of MS31.
    Using this code i can get only single plant...
    If i want to get multiple plants from an internal table,how i can change this code?
    Since it is a recording i cant put this code in LOOP..ENDLOOP.
    Suggest any method for doing this....
    Awaiting for ur reply...

    Hi,
    While recording also record the scroll down button.
    The you can place different plant in the BDC using loop and endloop
    Regards
    Arun

  • Deleting records from internal table.

    Hello Friends,
    I have done F1 on delete and also went through the forum . I want to do a delete effectively as it involves huge amount of data ..
    Lets cosider I have two internal tables ITAB 1 and ITAB 2 .
    ITAB 1 has 10000 records  having two key fields
    ITAB2 has 1000 records having the same two key fields in it .
    THe other fields are different .
    Now I want to perform an operation where for corresponding  1000 records in ITAB2 I must delete the records in ITAB1 and result in ITAB 1 must be 10000 - 1000 = 9000 records.
    Which could be the most effecient way to do this.?
    Comradely,
    K.Sibi

    Are you sure that the keys are all unique? That is non trivial with internal tables.
    If yes, then you should define itab1 as a hashed table or copy into a hashed table.
    LOOP AT itab2
        READ TABLE itab1 WITH TABLE KEY ...
        IF ( sy-subrc = 0 ).
          DELETE itab1 WITH TABLE KEY ...
        ENDIF
    ENDLOOP.
    You can also use sorted tables and delete with index, will be somewhat slower. Or standard table with REAB BINARY SEARCH and DELETE with index.
    If the uniqueness is unclear, then you must change the order and LOOP itab1first and comletely, because the same key can appear several times.
    A READ without BINARY SEARCH will kill you, i.e. the above recommendation is incorrect.
    Siegfried

  • Trouble fetching record from Internal table

    Hi all,
    I am using a binary search read for retrieving data from an internal table, but i am not able to fetch a particular record even while it is present in the internal table.

    Check if you are sorting the table. When you are not sorting the table, the read fetch the next highest key field from the table e.g.
    Suppose if you have an internal table with following keys:
    12
    9
    13
    2
    22
    the read will pick only 12,13 & 22 record.
    Regards,
    Prashant.

  • Help on to Filter records from internal table

    Hi,
    Here is my Internal table and need to filter the records based on some condition.
              OBJID |  ENDDA | MC_SHORT   | MC_STEXT
        1   20000027|20061231|20000027    |WIT-SP
        2   20000027|99991230|20000027    |WIT-SP
        3   20000027|20051131|20000027    |WIT-SP                              
        4   20000033|20070131|20000033    |WIT-SP-BC                                 
        5   20000033|99990931|20000027    |WIT-SP
        6   20000034|20061231|20000034    |WIT-SP-SA                                 
        7   20000035|20061231|20000035    |WIT-SP-Q                                  
        8   20000036|20070131|20000036    |WIT-SP-E       
        9   20000036|99991231|20000027    |WIT-SP
    This is my internal table data. Now i need to delete the records for each OBJID where ENDDA(Date field) is not eaual to the year 9999. And also if there is no OBJID with year as 9999 then need to keep the reocrd for further processing.Here in this case i should not delete that record.
    Please help me out in writing the logic for the same.
    Regards
    Ramesh

    hi Ram
    its very simple please check this code
    DATA : BEGIN OF itab OCCURS 0,
              objid TYPE i,
              endda TYPE d,
           END OF itab.
    itab-objid = 1.itab-endda = sy-datum.
    APPEND itab.
    itab-objid = 2.itab-endda = sy-datum.
    APPEND itab.
    itab-objid = 3.itab-endda = sy-datum.
    APPEND itab.
    itab-objid = 0.itab-endda = sy-datum.
    APPEND itab.
    itab-objid = 4.itab-endda = '20041212'.
    APPEND itab.
    itab-objid = 5.itab-endda = '99991212'.
    APPEND itab.
    itab-objid = 0.itab-endda = '99991212'.
    APPEND itab.
    CLEAR itab.
    LOOP AT itab.
      WRITE : / itab-objid , itab-endda.
    ENDLOOP.
    WRITE :/.
    DELETE itab WHERE endda+0(4) NE '9999' AND objid IS INITIAL.
    LOOP AT itab.
      WRITE : / itab-objid , itab-endda.
    ENDLOOP.
    regards
    navin k

  • How to generate a text file with values from internal table

    hi,
    can anybody help me out to get the values from different internal table written into a text file.
    regs,
    raja

    used gui_download,ws_download,cl_gui_file_save.
    data: ld_filename type string ;
    ld_filename = 'c:\demo.txt'.
    DATA: begin of it_datatab occurs 0,
    row(500) type c,
    end of it_datatab.
    HII
    call function 'GUI_DOWNLOAD'
    exporting
    filename = ld_filename
    filetype = 'ASC'
    tables
    data_tab = it_datatab[]
    exceptions
    file_open_error = 1
    file_write_error = 2
    others = 3.
    gui_download

  • Unable to delete double records from internal table

    Hi all,
    The internal table is like this
    begin of ta_itab1 occurs 0,
          mark type c,
          cnt_hedg type c,
          kunnr like vbak-kunnr,
          vbeln like vbak-vbeln,
          posnr like vbap-posnr,
          matnr like vbap-matnr,
          kwmeng like vbap-kwmeng,
          h_kwmeng like vbap-kwmeng,
          spart like vbap-spart,
          werks like vbap-werks,
          component like bom_item_api01-component,
          comp_qty like bom_item_api01-comp_qty,
          comp_qty1 like bom_item_api01-comp_qty,
          base_quan like stko_api02-base_quan,
          comp_unit like bom_item_api01-comp_unit,
          base_unit like bom_item_api01-comp_unit,
          bukrs_vf like vbak-bukrs_vf,
          end of ta_itab1.
    and used the sytax:
    sort ta_itab6 by kunnr vbeln.
    DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1.
    but Im unable to delete duplicate record .
    Thank You.
    anu

    Hi ,
    You need to use the fields in sort statement on whichyiu wnat to perform Delete Adjacent duplicates..
    sort ta_itab6 by kunnr vbeln COMP_QTY COMP_QTY1.
    DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1.

  • Delete records from internal table using another internal table

    HI,
    I have two internal tables itab1 and itab2 which have same records initially.Later some records of itab2 are deleted .Then i want to delete those records from itab1 also ie,those records not found in itab2 .Is there any method other than looping.
    So that itab1 again becomes equal to itab2.
    Thanks in advance.
    Sowmya.

    Soumya,
    Itab1 , Itab2 .
    Before deleting the records from itab2  move those records to one more internal table itab3.
    Now you have deleted records  of itab2  in itab3.
    SORT ITAB3,ITAB1 by your main key field.
    LOOP AT itab3.
      READ TABLE ITAB1 WITH KEY key field = itab3-
      keyfield.
    IF sy-subrc EQ 0.
    DELETE itab1 where keyfield eq itab3-keyfield.
    ENDIF.
    ENDLOOP.

Maybe you are looking for

  • Obiee 11g error

    Hi All, I am using obiee 11g for a demo project.When i a run the a report just with 2 columns from 1 from dimension and 1 from fact.It is throwing an error.the error message is Query Failed: [nQSError: 14025] No fact table exists at the requested lev

  • HT3290 Video will not import after updating my iMovie from '09 to '11

    I updated my imovie '09 to '11 and now my video files from my camcorder JVC (model GZ_MG330HU) will not import.  The video files show up in my iMovie library but when I try to create a project or movie and then share what I have created the files are

  • Clean Install / Cloning to an second internal drive?

    My boot drive is full and now seems slower - is it file fragmentation which slows a full drive? Here's my set up - I've just added a second internal 1TB drive and want to clean install the original boot drive (350gb) which is almost full and seems to

  • IChat AV 4 - Leopard - Where is the side-by-side iChat theater?

    It's shown in the Leopard preview (http://images.apple.com/macosx/features/ichat.html) under "Showing off without showing up". But, how do you start this mode? I can share files, keynotes, iPhoto, etc. But, I can't find how to show the video feed sid

  • Verify email address against local exchange server

    I want to authenticate a web user by their email address against our Microsoft Exchange Server before granting access to controlled material. How can I access the GAL and determine if a supplied address is in our GAL? Is JavaMail the appropriate API