Dynamic Table in ALV

Hello experts,
is it possible to call an ALV via ( class cl_salv or fm REUSE_ALV_GRID_DISPLAY) with a dynamic table?
This dynamic table has for example one fix column for the material number and dynamic colums for additional data.
One material has 1 additional column, the other material has two additional columns.
So i need an ALV with 3 columns material add_data1 add_data2 (add_data2 of material one is empty this is ok).
To build an itab which can handle this is possible i know.

Hello Benjamin,
Maybe you already found a solution for this, but if not (or for others looking for a solution), here is a sample program that creates, fills, and displays a dynamic table:
report ztpar_dynamic_salv.
parameters: p_colnr type i default 3.
start-of-selection.
  perform execute.
form execute.
  data t_table type ref to data.
** create dynamic table
  perform create_dynamic_table using p_colnr
                            changing t_table.
** fill dynamic table
  perform fill_dynamic_table changing t_table.
** display dynamic table
  perform display_table using t_table.
endform.
form create_dynamic_table using colnr type i
                       changing table type ref to data.
  data: lo_field type ref to cl_abap_typedescr,
        lo_struct type ref to cl_abap_structdescr,
        lo_table type ref to cl_abap_tabledescr.
  data: t_comp type cl_abap_structdescr=>component_table,
        l_comp like line of t_comp.
  lo_field ?= cl_abap_typedescr=>describe_by_name( 'CHAR10' ).
  do p_colnr times.
    move sy-index to l_comp-name.
    concatenate 'COLUMN' l_comp-name into l_comp-name.
    condense l_comp-name no-gaps.
    l_comp-type ?= lo_field.
    append l_comp to t_comp.
  enddo.
  lo_struct = cl_abap_structdescr=>create( p_components = t_comp p_strict = space ).
  lo_table = cl_abap_tabledescr=>create( lo_struct ).
  create data table type handle lo_table.
endform.
form fill_dynamic_table changing table type ref to data.
  field-symbols: <fs_table> type standard table,
                 <fs_line> type any,
                 <fs_field> type any.
  assign table->* to <fs_table>.
  do 5 times.
    append initial line to <fs_table> assigning <fs_line>.
    do.
      assign component sy-index of structure <fs_line> to <fs_field>.
      if sy-subrc ne 0.
        exit.
      endif.
      <fs_field> = sy-index.
    enddo.
  enddo.
endform.
form display_table using i_table type ref to data.
  data lo_alv type ref to cl_salv_table.
  field-symbols <fs_tab> type any table.
  assign i_table->* to <fs_tab>.
  try.
      cl_salv_table=>factory(
        importing
          r_salv_table = lo_alv
        changing
          t_table      = <fs_tab> ).
    catch cx_salv_msg.
      message 'Cannot display result!' type 'E'.
  endtry.
  lo_alv->display( ).
endform.
Best regards,
Tanguy

Similar Messages

  • Show dynamic table in ALV grid

    Hi !
    how do I show a dynamic table in ALV GRID ?
    I used the following commands:
    call method cl_alv_table_create=>create_dynamic_table
      exporting
        it_fieldcatalog = it_fieldcat[]
      importing
        ep_table        = gt_new_table.
      assign gt_new_table->* to <l_table>.
      create data gs_new_line like line of <l_table>.
      assign gs_new_line->* to <l_line>.
    I added records into the table
    Now I got a dynamic table.
    How do I show it in ALV GRID ?
    thanks
      Adi

    Hi,
    Check these links
    Re: Dynamic table
    http://sap.ittoolbox.com/code/d.asp?a=s&d=3038
    http://www.sap4.com/codigo-138.html
    http://www.sapassist.com/code/d.asp?a=s&d=3365
    There is an example in the report BCALV_TABLE_CREATE
    report BCALV_TABLE_CREATE.
    data: ok_code like sy-ucomm,
         g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
         grid1  type ref to cl_gui_alv_grid,
         g_custom_container type ref to cl_gui_custom_container.
    data: gt_fieldcat type lvc_t_fcat.
    data: gp_table type ref to data.
    field-symbols: <gt_table> type table.
    parameters: n type i.
    if n > 100.
    message a000(0k) with 'N <= 100'.
    endif.
    perform fieldcat_build.
    call method cl_alv_table_create=>create_dynamic_table
                            exporting it_fieldcatalog = gt_fieldcat
                            importing ep_table = gp_table.
    assign gp_table->* to <gt_table>.
    perform fill_table.
    call screen 100.

  • Making cell non editabale (of dynamic table) in alv

    Hi,
    I am working on a editable alv with a dynamic table <itab> .This table gets populated during runtime.Now I want to make few cell of this table not editabale (only few cell not the full columns) I knwo that the procedure is to
    declare my outtab like
    TYPES: BEGIN OF gs_outtab.
    TYPES: celltab TYPE lvc_t_styl.        "field to switch editability
            INCLUDE TYPE /npu/edmt_aa_eac.
    TYPES: END OF gs_outtab.
    and in the celltab i pass the information of cells which will be non editable...But the problem is as my outtab is a dynamic table I cannot INCLUDE IT IN ANOTHER types.
    Please help me how to do it???? Or is there any other way of doing it???

    Hi Priya
    Add the field of type lvc_t_styl while creating the field catalog.
    Now
    DATA lo_table TYPE REF TO data.
      cl_alv_table_create=>create_dynamic_table(
        EXPORTING
          it_fieldcatalog = lt_fieldcat  "the field catalog table
        IMPORTING
          ep_table = lo_table ). "the reference to the table gt_outtab with the style tab
    FIELD-SYMBOLS <tab> TYPE ANY TABLE.
    ASSIGN lo_table->* TO <tab> .
    Now you can fill your <tab>.
    Pushpraj

  • Dynamic table with alv rows & colums

    Hey,
    How to create dynamic internal table with alv grid rows & columns with data .

    TYPE-POOLS : abap.
    FIELD-SYMBOLS: <f_dyn_table> TYPE STANDARD TABLE,
                 <f_dyn_wa>.
    DATA: t_dy_table TYPE REF TO data,
          dy_line  TYPE REF TO data,
          wa_xfc TYPE lvc_s_fcat,
          t_ifc TYPE lvc_t_fcat.
    *get the structure
      DATA: $field        TYPE lvc_fname,
            $counter(2)   TYPE n.
      DATA: $output_field(25) TYPE c,
            $fld_len      TYPE i.
      FIELD-SYMBOLS: <f_out_field> TYPE ANY.
      DATA : $t_idetails  TYPE abap_compdescr_tab,
             $wa_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( c_struc ).
      $t_idetails[] = $ref_table_des->components[].
      LOOP AT $t_idetails INTO $wa_xdetails.
        CLEAR: wa_xfc, $output_field, $fld_len.
        wa_xfc-fieldname = $wa_xdetails-name .
        wa_xfc-datatype  = $wa_xdetails-type_kind.
        wa_xfc-inttype   = $wa_xdetails-type_kind.
        IF $wa_xdetails-type_kind EQ 'C'
           OR $wa_xdetails-type_kind EQ 'N'.
          CONCATENATE 'WA_OUTTAB' '-' $wa_xdetails-name
                                         INTO $output_field.
          ASSIGN ($output_field) TO <f_out_field>.
          IF <f_out_field> IS ASSIGNED.
            DESCRIBE FIELD <f_out_field> LENGTH $fld_len
                                           IN CHARACTER MODE.
            wa_xfc-intlen    = $fld_len.
          ENDIF.
        ELSE.
          wa_xfc-intlen    = $wa_xdetails-length.
        ENDIF.
        wa_xfc-decimals  = $wa_xdetails-decimals.
        APPEND wa_xfc TO t_ifc.
        CLEAR $wa_xdetails.
      ENDLOOP.
    here if you have any other fields to be added to the dynamic structure based on your requirement, you can add then and apped them to t_ifc. There is a special handling for unicode conversion- so for the numc and char fields the length is passed in a different mothed.
    create dynamic internal table and assign to fs*
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = t_ifc
          i_length_in_byte          = 'X'
        IMPORTING
          ep_table                  = t_dy_table
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
      IF sy-subrc <> 0.
      ELSE.
        ASSIGN t_dy_table->* TO <f_dyn_table>.
    create dynamic work area and assign to fs
        CREATE DATA dy_line LIKE LINE OF <f_dyn_table>.
        ASSIGN dy_line->* TO <f_dyn_wa>.
      ENDIF.
    *move the data into <f_dyn_wa> and then append this to output table <f_dyn_table>.
    example:-
        IF <f_dyn_wa> IS ASSIGNED AND <f_dyn_table> IS ASSIGNED.
          MOVE-CORRESPONDING wa_outtab TO <f_dyn_wa>.
    APPEND <f_dyn_wa> TO <f_dyn_table>.
    endif.
    Edited by: Krishna Adabala on Dec 2, 2008 7:57 AM

  • Dynamic Table with ALV

    Hello.
    My WD Application should offer a editable ALV Table View.
    The structure and content of the table is only known at runtime. How can I use the ALV dynamically, so that I also can detemine the cells properties (dropdown, data type, ...) at runtime.
    Does anybody know some examples using ALV?
    Thanks and kind regards.
    Carola
    P.S: what are the advantages to use ALV instead of a table UI element?

    Hi Carola,
    Try going through this [thread|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4c70444a-0801-0010-7688-9e4bd844b783] for info about using an ALV Table with Dynamic Context Nodes.
    The ALV provides many useful built in features without the need for any additional programming effort. These are:
    • Sorting
    • Filtering
    • Selecting rows
    • Scrolling up/down
    • Exporting to Microsoft Excel
    • Exporting to PDF
    The Settings link can be used to open a dialog box, which allows you to adapt
    additional settings:
    • Hiding columns
    • Defining sorting columns and sorting direction
    • Defining complex filters
    • Changing table display settings
    • Defining settings for PDF export
    These settings can be saved and used as the user's default display variant.If the Web Dynpro application is started in Customizing mode (adding sap-config-mode=X to the URL), the settings can be saved for all users. In addition, the settings can be added to a transport request using a Customizing task.
    Regards,
    Uday

  • Column Dynamic Table ( non ALV) visible - non visible

    Hello
    Using the dynmic table creation and I want to set some columns to invisible per default per
              ls_column->set_visible( 01 ).
    But I want that the user can make this column visible, if necessary.
    In ALV a user can use the standard personalization function to set the invisible columns to visible.
    How can I do this with a normal table ?
         lo_table TYPE REF TO cl_wd_table,
    Thanks and regards,
    Carola

    Hi,
    You should bind your visibility property to your context, then you will be able to provide a personalization view to your user.
    Regards,
    Joseph BERTHE

  • Dynamic table with field type table

    Hi,
    I´m using "cl_alv_table_create=>create_dynamic_table" to create a dynamic table for ALV Grid.
    But...I need to use colors in ALV, then I need to declare a field type LVC_S_SCOL in dynamic table from "cl_alv_table_create=>create_dynamic_table".
    How can I declare this in fieldcat?
    The code:
    Creating dynamic table
    DATA: table_agrup TYPE REF TO data,
            line_agrup  TYPE REF TO data.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = t_fieldcat
        IMPORTING
          ep_table                  = table_agrup
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
        ASSIGN table_agrup->* TO .
    Printing ALV
      CALL METHOD obj_grid->set_table_for_first_display
        EXPORTING
          is_variant                    = w_variant
          i_save                        = 'A'
          is_layout                     = w_layout
        CHANGING
          it_outtab                     =
          it_fieldcatalog               = t_fieldcat
          it_sort                       = t_sort
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
    Thanks.

    It is not possible with the  METHOD cl_alv_table_create=>create_dynamic_table to include another table inside that newly generated table.
    I have tried to do it with the code and I got the dynamic table created after at the end of the program.
    In the code,
    <DYN_TABLE> has same effect as your <table> variable
    <DYN_WA> has same effect as your <HEADER>
    REPORT  ZTEST_NP_DYNAMIC.
    DATA: DY_TABLE TYPE REF TO DATA,
          DY_LINE  TYPE REF TO DATA.
    FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
                   <DYN_WA>,
                   <DYN_FIELD>.
    FIELD-SYMBOLS: <FS> TYPE ANY.
    * To generate the Dyanmic table with the COLOR
    DATA: LS_SOURCE TYPE STRING.
    DATA: LT_SOURCE LIKE STANDARD TABLE OF LS_SOURCE WITH HEADER LINE.
    DATA: L_NAME LIKE SY-REPID.
    DATA: L_MESSAGE(240) TYPE C,
          L_LINE TYPE I,
          L_WORD(72) TYPE C.
    DATA: L_FORM(30) TYPE C VALUE 'TABLE_CREATE'.
    LT_SOURCE = 'REPORT ZTEST_SUBROUTINE_POOL.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'FORM  TABLE_CREATE USING I_FS TYPE ANY.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'DATA: BEGIN OF LT_GENTAB OCCURS 0.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'DATA: BUKRS TYPE BUKRS. '.
    APPEND LT_SOURCE.
    LT_SOURCE = 'DATA: BKTXT TYPE BKTXT. '.
    APPEND LT_SOURCE.
    * you can add your fields here.....
    LT_SOURCE = 'DATA: COLOR TYPE lvc_t_scol. '.
    APPEND LT_SOURCE.
    LT_SOURCE = 'DATA: END OF LT_GENTAB.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'DATA: POINTER TYPE REF TO DATA.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'CREATE DATA POINTER LIKE STANDARD TABLE OF LT_GENTAB.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'I_FS = POINTER.'.
    APPEND LT_SOURCE.
    LT_SOURCE = 'ENDFORM. '.
    APPEND LT_SOURCE.
    L_NAME = 'ZTEST_SUBROUTINE_POOL'.
    CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 9.
      GENERATE SUBROUTINE POOL LT_SOURCE NAME L_NAME
               MESSAGE L_MESSAGE LINE L_LINE WORD L_WORD.  "#EC CI_GENERATE
    ENDCATCH.
    IF NOT L_MESSAGE IS INITIAL.
      MESSAGE E000(0K) WITH L_MESSAGE L_LINE L_WORD.
    ENDIF.
    ASSIGN DY_TABLE TO <FS>.
    PERFORM (L_FORM) IN PROGRAM (L_NAME) USING <FS>.
    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>.
    Write: 'bye'.
    Regards,
    Naimesh Patel

  • Dynamic display of fields of table in ALV report.

    To display the records of a table in ALV report dynamically such that first 10 fields of the table should only be displayed excluding 'mandt' field .
    That is field no 2nd to 11th should be displayed.

    parameters: p_vari type slis_vari.
    at selection-screen on value-request for p_vari.
      perform alv_variant_f4 changing p_vari.
    form alv_variant_f4 changing l_vari type slis_vari.
    On F4 for layout selection - Get laouts created to this report.
      data: l_variant type disvariant.
      l_variant-report   = sy-repid.
      l_variant-username = sy-uname.
      call function 'REUSE_ALV_VARIANT_F4'
        exporting
          is_variant = l_variant
          i_save     = 'A'
        importing
          es_variant = l_variant
        exceptions
          others     = 1.
      if sy-subrc = 0.
        l_vari = l_variant-variant.
      endif.
    Create a structure
    data: wa_layout type disvariant.
    fill up the layout with selected fields.
    wa_layout-report = sy-repid.
    wa_layout-username = sy-uname " Choose this if you want user specific
    wa_layout-variant = p_vari.
    Assign the same to the REUSE_ALV_GRID_DISPLAY
    it is a import paramter  IS_VARIANT = wa_layout.
    All you have to do is first execute the report and save layouts what exactly you want
    and then next time you run the report you will get a chance to select the layout of your own.
    or
    You can get rid of MANDT field from fieldcatalog and internal table by creating a new
    structure. I mean, if you know you always want to display the field from 2 to 11 then simply
    delete the field from fieldcatalog.
    You can assign to different field catalog using Field symbols and change your internal
    table as well since you have created a dynamic internal table.
    Let me know if you need more.

  • How to give color of particular cell in alv list display for dynamic table

    Dear Experts,
    i want to give color of a particular cell in alv list display (reuse_alv_list_display). Here i am passing data through dynamic table?

    Hi,
    Se this:
    DATA: lt_color    TYPE lvc_t_scol WITH HEADER LINE.
    DATA: BEGIN OF data_tab OCCURS 0.
             tabcolor     TYPE   lvc_t_scol,
          END OF data_tab.
    * Befone ALV call
      alv_layout-coltab_fieldname  = 'TABCOLOR'.
    * For each row in data_tab
    REFRESH: lt_color.
    CLEAR: lt_color.
    lt_color-color-col = 6.
    lt_color-color-int = 1.
    lt_color-fname = FIELD1'.
    APPEND lt_color.
    lt_color-color-col = 2.
    lt_color-color-int = 0.
    lt_color-fname = 'FIELD2'.
    APPEND lt_color.
    data_tab-tabcolor[] = lt_color[].
    append data_tab.
    Best regards,
    Leandro Mengue

  • WD4A Dynamic ALV Table with dynamic tables

    Hi all,
    first I want give you the information what I try to do.
    I have an another WD4A application for administrative use in which I can assign certain tablefields to a certain user. You can say it's something like a customizing application.
    In the next application (with my issues) I will display the tables for the user, but these tables are not the complete table.
    I have a node in my context of the component controller which is bound to my ALV. I add during the runtime attributes to my node.
    * .... coding ....declaration
    * get the node
      lr_node = wd_context->get_child_node( 'M_TABLE' ).
      lr_node_info ?= lr_node->get_node_info( ).
    * remove the attributes, if exists
      lr_node_info->remove_dynamic_attributes( ).
    * .... coding ....
    *   add attributes
        LOOP AT l_t_m_table INTO l_s_m_table.
          CLEAR ls_attribute.
    *     name of the attribute
          MOVE l_s_m_table-NAME TO ls_attribute-NAME.
    *     DDIC type of the attribute
          MOVE l_s_m_table-TYPE_NAME TO ls_attribute-TYPE_NAME.
    *     If the DDIC has a gen namespace like /B135/ replace the / with _
          REPLACE ALL OCCURRENCES OF '/' IN ls_attribute-NAME WITH '_'.
    *     add the attribute
          lr_node_info->add_attribute( EXPORTING
                                         attribute_info = ls_attribute ).
        ENDLOOP.
    This coding works fine I get the columns in my ALV. Then I tried to fill my ALV table with data from a database table.
    I created dynamicly an internal table with the following coding:
    *   Create dynamic table
        CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
          EXPORTING
            IT_FIELDCATALOG = l_t_FLDCAT
          IMPORTING
            EP_TABLE = l_t_NEW_M_TABLE.
    *   assign the table
        ASSIGN l_t_NEW_M_TABLE->* TO <M_TABLE>.
    *   structure of table
        CREATE DATA l_s_NEW_M_TABLE LIKE LINE OF <M_TABLE>.
        ASSIGN l_s_NEW_M_TABLE->* TO <l_s_m_table>.
    * get data from database
    SELECT * FROM (l_m_table) INTO CORRESPONDING FIELDS OF TABLE <M_table> WHERE OBJVERS = 'A'.
    With this coding I get the data from the database and only the required fields that means I have e.g. an itab with columns1, columns3, columns4 from the database.
    I also added e.g. these columns  (columns1, columns3, columns4 from the database) to the node as attribute. Now it should be possible to bind the table to the structure with this coding:
    lr_comp_usage_m = wd_this->wd_cpuse_usage_alv_M_table( ).
    *   create component if not active
        IF lr_comp_usage_m->has_active_component( ) IS INITIAL.
          lr_comp_usage_m->create_component( ).
        else.
    * set data if node exists
          l_ref_interfacecontroller = wd_this->wd_cpifc_usage_alv_M_table( ).
          l_ref_interfacecontroller->set_data( lr_node ).
        endif.
    *   bind table
        lr_node->bind_table( <M_TABLE> ).
    Now, I get an error, which is caused by the table binding.
    In ST22 I get:
    Short text
        Line types of an internal table and a work area not compatible.
    What happened?
        Error in the ABAP Application Program
        The current ABAP program "CL_WDR_CONTEXT_NODE_VAL=======CP" had to be
         terminated because it has
        come across a statement that unfortunately cannot be executed.
    Error analysis
        The statement
           "INSERT wa INTO TABLE itab"
        requires the lines of the internal table "TABLE" and the
        work area " wa" to be compatible. Compatibility means
        equivalence in the context of ABAP/4 type checking.
        In this case, the condition is not satisfied because the internal table
        "TABLE" has the line type "u" and the length 28, but the work area " wa"
        has the type "C" and the length 2.
        (If the work area " wa" is the header line of the internal
        table "TABLE", the above inconsistency can arise if an internal
        table t with the line type T1 is passed to a subroutine (FORM or
        FUNCTION) as an actual parameter and the corresponding formal
        parameter p is declared in the subroutine by "TABLES p STRUCTURE T2".
        If then T1 and T2 are incompatible, the header line p
        has the type T2 (specifed by STRUCTURE), but the internal
        table p has the line type T1 (passed from the actual parameter)).
    Source Code Extract
    Line  SourceCde
        1 method if_wd_context_node~get_static_attributes_table .
        2
        3   field-symbols:
        4     <element> like line of me->collection,
        5     <static_attributes> type data,
        6     <table> type index table.
        7
        8 * check whether elements are supllied or not
        9   if me->elements_supplied = abap_false.
       10     me->supply_elements( ).
       11   endif.
       12
       13   clear table.
       14
       15   if me->table_ref is not initial.
       16     assign me->table_ref->* to <table>.
       17     table = <table>.
       18   else.
       19     loop at me->collection assigning <element> from from to to.
       20       assign <element>->static_attributes->* to <static_attributes>.
    error in line 21       insert <static_attributes> into table table.
       22     endloop.
       23   endif.
       24
       25 endmethod.
    Any suggestions? Is it allowed to use bind_table() with a field symbol?
    Another strange thing is that if I try the same with static itab and attributes during runtime it works, but only if the fields of the itab has the same name as the attributes, which means that I can not use itabs with fieldnames like /BI0/S_CUSTOMER and if I can not use them it's difficult to read data from database with SELECT * FROM ... INTO CORRESPONDING FIELDS OF TABLE itab.
    Thanks in advance for your suggestions!
    Best Regards,
    Marcel

    Hi Francois,
    I solve it with the RTTI and the method    
    lr_node_info = lr_node_info->add_new_child_node(
                          name = 'Dynamic_TABLE'
                          IS_MANDATORY = ABAP_false
                          IS_MULTIPLE = ABAP_true
                          STATIC_ELEMENT_RTTI = lr_struct_descr
                          IS_STATIC = ABAP_false
    I don't know why it doesn't work with adding attributes and binding the table after adding the attributes.
    Anyway thanks for your help.
    Best Regards,
    Marcel

  • Subtotals in dynamic internal table using alv grid

    hi experts i have created one dynamic table.  The requirement is to display the subtotals in the output using reuse_alv_grid.
    Dynamic itab (field-symbols) and ALV event BEFORE_LINE_OUTPUT
    the above is the thread related and could any one please provide the sample code for this task.
    can any one post the solution for that.
    rewards points will be awarded.
    khazi

    * ASSINING STRUCTURE FOR FILD CATLOGS
    DATA: DYN_TABLE    TYPE REF TO DATA,
          DYN_LINE     TYPE REF TO DATA,
          LS_FIELDCAT TYPE LVC_S_FCAT,
          LT_FIELDCAT TYPE LVC_T_FCAT.
      LOOP AT LT_DMTAB INTO LS_DMTAB.
        CLEAR LS_FIELDCAT.
        LS_FIELDCAT-FIELDNAME = LS_DMTAB-SDATE .
        LS_FIELDCAT-DATATYPE  = 'DEC'.
        LS_FIELDCAT-INTTYPE   = 'P'.
        LS_FIELDCAT-INTLEN    = '16' .
        LS_FIELDCAT-DECIMALS  = '03'.
        LS_FIELDCAT-JUST      = 'C'.
        APPEND LS_FIELDCAT TO LT_FIELDCAT.
      ENDLOOP.
    *& For grouping the table rows for Under Line
      LS_FIELDCAT-FIELDNAME = 'ULFIELD' .
      LS_FIELDCAT-DATATYPE  = 'INT'.
      LS_FIELDCAT-INTTYPE   = 'P'.
      LS_FIELDCAT-INTLEN    = '2' .
      LS_FIELDCAT-DECIMALS  = ''.
      APPEND LS_FIELDCAT TO LT_FIELDCAT.
      "* Create dynamic internal table and assign to Field-Symbol
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = LT_FIELDCAT
        IMPORTING
          EP_TABLE        = DYN_TABLE.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ASSIGN DYN_TABLE->* TO <LT_AREA_F>.
      "* Create dynamic work area and assign to Field Symbol
      CREATE DATA DYN_LINE LIKE LINE OF <LT_AREA_F>.
      ASSIGN DYN_LINE->* TO <LS_AREA_F>.
    You check in Field cat level you will get  Check Sub total field will exist
    Thanks and regards
    Jogu

  • Manipulate Layout on ALV Grid with dynamic table

    Dear all
    i'm generating a dynamic table depending of a date selection. That means that I show columns for weeks and the quantity of weeky migh change.
    Now the users wants to have a specific layout of the ALV grid with totals. When he saves the layout, only the weeks at this selection will show the next time he runs the programm with a larger selection.
    a) Is it possible to modify the layout during runtime by programming?
    b) Do you have any other ideas how to solve this problem?
    Thank you

    You don't know the names of your columns? hmm you do, because before you created dynamic table you had to create field catalog, so the structure and column names of newly (dynamically) created table will be the same like defined in the field catalog.
    The last loop also does not look good, in my opinion should be something like:
    LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
        AT NEW pernr.
          APPEND initial line to <fs_1> assigning <fs_2>.
          <fs_2>-pernr = <ls_data4>-pernr.
        ENDAT.
        ASSIGN COMPONENT <ls_data4>-wage_type OF STRUCTURE <fs_2> TO <fs_5>.
        <fs_5> = <ls_data4>-amount.
    ENDLOOP.
    also keep in mind that number of calls of method cl_alv_table_create=>create_dynamic_table is limited to 36 (?) calls within one program session because it uses dynamic subroutine pool behind so you will have short dump if you will execute that 37 times.

  • Show dynamic columns in ALV table

    I have a question that i need to create report in ALV
    like this ...
    i need to select doc date e.g. from 03.11.2007 to 05.02.2008
    and the report is expected to show like this
    SO#   |  cust |  sales gp | 2007-11 order amt | 2007-12 order amt | 2008-01 order amt | 2008-02 order amt
    ____ |_____|________|________________|________________|________________|_________________
              |         |               |                            |                            |                            | 
    something like that ....
    the no. of period column which is depend on the range of selected doc date....
    so how to do that ?!?!?

    hi sky ,
      use dynamic table as:-
      Declaration for Dynamic Table:-
    FIELD-SYMBOLS: <dyn_table>  TYPE STANDARD TABLE,
                   <dyn_table1> TYPE STANDARD TABLE,
                   <dyn_wa1>,
                   <dyn_wa>.
    FIELD-SYMBOLS: <l_fs_dyn> TYPE ANY,
                   <l_fs_bom> TYPE ANY.
    *---Dynamic Internal Table
    DATA: dy_table            TYPE REF TO data,
          dy_table1           TYPE REF TO data,
          dy_line             TYPE REF TO data.
    Creation of Dynamic Internal Table:-
      CALL METHOD cl_alv_table_create=>create_dynamic_table
           EXPORTING
             it_fieldcatalog = fcat  (for which internal table needs to be built)
           IMPORTING
             ep_table = dy_table
           EXCEPTIONS
             generate_subpool_dir_full = 1
             OTHERS = 2
      IF sy-subrc <> 0.
      ENDIF.
    Population of Dynamic Internal Table:-
    CLEAR: l_tabix,
           w_tabix.
      ASSIGN dy_table->* TO <dyn_table>.
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
      ASSIGN dy_table->* TO <dyn_table1>.
      CREATE DATA dy_line LIKE LINE OF <dyn_table1>.
      ASSIGN dy_line->* TO <dyn_wa1>.
       LOOP AT it_parent.
        l_tabix = sy-tabix.
        LOOP AT fcat INTO ls_fcat TO 23."WHERE col_pos <= '19'.
            ASSIGN COMPONENT ls_fcat-fieldname
                OF STRUCTURE <dyn_wa> TO <l_fs_dyn>.
            ASSIGN COMPONENT ls_fcat-fieldname
                OF STRUCTURE it_parent TO <l_fs_bom>.
            <l_fs_dyn> = <l_fs_bom>.
          ENDIF.
        ENDLOOP
    Thanks & Regards,
    Ruchi Tiwari

  • Dynamic ALV: but with globally available dynamic table type

    Hello,
    I would like to create a dynamic node for a ALV and dynamic table types to fill and the ALV.
    The ALV data can be changed so I need to read it again.
    I have read all the threads about dynamic node create and i have no problem with it. I can create a structure and a table dynamically. thats also no issue for me.
    But. I fill the ALV data in a method and read it in another method to save the changes in a data base table.
    Thats also no problem
    So where i need your help? I currently create the dynamic table and structure in both methods. That works, but why do the same thing twice?
    I cant figure out by myself how to create a dynamic table/structure in a global way, so the dynamic table/structure is created once and then available in the whole WD4A view.
    I tried is with a class type in se24 with reference to CL_ABAP_STRUCTDESCR but I cant make that run, because to access the type I created an attribute in se24 with reference to the class type that I now try in instance and fill in the method. But ABAP thinks that my attribute is not compatible anymore.
    Any idea how to make a dynamic table globally available? That must be an ABAP god who can answer this question, hehe. So imagin me falling on my knees for the one who has an answer that really works
    Kind regards,
    Hendrik

    This doesn't seem too difficult really. For a dynamic table you just need to declare the internal table as TYPE REF TO DATA.
    Just more this declaration to the attributes of your Component Controller. So for instance in my component controller I have an attribute called i_data with the RefTo column checked and the associated type = DATA.
    So now I could do the following:
      create data wd_this->idata type table of (tablename).
    Or however you are dynamically creating the table - maybe with TYPE HANDLE instead.
    The point is that your dynamic table is now global to your entire component and you can read and write to it from different methods.
    Is this what you were looking for?  Without knowing more about your existing coding, it is difficult to say more.

  • HR Logical database PNP. OO to fill table dynamic table  from PNP  ?

    Hi all
    I want to get some stuff from the HR logical database into a dynamic table
    Here's a real simple example that writes info out to a normal list.
    (report is based on using Logical DB PNP)
    tables: pernr.
    INFOTYPES: 0001,                     "Organizational Assignment
               0002.                     "Personal Data
    SELECT-OPTIONS: language FOR p0002-sprsl.
    INITIALIZATION.
      pnptimed = 'D'.
    GET pernr.
      PROVIDE * FROM p0002 BETWEEN pn-begda AND pn-endda.
        CHECK language.
        WRITE: / p0002-pernr,
                 sy-vline,
                 p0001-ename,
                 sy-vline,
                 p0002-sprsl,
                 sy-vline,
                 p0002-gbdat.
      ENDPROVIDE.
    endform.
    Now what I want to do is replace the write stuff by appending the entries into a dynamic table which I will display as an ALV Grid.
    so I add my structure in the data declarations
    types:  begin of s_elements,
       pernr  type  p0002-pernr,
       ename  type p0001-ename,
       sprsl  type p0002-sprsl,
       gbdat   type p0002-gbdat.
      drop_down_handle  type int4.
    types: end of    s_elements.
    include zz_jimbo_incl.
    build the dynamic table
    create data dref type s_elements.
      assign dref->* to <fs>.
      i_routine = 'POPULATE_DYNAMIC_ITAB'.*
    i_names   = 'NAME_COLUMNS'.
      i_gridtitle = 'HR  TEST'.
    invoker = sy-repid.
    i_zebra = 'X '.
    i_edit = '  '.
    call function 'ZZ_CALL_SCREEN'
         exporting
              invoker     = invoker
              my_line     = <fs>
              i_gridtitle = i_gridtitle
              i_edit      = i_edit
              i_zebra     = i_zebra
              i_names     = i_names
              i_routine   = i_routine
         importing
              z_object    = z_object
              dy_table    = dy_table.
    Now to populate the dynamic Itab the routine below is entered.
    form populate_dynamic_itab changing dy_table.
      assign dy_table->* to <dyn_table>.
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    However I can't use GET / PROVIDE / ENDPROVIDE in a Form.
    Anyway round this ---seems HR has an aversion to OO.
    Cheers
    jimbo

    Hi,
    well, GET_PERNR is a so called event_statement. It has nothing to do with ABAP 00.
    Normally it will be like this:
    START-OF-SELECTION.
    GET_PERNR.
    PROVIDE ....
    END-OF-SELECTION.
    -> and here the CALL SCREEN NNNN for ALV-Display.
    Provide-statements you can use in forms of course, and as many times you want during GET and END-OF-SELECTION.
    But as I understood : you just want to save the write-statements?
    I always develop a DDIC-Structure, declarate the data objects in the programm, read the data via Provide into the infotypes, and then make a move-corresponding to my structure. and display it.
    Normally no problem.
    kind regards
    maik

Maybe you are looking for