Find unique row with max func

I am really stupid of this right now. Have not tried the regular SQL for long time, so my question is that I have a table- Cost
A     B     C     D     E     F
0002     6002     5     55     68.35     6.12
0003     6003     5     99.26     89.33     8.23
0004     6004     5     78.85     4.4     7.42
0004     6004     6     78.85     8.1     1.7
0004     6004     7     78.85     70.9     6.73
0005     6005     5     49.88     76.1     68.53
0005     6005     6     49.88     93.7     18.57
0005     6005     7     49.88     255.7     63
How can I get the column E and F, when I want to get the row with highest order in C as result in
A     B     C     D     E     F
0002     6002     5     55     68.35     6.12
0003     6003     5     99.26     89.33     8.23
0004     6004     7     78.85     70.9     6.73
0005     6005     7     49.88     255.7     63
I used the max () and group by in query as
select A, B, max(C), D
from cost
group by A,B,D
If I added the max(E) and max(F) in the SELECT, I got correct row in E but not the F.
Please help me out. Thanks.

an alternative using analytic fiunctions would be:
select "A","B",max("C"),"D","E","F" from
(select "A","B","C",last_value("D") over (partition by "A","B" order by
"A","B","C" rows between unbounded preceding and unbounded following) "D",
last_value("E") over (partition by "A","B" order by
"A","B","C" rows between unbounded preceding and unbounded following) "E",
last_value("F") over (partition by "A","B" order by
"A","B","C" rows between unbounded preceding and unbounded following) "F"
from test1)
group by "A","B","D","E","F"
order by "A","B"
this appears to give a better plan on the test data but you would want to test with a larger volume, we have reduced to numbet of buffer gets but added two sorts currently these fit in memory but you may find with a larger dataset these result in disk sorts.
Chris
Autotrace output:
SQL> select * from test1 where "A"||B||"C" in (select "A"||B||Z from (select "A", B, max("C") Z from test1 group by "A",B));
A    B             C          D          E          F
0002 6002          5         55      68.35       6.12
0003 6003          5      99.26      89.33       8.23
0004 6004          7      78.85       70.9       6.73
0005 6005          7      49.88      255.7         63
Execution Plan
Plan hash value: 2706139598
| Id  | Operation             | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT      |          |     1 |    50 |     8  (25)| 00:00:01 |
|*  1 |  HASH JOIN            |          |     1 |    50 |     8  (25)| 00:00:01 |
|   2 |   TABLE ACCESS FULL   | TEST1    |     8 |   192 |     3   (0)| 00:00:01 |
|   3 |   VIEW                | VW_NSO_1 |     8 |   208 |     4  (25)| 00:00:01 |
|   4 |    HASH UNIQUE        |          |     8 |   104 |     4  (25)| 00:00:01 |
|   5 |     HASH GROUP BY     |          |     8 |   104 |     4  (25)| 00:00:01 |
|   6 |      TABLE ACCESS FULL| TEST1    |     8 |   104 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("$nso_col_1"="A"||"B"||TO_CHAR("C"))
Statistics
          0  recursive calls
          0  db block gets
         64  consistent gets
          0  physical reads
          0  redo size
        795  bytes sent via SQL*Net to client
        381  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed
SQL>
SQL> select "A","B",max("C"),"D","E","F" from
  2  (select  "A","B","C",last_value("D") over (partition by "A","B" order by
  3  "A","B","C" rows between unbounded preceding and unbounded following) "D",
  4  last_value("E") over (partition by "A","B" order by
  5  "A","B","C" rows between unbounded preceding and unbounded following) "E",
  6  last_value("F") over (partition by "A","B" order by
  7  "A","B","C" rows between unbounded preceding and unbounded following) "F"
  8  from test1)
  9  group by "A","B","D","E","F"
10  order by "A","B";
A    B      MAX("C")          D          E          F
0002 6002          5         55      68.35       6.12
0003 6003          5      99.26      89.33       8.23
0004 6004          7      78.85       70.9       6.73
0005 6005          7      49.88      255.7         63
Execution Plan
Plan hash value: 3359524756
| Id  | Operation            | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT     |       |     8 |   496 |     5  (40)| 00:00:01 |
|   1 |  SORT GROUP BY       |       |     8 |   496 |     5  (40)| 00:00:01 |
|   2 |   VIEW               |       |     8 |   496 |     4  (25)| 00:00:01 |
|   3 |    WINDOW SORT       |       |     8 |   192 |     4  (25)| 00:00:01 |
|   4 |     TABLE ACCESS FULL| TEST1 |     8 |   192 |     3   (0)| 00:00:01 |
Statistics
          0  recursive calls
          0  db block gets
          7  consistent gets
          0  physical reads
          0  redo size
        802  bytes sent via SQL*Net to client
        381  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          4  rows processed
SQL>

Similar Messages

  • Alternative to find unique records with 60 character in selection string.

    Hi,
    We have to find out the values from the Infoobject. When we try to display data from an master object, the maximum length of selection it accepts 45 characters only but we need to input data around 60 characters in selection.
    Thing we tried:
    1. Selecting complete data without any condition but it did not work due to large volume of data.
    2. We tried to extract data from RSA3 but it did not work due to large volume of data.
    Please suggest me alternative to find unique records with 60 character in selection string.
    Regards,
    Himanshu Panchal.

    This sounds a bit strange. Are you perhaps mistakenly storing text data incorrectly as the primary key of the master data? I can't think of any actual data that is that length to ensure usinqueness - even GUIDs are maximum 32 characters - but GUIDs don't count as actual "readable" data although you do need to be able to select it from time to time. Perhaps you have a super secure password hash or something like it ?
    Also are you expecting to have a unique single record returned by your selection? To do this would in general REQUIRE that ALL the data is read because master data is not stored in the DB sorted by the data itself, but stored instead sorted by the it's SID.
    When you say you are selecting data from master data, which master data tables are you using? I have been able to select data from very large MD table (15 million unique records) using SE16 with no problems. Just enter the table name, and before you execute just count the number of records - it helps to know what you want to end up with.
    Have you tried using wild cards (the *) to preselect a smaller number of records : * a bit of your 60 character string *
    If you are trying to select from a non-key field you will encounter performance issues, but you can still use the wildcards, and get a result.
    Don't use RSA3 it was designed to make selections and group them into datapackets. It's not the same as selecting directly on the table in SE11 or SE16

  • Query to get row with max values for distinct

    I have a table test with ID, ADID, MTMST columns.
    ID     ----ADID----     MTMST
    1     ----100----     24-MAR-12 08.17.09.000000 PM
    1     ----101----     24-MAR-12 08.18.15.000000 PM
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----103----     24-MAR-12 08.19.21.000000 PM
    2     ----104----     24-MAR-12 08.19.36.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    3     ----99----      22-MAR-12 09.48.22.000000 PM
    I need the rows with max ADID for each ID.
    I used the following query but it provided max ADID of the table but not the distinct ID
    select * from test where ADID in (select max(ADID) from test where id in (select distinct(id) from test where mtmst > sysdate -1))
    Result:*
    ID     ----ADID----     MTMST
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Expected result:*
    ID     ----ADID----     MTMST
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Thanks,
    Dheepan
    Edited by: Dheepan on Mar 24, 2012 9:53 AM

    select id, adid, mtmst from test where (id, adid) in (select id, max(adid) from test group by id) and MTMST>sysdate-1
    is the answer.

  • Using a table alias to identify row with max timestamp for same ID, syntax?

    Hello experts
    I have created an alias of a table, so now I have table T1 and its alias T2. (T2 is not joined to anything in the universe currently)
    I need to identify the row from T1 with the maximum timestamp for any given ID:
    ID                       Timestamp
    1                         2011-01-24 16:26:00.000
    1                         2011-02-24 14:21:00.000
    1                         2011-02-24 13:49:00.000
    I couldn't find anything on the SAP forums, but elsewhere suggested my approach should be thus:
    1) Create a table alias (leave it free standing i.e. not joined) - DONE
    2) For T1, create a dimension object named Timestamp - DONE
    3) Create a seperate predefined condition icon funnel / filter - in the where clause:
    T1.timestamp = (SELECT max(T2.timestamp) from T2 WHERE
    T1.Key = T2.Key)
    I'm stuck with the BO XI 3.1 syntax on step 3. I can't get it to parse.
    In the where clause, mine starts with @select(T1\Timestamp) = max(@select(T2\Timestamp)
    @where T1.Claim_no = T2.Claim_no)
    Please can someone help me with the syntax so this thing will parse.
    Many thanks in anticipation.
    Eddie

    Hi ,
    Can you try
    SELECT   ID, MAX(datetime) FROM T1 GROUP BY by ID
    Thanks
    Ponnarasu

  • SQL subquery returning too many rows with Max function

    Hello, I hope someone can help me, I been working on this all day. I need to get max value, and the date and id where that max value is associated with between specific date ranges. Here is my code , and I have tried many different version but it still returning
    more than one ID and date
    Thanks in advance
    SELECT
      distinctbw_s.id, 
    avs.carProd,cd_s.RecordDate,
    cd_s.milkProductionasMilkProd,
    cd_s.WaterProductionasWaterProd
    FROMtblTestbw_s
    INNERJOINtblTestCpcd_sWITH(NOLOCK)
    ONbw_s.id=cd_s.id   
    ANDcd_s.recorddateBETWEEN'08/06/2014'AND'10/05/2014'
    InnerJoin
    (selectid,max(CarVol)ascarProd
    fromtblTestCp
    whererecorddateBETWEEN'08/06/2014'AND'10/05/2014'
     groupby 
    id)avs
    onavs.id=bw_s.id
    id RecordDate carProd       MilkProd WaterProd
    47790 2014-10-05   132155   0 225
    47790 2014-10-01   13444    0 0
    47790 2014-08-06   132111    10 100
    47790 2014-09-05   10000    500 145
    47790 2014-09-20   10000    800 500
    47791 2014-09-20   10000    300 500
    47791 2014-09-21   10001    400 500
    47791 2014-08-21   20001    600 500
    And the result should be ( max carprod)
    id RecordDate carProd       MilkProd WaterProd
    47790 2014-10-05   132155  0 225
    47791 2014-08-21   20001    600 500

    Help your readers help you.  Remember that we cannot see your screen, do not know your data, do not understand your schema, and cannot test a query without a complete script.  So - remove the derived table (to which you gave the alias "avs")
    and the associated columns from your query.  Does that generate the correct results?  I have my doubts since you say "too many" and the derived table will generate a single row per ID.  That suggests that your join between the first
    2 tables is the source of the problem.  In addition, the use of DISTINCT is generally a sign that the query logic is incorrect, that there is a schema issue, or that there is a misunderstanding of the schema. 

  • Row with max date

    Hi guys,
    Quick question which I would appreciate some help with. I am currently querying a table with multiple rows but I only want it to return 1 row (the one which was created most recently) ie. the one with the max date_Created field.
    I was thinking I could do this:
    Select *
    from table
    where date_created = max(date_created)
    but you will probably know I cant do this. I know I can partition etc but since I am calling this as a cursor from oracle forms I cant use partition, can anyone help me out please?
    Thanks.

    Hi,
    Here's one way:
    WITH     got_r_num     AS
         SELECT     t.*
         ,     ROW_NUMBER () OVER (ORDER BY  date_created  DESC)
                  AS r_num
         FROM    table_x  t
    SELECT     *   -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    786733 wrote:Hi guys,
    Quick question which I would appreciate some help with. I am currently querying a table with multiple rows but I only want it to return 1 row (the one which was created most recently) ie. the one with the max date_Created field.
    I was thinking I could do this:
    Select *
    from table
    where date_created = max(date_created)
    but you will probably know I cant do this. You can do something pretty close:
    SELECT     *
    FROM     table_x
    WHERE     date_created = (
                         SELECT  MAX (date_created)
                      FROM        table_x
    ;However, if there is a tie (that is, 2 or more rows that have exactly the same date_created, and none later), then this will return all of them, and you said you only want 1 row.
    I know I can partition etc but since I am calling this as a cursor from oracle forms I cant use partition, can anyone help me out please?Sorry, I don;t undersand what you're saying about partitions.
    If there's something that you can do in, say, SQL*Plus, but not in Forms, then hre's probably a way to "hide" it (in a view, perhaps) so that the part Forms can't hande isn't being done in Forms.

  • How To Find Last Row With Data +2, Then Format?

    I need to find the last row +2, select the range A:L, then format.
    Could someone please supply the code?  I can handle the format part.
    Thanks!
    A. Wolf

    Works great!
    I need to do 2 other things:
    1) Add a text value to r in A: & center over selection A:L
    Dim r As Long
        r = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
           USED THIS BUT ENDING UP IN MIDDLE OF L:!
        ActiveCell = Range("A" & r)
        ActiveCell.Value = "Estimated True Up Total"
    2) 2) Format a total in r as currency/2 decimels/aligned to right.
    THANKS AGAIN!!!
    A. Wolf

  • Select unique rows from two tables...

    Hi,
    I have two tables, replies1 and replies2.
    SQL> desc replies
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    FILESIZE NUMBER
    AS_NUM VARCHAR2(6)
    SQL> desc replies2
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    AS_NUM VARCHAR2(6)
    Both of the tables have no primary keys, but I have indixes on (urn, addrss) combination on both....
    I am trying to select the unique rows with (urn, address) from replies2, and then find the matching size from replies...
    I am using the following query:
    select distinct replies2.urn, replies2.address, replies.filesize from replies2, replies where replies2.AS_NUM like 'XYZ' and replies.urn = replies2.urn;
    I cannot figure out why it won't work. the way I understand it is that, distinct will give all distinct combination of all column names that follow, which is what I want...
    I know it is wrong, because the query:
    select count(*) from replies2 where AS_NUM like 'XYZ' returns less number of rows than the above query.
    Any help would be greatly appreciated.
    Thank you
    Oz.

    Thanks a lot Mohan for your reply.
    urn is not a unique key. Several rows could have the same (urn, address) pair in both tables. What I want is retrieve all (urn, address) rows from one table, and find the size from the other table to make a (urn, address, size). I want all unique combinations of (urn, address) to appear in the output.
    AS_NUM is an empty column in replies... It would've been a lot easier if it wasn't, since then I'll just say: select distinct urn, address, filesize from replies where AS_NUM like 'XYZ';
    I will try your query though and let u know how it goes. It takes quite a while to run since my tables are huge.

  • How to fetch a row with maximum rownum

    In my sql query, how can i fetch the row with max row count? the query has around 10 columns.
    Thank You
    KK

    Hi,
    It's not very clear what you want.
    It sounds like you want a Top=-N Query , perhaps like this:
    WITH     got_row_cnt     AS
         SELECT       job
         ,       COUNT (*)                         AS row_cnt
    --     ,       ...  -- other columns
         ,       RANK () OVER (ORDER BY  COUNT (*) DESC)     AS rnk
         FROM       scott.emp
         GROUP BY  job
    SELECT     *     -- or list all columns except rnk
    FROM     got_row_cnt
    WHERE     rnk     = 1
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • SQL: Find table with max no. of rows

    I have a table containing list of table names for each owner; as
    ## Table: db_tables
    OWNER TABLE_NAME
    a ta_1
    a ta_2
    a ta_3
    b tb_1
    b tb_2
    c tc_1
    Now, i want to know the table with max. no. of rows for each owner
    Plz....can anyone gimme a solution for the above ......

    Assuming 10g and above:
    SQL>  SELECT owner,
                 MAX(table_name) KEEP (DENSE_RANK FIRST ORDER BY XMLQUERY (t RETURNING CONTENT).getnumberval() DESC) table_name,
                 MAX(XMLQUERY (t RETURNING CONTENT).getnumberval()) cnt
        FROM (SELECT owner,table_name,    'count(ora:view("' || table_name || '"))' t
                FROM all_tables
               WHERE owner IN ('MICHAEL','SCOTT'))
               GROUP BY owner
    OWNER                          TABLE_NAME                            CNT
    MICHAEL                        SERVICE_ZIP                       1000000
    SCOTT                          EMP                                    14
    2 rows selected.

  • Selecting the rows with the max rank

    Using Siebel CRM and tested conditions in Answers - It was observed that one email ID is linked to multiple customers. For an email campaign we need to select only one customer per email basically had to remove all the duplicate email addresses from the list as customer IDs are anyways unique.
    Tried using the RANK function - RANK(customer ID by Email) = 1 it gave me unique email addresses and customer IDs but the problem is that the RANK 1 is given to the latest customer added (customer IDs are numeric)
    I need a solution to select all the rows with the max rank / all the customers that were added first for all the emails

    Don't know what you want to achieve but here is way to do this:
    SQL> select * from test;
    NO
    1
    2
    3
    4
    5
    SQL> select * from test union all select * from test;
    NO
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5
    10 rows selected.
    Daljit Singh

  • Rows to columns with MAX(DECODE)

    Hi Guys,
    I got a problem when transposing my rows to columns again.
    this select gets me the unique combination of a translation in 3 languages.
    what makes it unique is the combination of table_id, table_name,column_name.
    select TABLE_ID,TABLE_NAME, COLUMN_NAME,Lang,Trans_TEXT from T_translations where TABLE_NAME='table1' and COLUMN_NAME ='column1' and Table_id='231441';
    gives me three rows with the same table_id_table_name and column_name, what differs is the language each time and the text.
    I guess the unique-making columns also have to be in the partition by cause:
    SELECT TABLE_PK1,
    MAX(DECODE ( rn , 1, Trans_TEXT)) English,
    MAX(DECODE ( rn , 2, Trans_TEXT)) Chinese,
    MAX(DECODE ( rn , 3, Trans_TEXT)) Russian
    FROM
    (SELECT TABLE_ID,Table_Name,Column_Name Trans_TEXT,
    row_number() OVER ( partition by TABLE_ID,Table_Name,Column_Name order by rownum) rn
    FROM T_translations where Trans_TEXT is not null)
    group by TABLE_id,Table_Name,Column_Name
    The problem is that everything comes out scrabled. all the translated text is mixed up. English text
    is in column Chinese and Russian is in,.... I cant see a logic.
    Does someone have an idea?

    Hi,
    Instead of this
    row_number() OVER ( partition by TABLE_ID,Table_Name,Column_Name order by rownum) rnselect LANG and do your decode on that.
    Something like (No need for the subselect)
    SELECT   table_id,
             MAX (DECODE (lang, 'ENGLISH', trans_text)) english,
             MAX (DECODE (lang, 'CHINESE', trans_text)) chinese,
             MAX (DECODE (lang, 'RUSSIAN', trans_text)) russian
    FROM  t_translations
    WHERE  lang IN ('RUSSIAN', 'ENGLISH', 'CHINESE')
    GROUP BY table_id,
             table_name,
             column_name;Regards
    Peter

  • I want the max date but only look at rows with a certain category value.

    I want a way to get the max date but only look at rows with a certain category value - ignoring the other rows.  My detail table contains expenditures including date (col A) and category (col D) the number of rows will increase with expenditures over time.  My summary table will have a cell for each category and display the last expense date for that category using a functionality that I must ask of you, dear community.
    I am using the latest numbers on an iPad (4) with IOS6.
    Secondarily, I would like to add another cell in the summery table with the value (col E) of the last expense for each category.
    Thank you,
    Warren

    ...later...
    With the addition of an auxiliary column to the Main table, a second header row to the Most recent table, and a minor modification to the formula on the second table, the tables can handle a range of dates set by entering the first and last date into A1 abd B1 respectively of the summary table, Most recent.
    Note that the selected range, shown with a green background in the auxiliary column, does not contain any category B expenses. Using LOOKUP, this would result in a repeat of the January 6 expense bering listed in this row. Switching to VLOOKUP, which can be set to require an exact match, allows the result shown—if there are no expenses in a given category, the formula returns "none" (or whatever message you substitute for "none" in the formula in that column).
    Formulas:
    Main::A2: =IF(OR(B<Most recent :: $A$1,B>Most recent :: $B$1),"x"&E,E)
    Fill down to the end of column A.
    This column must be located on the left side of the table (ie. must be column A), but may be hidden.
    Most recent::A2: =IFERROR(VLOOKUP($D,Main :: $A:$D,COLUMN()+1,FALSE),"none")
    "FALSE" will display as "Exact match" in Numbers's formula editor.
    Fill down to the end of the table and right to column C.
    Regards,
    Barry

  • How to find selected rows in REUSE_ALV_GRID_DISPLAY

    HEllo All,
    In OO we have a method to find get_selected_rows but i am unable to what is the way to find selected rows in REUSE_ALV_GRID_DISPLAY.
    I am able to find a single row but i have to find multiple cleans in ALV. How can i do this.
    Please help me with some ideas or please post some sample codes.
    Regards,
    Lisa

    Hi,
    Check this code..
    REPORT  zdayatest1.
    TABLES :t247.
    TYPE-POOLS slis. "Type definitions for alv report
    TYPES: BEGIN OF ty_func_tab,
            fcode    TYPE rsmpe-func,
            END OF ty_func_tab.
    DATA: it_fieldcat TYPE  lvc_t_fcat,
          wa_fieldcat TYPE  lvc_s_fcat.
    DATA: is_lvc_s_glay TYPE lvc_s_glay.
    DATA: wa_layout TYPE lvc_s_layo.
    DATA: is_rxtab  TYPE ty_func_tab.
    DATA: BEGIN OF it_final OCCURS 0,
          check(1),
          mnr LIKE t247-mnr,
          ltx LIKE t247-ltx,
          END OF it_final.
    DATA: wa_final LIKE it_final.
    DATA: w_repid LIKE sy-repid.
    START-OF-SELECTION.
      w_repid = sy-repid.
      REFRESH it_final.
      SELECT mnr ltx
      FROM t247
      INTO CORRESPONDING FIELDS OF TABLE it_final
      WHERE spras EQ 'E'.
      wa_fieldcat-fieldname = 'CHECK'.
      wa_fieldcat-tabname   = 'IT_FINAL'.
      wa_fieldcat-checkbox  = 'X'.
      wa_fieldcat-edit      = 'X'.
      wa_fieldcat-outputlen = '3'.
      wa_fieldcat-col_pos   = '1'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname  = 'MNR'.
      wa_fieldcat-tabname    = 'IT_FINAL'.
      wa_fieldcat-outputlen  = '8'.
      wa_fieldcat-col_pos    = '2'.
      wa_fieldcat-coltext  = 'Month'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname  = 'LTX'.
      wa_fieldcat-tabname    = 'IT_FINAL'.
      wa_fieldcat-outputlen  = '20'.
      wa_fieldcat-col_pos    = '3'.
      wa_fieldcat-coltext  = 'Month Desc'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_layout-zebra = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_callback_program       = w_repid
          i_callback_pf_status_set = 'SUB_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND'
          i_grid_title             = 'TESTING'
          is_layout_lvc            = wa_layout
          it_fieldcat_lvc          = it_fieldcat
        TABLES
          t_outtab                 = it_final
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    *&      Form  USER_COMMAND
    FORM user_command USING ucomm LIKE sy-ucomm
                            selfield TYPE slis_selfield.
      IF selfield-fieldname = 'CHECK'.
        DATA ref1 TYPE REF TO cl_gui_alv_grid.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            e_grid = ref1.
        CALL METHOD ref1->check_changed_data.
        LOOP AT it_final WHERE check = 'X'.
          IF it_final-check IS INITIAL.
            it_final-check = 'X'.
          ELSE.
            CLEAR it_final-check.
          ENDIF.
          MODIFY it_final.
        ENDLOOP.
        selfield-refresh = 'X'.
      ENDIF.
    ENDFORM.                    "USER_COMMAND
    *&      Form  sub_pf_status
    *       text
    *      -->RT_EXTAB   text
    FORM sub_pf_status USING rt_extab TYPE slis_t_extab.        "#EC CALLED
      CLEAR is_rxtab.
      is_rxtab-fcode = 'TEST'.
      APPEND is_rxtab TO rt_extab.
      SET PF-STATUS 'PF_STATUS' ."EXCLUDING rt_extab.
    ENDFORM.                    "sub_pf_status

  • How can i find Duplicate Rows in forms6i

    Hi,
    How can i find duplicate rows in multiple record in forms6i.
    Thanks
    Raghu.K

    Oops, sorry for misreading your question. (However the SQL I gave you above is also very handy, and worth saving.)
    Okay, this is off the top of my head and untested, but might just work. Assuming that your data block name is MYBLOCK, and that the item that you want to check for dups on is named MYNUM, create an item-level WHEN-VALIDATE-ITEM trigger with the following code.
    declare
    l_newest_record number(10) := :system.cursor_record;
    l_newest_mynum number(10) := :myblock.mynum;
    l_dup_found boolean := false;
    begin
    -- In this loop, we skip backwards through all new records to look for dups.
    while :system.cursor_record > 1 loop
    previous_record;
    if :system.record_status = 'NEW' then
    if :myblock.mynum := l_newest_mynum then
    l_dup_found := true;
    exit; -- Dup found!
    end if;
    else
    exit; -- We've gone backwards past the first new record.
    end if;
    end loop;
    -- In this loop, we return to the current record.
    while :system.cursor_record < l_newest_record loop
    next_record;
    end loop;
    if l_dup_found then
    raise duplicate_row_found; -- user-defined exception
    end if;
    end;
    The above code only checks for dups in the new form records. It assumes that a unique constraint in the database will deal with records actually committed.
    Armand

Maybe you are looking for