Rows as columns and dynamic alv display

Hi everyone,
I need to build a intenal table dynamically as well as dispaly few rows as columns in alv output.
I have seen posts where internal table has been created dynamicaaly as well seen the posts where rows of the table are displayed as columns but, can we achieve both the functionalities at same time.
I have table as:
SO     PO     Date    MAT    QTY  
1        A       X    Y1      10 
                       K1      15
                       M2      11
2       B       X1     Y2       5
                       M1      12
3       C       1x     Z1      15
                       K1       6
                       L1      10
Now the ouput has to be :
SO     PO   Date     MAT-Y1    MAT-K1    MAT-Y2   MAT-L1     Mat-Z1    MAT-M1   MAT-M2
1        A     X      10          15                                               11            
2        B     X1                         5                             12                
3        C     1X                  6                10          15                                       
I will not be knowing the number of materials untill runtime(dynamic) and as well the rows has to be displayed as columns. Is it possible to do that.
Regards
Edited by: Madhu Posanipalli on Jun 6, 2011 4:51 PM

Hi,
Check below code. It will work definitly.
*& Report  YTEST_PROG_RP
REPORT  YTEST_PROG_RP.
type-POOLs slis.
TYPES: BEGIN OF ty_tab,
    so TYPE i,
    po TYPE c,
    date(2) TYPE c,
    mat(2) TYPE c,
    qty TYPE i,
END OF ty_tab.
DATA: itab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
      jtab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
      ktab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
      wa_tab TYPE ty_tab, wa_j TYPE ty_tab, wa_k TYPE ty_tab.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
               <fs_dyntable>,
               <fs_fldval> type any.
*ALV data declarations
data: fieldcatalog type LVC_T_FCAT, " with header line, "slis_t_fieldcat_alv with header line,
      fieldcatalog1 TYPE LVC_s_FCAT,
      fieldcatalog2 type  slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.
DATA t_newtable TYPE REF TO data.
DATA t_newline  TYPE REF TO data.
DATA wa_flname TYPE string.
*Start-of-selection.
START-OF-SELECTION.
  perform data_retrieval.
  perform build_fieldcatalog.
  perform dynamic_table.
  perform build_layout.
  perform build_events.
  perform build_print_params.
  perform display_alv_report.
*&      Form  BUILD_FIELDCATALOG
      Build Fieldcatalog for ALV Report
form build_fieldcatalog.
  DATA: lv_field1 TYPE string, lv_cnt LIKE sy-tabix VALUE 3, itab_lines TYPE i.
  DATA: fieldname(20) TYPE c.
  DATA: fieldvalue(10) TYPE c.
  DATA: index(3) TYPE c.
  DATA: wa_cat LIKE LINE OF fieldcatalog2,
  wa_colno(2) TYPE n,
  wa_flname(5) TYPE c. .
  fieldcatalog1-fieldname   = 'SO'.
fieldcatalog1-seltext   = 'SO'.
  fieldcatalog1-col_pos     = 1.
  fieldcatalog1-outputlen   = 2.
fieldcatalog-emphasize   = 'X'.
fieldcatalog-key         = 'X'.
fieldcatalog-do_sum      = 'X'.
fieldcatalog-no_zero     = 'X'.
  append fieldcatalog1 to fieldcatalog.
  clear  fieldcatalog1.
  fieldcatalog1-fieldname   = 'PO'.
fieldcatalog1-seltext   = 'PO'.
  fieldcatalog1-col_pos     = 2.
  fieldcatalog1-outputlen   = 2.
  append fieldcatalog1 to fieldcatalog.
  clear  fieldcatalog1.
  fieldcatalog1-fieldname   = 'DATE'.
fieldcatalog1-seltext   = 'Date'.
  fieldcatalog1-col_pos     = 3.
  fieldcatalog1-outputlen   = 2.
  append fieldcatalog1 to fieldcatalog.
  clear  fieldcatalog1.
  LOOP AT itab INTO wa_tab.
    lv_cnt = lv_cnt + 1.
    CONCATENATE 'MAT-' wa_tab-mat into lv_field1.
    TRANSLATE lv_field1 TO UPPER CASE.
    fieldcatalog1-fieldname   = lv_field1.
   fieldcatalog1-seltext   = lv_field1.
    fieldcatalog1-col_pos     = lv_cnt.
    fieldcatalog1-outputlen   = 6.
    append fieldcatalog1 to fieldcatalog.
    clear fieldcatalog1.
    CLEAR: lv_field1, wa_tab.
  ENDLOOP.
  CLEAR lv_cnt.
Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = fieldcatalog
    IMPORTING
      ep_table        = t_newtable.
  ASSIGN t_newtable->* TO <t_dyntable>.
  CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
  ASSIGN t_newline->* TO <fs_dyntable>.
DESCRIBE TABLE fieldcatalog LINES itab_lines.
  loop at fieldcatalog INTO fieldcatalog1.
    CLEAR wa_cat.
    wa_cat-fieldname = fieldcatalog1-fieldname.
    wa_cat-seltext_s = fieldcatalog1-fieldname.
    wa_cat-outputlen = fieldcatalog1-outputlen.
    APPEND wa_cat TO fieldcatalog2.
    CLEAR fieldcatalog1.
  ENDLOOP.
endform.                    " BUILD_FIELDCATALOG
*&      Form  BUILD_LAYOUT
      Build layout for ALV grid report
form build_layout.
gd_layout-no_input          = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text       = 'Totals'(201).
gd_layout-totals_only        = 'X'.
gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                        "click(press f2)
gd_layout-zebra             = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT
*&      Form  DISPLAY_ALV_REPORT
      Display report using ALV grid
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
           i_callback_program      = gd_repid
           i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
           i_callback_user_command = 'USER_COMMAND'
           i_grid_title           = outtext
           is_layout               = gd_layout
            it_fieldcat             = fieldcatalog2[]
           it_special_groups       = gd_tabgroup
           it_events               = gt_events
           is_print                = gd_prntparams
           i_save                  = 'X'
           is_variant              = z_template
       tables
            t_outtab                = <t_dyntable>
       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.
endform.                    " DISPLAY_ALV_REPORT
*&      Form  DATA_RETRIEVAL
      Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
  DATA: lv_index LIKE sy-tabix.
  wa_tab-so = 1.
  wa_tab-po = 'A'.
  wa_tab-date = 'X'.
  wa_tab-mat = 'Y1'.
  wa_tab-qty = 10.
  append wa_tab to itab.
  clear wa_tab.
  wa_tab-mat = 'K1'.
  wa_tab-qty = 15.
  append wa_tab to itab.
  CLEAR wa_tab.
  wa_tab-mat = 'M2'.
  wa_tab-qty = 11.
  append wa_tab to itab.
  CLEAR wa_tab.
  wa_tab-so = 2.
  wa_tab-po = 'B'.
  wa_tab-date = 'X1'.
  wa_tab-mat = 'Y2'.
  wa_tab-qty = 5.
  append wa_tab to itab.
  CLEAR wa_tab.
  wa_tab-mat = 'M1'.
  wa_tab-qty = 12.
  append wa_tab to itab.
  CLEAR wa_tab.
  wa_tab-so = 3.
  wa_tab-po = 'C'.
  wa_tab-date = '1x1'.
  wa_tab-mat = 'Z1'.
  wa_tab-qty = 15.
  append wa_tab to itab.
  CLEAR wa_tab.
wa_tab-mat = 'K1'.
wa_tab-qty = 6.
append wa_tab to itab.
CLEAR wa_tab.
  wa_tab-mat = 'L1'.
  wa_tab-qty = 10.
  append wa_tab to itab.
  CLEAR wa_tab.
  LOOP AT itab INTO wa_tab.
    if wa_tab-so is NOT INITIAL AND wa_tab-po is NOT INITIAL AND wa_tab-date is NOT INITIAL.
      wa_j-so = wa_tab-so.
      wa_j-po = wa_tab-po.
      wa_j-date = wa_tab-date.
      lv_index = wa_tab-so.
    else.
      READ TABLE itab INTO wa_j WITH KEY so = lv_index.
    ENDIF.
    wa_j-mat = wa_tab-mat.
    wa_j-qty = wa_tab-qty.
    APPEND wa_j to jtab.
    CLEAR: wa_tab, wa_j.
  ENDLOOP.
endform.                    " DATA_RETRIEVAL
Form  TOP-OF-PAGE                                                 *
ALV Report Header                                                 *
Form top-of-page.
**ALV Header declarations
*data: t_header type slis_t_listheader,
     wa_header type slis_listheader,
     t_line like wa_header-info,
     ld_lines type i,
     ld_linesc(10) type c.
Title
wa_header-typ  = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ  = 'S'.
wa_header-key = 'Date: '.
CONCATENATE  sy-datum+6(2) '.'
              sy-datum+4(2) '.'
              sy-datum(4) INTO wa_header-info.   "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
                   into t_line separated by space.
wa_header-typ  = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
      exporting
           it_list_commentary = t_header.
           i_logo             = 'Z_LOGO'.
endform.                    "top-of-page
      FORM USER_COMMAND                                          *
      --> R_UCOMM                                                *
      --> RS_SELFIELD                                            *
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
   WHEN '&IC1'.
  Check field clicked on within ALVgrid report
   IF rs_selfield-fieldname = 'EBELN'.
    Read data table, using index of row user clicked on
     READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    Set parameter ID for transaction screen field
     SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    Sxecute transaction ME23N, and skip initial data entry screen
     CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
   ENDIF.
ENDCASE.
ENDFORM.                    "user_command
*&      Form  BUILD_EVENTS
      Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
      exporting
           i_list_type = 0
      importing
           et_events   = gt_events[].
read table gt_events with key name =  slis_ev_end_of_page
                          into ls_event.
if sy-subrc = 0.
   move 'END_OF_PAGE' to ls_event-form.
   append ls_event to gt_events.
endif.
   read table gt_events with key name =  slis_ev_end_of_list
                          into ls_event.
if sy-subrc = 0.
   move 'END_OF_LIST' to ls_event-form.
   append ls_event to gt_events.
endif.
endform.                    " BUILD_EVENTS
*&      Form  BUILD_PRINT_PARAMS
      Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS
*&      Form  END_OF_PAGE
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.
  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.                    "END_OF_PAGE
*&      Form  END_OF_LIST
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.
  skip.
  write:/40 'Page:', sy-pagno .
endform.                    "END_OF_LIST
*&      Form  dynamic_table
      text
-->  p1        text
<--  p2        text
FORM dynamic_table .
  DATA: lv_s1 TYPE string, lv_s2 TYPE string.
  DATA lv_mat TYPE string.
  DATA: fieldvalue(10) TYPE c.
  ktab[] = jtab[].
  delete ADJACENT DUPLICATES FROM ktab COMPARING so.
  loop at ktab INTO wa_tab.
Field1
    wa_flname = 'SO'.
    fieldvalue = wa_tab-so.
    CONDENSE    fieldvalue NO-GAPS.
    ASSIGN COMPONENT  wa_flname
        OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> =  fieldvalue.
    CLEAR fieldvalue.
Field2
    wa_flname = 'PO'.
    fieldvalue = wa_tab-po.
    CONDENSE    fieldvalue NO-GAPS.
    ASSIGN COMPONENT  wa_flname
        OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> =  fieldvalue.
    CLEAR fieldvalue.
Field3
    wa_flname = 'DATE'.
    fieldvalue = wa_tab-date.
    CONDENSE    fieldvalue NO-GAPS.
    ASSIGN COMPONENT  wa_flname
        OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> =  fieldvalue.
    CLEAR fieldvalue.
    loop at jtab INTO wa_j WHERE so = wa_tab-so.
      CONCATENATE 'MAT-' wa_j-mat INTO lv_mat.
      wa_flname = lv_mat.
      fieldvalue = wa_j-qty.
      CONDENSE    fieldvalue NO-GAPS.
      ASSIGN COMPONENT  wa_flname
          OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
      <fs_fldval> =  fieldvalue.
      CLEAR: wa_j, fieldvalue.
    ENDLOOP.
    APPEND <fs_dyntable> TO <t_dyntable>.
    CLEAR wa_tab.
    FREE <fs_dyntable>.
  ENDLOOP.
ENDFORM.                    " dynamic_table
Ram.

Similar Messages

  • Can anybody help....SQL to display row as column and column as rows

    Can anybody help in writing a SQL to display row as column and column as rows?
    Thanks

    check this link:
    Re: Creating Views - from rows to a new column?

  • In the final display list how can i change rows to columns and vice versa

    in the final display list how can i change rows to columns and vice versa
    It's Urgent
    Thanks
    Basu

    Hai,
    Check this following Threads,
    converting rows to columns in internal tables
    Re: logic- report to move columns to row in a list
    Regards,
    Padmam.

  • Rows as Columns and Columns as Rows

    Hi,
    How to print rows as columns and columns as rows?
    Suppose I've the following data
    colA colB
    X 1
    Y 2
    Z 3
    I want the output to be something like
    X Y Z
    1 2 3.
    Is this possible? Please let me know.
    Regards,
    Jai.

    The following assumes that there is only one value of colb for each value of cola, but allows for any number of values of cola. The script below creates the query and results below that, given the test data that you provided.
    -- script:
    STORE  SET saved_settings REPLACE
    SET    ECHO OFF FEEDBACK OFF HEADING OFF PAGESIZE 0 VERIFY OFF WRAP ON
    SPOOL  query.sql
    SELECT 'SELECT MAX (DECODE (cola, ''' || cola || ''', colb)) AS "' || cola || '"'
    FROM   (SELECT MIN (cola) AS cola
            FROM   test_table)
    SELECT ', MAX (DECODE (cola, ''' || cola || ''', colb)) AS "' || cola || '"'
    FROM   (SELECT DISTINCT cola
            FROM   test_table
            WHERE  cola >
                   (SELECT MIN (cola)
                    FROM   test_table))
    PROMPT FROM   test_table
    PROMPT /
    SPOOL  OFF
    START  saved_settings
    START  query.sql
    -- query and results:
    SQL> SELECT MAX (DECODE (cola, 'X', colb)) AS "X"
      2  , MAX (DECODE (cola, 'Y', colb)) AS "Y"
      3  , MAX (DECODE (cola, 'Z', colb)) AS "Z"
      4  FROM   test_table
      5  /
             X          Y          Z
             1          2          3
    SQL>

  • Interchanging of Rows to Columns and Columns to Rows

    Can anyone help me in this query ....
    Interchanging of Rows to Columns and Columns to Rows in Oracle
    Ex :- Actual Data
    EmpId Ename Sal
    1 A 2000
    2 B 3000
    3 C 1000
    4 D 3000
    Query Result should be like below ::::::::::
    after Transposing [ Interchanging of Rows to Columns and Columns to Rows ]the data should come like below
    Empid 1 2 3 4
    EName A B C D
    Sal 2000 3000 1000 3000
    Thanks
    Kavitha and Sudhir

    Please see the following links
    transpose my table column
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1532380262922962983::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:52733433785851
    pivot a result set
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1532380262922962983::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:124812348063

  • Resulting grid does not contain at least one row, one column and one POV

    I have upgraded to 9.3.3 recently.
    We have a front end app which will run MDX queries to retrieve data.
    Sometimes based on the users selections MDX query might get back nothing i.e will get #missing across all rows/columns and this works fine with the existing 9.3.1 essbase server.
    If I run the same query against a 9.3.3 essbase cube I get the error "Resulting grid does not contain at least one row, one column and one POV. If you have any suppress row options selected pls clear them."
    I DO NOT have Supress missing data/zero enabled. Not sure why I get this error even though I dont have that option enabled.
    Essbase 9.3.3 on HP-UX ITanium 11.31
    APS 9.3.3 on win 2003 R2
    Smartview 9.3.3 - also tried with smartview 9.3.1.6 and see the same error.
    Any suggestions to fix this issues?

    The front end is using a VBA command "hypexecutequery" and with 9.3.3 essbase I get a return code -9 which means Operation was cancelled as per the smartview doc.
    In 9.3.1 essbase I get the return code 0 which means the query is fine even if it does not return any data.
    The query I am using now will return nothing as it is a check to see if there is any data. But with 9.3.3 Essbase I get an error code -9 which looks like it does not like the syntax or something.
    Any suggestions?

  • Dynamic ALV Display

    Hi all,
    I have a program where i need to display split screen ALV.
    One ALV table on the left and one the right.
    In the left ALV i display 10 table names..
    If i click on the table name then the table should be displayed in the right side ALV.
    This i can successfully do it  but if i click on the another table after displaying the one table the new table will not be displayed where as still the first displayed tabled is shown..
    Below is my coding please have a look and let me know the error..
    IF gr_custom_container_02 IS INITIAL.
        CREATE OBJECT gr_custom_container_02
              EXPORTING
                container_name = 'CUSTOM'.
        Split the Container---------------------------------------------------*
        CREATE OBJECT splitter
          EXPORTING
            parent    = gr_custom_container_02
            rows       = 1
            columns    = 2.
        CALL METHOD splitter->get_container
          EXPORTING
            row       = 1
            column    = 1
          RECEIVING
            container = container_1.
    create the ALV Table-------------------------------------------------*
        CREATE OBJECT gr_alv_grid_02
          EXPORTING
            i_parent = container_1.
      create Fieldcatalog--------------------------------------------------*
        PERFORM prepare_fieldcat_02 CHANGING g_t_fieldcat_02.
      To Customize the layout
        PERFORM prepare_layout_02 CHANGING g_s_layout_02.
      Show ALV-------------------------------------------------------------*
        CALL METHOD gr_alv_grid_02->set_table_for_first_display
          EXPORTING
            is_layout       = g_s_layout_02
          CHANGING
            it_fieldcatalog = g_t_fieldcat_02
            it_outtab       = g_t_queuename.
        SET HANDLER event_receiver->handle_hotspot_click FOR gr_alv_grid_02.
      ELSE.
    To refresh the table for displaying.
        CALL METHOD cl_gui_cfw=>flush.
        CALL METHOD gr_alv_grid_02->refresh_table_display
          EXCEPTIONS
            finished = 1
            OTHERS   = 2.
      ENDIF.
        CALL METHOD splitter->get_container
          EXPORTING
            row       = 1
            column    = 2
          RECEIVING
            container = container_2.
    create the ALV Table-------------------------------------------------*
        CREATE OBJECT gr_alv_grid_03
          EXPORTING
            i_parent = container_2.
      Show ALV-------------------------------------------------------------*
        CALL METHOD gr_alv_grid_03->set_table_for_first_display
          EXPORTING
          CHANGING
            it_fieldcatalog      = g_t_fieldcat_03
            it_outtab            = <select_queue_table>.

    Hi,
    You should develop an event handler method where you will catch the click on the left container. There you should evaluate the the data and you should free the ALV grid from the right container and then you should call the method set_table_for_first_display with the data that you want. At the end you should call the static method CL_GUI_CFW=>FLUSH to synchronize the ALV framework.
    With Regards
    George

  • User Command in Dynamic ALV Display

    Hi,
    I have an requirement where i'm displaying Dynamic ALV grid by calling the method by passing the field Symbol in  it_outtab parameter:
    CALL METHOD cl_gui_alv_grid->set_table_for_first_display
    For this i'm creating a custom container in my screen container
    CREATE OBJECT cl_gui_custom_container
            EXPORTING container_name = lv_container.
    Now in the output every record is having a checkbox in the end.Now if the user check this checkbox n clicks on push button(added in Application toolbar) then this record should be kept and rest all the records should be deleted.
    This can be done if an internal table is passed to the method as the field symbol doesnt hold any data after the output is displayed.
    Is there any solution where this can be made possible.
    Thanks in advance.
    Sheetal

    try this ..
    before displaying ALV , store all the data in the fieldsymbol into another internal table
    then display ALV with field symbol
    after u click the pushbutton , get the seleted rows into another table using get_selected rows,
    now again call CALL METHOD cl_gui_alv_grid->set_table_for_first_display
    and give the new selected rows of internal table and refresh the grid

  • Transpose columns and rows / Switch columns and rows

    Hello,
    Is it possible to interchange columns and rows in order to create a left-to-right scrolling table instead of a top-to-bottom scrolling one?
    In detail:
    I have this:
          | col 1 | col 2 | col 3
    row 1 |       |       |
    row 2 |       |       |
    row 3 |       |       |
    ...   |       |       |
    ...and want to have this:
          | row 1 | row 2 | row 3 | ...
    col 1 |       |       |       |
    col 2 |       |       |       |
    col 3 |       |       |       |
    Does anyone know if this is possible with the standard table or the ALV?
    Thanks in advance & Kind regards,
    Robert

    Hi,
    So there is no easy solution by just setting a flag in the ALV config!? ...too bad!
    As for the dynamic creation:
    Would there be an issue with different data types in one "column" (former row)? As a matter of fact there probably will be a mix of character, numbers, ...
    Regards,
    Robert

  • Converting rows to columns using dynamic query.

    I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
    declare
        lv_sql varchar2(32767) := null ;
    begin
        lv_sql := 'SELECT Iplineno ';
        for lv_rec in (SELECT distinct vendor from bidtabs  where letting = '10021200' and call ='021')
        loop
            lv_sql :=   lv_sql
                        || CHR(10)
                        || ', MAX( DECODE( vendor, '
                        || chr(39)
                        || lv_rec.vendor
                        || CHR(39)
                        || ', bidprice, NULL ) ) as "'
                        || lv_rec.vendor
                        || '" ' ;
        end loop;
        lv_sql :=   lv_sql
                    || CHR(10)
                    || 'FROM bidtabs  where letting =  ''10021200''  and call =  ''021''  and lineflag = ''L''  '
                    || CHR(10)
                    || 'GROUP BY iplineno ;' ;
    here is the result
    BIDPRICE     CALL     IPLINENO     LETTING     VENDOR
    9,585     021     0010     10021200     C0104        
    1,000     021     0020     10021200     C0104        
    1,000     021     0030     10021200     C0104        
    17     021     0040     10021200     C0104        
    5     021     0050     10021200     C0104        
    11,420     021     0010     10021200     K0054        
    1,100     021     0020     10021200     K0054        
    1,100     021     0030     10021200     K0054        
    5     021     0040     10021200     K0054        
    3     021     0050     10021200     K0054        
    8,010     021     0010     10021200     V070         
    900     021     0020     10021200     V070         
    1,320     021     0030     10021200     V070         
    11     021     0040     10021200     V070         
    3     021     0050     10021200     V070         
    and here is the desired output
    CALL     IPLINENO     LETTING      C0104              K0054              V070         
    021     0010     10021200      9,585                     11,420                                   8,010
    021     0020     10021200      1,000       1,100     900
    021     0030     10021200      1,000     1,100     1,320
    021     0040     10021200       17     5     11
    021     0050     10021200      5     3     3

    Here is the error message I am getting:
    RA-06550: line 22, column 43:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimited-identifier>
    <a bind variable> << close current delete fetch lock insert
    open rollback savepoint set sql execute commit forall merge
    pipe

  • Rows to column and need to nvl for that newly  columns

    Hi,
    I have to create  rows to column query in rdf and in turn i have  to created excel rtf template to produce excel output.
    select max(decode (test.role, 'PA-ELT Member', test.full_name )) ELT_MEMBER,
    max(decode (test.role, 'PA-IT Director', test.full_name )) IT_MEMBER,
    max(decode (test.role, 'Project Manager', test.full_name )) Project_Manager,
    TEST.segment1 project_NUMber,
    test.name project_Name,
    test.project_id,
    test.project_type ,
    test.organization_name,
    TEST.project_status_name Status_Name,
    TEST.start_date Start_date,
    TEST.COMPLETION_DATE,
    TEST.Planned_OOE,
    TEST.Planned_Dep,
    TEST.Planned_lab
      from
    (select
    pppv.full_name,
    pppv.role,
    ppa.name,
    ppa.project_id,
    ppa.segment1, 
    ppa.project_type,
    (select name from PA_ALL_ORG_V  where organization_id = ppa.CARRYING_OUT_ORGANIZATION_ID) organization_name,
    ppa.PROJECT_STATUS_CODE,
    pps.PROJECT_STATUS_NAME,
    ppa.START_DATE,
    ppa.COMPLETION_DATE,
    (select N_EXT_ATTR1 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_OOE,
    (select N_EXT_ATTR2 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_Dep,
    (select N_EXT_ATTR3 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_lab
    from
    PA_PROJECTS_ALL ppa, PA_PROJECT_PLAYERS_V pppv, pa_project_statuses pps
    where ppa.project_id = pppv.project_id
    and ppa.PROJECT_STATUS_CODE = pps.PROJECT_STATUS_CODE
    and pppv.role in ('PA-ELT Member','PA-IT Director','Project Manager')
    and ppa.CARRYING_OUT_ORGANIZATION_ID=3994
    )test
    where  1=1
    and TEST.project_type = nvl(:P_PROJECT_TYPE,test.project_type)
    and TEST.project_status_name = nvl(:P_PROJECT_STATUS,test.project_status_name)
    and TEST.segment1 = nvl(:P_PROJECT_NUMBER,test.segment1)
    and TEST.full_name = nvl(:P_ELT_MEMBER, test.full_name)
    and test.full_name = nvl(:P_IT_DIRECTOR,test.full_name)
    and TEST.full_name = nvl(:P_PROJECT_MANAGER,test.full_name)
    group by 
    TEST.segment1,
    test.name,
    test.project_id,
    test.project_type,
    test.organization_name,
    TEST.project_status_name,
    TEST.start_date,
    TEST.COMPLETION_DATE,
    TEST.Planned_OOE,
    TEST.Planned_Dep,
    TEST.Planned_lab
    order by TEST.SEGMENT1
    see ELT_MEMBER,IT_MEMBER and Project_Manager  are columns created from rows to column.
    now if i put where clause for this any columns for Eg: ELT_MEMBER it is giving Elt_member column values alone not remaining IT_member  and Project Manager it show null even it has values .
    it is because of this where clause
    and TEST.full_name = nvl(:P_ELT_MEMBER, test.full_name)
    and test.full_name = nvl(:P_IT_DIRECTOR,test.full_name)
    and TEST.full_name = nvl(:P_PROJECT_MANAGER,test.full_name)
    though i have ELT_MEMBER, IT_member and Project Manager column in where clause i have to call parent sql query column full_name.
    i have tried to have nvl on column like below.
    nvl( max(decode (test.role, 'Project Manager', test.full_name )),(select full_name from PA_PROJECT_PLAYERS_V where project_id = test.project_id and role ='Project Manager')) Project_Manager,
    but it is showing error single -row subquery error .
    it is possible to have a where clause for rows to columns .
    Please help in this regards

    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'john,henry,michi,glen' as customer_name, 25000 as credit_limit from dual union all
      2             select 'dilon,bryan', 10000 from dual union all
      3             select 'raymond', 8000 from dual)
      4  -- END OF TEST DATA
      5  select regexp_substr(customer_name, '[^,]+', 1, rn) as customer_name, credit_limit
      6  from   t
      7        ,(select rownum rn
      8          from dual
      9          connect by rownum <= (select max(length(regexp_replace(t.customer_name,'[^,]'))+1) from t))
    10  where regexp_substr(customer_name, '[^,]+', 1, rn) is not null
    11* order by credit_limit desc
    SQL> /
    CUSTOMER_NAME         CREDIT_LIMIT
    john                         25000
    henry                        25000
    michi                        25000
    glen                         25000
    bryan                        10000
    dilon                        10000
    raymond                       8000
    7 rows selected.
    SQL>Just replace "t" with your query to select the data from the external table.

  • What is the difference between ALV list FM display and OO ALV Display?

    What is the difference between ALV Function Modules and Object Oriented ALV Display?

    Hi Sathish ,
      There is not much diffrence , it is only another way of implementing it.
    Regards
    Arun

  • Problems with recordset paging and dynamic menu displaying all the options

    Hi hope someone can help on this - I've posted the code on the FoEd Backend Blight - with no takers/success yet -
    I've created a jobs page using DWCS3 which has a dynamic drop down menu filtering the 'countries' that jobs are located in.  When I introduce a recordset page only those countries associated with the jobs on that particular page are shown in the dynamic menu above, not all of the countries listed in the database. When I get to the second page of results - again - only those jobs' countries are shown in the menu (and not the previous pages/next pages as well).
    I'd clearly like a user to be able to select from the menu of countries available for all the jobs in the database, and not just those on the page.  Any ideas?
    On a similar strain - my country menu/filter is wrapped up in a form above the list of jobs.  On loading the page, only the search and menus appear.  No jobs are shown until I hit submit.  Is there a way to have all the jobs display on first load, and then for the search/menu filter to work on the displayed jobs. I've tried altering the variables on the search to 1 from -1, and other options but I can't seem to get a page of content on first load.
    I'd really appreciate any pointers on the above, as this would help solve the final stage of my project. The full post and code can be seen on the friendsofed website under backend blight.
    Many thanks in advance.
    Matt

    I'm still stuck on getting the page to load with some actual content, however.  I'm just getting the search box and country filter displaying on first load.
    Pages 584-6 explain why you get nothing when a page first loads. Dreamweaver sets the default value to -1. The problem with trying to change the default value even to an empty string or % is that Dreamweaver's security function, GetSQLValueString() changes an empty string to NULL and wraps % in quotes, so neither will work.
    One way to display all records when the page first loads is to create another recordset that selects all records. Wrap the code in a conditional statement that checks whether the $_GET array contains any values:
    if (!$_GET) {
      // recordset to retrieve all records here
    This means that you need two repeat regions to display the results. Wrap both of them in conditional statements:
    if (isset($fullRecordsetName)) {
      // display the full recordset
    } elseif (isset($searchResultsRecordsetName)) {
      // display the search results
    You also need to wrap the mysql_free_result() statements in conditional statements at the end of the page:
    if (isset($fullRecordsetName)) mysql_free_result($fullRecordsetName);
    if (isset($searchResultsRecordsetName)) mysql_free_result($searchResultsRecordsetName);
    Another way to do it is to use just one recordset, but split the SQL query into two sections:
    $query_RecordsetName = "SELECT * FROM myTable";
    if (isset($_GET['searchTerm')) {
    $query_RecordsetName .= sprintf(" WHERE searchTerm LIKE %s",
         GetSQLValueString("%" . $colname_RecordsetName . "%", "text"));
    This uses the combined concatenation operator to add the WHERE clause to the query only if $_GET['searchTerm'] has been set. Notice that you need a space before the "WHERE".

  • ROWS to COLUMNS and COLUMNS to ROWS (Earlier Docs/Threads Didn't help)

    Hi Guys,
    I have gone through the earlier threads and documents on this. But didn't help.
    In lots of cases they have used DECODE statement. However, it works if you know the number of columns and rows...what if we are not sure of the number of records? How does it work?
    Please direct me to any thread or any other documents.
    -Sandeep

    Pivoting in SQL
    a. 10g Model Clause
    SQL> create table test(id varchar2(2), des varchar2(4), t number);
    Table created
    SQL> INSERT INTO test values(’A',’a1',12);
    1 row inserted
    SQL> INSERT INTO test values(’A',’a2',3);
    1 row inserted
    SQL> INSERT INTO test values(’A',’a3',1);
    1 row inserted
    SQL> INSERT INTO test values(’B',’a1',10);
    1 row inserted
    SQL> INSERT INTO test values(’B',’a2',23);
    1 row inserted
    SQL> INSERT INTO test values(’C',’a3',45);
    1 row inserted
    SQL> commit;
    Commit complete
    SQL> SELECT * FROM test;
    ID DES T
    A a1 12
    A a2 3
    A a3 1
    B a1 10
    B a2 23
    C a3 45
    6 rows selected
    SQL> select distinct i, A1, A2, A3
    2 from test c
    3 model
    4 ignore nav
    5 dimension by(c.id i,c.des d)
    6 measures(c.t t, 0 A1, 0 A2, 0 A3)
    7 rules(
    8 A1[any,any] = t[cv(i),d = ‘a1'],
    9 A2[any,any] = t[cv(i),d = ‘a2'],
    10 A3[any,any] = t[cv(i),d = ‘a3']
    11 );
    I A1 A2 A3
    C 0 0 45
    B 10 23 0
    A 12 3 1
    SQL> select distinct d, A, B, C
    2 from test c
    3 model
    4 ignore nav
    5 dimension by(c.id i,c.des d)
    6 measures(c.t t, 0 A, 0 B, 0 C)
    7 rules(
    8 A[any,any] = t[i = ‘A’, cv(d)],
    9 B[any,any] = t[i = ‘B’, cv(d)],
    10 C[any,any] = t[i = ‘C’, cv(d)]
    11 );
    D A B C
    a1 12 10 0
    a3 1 0 45
    a2 3 23 0
    b. Pivoting INSERT example;
    INSERT ALL
    INTO sales_info VALUES (employee_id,week_id,sales_MON)
    INTO sales_info VALUES (employee_id,week_id,sales_TUE)
    INTO sales_info VALUES (employee_id,week_id,sales_WED)
    INTO sales_info VALUES (employee_id,week_id,sales_THUR)
    INTO sales_info VALUES (employee_id,week_id, sales_FRI)
    SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,sales_WED, sales_THUR,sales_FRI
    FROM sales_source_data;
    c. 11g sql pivot keyword
    http://oraclebizint.wordpress.com/2007/09/05/oracle-11g-pivot-and-unpivot/
    d. reference for others :)
    http://laurentschneider.blogspot.com/2005/08/pivot-table.html

  • How to transpose rows to columns and columns to rows in alv grid

    can u plz tell me in alv grid how to
    display data from itab having data
    1
    2
    3 and so on
    how to print in alv in a single row ie
    1 2 3 and so on

    chk this code...
    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>.

Maybe you are looking for