Help needed to get unique record from an internal table

Hi Everybody,
I have to get unique record from an internal table. i know we can use read statement with key condition .
But the problem is i have to use some relational operators like GE or LE.
eg
read table itab into wa with key width GE itab-widthfrom
                                                   width LE itab-widthto
                                                   machno eq itab-machno.
Its giving me error when I use the operators GE , LE.( I think since it can't find a unique record with those relational
operators in the with key statement)
Is there any other way to get unique record from internal table without using the loop?
Thanks,
Sunny

Using the read statement you will need some kind of loop. For example.
DO.
READ TABLE......
  WITH KEY ......
                    READ = SPACE
IF SY-SUBRC EQ 0
  TABLE-READ = 'X'.
  MODIFY TABLE
  ADD 1 TO W_FOUND.
ELSE
  EXIT.
ENDIF
ENDDO.
IF W_FOUND EQ 1.
...record is unique.
ENDIF.

Similar Messages

  • Help - Need to Get Max(Date) from An Unrelated Table in PowerPivot

    I have two tables in my Power Pivot model:
    Table A (a many table)
    Asset    
    SerialNumber                   
    User
    CTUT111                             
    YC112233                                            
    Bob
    CTUT222                             
    ZZ221144                                            
    Susy
    CTUT222                             
    ZZ221144                                            
    Larry
    CTUT333                             
    AB332244                                           
    Bob
    Table B (a many table, a CSV import from another system)
    Asset                    
    SerialNumber                                   
    CheckIn_Date
    CTUT111                             
    YC112233                                            
    6/15/2014
    CTUT111                             
    YC112233                                            
    6/20/2014
    CTUT222                             
    ZZ221144                                            
    6/18/2014
    CTUT333                             
    AB332244                                           
    6/20/2014
    I know it appears odd that Table B would have two entries for the same Asset (CTUT111), but it does.
    I know I could write a SQL query that gave me the MAX(CheckIn_Date), but I’m not staging these datasets in a SQL server first. 
    I’m pulling directly from CSV tables.
    I don’t want to have bridge tables either, if possible. 
    So, I’m left with a many-to-many situation in Power Pivot.
    I want to add a Calculated Column to Table A, called ‘Latest CheckIn Date’ – which I get from Table B, matching on Serial Number.
    So, when I’m done, I would expect the value for Asset=CTUT111 to be 6/20/2014 (since it’s the MAX of a value of dates)
    I’m trying this pattern from Marco Russo in which you don’t need to relate two tables to exchange information, but it doesn’t appear to be working.
    =CALCULATE (
    MAX ( VALUES ( TableB[CheckIn_Date] ) ),
    FILTER (
    TableB,
    'TableA'[SerialNumber]
    = TableB[SerialNumber]
    I’ve also tried to use LOOKUPVALUE, but I can’t seem to figure it out.
    Would appreciate the help.
    Thanks in advance.
    -Eric

    Hi Eric,
    Please, try this one formula:
    =CALCULATE (
                MAXX ( VALUES( TableB[CheckIn_Date] ); TableB[CheckIn_Date] );
                FILTER (
                    TableB;
                    'TableA'[SerialNumber] = TableB[SerialNumber]
    P.S. In my locale I use ";". According to your locale you should use ",".
    Truly yours,
    Paul

  • How to collect similar record from the internal table

    I need to collect exact matched records from 1 internal table to another internal table by searching 5 fields. I need to have records which are exactly matched for 5 fields. i have written a code wich is mention below it gave me only similar records but not 100% matched record.. would you like to help me. any correction, suggetion,. Will be great help to me.

    To get exact match of 5 records, do as follows.
    Check whether internal table gives only one record or not after READ statement.If internal table gives more than one entry for READ then the results will be improper.
    I think there is no need of READ statement on same internal table within LOOP. I commented the same in code.
    sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.
    loop at i_bp_p into wa_i_bp_p.
    *lv_tabix = sy-tabix.
    *read table i_bp_p index lv_tabix into wa_i_bp_p.read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber
    idtype = wa_i_bp_p-idtype binary search.
    if sy-subrc = 0.
    read table i_but000 into wa_but000 with key title = wa_i_bp_p-title
    initials = wa_i_bp_p-initials
    name_last = wa_i_bp_p-name_last binary search.
    if sy-subrc = 0.
    read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code
    rbcode = wa_i_bp_p-rbcode binary search.
    if sy-subrc = 0.
    move-corresponding wa_i_bp_p to i_bp_p100.
    append i_bp_p100.
    endif.
    endif.
    endif.
    endloop.
    sort i_bp_p100 by partner.
    loop at i_bp_p100.
    write : /10 i_bp_p100-partner,
    20 i_bp_p100-title,
    30 i_bp_p100-initials,
    40 i_bp_p100-name_last,
    53 i_bp_p100-idnumber,
    70 i_bp_p100-idtype,
    85 i_bp_p100-rbcode,
    95 i_bp_p100-f50code.
    endloop.
    sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.
    loop at i_bp_p into wa_i_bp_p.
    lv_tabix = sy-tabix.
    read table i_bp_p index lv_tabix into wa_i_bp_p.
    if sy-subrc = 0.
    read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber
    idtype = wa_i_bp_p-idtype binary search.
    if sy-subrc = 0.
    read table i_but000 into wa_but000 with key title = wa_i_bp_p-title
    initials = wa_i_bp_p-initials
    name_last = wa_i_bp_p-name_last binary search.
    if sy-subrc = 0.
    read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code
    rbcode = wa_i_bp_p-rbcode binary search.
    if sy-subrc = 0.
    move-corresponding wa_i_bp_p to i_bp_p100.
    append i_bp_p100.
    endif.
    endif.
    endif.
    endif.
    endloop.

  • Filtering records from one internal table based on ranges in another itab

    Hi guys,
    I have 1 internal table with set of GL accounts. I have 2nd internal table where lower interval  and upper interval of GL accounts
    How to filter out records from 1 internal table by comparing with the GL account ranges present in 2nd internal table.
    Please reply.

    Hi
    Create a RANGE for GL Accounts.
    LOOP the second Internal Table.
    And assign HIGH & LOW to ranges from second ITAB.
    And Delete the accounts which are not there in the range.
    Use the below code as reference.
    DATA: itab TYPE TABLE OF mara WITH HEADER LINE.
    DATA: r_matnr TYPE RANGE OF matnr WITH HEADER LINE.
      SELECT * FROM mara INTO TABLE itab UP TO 10 ROWS.
      r_matnr-sign = 'I'.
      r_matnr-option = 'BT'.
      r_matnr-low  = '000000000016900036'.
      r_matnr-high = '000000000016900040'.
      APPEND r_matnr.
      DELETE itab WHERE matnr NOT IN r_matnr.

  • Extracting unique records from two different tables record

    Hello,
    In the following code of two different tables www.testing.com exists in both tables. I want to compare two different columns of the two different tables to get unique records.
    SQL> select unique(videoLinks) from saVideos where sa_id=21;
    VIDEOLINKS
    www.testing.com
    SQL> ed
    Wrote file afiedt.buf
      1* select unique(picLinks) from saImages where sa_id=21
    SQL> /
    PICLINKS
    test
    test14
    www.hello.com
    www.testing.comThanks & best regards

    Unfortunatly you didn't mention the expected output. I guess it would be the one line
    "www.testing.com"
    in that case simply join the two tables.
    select *
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;If needed then you could change the select list to retrieve only distinct values.
    select unique v.sa_id, v.videolinks
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;I usually avoid distinct/unique whereever possible. This requires the database to do a sort and makes the query slow.
    Edited by: Sven W. on Feb 10, 2011 1:55 PM

  • How to delete records from dynamic internal table.

    Hi Experts,
    Need urgent help!!!
    Issue is with Dynamic internal tables.
    Below is code written by me :
    FORM select_query USING Lw_tabnam
                      TYPE  t682i-kotabnr.
      DATA :  lw_line  TYPE REF TO data,
              lw_line1 TYPE REF TO data.
        CREATE DATA Lw_line    TYPE (lw_TABNAM).
        ASSIGN      Lw_line->* TO   <WA_tbl>.
        CREATE DATA LW_LINE    TYPE STANDARD TABLE OF (Lw_tabnam)
                               WITH NON-UNIQUE DEFAULT KEY.
        ASSIGN      Lw_line->* TO <TBL>.
        SELECT * FROM  (Lw_tabnam)
                 INTO CORRESPONDING FIELDS OF TABLE <TBL>
                 WHERE (t_keys).
    Endform.
    code is working fine.
    here even the table name and where condition are dynamic,everything is fine upto this point.
    Now i have to delete some record from <TBL> based on some conditons.
         for ex : ( here lc_fieldname is KUNNR)
          loop at t_kunnr.
              lw_tabix = sy-tabix.
            Read table <tbl>
                    with key (lc_fieldname) = t_kunnr-kunnr ASSIGNING <wa_tbl>.
            If sy-subrc = 0.
            *Delete
            delete <tbl> from <wa_tbl>
    delete <tbl> index  lw_tabix.
            Endif.
         Endloop.
    The above delete statement doesn't work ,even we can't use index as it gives a syntax error " something related to "index is not allowed in standard table or hash table.
    Can you help me ab't how to delete records in Dynamic internal table?
    Other option that i am thinking of is to create a static table of type dynamic table.
    means, data itab type standard table of <tbl> .I know the syntax is wrong ,however is there any way to do this?
    Thanks in advance ,
    If you have any suggestion ab't this then do let me know.
    bye,
    Gaurav.

    Hi
    I wrote this code and it works fine:
    DATA LW_TABNAM(10) VALUE 'LFA1'.
    DATA : LW_LINES TYPE REF TO DATA,
           LW_LINE  TYPE REF TO DATA.
    FIELD-SYMBOLS: <TABLE> TYPE TABLE,
                   <WA>    TYPE ANY.
    CREATE DATA LW_LINES TYPE TABLE OF (LW_TABNAM)
    WITH NON-UNIQUE DEFAULT KEY.
    ASSIGN LW_LINES->* TO <TABLE>.
    CREATE DATA LW_LINE TYPE (LW_TABNAM).
    ASSIGN LW_LINE->* TO <WA>.
    DO 10 TIMES.
      APPEND INITIAL LINE TO <TABLE>.
    ENDDO.
    SY-TABIX = 4.
    DELETE <TABLE> INDEX SY-TABIX.
    WRITE SY-SUBRC.
    I hope it help you
    Max

  • Get the Common from Two Internal Tables with same structure

    Hi ,
    I need to get the Common data from Two Internal Tables with same structure with using the looping method.
    For e.g.
    I have two internal table say ITAB1 and ITAB2.
    ITAB1 has values A,B,C,D,E,F
    ITAB2 has values A,H,B,Y,O
    Output at runtime should be : A,B

    Hi mohit,
    1. If u want to compare all fields,
       for matching purpose,
       then we can do like this.
    2.
    report abc.
    data : a like t001 occurs 0 with header line.
    data : b like t001 occurs 0 with header line.
    loop at a.
      LOOP AT B.
        IF A = B.
          WRITE :/ 'SAME'.
        ENDIF.
      endloop.
    ENDLOOP.
    regards,
    amit m.

  • How to delete the matching records from two internal tables

    Hi ,
    I have two internal tables say A and B of the same type. If A has 10 records and B has 4 records , I want to delete the 4 records in B from A .
    loop at B into wa .
    delete A where key = wa - key .
    endloop.
    takes a long time if the table B is huge. how can I improve the performance.
    Thanks.
    Gayathri

    Hi Gayathri,
    You could try field-symbols. It reduces the data transfer from the internal table B to the work area.
    field-symbols <fs_itab_b> like line of B.
    loop at B assigning <fs_itab_b>.
      delete A where key = <fs_itab_b>?-key.
    endloop.
    Regards,
    <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=zwcc%2fwm4ups%3d">anand Mandalika</a>.

  • Can we get the data from two internal tables in ALV.

    hi friends i would like to display the data using two internal tables using alv grid.please guide me.

    Hi,
    ALV would be having a specific layout say :
    MATNR
    MAKTX
    QTY
    Now, if you have two internal tables, then do they have a different structure. If they have different structures, then what kind of ALV layout you expect. The ALV output should be as per the structure of 1st or 2nd internal table.
    If both internal table have same layout, then populate the data from 2nd internal table into 1st internal table and pass the 1st internal table ( it will have data of both internal tables) to ALV.
    Best regards,
    Prashant

  • Getting the last record from the internal table

    When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
    I have a internal table like
    id     type
    N1      A
    N1      T
    N1      A
    N1      6 ----> LAST RECORD
    my code is
    read table itab wIth key id = netobjid.
    for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
    How to do that?

    HI
    actually i have done same requirement like this ...
    Take  one count variable into your internal table ..you pass the number of records into cont variable for every time  u enter the loop .
    Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
    Then use read statement with sy-index = 1 .
    USe below logic ,............
    data  :  count  type i value '0'.
    LOOP at int .
    count = count + 1 .
    endloop.
    sort int count descending .
    read int  with  index = 1 .

  • Error in splitting records from an internal table

    Hi all,
        After uploading the data from flat file into an internal table the data consists of # between each field and while I try to split each field and assign to a different table the data is not getting split properly ,
    i.e. split function splits the fields after 3 '#' and storing it in the table field.
    Thanks & Regards
    Jerry

    Hi Jerry,
    What Uwe said is correct. We too faced that kind of scenario. In the internal table when uploaded from flat file it will show '#' but it wont get split with '#' symbol in the program. However we solved the issue with the following class.
    Data: c_tab value cl_abap_char_utilities=>newline,
             it_string type table of string.
    " if it_table1 is the table which contains the flat file data, then go throuhg  this logic.
    loop at it_table1 into wa_table1.
    split wa_table1 at c_tab into table it_string.
    endloop.
    If the table is not getting split with cl_abap_char_utilities=>newline, then try using differnt attributes of that class ( like cl_abap_char_utilities=>cr_lf, cl_abap_char_utilities=>backspace so on ).
    Hope this will help.
    Regards,
    Swarna Munukoti.
    Edited by: Swarna Munukoti on Sep 13, 2008 5:54 PM

  • Pick Common records from 2 internal tables

    Hi,
    I have 2 similar internal tables it_bseg1 (contain records based on the Posting Date BUDAT of document) & it_bseg2 (contain records based on the Customer Code KUNNR). Both these tables contains some common records. And I want these common records only. So please tell me to get the common records in the easiest way.
    Regards,
    Vishal

    Hi,
    There must be atleast one common field for these two internal tables to get the common records.
    If you identify the common field then you can use this logic.
    Loop at it_bseg1 into wa_bseg1.
    Read table bseg2 into wa_bseg2 with key <commonfield > = wa_itab1-<commonfield>.
    If sy-subrc eq 0.
    Append wa_bseg1 to it_bseg3.
    Endif.
    Endloop.
    Now it_bseg3 contains the common records.
    If there is no use of it_bseg1 in your further development then you can do teh logic without declaring third internal table it_bseg3.
    Loop at it_bseg1 into wa_bseg1.
    Read table bseg2 into wa_bseg2 with key <commonfield > = wa_itab1-<commonfield>.
    If sy-subrc ne 0.
    delete it_bseg1 where <commonfield> = wa_itab1-<commonfield>.
    Endif.
    Endloop.
    Now it_bseg1 contains teh common records of it_bseg1 and it_bseg2.
    Hope this will help.
    Regards,
    Swarna Munukoti.
    Edited by: Swarna Munukoti on Sep 3, 2008 2:05 PM

  • HELP NEEDED: Use a new record for a customized table as a workflow trigger

    Hi SAP Workflow Gurus,
    Good day!
    One of our requirements is to have the creation of a new record in a custom database table trigger a workflow. I read and followed the steps as indicated in this link
    http://www.****************/Tutorials/Workflow/Table/events.htm
    As a summary, here is what I did:
    1. Created a subroutine for the custom table ZPA2003 for the create event
    2. Defined this event as a trigger for the custom workflow WS90000019
    3. Maintained and activated the event linkage via SWETYPV
    Basically I tried following the instructions indicated on the link
    Note that the entries for the custom table are created via a function module.
    Now during testing of the workflow, the system was able to complete the notification message. However, when I triggered the event via creation of the entry in the custom db table nothing happened
    1. Is there a way to debug/find out whether the link between the subroutine in the table and event itself are connected?
    2. I also tried running the event trace to check the activities executed but found nothing.
    Can you guys help me check on what I may have missed out?
    Regards,

    Hi All,
    Basically these are the requirements for the work schedule substitution:
    1. Employee enters the request via ESS (custom portal transaction)
    2. Upon saving of the entry (request) in a custom  table, this should trigger the workflow at the backend
    3. The Manager should then receive a work item in his Universal Worklist at the MSS side of the portal
    4. Upon clicking on the work item, a new screen will pop up showing the work schedule substitution details as well as an interface which will allow him to enter his/her usage decision
    5. Depending on the decision, the workflow must execute the necessary notifications as well as changes in the custom and PA2003 tables
    Now, we have accomplished step 1 and I am currently in the process for step 2. Now I have some queries:
    1. For the Manager to view and approve the substitution details, I used two methods for each process (view and approve) since our ABAPer mentioned that this cannot be done in 1 function module. Is there a way to simplify this step or is it really valid that they need to be executed in 2 different methods?
    2. As per our ABAPer, function Modules only import and export variables; they do not have the facility of say having tags on the details being displayed. Hence, if the details are 10001 (Employee Number), 10/20/2011 (Start Date), 10/25/2011 (End Date) the output would be 10001, 10/20/2011, 10/25/2011. Is there a way within the function module (or dynpro interface) to show it like this: Employee Number: 10001
                               Start Date: 10/20/2011
                               End Date: 10/25/2011
    3.  Speaking of dynpro applications, do I need to still develop one to allow the Manager to view and approve/reject the request via the MSS portal upon accessing the work item via the UWL? How would the work item go about calling the dynpro application? or is this even possible?
    It would have been easier if the facility would not pass through workflows since it will be just direct web dynpro/ABAP calls. Having to include it as a work item in the UWL puts a certain twist to it
    Your inputs are well-appreciated.
    Regards,

  • *Query needs The Delta changeed records from Change log table*

    Hello Friends,
    I got an requirement where they want to see the current data and also the changes that happened last week. For e.g.
    Sales Order 1       100 Qty      Nov 1 2009
    sales Order 1         50 Qty      Oct 25 2009
    as you can see, they want to see these both records in the query. I am running out of ideas , on how to establish this scenario. Can we some how report directly on the changelog table where it maintains all the delta changes.....
    Appreciate your answers........ Thanks for your time......

    Hi,
    you can do the following:
    to find last week
    Create a Customer Variable for Calday
    EXIT_SAPLRSOO_001 ---> Include ZXRSRUO1 write the code for the variable created above
    DATA : date TYPE sy-datum.
    date = sy-datum. "Today
    date+6(2) = '01'. "First day of this month
    date = date - 7. "Previous week before first day of this month = last week of last month
    Current week take the system Date ( with give the current week)
                                 OR (more options)
    Some function modules you can use in exits are
    DATE_GET_WEEK - Will return a week that the day is in. ( Current week)
    DATE_GET_WEEK -1 will returne the previous week of the day is ( previous week)
    Santosh

  • 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

Maybe you are looking for