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

Similar Messages

  • How to join  fields from different internal tables and display into one int

    hai i have one doubt...
    how to join  fields from different internal tables and display into one internal table..
    if anybody know the ans for this qus tell me......

    hii
    you can read data as per condition and then can join in one internal table using READ and APPEND statement..refer to following code.
    SELECT bwkey                         " Valuation Area
             bukrs                         " Company Code
        FROM t001k
        INTO TABLE i_t001k
       WHERE bukrs IN s_bukrs.
      IF sy-subrc EQ 0.
        SELECT bwkey                       " Valuation Area
               werks                       " Plant
          FROM t001w
          INTO TABLE i_t001w
           FOR ALL ENTRIES IN i_t001k
         WHERE bwkey = i_t001k-bwkey
           AND werks IN s_werks.
        IF sy-subrc EQ 0.
          LOOP AT i_output INTO wa_output.
            READ TABLE i_t001w INTO wa_t001w WITH KEY werks = wa_output-werks.
            READ TABLE i_t001k INTO wa_t001k WITH KEY bwkey = wa_t001w-bwkey.
            wa_output-bukrs = wa_t001k-bukrs.
            MODIFY i_output FROM wa_output.
            CLEAR wa_output.
          ENDLOOP.                         " LOOP AT i_output
        ENDIF.                             " IF sy-subrc EQ 0
    regards
    twinkal

  • Find min and max from a bunch of numbers

    hi,
    i have a bunch of numbers, and i need to find the min and max.
    so i have a arraylist which contains objects....whats the best way to find the min number and max number of all these objects?
    thanks

    You're close, but you can do them all at the same time without temp variables..
    double maximumX = 0;
    double minimumX = 0;
    double maximumY = 0;
    double minimumY = 0;
    for (int i = 0; i < myobjects.size(); i++) {
         mything d2d = (mything) myobjects.get(i);
         maximumX = Math.max(d2d.getBounds().getMaxX(), maximumX);
         minimumX= Math.min(d2d.getBounds().getMinX(), minimumX);
         maximumY = Math.max(d2d.getBounds().getMaxY(), maximumY);
         minimumY = Math.min(d2d.getBounds().getMinY(), minimumY);
    }Since you are dealing with rectangles, you could add them all to an Area and get the bounds of the Area, but that's probably slower.

  • Finding Min and Max

    I have the following data stored in java. The names are stored as a 1 dimensional array and the figures as a 2 dimensional array.
    -----------------------------Min Max
    Joe Jones 32 22 20 10 ? ?
    Jim Long 10 45 10 60 ? ?
    Tom Doon 5 10 50 70 ? ?
    What I want to do is to find the Mininum and Maximum value of each row. It would be displayed where the question ,marks are. What should my code be???

    you can use the sort method to determine which is the max/min and then return them & still keep your list as is.
    something like:
    -----------------------------Min Max
    Joe Jones 32 22 20 10 sort.getMax() sort.getMin()
    Jim Long 10 45 10 60 ? ?
    Tom Doon 5 10 50 70 ? ?
    for the getMax() method - return the last element in the sorted array
    for the getMin() method - return the first element in the sorted array

  • How to show Min and Max values when another value "changes to a new value"

    Hi
    If I have this data (generated with this query: SELECT 1 A, 1 B UNION ALL SELECT 2, 1 UNION ALL SELECT 3, 2 UNION ALL SELECT 4, 2 UNION ALL SELECT 5, 1)
    A B
    1 1
    2 1
    3 2
    4 2
    5 1
    How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1)
    Amin Amax B
    1 2 1
    3 4 2
    5 5 1
    Thanks.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. You also do not know the ANSI/ISO syntax for insertion and you did the old Sybase insertion kludge wrong, that we need keys, etc.
    CREATE TABLE Foobar
    (foo_seq INTEGER NOT NULL PRIMARY KEY,
     glop_score INTEGER NOT NULL);
    INSERT INTO Foobar
    VALUE
    (1,1),
    (2,1),
    (3,2),
    (4,2),
    (5,1);
    >> How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1) <<
    This makes no sense; you have the wrong syntax and mixed data types. My guess is: 
    SELECT MIN(foo_seg), MAX(foo_seq), MAX(glop_score)
      FROM Foobar
     GROUP BY glop_score
    HAVING MIN(glop_score) = MAX(glop_score); 
    Amin Amax B
    1 2 1
    3 4 2
    5 5 1
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Best Way to find min and max

    Hi
    I wish to know is there any better way to get min(zseq) from a query statement?
    I have data as :
    00010 10 1 10/10/2006   - need to get tihs date (min)
    00010 10 2 12/10/2006
    00010  10 3 15/10/2006 - need to get this date(max-1)
    00010 10 4 18/10/2006 - need to get this date (max)
    My query :
    SELECT ZCDD FROM ZVI2D INTO S_1ST_ZCDD
          WHERE ZVBELN = WA_OUTPUT_ALL-VBELN AND ZPOSNR = WA_OUTPUT_ALL-POSNR
            AND ZSEQ IN ( SELECT MIN( ZSEQ ) FROM ZVI2D WHERE ZVBELN = WA_OUTPUT_ALL-VBELN AND ZPOSNR = WA_OUTPUT_ALL-POSNR ).
             AND ZDATUM = WA_OUTPUT_ALL-ZDATUM ).
        ENDSELECT
    I will reward points if you are able to give a good uggestion. Thanks.

    i think you can get max and min from the select query itself just check my previous posting for the min. But i dont think you can get the second maximum value from the select query. For that you have to store the data in itab and sort that by descending read thae table itab with index 1(max) and index 2(second largest) and last for min.
    suppose you have data inyour itab.
    data : lin type i.
    sort itab by <field name> descending.
    read table itab index 1."for max value.
    write : / itab-<field>.
    read table itab index 2."second largest.
    write : / itab-<field>.
    describe table itab lines lin.
    read table itab index lin.
    write :  / itab-<field>.
    regards
    shiba dutta

  • Get min and max for a column from table with 24 million rows.

    What is the best way to re-write the following query in a procedure for the table which has around 24 million rows?
    SELECT MIN(ft_src_ref_id), MAX(ft_src_ref_id )
    INTO gn_Min_ID, gn_Max_ID
    from UI_PURGE_FT;
    Thanks
    Edited by: tcode on Jun 21, 2012 12:31 PM

    Which of the following plan is better, can you please breifly explain?
    Also I need to gather statics to know recursive calls , db block gets ,consistent gets etc. etc. how can I get that?
    Thanks
    1.
    Execution Plan
    Plan hash value: 3702745568
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 6 | 13991 (2)| 00:02:48 |
    | 1 | SORT AGGREGATE | | 1 | 6 | | |
    | 2 | INDEX FAST FULL SCAN | UI_PURGE_FT_PK | 23M| 136M| 13991 (2)| 00:02:48 |
    2.
    Execution Plan
    Plan hash value: 1974183109
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | | 2 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 6 | | |
    | 2 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
    | 3 | SORT AGGREGATE | | 1 | 6 | | |
    | 4 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
    | 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------

  • How to Find the Data Type of the Field In a Database Table

    Hi Experts,
    I'm currently working on a program which needs to find out the data type of the given field in a database table. In addition to accessing DD03L directly, is there any other workaround such as function module to help me achieve this? It would be helpful if a demo example could be provided.
    Thanks a lot.

    Hi,
    Use this..
    DESCRIBE FIELD dobj  TYPE typ.
    write typ.
    type will contain the data type of the object.
    and check this thread also....
    Re: How to get datatype of fields in dynamic structures
    Cheers,
    Simha.
    Reward all the helpful answers..

  • How to change the data  type of a field in an internal table dynamically ?

    I have an internal table :
    Data: Begin of itab_data occurs 0,
    field1 type i,
    field2 type p decimals 2,
    end of itab_data.
    My requirement is to decide the number of decimals of "field2" dynamically .
    ie. based on the input in selection-screen , the declaration has to change .How can this be done ?
    Hope the question is clear..
    Its urgent. Please help me.
    Thanks in advance .
    Shankar

    I dont think you can change it dynamically...but as per your requirement ...why dont you define the variable with maximum decimal length and depending on the parameter(from your selection-screen) use the WRITE command to populate it with the specified decimals.
    Example
    begin of itab
    field2 type p decimals 5.
    end of itab.
    write itab-field2 to lfield decimals p_dec.
    Message was edited by: Anurag Bankley

  • How to increase min and max range of resulting XML report output?

    Hi,
    I'm trying to massage search results into a digestible format using XSLT. Its relatively straigh-forward. But what I'd like is to be able to increase the character result range to capture hopefully more parts to a URL - if that's our current search result.
    Here's an existing report XML node containing the min/max attributes I'm trying to adjust:
    <mm_reportitem>
    <mm_file>link_report_210611\poc_home_2011\home_200.html</mm_file>
    <mm_displaystr><![CDATA[...template 'tracking' tools are located in the {a href="http://subdomainname.domainname.net.nz/files/index....]]></mm_displaystr>
    <mm_data mm_rangemin="3197" mm_rangemax="3210" mm_filename="Z:\projects\clinetname\link_report_210611\poc_home_2011\home_200.html" mm_replaced="false" mm_matchedtextdirty="false" />
    </mm_reportitem>
    I basically want to try and capture reasonably long URL strings (in green) by, hopefully, adjusting the ranges (in red).
    Any ideas?
    EDIT: Ok, the colours were stripped out when I posted, so basically I want the CDATA node text in "mm_display_str" to be longer to capture an entire, possibly lengthy URL.
    EDIT:  Best file I can find so far is:  C:\Documents and Settings\Dave\Application Data\Adobe\Dreamweaver CS5\en_US\Configuration\Menus\Cache\Menus\DWSiteReportsTab.xml   --  but it doesn't look like it contains anything like range values, or in fact any numeric values to adjust.

    Hi Don,
    Are you trying to mean, I need to apply this logic to get min(result_no):
    Ex :
    min(cast(order_date as date) by patient_id) = order_date then result_no.
    Thanks,
    Karthikeyan V

  • Finding Min and Max date

    SELECT * FROM (
    SELECT 'STOR_A' STORE_NAME ,'BX1' BOX_NO, 'X11' LOC, '01-JAN-2010' MOVE_DT FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX1' , 'X21' , '03-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX1' , 'X13' , '05-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX1' , 'X41' , '07-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX1' , 'X15' , '09-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX2' , 'X31' , '02-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX2' , 'X71' , '04-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX2' , 'X18' , '06-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX3' , 'X91' , '04-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX3' , 'X10' , '05-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX3' , 'X14' , '07-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX3' , 'X51' , '10-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_A'  ,'BX3' , 'X16' , '12-JAN-2010'  FROM DUAL UNION ALL 
    SELECT 'STOR_B'  ,'BX2' , 'X41' , '09-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_B'  ,'BX2' , 'X74' , '11-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_B'  ,'BX2' , 'X31' , '12-JAN-2010'  FROM DUAL UNION ALL
    SELECT 'STOR_B'  ,'BX2' , 'X68' , '17-JAN-2010'  FROM DUAL
    [pre/]
    I have the data of the Boxes which came to the store and changed the locations on a date.
    how can i select in a single row the as below. Boxwise the date and location on which received in and sent out
    [pre]
    BOX_NO     STORE_NAME     IN_LOC              IN_DATE          OUT_LOC     OUT_DATE
    BX1     STOR_A          X11          01-Jan-10     X15     09-Jan-10
    BX2     STOR_A          X31          02-Jan-10     X18     06-Jan-10
    BX3     STOR_A          X91          04-Jan-10     X16     12-Jan-10
    BX2     STOR_B          X41          09-Jan-10     X68     17-Jan-10
    [pre/]
    Can someone helpout from the query                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    using aggregate keep first/last functions:
    with my_tab as (SELECT 'STOR_A' STORE_NAME ,'BX1' BOX_NO, 'X11' LOC, to_date('01-JAN-2010', 'dd-MON-yyyy') MOVE_DT FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX1' , 'X21' , to_date('03-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX1' , 'X13' , to_date('05-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX1' , 'X41' , to_date('07-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX1' , 'X15' , to_date('09-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX2' , 'X31' , to_date('02-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX2' , 'X71' , to_date('04-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX2' , 'X18' , to_date('06-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX3' , 'X91' , to_date('04-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX3' , 'X10' , to_date('05-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX3' , 'X14' , to_date('07-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX3' , 'X51' , to_date('10-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_A'  ,'BX3' , 'X16' , to_date('12-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL 
                    SELECT 'STOR_B'  ,'BX2' , 'X41' , to_date('09-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_B'  ,'BX2' , 'X74' , to_date('11-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_B'  ,'BX2' , 'X31' , to_date('12-JAN-2010', 'dd-MON-yyyy')  FROM DUAL UNION ALL
                    SELECT 'STOR_B'  ,'BX2' , 'X68' , to_date('17-JAN-2010', 'dd-MON-yyyy')  FROM DUAL)
    select box_no,
           store_name,
           min(loc) keep (dense_rank first order by move_dt) in_loc,
           min(move_dt) in_date,
           max(loc) keep (dense_rank last order by move_dt) out_loc,
           max(move_dt) out_date
    from   my_tab
    group by box_no,
             store_name
    order by store_name, box_no;
    BOX STORE_ IN_ IN_DATE             OUT OUT_DATE
    BX1 STOR_A X11 01/01/2010 00:00:00 X15 09/01/2010 00:00:00
    BX2 STOR_A X31 02/01/2010 00:00:00 X18 06/01/2010 00:00:00
    BX3 STOR_A X91 04/01/2010 00:00:00 X16 12/01/2010 00:00:00
    BX2 STOR_B X41 09/01/2010 00:00:00 X68 17/01/2010 00:00:00Edited by: Boneist on 29-Jul-2010 14:32
    Oh darn it! Too slow! {noformat}*pootles off for more caffeine*{noformat}

  • Optimized query to find Min and max of a col in a table

    I have a table doc_boe_rec with record count 12375934
    the primary key columns are (boe_rec_id,psd_serial_num).
    No other ndexes are present on this table.
    I want an optimized query which will give both the results :
    1.Min boe_rec_id (boe_rec_id from 1st record)
    2.Max boe_rec_id from this table with rows limited to a value say 5000.
    i.e (boe_rec_id from 5000th column value from table )
    Thanks
    Manoj

    1.Min boe_rec_id (boe_rec_id from 1st record)It is confusing for me. The min value for the first, hmmm...
    2.Max boe_rec_id from this table with rows limited to a value say 5000.Not more clear...
    Please details your requirements.
    Nicolas.

  • How to find difference in amount between two fields in two different tables

    Hi,
    I am new to PL/SQL. I need to write a procedure to calculate the difference between two columns of two seperate tables. For example:
    I have Table a and Table b. Both with two columns Id and Amount. I need to find the difference of Amount between table a and table b value for each record in table b, store it in variable and then do further operations using that difference. Kindly help me with this.

    Something like this?
    INSERT INTO table_c (id, diff, p_or_n)
    SELECT
    a.a_id,
    a.a_value - b.b_value
    DECODE( SIGN(a.a_value - b.b_value),
      1 , 'P',
      0 , 'P',
      -1, 'N'
    FROM table_a a JOIN table_b b
    ON (a.a_id = b.b_id);
    -- Ranit

  • Find more than one min and max in 2D array contain 0 rows

    Hi
    I have a 2D array and I would like to find the max and min elements between series of 0s. As you can see in the picture If I remove all 0s from the array and use the max and min function then I will have just one min and one max but I need to find min and max after every 0 rows so you can see from the picture ( just as an example) I will have 3 min and 3 max numbers. Would you please help me with this code. Do you now any algorithm that can find min and max between 0s?
    I have also attached my code to remove 0s and then search for max and min numbers but as I mentioned I need min and max for every part
    Many thanks
    Attachments:
    2.jpg ‏82 KB
    3.jpg ‏27 KB

    Thanks altenbach
    I have attached the vi to this post. I would really apperciate if you help me with this example. The min values should be 100, 1500 and 4000 and the max values should be 1200,2600,5400 so as u mentioned the output should be this 2D array 
    100,1200
    1500,2600
    4000,5400
    Attachments:
    new.vi ‏6 KB

  • How to split all the fields of output ls-l from an internal table

    Hi all,
    Using ls-l command i have brought the file attributes of a file like its read and write permissions,creation date ,path etc in a internal table.
    Now how to split all these fields from the internal table or what should be the splitting criteria.
    The field contents of internal table are like this:
    -rw-rw----    1  devadm     sapsys     18360    apr  29......so on
    I want to split this into different fields.
    Kindly suggest.
    Thank You.

    Hi,
    I think the delimiter will be space. For date alone (Apr 29) you need to concatenate after the string has been split.
    Thanks and regards,
    S. Chandramouli

Maybe you are looking for