Rows to Column Conversion in ABAP

Hello guys,
I wanted to create a report in which I need to convert rows in to column.
e.g.
I have a itab_col which contains my column header as follows.
itab_col-plant        itab_col-name
1000                     Plant A
2000                     Plant B
3000                     Plant C    
I have a itab_data which contains my data as follows .
itab_data-date    itab_data-qty       itab_data-plant
01.06.2006           10                  1000
01.06.2006           20                  1000
01.06.2006           50                  2000
02.06.2006           20                  3000
I need to print the report as follows
  Date       Plant A      Plant B      Plant C
01.06.2006     30           50           0
02.06.2006     0            0            20
Could you tell me how I can do it in abap.

Hi,
first create table with following attribute.
table_row_to_column
1. date
2. Plant A
3. Plant B
4. Plant C.
.............D E F ..number of plant possible.
Sum Up The data
01.06.2006 10 1000
01.06.2006 20 1000
01.06.2006 50 2000
02.06.2006 20 3000
01.06.2006 30 1000
01.06.2006 50 2000
02.06.2006 20 3000
to new data_table_sum_value
<b>for that u have to</b>
1) Sort the table date & plant.
2) sum up records for similar plant based on date
<b>Convert rows in to column.</b>
loop at data_table_sum_value.
  case data_table_sum_value-plant.
    when 1000.
       table_row_to_column-plant_A = data_table_sum_value-qnty.
    when 2000.
       table_row_to_column-plant_B = data_table_sum_value-qnty.
    when 3000.
       table_row_to_column-plant_C = data_table_sum_value-qnty.
    when 4000.
       table_row_to_column-plant_D = data_table_sum_value-qnty.
    when 5000.
       table_row_to_column-plant_E = data_table_sum_value-qnty.
  endcase.
   at end of date.
     append table_row_to_column.
   endat.
endloop.
<b>Please Mark Helpful Answers & Rewards Points.
Dont Forget to mark as problem solved if solved</b>
Regards

Similar Messages

  • Row to Column conversion

    Hi,
    i am having following table
    SELECT* FROM Col_to_row;
    output is:
    A      B      C
    X      Y      Z
    1      2      3
    i want to write query for below output, need to convert row into column for n number of rows for example i have taken only 3 rows:
    A X 1
    B Y 2
    C Z 3

    Three things to notice in this solution:
    1) I am ordering by the original column name. You may want to order by something else.
    2) When pivoting, you must indicate the name, number and datatype of the columns, so if there is a fourth line of input you have to add a column to the query.
    3) This works on Oracle 11GR1 and above. Next time, be sure to indicate your Oracle version from the start.create table COL_TO_ROW(C1, C2, C3) as select
    'A', 'B', 'C' from DUAL union all select
    'X', 'Y', 'Z' from DUAL union all select
    '1', '2', '3' from dual;
    select * from (select rownum rn, a.* from COL_TO_ROW a)
    UNPIVOT(VAL for COL in(C1, C2, C3))
    PIVOT(max(VAL) for RN in (1,2,3))
    order by col;
    COL 1 2 3
    C1  A X 1
    C2  B Y 2
    C3  C Z 3

  • Row to column conversion during excel download

    Dear Experts,
    I have an internal table with one column.
    It has some entries say ten.
    I want this ten rows of entries to be displayed in the excel sheet as a single row. It means each row entry of the internal table should fit in to each cell.
    Is there any possibility with GUI_DOWNLOAD FM to do this?
    If not, then how could i do that?
    Please let me know its urgent.
    Regards,
    Shashi

    Hi,
    i m not aware of whether it can be done through FM 'GUI_DOWNLOAD' but i have one sugeestion.
    You can first transpose your internal table and then download it.
    Sample code for obtaining the transpose is as follows:
    *& Report Z_TRANPOSEALV *
    *& Author : Swarna.S.
    *& AS: This simple ALV report display is in a transposed way
    *& Publised at ****************
    REPORT Z_TRANSPOSEALV .
    Type pools declaration for ALV
    TYPE-POOLS: slis.
    *Declarations for ALV, dynamic table and col no for transpose
    DATA: l_col TYPE sy-tabix,
    l_structure TYPE REF TO data,
    l_dyntable TYPE REF TO data,
    wa_lvc_cat TYPE lvc_s_fcat,
    lt_lvc_cat TYPE lvc_t_fcat,
    lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
    wa_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv,
    lt_layout TYPE slis_layout_alv.
    *Field symbols declarations
    FIELD-SYMBOLS :
    <header> TYPE ANY,
    <dynheader> TYPE ANY,
    <dyndata> TYPE ANY,
    <ls_table> TYPE ANY,
    <dynamictable> TYPE STANDARD TABLE,
    <it_table> TYPE STANDARD TABLE.
    *Input the name of the table
    PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY.
    *Initialization event
    INITIALIZATION.
    *Start of selection event
    START-OF-SELECTION.
    Create internal table of dynamic type
    CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
    WITH NON-UNIQUE DEFAULT KEY.
    ASSIGN l_dyntable->* TO <it_table>.
    *select statement to select data from the table as input into
    *our dynamic internal table.
    *Here i have restricted only till 5 rows.
    *You can set a variable and give no of rows to be fetched
    *The variable can be set in your select statement
    SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
    FROM (p_table) up to 5 rows.
    *Fieldcatalogue definitions
    wa_lvc_cat-fieldname = 'COLUMNTEXT'.
    wa_lvc_cat-ref_table = 'LVC_S_DETA'.
    APPEND wa_lvc_cat TO lt_lvc_cat.
    wa_fieldcat-fieldname = 'COLUMNTEXT'.
    wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
    wa_fieldcat-key = 'X'..
    APPEND wa_fieldcat TO lt_fieldcat.
    DESCRIBE TABLE <it_table>.
    DO sy-tfill TIMES.
    For each line, a column 'VALUEx' is created in the fieldcatalog
    Build Fieldcatalog
    WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
    CONCATENATE 'VALUE' wa_lvc_cat-fieldname
    INTO wa_lvc_cat-fieldname.
    wa_lvc_cat-ref_field = 'VALUE'.
    wa_lvc_cat-ref_table = 'LVC_S_DETA'.
    APPEND wa_lvc_cat TO lt_lvc_cat.
    Build Fieldcatalog
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
    wa_fieldcat-ref_fieldname = 'VALUE'.
    wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
    APPEND wa_fieldcat TO lt_fieldcat.
    ENDDO.
    Create dynamic internal table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = lt_lvc_cat
    IMPORTING
    ep_table = l_dyntable. ASSIGN l_dyntable->* TO <dynamictable>.
    Create structure as structure of the internal table
    CREATE DATA l_structure LIKE LINE OF <dynamictable>.
    ASSIGN l_structure->* TO <header>.
    Create structure = structure of the internal table
    CREATE DATA l_structure LIKE LINE OF <it_table>.
    ASSIGN l_structure->* TO <ls_table>.
    Create field catalog from our table structure
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    i_structure_name = p_table
    CHANGING
    ct_fieldcat = lt_fieldcatalogue
    EXCEPTIONS
    inconsistent_interface = 1
    program_error = 2
    OTHERS = 3.
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF. DESCRIBE TABLE lt_fieldcatalogue.
    Fill the internal to display <dynamictable>
    DO sy-tfill TIMES.
    IF sy-index = 1.
    READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
    ENDIF.
    For each field of it_table
    ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
    Fill 1st column
    <dynheader> = wa_fieldcat-seltext_m.
    IF <dynheader> IS INITIAL.
    <dynheader> = wa_fieldcat-fieldname.
    ENDIF.
    *Filling the other columns
    LOOP AT <it_table> INTO <ls_table>.
    l_col = sy-tabix + 1.
    ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
    <dynheader>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
    ENDLOOP.
    APPEND <header> TO <dynamictable>.
    ENDDO.
    *Layout for ALV output
    lt_layout-zebra = 'X'.
    lt_layout-no_colhead = 'X'..
    lt_layout-colwidth_optimize ='X'.
    lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.
    *ALV Grid output for display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    is_layout = lt_layout
    it_fieldcat = lt_fieldcat
    TABLES
    t_outtab = <dynamictable>.
    Regards,
    Karuna.

  • Row to column conversion in large result set

    I need to get the differnt levels of alerts for each user, with the total alert counts and counts for each type of alert.
    SELECT COUNT(*) TOTAL,
            u.name,
            d.deptname,
            COUNT(CASE WHEN al.severity = 5 THEN 1 END) INDETERMINATE,
            COUNT(CASE WHEN al.severity = 4 THEN 1 END) WARNING,
            COUNT(CASE WHEN al.severity = 3 THEN 1 END) MINOR,
            COUNT(CASE WHEN al.severity = 2 THEN 1 END) MAJOR,
            COUNT(CASE WHEN al.severity = 1 THEN 1 END) CRITICAL
    FROM alerts al, user u, dept d
    WHERE al.userid = u.userid
      AND u.deptid = d.deptid
      AND al.time = sysdate - 4/24
      AND al.time <= sysdate
    GROUP BY u.name, d.deptname  This might be inefficient especially when the amount of data is huge and potentially you could be looking at millions of rows in a given interval. So I was thinking of grouping by severity, which would eliminate the CASE statements, but then the problem on group by is that I get it as a rows instead of columns.
    Would anyone have a suggestion as to do it effeciently especially one that has millions of rows? Thanks.

    I guess eventually we are probably going to move towards that, but using a staright forward query is the immediate solution and any help on that would be great. Thanks.

  • Reg:Row to column conversion

    Hi All,
    I will give string three string values in a single variable like CNTNS_VAL_STR = test,value,small
    but i need result like
    test
    value
    small
    Please help to reslove the one
    thanks,

    Your requirement isn't very clear anymore.
    Please post a small testcase, like I did below, assuming you're looking for a way to query column values based on an input string:
    SQL> create table t as
      2  select 1 rn,'A' descr from dual union
      3  select 2,'B' from dual union
      4  select 3,'C' from dual union
      5  select 4,'Q' from dual union
      6  select 5,'X' from dual;
    Table created.
    SQL> select * from t;
            RN D
             1 A
             2 B
             3 C
             4 Q
             5 X
    5 rows selected.
    SQL> create or replace function str2tbl( p_str in varchar2, p_delim in varchar2 default ',' )
      2  return sys.odcivarchar2list
      3  pipelined
      4  as
      5      l_str long default p_str || p_delim;
      6      l_n   number;
      7  begin
      8      loop
      9          l_n := instr( l_str, p_delim );
    10          exit when (nvl(l_n,0) = 0);
    11          pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );
    12          l_str := substr( l_str, l_n+1 );
    13      end loop;
    14      return;
    15  end;
    16  /
    Function created.
    SQL> select *
      2  from   t
      3  where descr in ( select column_value
      4                   from   table(str2tbl('A,B,C'))
      5                 );
            RN D
             1 A
             2 B
             3 C
    3 rows selected.
    So, I more or less 'joined' a table to a pipelined function (no cursor needed) based on an input string.
    If you search for 'str2tbl' on http://asktom.oracle.com then you'll find many more examples.

  • Rows to column conversion

    Hi,
    I know this question has been asked couple of times but I could not understand from them hence posting my query here.
    I have a table named XYX
    id attr_cd value
    1 ABC 1000
    1 PQR 2000
    1 XDR 1500
    2 PQR 1405
    2 ABC 1254
    etc
    My reqt is to write a procedure which will accept ID as i/o parameter and will populate another temp table temp as
    id ABC XDR PQR
    1 1000 1500 200
    2 1254 1405
    like that.
    Please comeone suggest a SIMPLE way to do that.
    Thanks in advance
    Aashish

    Could you please provide a simple code which can be understood?Not sure if it can be understood, but for academical reasons it might be useful ;)
    SQL>  with t as (
    select 1 id, 'ABC' attr_cd, 1000 value from dual union all
    select 1,    'PQR',         2000       from dual union all
    select 1,    'XDR',         1500       from dual union all
    select 2,    'PQR',         1405       from dual union all
    select 2,    'ABC',         1254       from dual
    select id,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="ABC"]/@VALUE') abc,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="PQR"]/@VALUE') pqr,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="XDR"]/@VALUE') xdr
      from t group by id
      ID ABC        PQR        XDR      
       1 1000       2000       1500     
       2 1254       1405                
    2 rows selected.

  • Row to Column Conversion Question

    Hi All,
               Could you please help on this sql query statement:
    SELECT BENEFIT FROM TEST_T ;
    BENEFIT
    QO,1G,1U,1W
    Out Put Needed like this
    BENEFIT
    QO
    1G
    1U
    1W
    Thanks,

    Hi,
    As I said, it depends on your data, your requirements and your version.
    REGEXP_COUNT was new in Oracle 11.1.  Since you're using an earlier version, you can see how many comma-delimited sub-strings you have by seeing how much shorter the string gets if you remove all the commas:
    1 + LENGTH (benefit)
      - LENGTH (REPLACE (benefit, ','))
    This assumes you don't have data with mutiple consecutive commas such as 'AB,,,,CD', but it might not cause any terrible results even if you do.
    The way I used CONNECT BY won't work in Oracle 10, either.
    Now I know everything I need to know about your Oracle version, but I don't know anything about your data or your requirements.  Do you want me to spend my time writing solutions that assume things about your data and your requirments, so you can spend your time trying them only to see that they don't do what you need?
    Explain what your data is like.  Do you have a fixed number of comma-delimited parts (e.g., always 4 parts).  If not, do you have an upper bound (e.g., never more than 10 parts)?  Can you have multiple consecutive commas?
    Explain what you need to get from that data.  Will you always be splitting one string into parts, as in the example you posted, or will you need to split multiple stings in the same query?  Will the correct results ever contain NULL?
    Post a little sample data (CREATE TABLE and INSERT statements), showing all special cases you need to handle.  Post the results you want from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Rows to Columns conversion in an Internal Table

    Hello All,
    I have data like below:
    Matnr1  ABC  100
    Matnr1  ABC  200
    Matnr1  ABC  500
    Matnr2  XYZ   300
    Matnr2  XYZ   600
    I want data like this:
    Matnr1  ABC  100  200  500
    Matnr2  XYZ   300  600
    Is it possible?  If yes, could anybody help achieving this?
    Thanks a lot in advance.
    Ajay

    Hi Ajay,
      Try this.
    ( this is temp table for your formate)
    data: begin of itab1 occurs 10,
          line(150),
         end of itab1.
    Sort itab by col1 col2.  ( Here itab is your table )
    loop at itab.
    at new col2.
      write: / itab-col1,
                 itab-col2.
      concatenate itab-col1
                        itab-col2
               into  itab1.
    endat.
      write  itab-col3.
      concatenate itab1
                        itab-col3
        into itab1.
    at end.
    append itab1.
      clear itab1.
    endat.
    endloop.
    loop at itab1.
      write / itab1.
    endloop.
    Plzzz Reward if useful,
    Mahi.
    Message was edited by:
            Maheswari Chegu

  • Editing rows and columns in alv reports in webdynpro abap

    how edit row and columns in webdynpro abap ?
    can i add colors to salv repotrs for below and above range of values  how ?
    if possible send source code for it.............

    hi
    check out this link for editing the columns of ALV
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0155eb5-b6ce-2b10-3195-d9704982d69b
    check out for this thread as well for coloring ALV
    Coloring of selected table cells: Ideas wanted
    regards,
    amit

  • Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).

    Hi,
    I have a file where fields are wrapped with ".
    =========== file sample
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    ==========
    I am having a .net method to remove the wrap characters and write out a file without wrap characters.
    ======================
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    ======================
    the .net code is here.
    ========================================
    public static string RemoveCharacter(string sFileName, char cRemoveChar)
                object objLock = new object();
                //VirtualStream objInputStream = null;
                //VirtualStream objOutStream = null;
                FileStream objInputFile = null, objOutFile = null;
                lock(objLock)
                    try
                        objInputFile = new FileStream(sFileName, FileMode.Open);
                        //objInputStream = new VirtualStream(objInputFile);
                        objOutFile = new FileStream(sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString(), FileMode.Create);
                        //objOutStream = new VirtualStream(objOutFile);
                        int nByteRead;
                        while ((nByteRead = objInputFile.ReadByte()) != -1)
                            if (nByteRead != (int)cRemoveChar)
                                objOutFile.WriteByte((byte)nByteRead);
                    finally
                        objInputFile.Close();
                        objOutFile.Close();
                    return sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString();
    ==================================
    however when I run the bulk load utility I get the error 
    =======================================
    Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).
    ==========================================
    the bulk insert statement is as follows
    =========================================
     BULK INSERT Temp  
     FROM '<file name>' WITH  
      FIELDTERMINATOR = ','  
      , KEEPNULLS  
    ==========================================
    Does anybody know what is happening and what needs to be done ?
    PLEASE HELP
    Thanks in advance 
    Vikram

    To load that file with BULK INSERT, use this format file:
    9.0
    4
    1 SQLCHAR 0 0 "\""      0 ""    ""
    2 SQLCHAR 0 0 "\",\""   1 col1  Latin1_General_CI_AS
    3 SQLCHAR 0 0 "\",\""   2 col2  Latin1_General_CI_AS
    4 SQLCHAR 0 0 "\"\r\n"  3 col3  Latin1_General_CI_AS
    Note that the format file defines four fields while the fileonly seems to have three. The format file defines an empty field before the first quote.
    Or, since you already have a .NET program, use a stored procedure with table-valued parameter instead. I have an example of how to do this here:
    http://www.sommarskog.se/arrays-in-sql-2008.html
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Converting key figures from rows to column using DSO and start routine

    Hi SDNer:
    I need some help to convert key figures from rows to column.
    The source is DSO 1 and I am thinking about writing ABAP in the start routine to do the conversion. The target is DSO2.
    Below is the  more detail information with example. Basically, for each record in DSO 1 I need to create 3 records (because there are 3 KF's) and output to DSO2.
    I would really appreciate some help on this.Thank you.
    Tony
    DSO 1 data format (SOURCE)
    Period   ID   KF1  KF2  KF3
    200702 100  300  200   750
    Output to DSO 2 (TARGET)
    Period   ID    KF  LABEL
    200702 100  300  KF1
    200702 100  200  KF2
    200702 100  750  KF3

    This is the code in BI 7.0.
    u need to put a field "Label" in DSO1. u dont need to populate this in DSO1 but it helps the code to populate the field in DSO2.
    DATA: wa_result TYPE _ty_s_sc_1,
    t_result TYPE STANDARD TABLE OF _ty_s_sc_1.
    DATA:counter(2) TYPE n.
    LOOP AT SOURCE_PACKAGE INTO wa_result.
    counter =0.
    while counter < 3 .
    wa_result- Period = wa_result-Period.
    wa_result- ID = wa_result-ID.
    if counter  = 0.
    wa_result- KF1 = wa_result-KF1.
    wa_result- Label = 'KF1'.
    elseif counter = 1.
    wa_result- KF1 = wa_result-KF2.
    wa_result- Label = 'KF2'.
    else.
    wa_result- KF1 = wa_result-KF3.
    wa_result- Label = 'KF3'.
    endif.
    APPEND wa_result TO t_result.
    counter = counter+1.
    endwhile.
    endloop.
    CLEAR: SOURCE_PACKAGE,wa_result.
    LOOP AT t_result INTO wa_result.
    APPEND wa_result TO SOURCE_PACKAGE.
    ENDLOOP.

  • Keeping row and column headers while scrolling inside a Web Dynpro table

    Hi,
    I have to display a 2x2 matrix with storage location names on the x-axis (i.e. as Column Headers) and material names on the y-axis (i.e. row headers). The table data represents the quantities of a particular material in a particular storage location.
    I am using dynamic UI generation to create this table. It can contain as many as 150 columns and almost as many rows. I dont want a page level scrollbar, and hence, have placed my table inside a scroll container UI element with a fixed height and width.
    I need a way to let the users use the scrollbars inside the scroll container, but still let them see the row  and column headers. Is there a way that I can do this in Dynpro for Java?
    Thanks,
    Navneet Nair.

    Hi Kenn,
    You are probably better off posting this request in this forum User Interface Development in ABAP as you are more likely to get a response.
    Cheers,
    Neil.

  • Web dynpro screen with multiple rows with columns that can be edited

    Web dynpro screen with multiple rows with columns that can be edited individually:
    Hi
    I am busy creating a screen in web dynpro for ABAP which we would like to make available via Portal ESS (Portal 7).
    I need to add 'n type of table (or almost something like Excel) or something in which someone can type a few paycode numbers (there should be lets say 10 blank rows in which info can be typed in and if I click on a button or so, more rows must be added if necessary.  Then in the other colums stuff like amounts must be entered which one should also be able to edit then and there.
    Can anyone assist in what I can use for this?  There does not seem to be some existing element that I can use.
    Help will be appreciated.
    Regards
    Debbie

    Hi Debbie,
    Whiel Creating table you need to be care full that use chose INPUT FIELD as the CELL EDITOR. Just guessing that if ur table is not editable u might have choosen TextView as default cell editor type.
    check link for details on TABLE UI
    [http://help.sap.com/saphelp_erp2005/helpdata/EN/b5/ac884118aa1709e10000000a155106/frameset.htm]
    easy way is to first add UI ELEMENT TABLE to your VIEW, then right click over it & select create binding from context. After you have a pop up where you can select what columns you want what should be its cell editor etc.
    Greetings
    Prashant

  • Converting from rows to columns

    Converting Rows to Columns
    We have one business requirment where they want to convert rows to columns. The data we are talking about is 2-3 TB of data. Data looks something in this format.
    Table Structure
    Date_1 Unit_Number Data_ID Data_Value
    2013-01-02 00:00:00 100013 123 671
    2013-01-02 00:00:00 100014 131 771
    2013-01-02 00:00:00 100015 281 812
    2013-01-02 00:00:00 100016 712 979
    2013-01-02 00:00:00 100017 715 719
    Pivoted table
    Date_1 RY XY HJ KD IK GH HH KK TK RT ...
    2013-01-02 00:00:00 671 771 812 979 719 979 719 980 799 79
    2013-01-02 00:10:00 671 771 812 979 719 979 719 980 799 79
    and so on
    We are pivoting this data using query and creating view using query something like below
    select a.date_1 date_1 a.unit_number system_number,
    max(CASE WHEN a.data_id= 123 then a.DATA_Value END) RY,
    max(CASE WHEN a.data_id= 281 then a.DATA_Value END) XY,
    max(CASE WHEN a.data_id=712 then a.DATA_Value END) HJ,
    max(CASE WHEN a.data_id=715 then a.DATA_Value END) KD,
    max(CASE WHEN a.data_id=666 then a.DATA_Value END) IK,
    max(CASE WHEN a.data_id=231 then a.DATA_Value END) GH,
    max(CASE WHEN a.data_id=881 then a.DATA_Value END) HH,
    max(CASE WHEN a.data_id=734 then a.DATA_Value END) KK,
    max(CASE WHEN a.data_id=734 then a.DATA_Value END) TK,
    max(CASE WHEN a.data_id=724 then a.DATA_Value END) TK,
    from FROM table_name group by 1,2
    We also tried pivot clause but still no major improvement in performance.
    There are about 40 such rows that we are trying to convert into columns. We created indexes, Primary, Secondary and referencial ones to tune this overall query. Also added paritions, We find this conversion works fine for smaller query, however for larger set of data we get high CPU and IO and also often runs into spool error. The data set we are runing on this query are about 3-4 TB. There is another table where we have about 100 rows which we need to convert into one row and again size goes to 4-5 TB
    Questions I have
    1) Is there better way to convert columns to Rows?
    2) What options can be use to reduce CPU, IO and Spool error?
    3) Does Orage 11g datawarehouse any feature which will hellp us here
    4) Any other appproach or design suggested here that will help us?
    This design is pushed by our business due to flexibility this design offers and we are runing into performance and we are trying to make this work without impacting CPU, Spool and IO
    Any suggestions would help us here, thanks for reading this

    Hi,
    Here's one way to do that:
    WITH     got_times     AS
         SELECT     MAX ( CASE
                   WHEN  msg_line = 'LONGITUDINAL REFRESH HAS BEGUN'
                   THEN  msg_datetime
                  )          AS start_time
         ,     MAX ( CASE
                   WHEN  msg_line = 'LONGITUDINAL REFRESH HAS COMPLETED'
                   THEN  msg_datetime
                  )          AS end_time
         FROM     xxwv.xxwv_hsum_info_reports
    SELECT     start_time
    ,     end_time
    ,     (end_time - start_time) * 24 * 60     AS duration_minutes
    FROM     got_times
    ;When you run the two different (but very similar) to get the two times, you have two different WHERE clauses. You can combine those two similar queries into one, but whatever WHERE clause you have will apply to the whole query. Whenever you wish you could apply a WHERE clause just to one column, think of CASE instead.

  • Rows and Columns

    Dear all,
    Could u plz tell me how to create rows and columns dynamically at runtime?
    I got 3 columns and multiple rows.How do i go about it?
    Is there ne FM to do this?

    Can you create an internal table dynamically? (at run time)
    Yes , you can create a Dynamic Internal table .Just chek out this program .
      type-pools : abap.
      field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
      data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
      selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
      start-of-selection.
        perform get_structure.
      perform create_dynamic_itab.      *********Creates a dyanamic internal table*********
      perform get_data.
      perform write_out.
      form get_structure.
      data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
      data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?= 
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
        loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
      endform.
      form create_dynamic_itab.
    Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc
                   importing
                      ep_table        = dy_table.
        assign dy_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
      endform.
      form get_data.
    Select Data from table.
      select * into table <dyn_table>
                 from (p_table).
      endform.
       Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index  
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    http://www.sap-img.com/ab030.htm

Maybe you are looking for

  • G5 suddenly will not boot up.

    Ok...this is serious for me, so I'm panicking. First of all, I have a 2.0ghz Dual G5 with two 23"monitors, within the G5 is 2 DSP protools cards, a LaCie external dvd-rw drive, and a 260G external LaCie harddrive. This is pretty much the load. Anyway

  • Windows 8 and extensions

    I just purchased a new computer with windows 8 and am trying to install Russel Browns watermark extension in CS5 Extended. The extension manager wont let me install it even as administrator nor does the manual instalation work. Any suggestions?

  • Insert with a duplicate constraint

    Hello guys, Version 5.0.97 Could I please clarify if it is possible to distinguish an insert from an update in BerkeleyDB JE (Collections API) ? I can provide some code if you need it but I thought I'd ask the question first, as I could be doing some

  • Backup and Sync Frenzy

    Did an erase and install on my iMac G5 of Leopard, then installed Backup 3.1.2. It has not stopped since. The screen just keeps popping up, even though I have it backing up weekly. I can "force quit" it, but it simply arises from the dead, demanding

  • Total of Hierarchy

    I have 0Product Hierarchy activated in the Row. The Hierarch has 3 level. In column, there are 3 Key Figure - A, B and C. Column C is the Average Amount, the fomular is Total of the 0Product Hierarchy divided by current Hierarchy Level. Question is h