ALV report with dynamic columns, and repeated structure rows

Hey Guys,
I've done some ALV programming, but most of the reports were straight forward. This one is a little interesting. So here go the questions...
Q1: Regarding Columns:
What is the best way to code a report with columns being dynamic. This is one of the parameters the user is going to enter in his input.
Q2: Regarding Rows:
I want to repeat a structure(say it contains f1, f2, f3) multiple time in rows. What is the best way to do it? The labels for these fields have to appear in the first column.
Below is the visual representation of the questions.
Jan 06  , Feb 06, Mar 06....(dynamic)
   material 1
Current Stock
current required
$Value of stock
   material 2
Current Stock
current required
$Value of stock
   material 3
Current Stock
current required
$Value of stock
Thanks for your help.
Sumit.

Hi Sumit,
Just check this sample from one of the SAP site
ABAP Code Sample for Dynamic Table for ALV with Cell Coloring
Applies To:
ABAP / ALV Grid
Article Summary
ABAP Code Sample that uses dynamic programming techniques to build a dynamic internal table for display in an ALV Grid with Cell Coloring.
Code Sample
REPORT zcdf_dynamic_table.
* Dynamic ALV Grid with Cell Coloring.
* Build a field catalog dynamically and provide the ability to color
* the cells.
* To test, copy this code to any program name and create screen 100
* as described in the comments. After the screen is displayed, hit
* enter to exit the screen.
* Tested in 4.6C and 6.20
* Charles Folwell - [email protected] - Feb 2, 2005
DATA:
r_dyn_table TYPE REF TO data,
r_wa_dyn_table TYPE REF TO data,
r_dock_ctnr TYPE REF TO cl_gui_docking_container,
r_alv_grid TYPE REF TO cl_gui_alv_grid,
t_fieldcat1 TYPE lvc_t_fcat, "with cell color
t_fieldcat2 TYPE lvc_t_fcat, "without cell color
wa_fieldcat LIKE LINE OF t_fieldcat1,
wa_cellcolors TYPE LINE OF lvc_t_scol,
wa_is_layout TYPE lvc_s_layo.
FIELD-SYMBOLS:
<t_dyn_table> TYPE STANDARD TABLE,
<wa_dyn_table> TYPE ANY,
<t_cellcolors> TYPE lvc_t_scol,
<w_field> TYPE ANY.
START-OF-SELECTION.
* Build field catalog based on your criteria.
wa_fieldcat-fieldname = 'FIELD1'.
wa_fieldcat-inttype = 'C'.
wa_fieldcat-outputlen = '10'.
wa_fieldcat-coltext = 'My Field 1'.
wa_fieldcat-seltext = wa_fieldcat-coltext.
APPEND wa_fieldcat TO t_fieldcat1.
wa_fieldcat-fieldname = 'FIELD2'.
wa_fieldcat-inttype = 'C'.
wa_fieldcat-outputlen = '10'.
wa_fieldcat-coltext = 'My Field 2'.
wa_fieldcat-seltext = wa_fieldcat-coltext.
APPEND wa_fieldcat TO t_fieldcat1.
* Before adding cell color table, save fieldcatalog to pass
* to ALV call. The ALV call needs a fieldcatalog without
* the internal table for cell coloring.
t_fieldcat2[] = t_fieldcat1[].
* Add cell color table.
* CALENDAR_TYPE is a structure in the dictionary with a
* field called COLTAB of type LVC_T_SCOL. You can use
* any structure and field that has the type LVC_T_SCOL.
wa_fieldcat-fieldname = 'T_CELLCOLORS'.
wa_fieldcat-ref_field = 'COLTAB'.
wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
APPEND wa_fieldcat TO t_fieldcat1.
* Create dynamic table including the internal table
* for cell coloring.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fieldcat1
IMPORTING
ep_table = r_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 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.
* Get access to new table using field symbol.
ASSIGN r_dyn_table->* TO <t_dyn_table>.
* Create work area for new table.
CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
* Get access to new work area using field symbol.
ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
* Get data into table from somewhere. Field names are
* known at this point because field catalog is already
* built. Read field names from the field catalog or use
* COMPONENT <number> in a DO loop to access the fields. A
* simpler hard coded approach is used here.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'ABC'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'XYZ'.
APPEND <wa_dyn_table> TO <t_dyn_table>.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'TUV'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'DEF'.
APPEND <wa_dyn_table> TO <t_dyn_table>.
* Color cells based on your criteria. In this example, a test on
* FIELD2 is used to decide on color.
LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
* Get access to internal table used to color cells.
ASSIGN COMPONENT 'T_CELLCOLORS'
OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
CLEAR wa_cellcolors.
wa_cellcolors-fname = 'FIELD2'.
IF <w_field> = 'DEF'.
wa_cellcolors-color-col = '7'.
ELSE.
wa_cellcolors-color-col = '5'.
ENDIF.
APPEND wa_cellcolors TO <t_cellcolors>.
MODIFY <t_dyn_table> FROM <wa_dyn_table>.
ENDLOOP.
* Display screen. Define screen 100 as empty, with next screen
* set to 0 and flow logic of:
* PROCESS BEFORE OUTPUT.
* MODULE initialization.
* PROCESS AFTER INPUT.
CALL SCREEN 100.
* MODULE initialization OUTPUT
MODULE initialization OUTPUT.
* Set up for ALV display.
IF r_dock_ctnr IS INITIAL.
CREATE OBJECT r_dock_ctnr
EXPORTING
side = cl_gui_docking_container=>dock_at_left
ratio = '90'.
CREATE OBJECT r_alv_grid
EXPORTING i_parent = r_dock_ctnr.
* Set ALV controls for cell coloring table.
wa_is_layout-ctab_fname = 'T_CELLCOLORS'.
* Display.
CALL METHOD r_alv_grid->set_table_for_first_display
EXPORTING
is_layout = wa_is_layout
CHANGING
it_outtab = <t_dyn_table>
it_fieldcatalog = t_fieldcat2.
ELSE. "grid already prepared
* Refresh display.
CALL METHOD r_alv_grid->refresh_table_display
EXPORTING
i_soft_refresh = ' '
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDIF.
ENDMODULE. " initialization OUTPUT
Regards
vijay

Similar Messages

  • Create a Procedural ALV Report with editable fields and save the changes

    Hi,
    I am new to ABAP. I have created a Procedural ALV Report with 3 fields. I want to make 2 fields editable. When executed, if the fields are modified, I want to save the changes. All this I want to do without using OO concepts. Please help . Also, I checked out the forum and also the examples
    BCALV_TEST_GRID_EDIT_01
    BCALV_TEST_GRID_EDIT_02
    BCALV_TEST_GRID_EDIT_04_FORMS
    BCALV_TEST_GRID_EDITABLE
    BCALV_EDIT_01
    BCALV_EDIT_02
    BCALV_EDIT_03
    BCALV_EDIT_04
    BCALV_EDIT_05
    BCALV_EDIT_06
    BCALV_EDIT_07
    BCALV_EDIT_08
    BCALV_FULLSCREEN_GRID_EDIT
    But all these are using OO Concepts.
    Please help.
    Regards,
    Smruthi

    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      line_color(4) TYPE c,     "Used to store row color attributes
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog 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.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
    fieldcatalog-edit             = 'X'
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    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-info_fieldname =      'LINE_COLOR'.
    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_pf_status_set = 'STATUS'
                i_callback_top_of_page   = 'TOP-OF-PAGE'
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = it_ekko
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      DATA: ld_color(1) TYPE c.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekko.
      LOOP AT it_ekko INTO wa_ekko.
        ld_color = ld_color + 1.
        IF ld_color = 8.
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
        MODIFY it_ekko FROM wa_ekko.
      ENDLOOP.
    ENDFORM.                    " DATA_RETRIEVAL
          FORM top-of-page                                              *
    FORM top-of-page.
      WRITE:/ 'This is First Line of the Page'.
    ENDFORM.
          FORM status                                                   *
    FORM status USING rt_extab TYPE slis_t_extab.  .
      SET PF-STATUS 'ALV'.
    ENDFORM.
          FORM USER_COMMAND                                          *
    -->  RF_UCOMM                                                      *
    -->  RS                                                            *
    FORM user_command USING rf_ucomm LIKE sy-ucomm
                             rs TYPE slis_selfield.            
      DATA ref1 TYPE REF TO cl_gui_alv_grid.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = ref1.
      CALL METHOD ref1->check_changed_data.
      CASE rf_ucomm.
    when 'SAVE'.
    get all the modified entries and store them in an internal table and udpate them in to the required transaction or your custom table.
    endcase.
    endform.
    ENDFORM.
    here u need to 2 performs for PF status and USER_COMMAND in the ALV parameters.
    create a custom PF status and create push buttons and assign your ok codes in your PF status.
    if the field has to be edited in the ALV then pass EDIT = 'X' for that field in the fieldcatlog preparation.
    Hope this will help you.
    Regards,
    phani.

  • Report with multiplying columns  and WITH clause

    Hello
    I saw sth strange in my report. I assume that it could happens very often.
    I have report with few columns which two of them ar most complicated (many joins subqueries aggreagations on joined values etc.) These two columns (i.e C3,C4) should be multiplied (C3*C4).
    When i do pure report without multiplying only columns C1,C2,C3,C4 everything is ok - duration about 15 sec. but... when I put next column on report which multiply these columns (in Answers C5=C3*C4)
    I wait 3-4 minutes and my database hungs :(. After investigation I saw that in first case to databese goes pure "SELECT" statement it means:
    "Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa"
    but in second case BI uses WITH clause it means:
    WITH SAWITH0 AS
    ( Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa )
    SELECT SAWITH0.C1 as C1,
    SAWITH0.C2 as C2,
         SAWITH0.C3 as C3,
         SAWITH0.C4 as C4,
         SAWITH0.C3*SAWITH0.C4 as C5 FROM SSS
    and this statement is long runninq query and kills my database :(.
    I checked that SQL like this:
    Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4, max(...)*sum(xxx)... As C5 from yyy,sss,ttt WHERE aaa" -
    runs few times faster than that above
    I know that I can do this multiply in business model layer but sometimes users can multiply(or other operations) on columns in reports without my knowledge and it kills my db :(. Where is bug? Why SQLs with WITH clause takes so much db time?
    Thank you for each kind of help

    WITH clause or Subquery Factoring allows the set of data to be reused multiple times within the SQL. Oracle will usually materialize the data into a temporary table (you will see it if you take an explain plan of the SQL).
    I would be surprised if it was the actual WITH clause that was causing the performance issue, however you can test this by turning the WITH clause feature off. Go to the Physical model, right mouse click on your Database > Properties > Features Tab, scroll down to WITH_CLAUSE_SUPPORTED and switch it off.
    I'd be interested to know if you do see actual improvement.
    Good Luck.

  • ALV with dynamic columns and description labels in header titles

    Hi everybody,
    I have to implement an ALV whose columns are not defined until runtime. Is it possible to do that in some simple way? Is it necessary to use objects to define this kind of ALV's?
    And another one query, is it possible to add description labels to column headers so that when the user points with the cursor in them he/she gets a little explanation about the detail of the column (for example, description name of the product hierarchy when pointing to the column named with one of the existing hierarchies, i.e 010102102)
    Thanks in advance,

    for your first question check this
    Just check this sample from one of the SAP site
    ABAP Code Sample for Dynamic Table for ALV with Cell Coloring
    Applies To:
    ABAP / ALV Grid
    Article Summary
    ABAP Code Sample that uses dynamic programming techniques to build a dynamic internal table for display in an ALV Grid with Cell Coloring.
    Code Sample
    REPORT zcdf_dynamic_table.
    * Dynamic ALV Grid with Cell Coloring.
    * Build a field catalog dynamically and provide the ability to color
    * the cells.
    * To test, copy this code to any program name and create screen 100
    * as described in the comments. After the screen is displayed, hit
    * enter to exit the screen.
    * Tested in 4.6C and 6.20
    * Charles Folwell - [email protected] - Feb 2, 2005
    DATA:
    r_dyn_table TYPE REF TO data,
    r_wa_dyn_table TYPE REF TO data,
    r_dock_ctnr TYPE REF TO cl_gui_docking_container,
    r_alv_grid TYPE REF TO cl_gui_alv_grid,
    t_fieldcat1 TYPE lvc_t_fcat, "with cell color
    t_fieldcat2 TYPE lvc_t_fcat, "without cell color
    wa_fieldcat LIKE LINE OF t_fieldcat1,
    wa_cellcolors TYPE LINE OF lvc_t_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:
    <t_dyn_table> TYPE STANDARD TABLE,
    <wa_dyn_table> TYPE ANY,
    <t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    START-OF-SELECTION.
    * Build field catalog based on your criteria.
    wa_fieldcat-fieldname = 'FIELD1'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 1'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    wa_fieldcat-fieldname = 'FIELD2'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 2'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Before adding cell color table, save fieldcatalog to pass
    * to ALV call. The ALV call needs a fieldcatalog without
    * the internal table for cell coloring.
    t_fieldcat2[] = t_fieldcat1[].
    * Add cell color table.
    * CALENDAR_TYPE is a structure in the dictionary with a
    * field called COLTAB of type LVC_T_SCOL. You can use
    * any structure and field that has the type LVC_T_SCOL.
    wa_fieldcat-fieldname = 'T_CELLCOLORS'.
    wa_fieldcat-ref_field = 'COLTAB'.
    wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Create dynamic table including the internal table
    * for cell coloring.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = t_fieldcat1
    IMPORTING
    ep_table = r_dyn_table
    EXCEPTIONS
    generate_subpool_dir_full = 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.
    * Get access to new table using field symbol.
    ASSIGN r_dyn_table->* TO <t_dyn_table>.
    * Create work area for new table.
    CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
    * Get access to new work area using field symbol.
    ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
    * Get data into table from somewhere. Field names are
    * known at this point because field catalog is already
    * built. Read field names from the field catalog or use
    * COMPONENT <number> in a DO loop to access the fields. A
    * simpler hard coded approach is used here.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'ABC'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'XYZ'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'TUV'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'DEF'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    * Color cells based on your criteria. In this example, a test on
    * FIELD2 is used to decide on color.
    LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    * Get access to internal table used to color cells.
    ASSIGN COMPONENT 'T_CELLCOLORS'
    OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
    CLEAR wa_cellcolors.
    wa_cellcolors-fname = 'FIELD2'.
    IF <w_field> = 'DEF'.
    wa_cellcolors-color-col = '7'.
    ELSE.
    wa_cellcolors-color-col = '5'.
    ENDIF.
    APPEND wa_cellcolors TO <t_cellcolors>.
    MODIFY <t_dyn_table> FROM <wa_dyn_table>.
    ENDLOOP.
    * Display screen. Define screen 100 as empty, with next screen
    * set to 0 and flow logic of:
    * PROCESS BEFORE OUTPUT.
    * MODULE initialization.
    * PROCESS AFTER INPUT.
    CALL SCREEN 100.
    * MODULE initialization OUTPUT
    MODULE initialization OUTPUT.
    * Set up for ALV display.
    IF r_dock_ctnr IS INITIAL.
    CREATE OBJECT r_dock_ctnr
    EXPORTING
    side = cl_gui_docking_container=>dock_at_left
    ratio = '90'.
    CREATE OBJECT r_alv_grid
    EXPORTING i_parent = r_dock_ctnr.
    * Set ALV controls for cell coloring table.
    wa_is_layout-ctab_fname = 'T_CELLCOLORS'.
    * Display.
    CALL METHOD r_alv_grid->set_table_for_first_display
    EXPORTING
    is_layout = wa_is_layout
    CHANGING
    it_outtab = <t_dyn_table>
    it_fieldcatalog = t_fieldcat2.
    ELSE. "grid already prepared
    * Refresh display.
    CALL METHOD r_alv_grid->refresh_table_display
    EXPORTING
    i_soft_refresh = ' '
    EXCEPTIONS
    finished = 1
    OTHERS = 2.
    ENDIF.
    ENDMODULE. " initialization OUTPUT

  • How to create a report with dynamic columns

    Hi all,
    I am using Apex 4.0 with Oracle 10g
    I am creating a report and I need to display columns dynamically based on the item values.
    example:
    I have a table employee with columns name, designation, sal
    In the report page i have a select list with designations and when I select a designation from the select list,
    I need to display the names of the employees horizontally,
    like each name as a new column in the report with that particular designation. and same has to continue when I select different designations.
    Can some one help me how we can do that.
    I appreciate your answer
    Thanks,
    Rik

    Essentially you want to write a pl/sql function which returns a varchar2 string. The contents of the string must be a valid sql statement.
    Once you have done this, you need to add a report region as type sql report and you will have the option of writing it as a query or as a function returning query. Choose function returning query and enter in the function call.
    Note your function must be valid, and must be executable by your apex parsing schema.
    example:
    create or replace
    function test_report(   p1_tablename       in varchar2)
    return varchar2
    is
    v_query varchar2(4000);
    begin
    v_query  :=
    'SELECT * from '||p_tablename;
    return v_query;
    end test_report;Edited by: Keith Jamieson on Aug 15, 2011 4:50 PM

  • How to create report with dynamic columns with static row labels

    Hi All,
    I am creating one report as per attached format. I have labels on the right side of the report
    and data in 3 columns. The data is taken dynamically from the command query.
    It gets data from 3 different result sets/command queries.
    I tried creating the report horizontally instead of vertically, but the logo image I am not able to rotate in 270degrees.
    Can anybody tell me how to create the report...??

    Hi Abhilash,
    Thanks for the quick reply.
    Actually the problem is with the image, as I am not able to rotate 270 degree. Crystal report cannot support the rotation of image.
    i have another problem, I have to create a report in which
    Lables are fixed on the left side of report and 3 columns per portrait page. Those columns are
    dynamically created and shown in the report.
    The format is like the above. Can you please help me in doing this report, as I tried it doing
    with CrossTab. I am really stuck to this report.

  • Interactive alv report with migo miro and purchase order

    hi all
    to make my alv interactive i put the following code....
    i dont know whether it is correct or not coz i hav not done alv before
    FORM display.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = sy-cprog
          is_layout          = wa_layout
          I_CALLBACK_USER_COMMAND  = 'HANDLE_USER_COMMAND'
          it_fieldcat        = it_fieldcat
        TABLES
          t_outtab           = itab.
    ENDFORM.                    "DISPLAY
    FORM HANDLE_USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                                  RS_SELFIELD TYPE SLIS_SELFIELD.
       CASE R_UCOMM.
        WHEN '&IC1'.
          IF RS_SELFIELD-FIELDNAME = 'EBELN'.
            READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.
            SET PARAMETER ID 'ITAB-EBELN' FIELD ITAB-EBELN.
           call transaction 'ME23N' AND SKIP FIRST SCREEN.
           CLEAR RS_SELFIELD.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "HANDLE_USER_COMMAND
    this code is working
    but i hav some problems
    when ever i double click on PO number
    1. it always opne the last PO number of the my alv list
    2. I want to open the migo with migo number when i double clik on the migo number
    3. and same for the MIRO
    plz help its very urgent...
    points wil b rewarded.

    Hi,
    Following report will explains how to do interactive list in alv report regarding purchase order. Kindly go through that one.
    REPORT  YMS_ALVINTERSAMPLE NO STANDARD PAGE HEADING LINE-SIZE 650
    MESSAGE-ID ZZ_9838.
    TYPE-POOLS: SLIS.
    *type declaration for values from ekko
    TYPES: BEGIN OF I_EKKO,
           EBELN LIKE EKKO-EBELN,
           AEDAT LIKE EKKO-AEDAT,
           BUKRS LIKE EKKO-BUKRS,
           BSART LIKE EKKO-BSART,
           LIFNR LIKE EKKO-LIFNR,
           END OF I_EKKO.
    DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,
          WA_EKKO TYPE I_EKKO.
    *type declaration for values from ekpo
    TYPES: BEGIN OF I_EKPO,
           EBELN LIKE EKPO-EBELN,
           EBELP LIKE EKPO-EBELP,
           MATNR LIKE EKPO-MATNR,
           MENGE LIKE EKPO-MENGE,
           MEINS LIKE EKPO-MEINS,
           NETPR LIKE EKPO-NETPR,
           END OF I_EKPO.
    DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,
          WA_EKPO TYPE I_EKPO .
    *variable for Report ID
    DATA: V_REPID LIKE SY-REPID .
    *declaration for fieldcatalog
    DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.
    declaration for events table where user comand or set PF status will
    be defined
    DATA: V_EVENTS TYPE SLIS_T_EVENT,
          WA_EVENT TYPE SLIS_ALV_EVENT.
    declartion for layout
    DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
    declaration for variant(type of display we want)
    DATA: I_VARIANT TYPE DISVARIANT,
          I_VARIANT1 TYPE DISVARIANT,
          I_SAVE(1) TYPE C.
    *PARAMETERS : p_var TYPE disvariant-variant.
    *Title displayed when the alv list is displayed
    DATA:  I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
    DATA:  I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.
    INITIALIZATION.
      V_REPID = SY-REPID.
      PERFORM BUILD_FIELDCATLOG.
      PERFORM EVENT_CALL.
      PERFORM POPULATE_EVENT.
    START-OF-SELECTION.
      PERFORM DATA_RETRIEVAL.
      PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
      PERFORM DISPLAY_ALV_REPORT.
    *&      Form  BUILD_FIELDCATLOG
          Fieldcatalog has all the field details from ekko
    FORM BUILD_FIELDCATLOG.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'EBELN'.
      WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'AEDAT'.
      WA_FIELDCAT-SELTEXT_M = 'DATE.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'BUKRS'.
      WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'BUKRS'.
      WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'LIFNR'.
      WA_FIELDCAT-NO_OUT    = 'X'.
      WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCATLOG
    *&      Form  EVENT_CALL
      we get all events - TOP OF PAGE or USER COMMAND in table v_events
    FORM EVENT_CALL.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
       IMPORTING
         ET_EVENTS             = V_EVENTS
    EXCEPTIONS
       LIST_TYPE_WRONG       = 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.                    "EVENT_CALL
    *&      Form  POPULATE_EVENT
         Events populated for TOP OF PAGE & USER COMAND
    FORM POPULATE_EVENT.
      READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'TOP_OF_PAGE'.
        MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
      ENDIF.
      READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'USER_COMMAND'.
        MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-NAME.
      ENDIF.
    ENDFORM.                    "POPULATE_EVENT
    *&      Form  data_retrieval
      retreiving values from the database table ekko
    FORM DATA_RETRIEVAL.
      SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.
    ENDFORM.                    "data_retrieval
    *&      Form  bUild_listheader
          text
         -->I_LISTHEADEtext
    FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
      DATA HLINE TYPE SLIS_LISTHEADER.
      HLINE-INFO = 'this is my first alv pgm'.
      HLINE-TYP = 'H'.
    ENDFORM.                    "build_listheader
    *&      Form  display_alv_report
          text
    FORM DISPLAY_ALV_REPORT.
      V_REPID = SY-REPID.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM                = V_REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
         I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
         I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
         I_GRID_TITLE                      = I_TITLE_EKKO
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         = ALV_LAYOUT
         IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
        i_default                         = 'ZLAY1'
         I_SAVE                            = 'A'
        is_variant                        = i_variant
         IT_EVENTS                         = V_EVENTS
        TABLES
          T_OUTTAB                          = IT_EKKO
    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  TOP_OF_PAGE
          text
    FORM TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY       = IT_LISTHEADER
       i_logo                   =
       I_END_OF_LIST_GRID       =
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  USER_COMMAND
          text
         -->R_UCOMM    text
         -->,          text
         -->RS_SLEFIELDtext
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
      CASE R_UCOMM.
        WHEN '&IC1'.
          READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
          PERFORM BUILD_FIELDCATLOG_EKPO.
          PERFORM EVENT_CALL_EKPO.
          PERFORM POPULATE_EVENT_EKPO.
          PERFORM DATA_RETRIEVAL_EKPO.
          PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
          PERFORM DISPLAY_ALV_EKPO.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  BUILD_FIELDCATLOG_EKPO
          text
    FORM BUILD_FIELDCATLOG_EKPO.
      WA_FIELDCAT-TABNAME = 'IT_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'EBELN'.
      WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'EBELP'.
      WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MATNR'.
      WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MENGE'.
      WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MEINS'.
      WA_FIELDCAT-SELTEXT_M = 'UOM'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'NETPR'.
      WA_FIELDCAT-SELTEXT_M = 'PRICE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCATLOG_EKPO
    *&      Form  event_call_ekpo
      we get all events - TOP OF PAGE or USER COMMAND in table v_events
    FORM EVENT_CALL_EKPO.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
       IMPORTING
         ET_EVENTS             = V_EVENTS
    EXCEPTIONS
      LIST_TYPE_WRONG       = 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.                    "event_call_ekpo
    *&      Form  POPULATE_EVENT
           Events populated for TOP OF PAGE & USER COMAND
    FORM POPULATE_EVENT_EKPO.
      READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'TOP_OF_PAGE'.
        MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
      ENDIF.
      ENDFORM.                    "POPULATE_EVENT
    *&      Form  TOP_OF_PAGE
          text
    FORM F_TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY       = IT_LISTHEADER
       i_logo                   =
       I_END_OF_LIST_GRID       =
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  USER_COMMAND
          text
         -->R_UCOMM    text
         -->,          text
         -->RS_SLEFIELDtext
    *retreiving values from the database table ekko
    FORM DATA_RETRIEVAL_EKPO.
    SELECT EBELN EBELP MATNR MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO.
    ENDFORM.
    FORM BUILD_LISTHEADER_EKPO USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
    DATA: HLINE1 TYPE SLIS_LISTHEADER.
    HLINE1-TYP = 'H'.
    HLINE1-INFO = 'CHECKING PGM'.
    ENDFORM.
    FORM DISPLAY_ALV_EKPO.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = V_REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = 'F_USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
       I_GRID_TITLE                      = I_TITLE_EKPO
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         =
       IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         =
       I_SAVE                            = 'A'
      IS_VARIANT                        =
       IT_EVENTS                         = V_EVENTS
      TABLES
        T_OUTTAB                          = IT_EKPO
    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.
    Thanks,
    Sankar  M

  • Create a ALV report with fields editable and  entry to be saved in ztable

    Hello Experts,
    I have created the ALV report which has two of the fields editable. Now whenever user puts an entry in the ALV it has to be saved in the ZTABLE.
    The report is displayed with editable fields but i'm not sure what has to be written in the 'USER COMMAND' subroutine to save the entries in ztable.
    Please see my code belwo:-
      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 = 'ALV_USER_COMM'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               it_events               = gt_events
               is_print                = gd_prntparams
                 i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = it_bg2
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
      IF sy-subrc <> 0.
    Thanks,
    Naveen
    Edited by: jaikrishna on Sep 4, 2010 8:13 AM

    Hi,
    I have worked on similar requirement. You can do that on sy-ucomm value only and you have to call a FM and a method. For that end user has to click on a button which you need to create in the application toolbar. Say that button function code is 'SAVE'. Write the following code in your user command :
    *&      Form  USER_COMMAND
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
            RS_SELFIELD TYPE SLIS_SELFIELD.
    *Code to reflect the changes done in the internal table
      DATA : REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
      DATA: L_VALID TYPE C.
      IF REF_GRID IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            E_GRID = REF_GRID.
      ENDIF.
      IF NOT REF_GRID IS INITIAL.
        CALL METHOD REF_GRID->CHECK_CHANGED_DATA
          IMPORTING
            E_VALID = L_VALID.
      ENDIF.
      CASE SY-UCOMM.
        WHEN 'SAVE'.
    *Data will come with the edited values from ALV
    *Here you write your code to save entries into Z table
    ENDCASE.
    ENDFORM. "USER_COMMAND
    Thanks & Regards,
    Rock.

  • Pivot Table with Dynamic Columns and Headers

    Hello,
    I'm trying to pivot a table of data where the column headers will be dynamic.  While I know how to pivot the table to get what I want how will I be able to pick up the table column header from the Pivot to display in the report?
    For example:
    Unpivoted data is Employee Code, Branch Code, Problem Code, # of Problems.
    There is many records for a given Employee and Branch that I want to pivot so the Column headers are the Problem Codes and the data below is the SUM(num_problems) for that Problem.
    So the data may look like this for Tech Bob, Branch NY.
    Problem = LEAK, Num_problem = 5
    Problem = DAMAGE, Num_problem = 2
    Problem = OTHER, Num_problem = 3
    Which problem codes may appear is unknown but selecting the DISTINCT(problem) across all techs gives me the column headings to use.
    So if I pivot this data, I get this Row:
    Tech = Bob, Branch = NY, DAMAGE = 2, LEAK = 5, OTHER = 3
    So first can SSRS handle having dynamic columns?  Only Tech and Branch are known and the remaining columns are dynamic based on how many Problems they worked on.
    Second, how can I set the column heading in my Tablix to be the Problem Code?
    Sherry

    You just need to use a  matrix container
    Use EmployeeCode and BranchCode for row group
    ProblemCode as column group and SUM([No Of Problems]) as the data expression and it will generate the columns for you based on ProblemCode values automatically.
    See an example here
    Sample Matrix
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to call a SP with dynamic columns and output results into a .csv file via SSIS

    hi Folks, I have a challenging question here. I've created a SP called dbo.ResultsWithDynamicColumns and take one parameter of CONVERT(DATE,GETDATE()), the uniqueness of this SP is that the result does not have fixed columns as it's based on sales from previous
    days. For example, Previous day, customers have purchased 20 products but today , 30 products have been purchased.
    Right now, on SSMS, I am able to execute this SP when supplying  a parameter.  What I want to achieve here is to automate this process and send the result as a .csv file and SFTP to a server. 
    SFTP part is kinda easy as I can call WinSCP with proper script to handle it.  How to export the result of a dynamic SP to a .CSV file? 
    I've tried
    EXEC xp_cmdshell ' BCP " EXEC xxxx.[dbo].[ResultsWithDynamicColumns ]  @dateFrom = ''2014-01-21''"   queryout  "c:\path\xxxx.dat" -T -c'
    SSMS gives the following error as Error = [Microsoft][SQL Server Native Client 10.0]BCP host-files must contain at least one column
    any ideas?
    thanks
    Hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Hey Jakub, thanks and I did see the #temp table issue in our 2008R2.  I finally figured it out in a different way... I manage to modify this dynamic SP to output results into
    a physical table. This table will be dropped and recreated everytime when SP gets executed... After that, I used a SSIS pkg to output this table
    to a file destination which is .csv.  
     The downside is that if this table structure ever gets changed, this SSIS pkg will fail or not fully reflecting the whole table. However, this won't happen often
    and I can live with that at this moment. 
    Thanks
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

  • Generate Paper Report with dynamic columns in Reports 9i

    Hi,
    I'd like to know if it's possible to select wich columns I want to show in the report just before it is shown.
    If yes, how can I do it?
    I'm using 9i Developer Suite and I'm calling the report from Oracle Forms.
    Thanx

    Set the Horizontal Elasticity to varaible.
    With a format trigger you control the visibility.
    function F_fieldFormatTrigger return boolean is
    begin
      if :hide = 'Y' then
        return(FALSE);
      end if;
      return (TRUE);
    end;

  • APEX report with Break columns and BI Publisher

    I am having an issue with APEX and using column breaks when printing to BI publisher.. It seems that when you write an APEX report that breaks on the 1st or 1st and 2nd columns, the grouping shows nicely in APEX, but when BI Publisher gets the XML data, and you do the same grouping using an RTF file, there is a group of rows with NO grouping info that occurs at the top of the report, then each group you expect has just ONE row..
    (Just giving this a bump to see anyone has an idea here..)
    Any suggestions?
    Thank you,
    Tony Miller
    Message was edited by:
    Tony Miller

    WITH clause or Subquery Factoring allows the set of data to be reused multiple times within the SQL. Oracle will usually materialize the data into a temporary table (you will see it if you take an explain plan of the SQL).
    I would be surprised if it was the actual WITH clause that was causing the performance issue, however you can test this by turning the WITH clause feature off. Go to the Physical model, right mouse click on your Database > Properties > Features Tab, scroll down to WITH_CLAUSE_SUPPORTED and switch it off.
    I'd be interested to know if you do see actual improvement.
    Good Luck.

  • Finding column count with dynamic columns and dynamic tables

    I've done some PL/SQL for awhile now but was trying to devise a solution for the following problem:
    I wish to find the number of times a specific value for a column exists in all the tables that contain the field and I have access to see with the current user. The column name and value will be passed in via parameters.
    I was hoping to use something like
    select table_name from all_tab_columns where column_name = <variable table name>;
    then use the results from this to create a select statment based off the tables from the select above. I know the difference between dba_tab_columns and all_tab_columns - I want to make sure that I only retrieve the values i have access to.
    Can anyone point me to some guide / website / reference material I can read to catch up on the idea of creating this statment?
    Thank you.

    Hi,
    it's a test version.
    You can naturally tune it, but it seemed to work:
    declare
    pi_column VARCHAR2(30) := 'DEPTNO';
    pi_value VARCHAR2(4000) := '20';
    v_count NUMBER := 0;
    v_count_tab NUMBER;
    BEGIN
    FOR I IN (select owner, table_name from dba_tab_columns
              where column_name = pi_column
    LOOP
        EXECUTE IMMEDIATE 'SELECT count(*) FROM '||i.owner||'.'||i.table_name||
                          ' WHERE '||pi_column||' = :pi_value'  INTO v_count_tab USING pi_value; 
        v_count := v_count + v_count_tab;
    END LOOP;                   
    dbms_output.put_line(v_count);
    END;Regards

  • How to create a report with dynamic no of columns

    Hi All,
    we have a report with 6 columns.
    and its been access by 10-20 people.
    the user dont want to have a fix report with 6 columns rather they want to have a flexibility to select the columns from the report they want to see.
    i.e. user one one time wasnt to see only one columns
    another time he want to see only column 2 and 4 of the report.
    its like there can be a multiple select option from where he can select the columns in the existing report and then see the same report with only that much column.
    Please tell me how to implement it.

    Abhip i thin you didnt get the problem.
    there is s exeiting report with 6 column
    Currently when i logging to OBIEE and see that report
    i will be getting report with 6 column
    but now i want a flexibility of selecting only 2 or 3 or 1 or 4 or 5 as i wish columns from this report and see the result only for that
    so is there by any chance i can have a check box for each column which i can check in dashborad to select that column
    and show the result were as by default it will show the report with 6 column.
    Thanks

  • How can we get Dynamic columns and data with RTF Templates in BI Publisher

    How can we get Dynamic columns and data with RTf Templates.
    My requirement is :
    create table xxinv_item_pei_taginfo(item_id number,
    Organization_id number,
    item varchar2(4000),
    record_type varchar2(4000),
    record_value CLOB,
    State varchar2(4000));
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'USES','fever','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'HOW TO USE','one tablet daily','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'SIDE EFFECTS','XYZ','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'DRUG INTERACTION','ABC','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'OVERDOSE','Go and see doctor','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'NOTES','Take after meal','TX');
    select * from xxinv_item_pei_taginfo;
    Item id Org Id Item Record_type Record_value State
    493991     224     1265-D30     USES     fever     TX
    493991     224     1265-D30     HOW TO USE     one tablet daily     TX
    493991     224     1265-D30     SIDE EFFECTS     XYZ     TX
    493991     224     1265-D30     DRUG INTERACTION     ABC     TX
    493991     224     1265-D30     OVERDOSE      Go and see doctor     TX
    493991     224     1265-D30     NOTES     Take after meal     TX
    Above is my data
    I have to fetch the record_type from a lookup where I can have any of the record type, sometime USES, HOW TO USE, SIDE EFFECTS and sometimes some other set of record types
    In my report I have to get these record typpes as field name dynamically whichever is available in that lookup and record values against them.
    its a BI Publisher report.
    please suggest

    if you have data in db then you can create xml with needed structure
    and so you can create bip report
    do you have errors or .... ?

Maybe you are looking for