Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Table - Deep Structure

0 Kudos

Hi Gurus,

this is my first posting, so be patient!

I want to create a deep structure dynamic table via method

cl_alv_table_create=>create_dynamic_table, is this possible? Are there tricks to make it happen?

Background: i wanna create an alv with dynamic fieldcatalalog, in this case i want to colour special fields, which is done by lvc_s_layo-?csp_fieldname? in combination with a field in my internal table which is typed ?lvc_t_scol?. Is this possible under 6.2.43

thanxs for your replies

juergen

- ?i dont actually know by rote the correct fieldnames of lvc_xxxxx?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Look if this weblog gives you any help for creating a deep structure dynamic table. If you are successful, do let us know. I am quite eager to find out how you did and the venture looks interesting.

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

Subramanian v.

7 REPLIES 7

ssimsekler
Active Contributor
0 Kudos

Hi Jürgen

At the end if you aim to build an ALV Grid list, I could not understand your requirement to have a dynamic field catalog. That is because, field catalog holds metadata and its structure is predefined. You can change its contents and reflect it to your ALV Grid (using the method "set_frontend_fieldcatalog") at any instance of runtime.

If your requirement is to create your data table dynamically, then it is insignificant whether you can create a deep-structured internal table since ALV Grid does only support flat structured (except special style table usage) data tables.

Hope I have understood your question right...

*--Serdar

Former Member
0 Kudos

Have you tried building a field catalog to pass to method create_dynamic_table, setting the last field to dictionary type lvc_t_scol? If so, did you get an error?

If this works, you will need a field catalog without this field to pass to your ALV call.

Let us know how it goes.

Former Member
0 Kudos

Look if this weblog gives you any help for creating a deep structure dynamic table. If you are successful, do let us know. I am quite eager to find out how you did and the venture looks interesting.

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

Subramanian v.

0 Kudos

Hi,

the purpose of the program is just to count different values.

The user can decide which values by filling a select-options on the selection screen, there are ~2000 different values possible, mostly there are 5 to 10 relevant

the values can be active or inactive

the user can decide what he wants to count

-> so i build up a fieldcatalog with the deranged select-options like it's described in the very interesting weblog of Subramanian,

then i create the table dynamically with the fieldcatalog,

then i count,

then i pass the data to REUSE_ALV_GRID with the fieldcatalog,

all that workes fine,

now i wonder if i coud colour fields like i described above,

looks like i can't put the colour table field into the dynamic table

overall it's just to know what's possible.

thank you for your input

Jürgen

0 Kudos

To know about colouring individual cells, I suggest you refer to this tutorial authored by Serdar Simsekler. An excellent tutorial, referred almost daily.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an easy reference for alv grid control.pdf

Regards,

Subramanian V.

0 Kudos

Hi Jurgen, I took on the challenge. This program provides a dynamic table with the ability to set the colors of the cells.

Create the structure ZCDF_CELL_COLOR in the dictionary as described in the program.

Create screen 100 as empty, with next screen set to 0, and the following flow logic:

PROCESS BEFORE OUTPUT.
  MODULE initialization.

PROCESS AFTER INPUT.

REPORT  zcdf_dynamic_table.

* Dynamic ALV Grid with Cell Coloring

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.

  t_fieldcat2[] = t_fieldcat1[].

* Add cell color table.
*  ZCDF_CELL_COLOR is a structure in the 
*   dictionary with one
*   field called T_CELL_COLOR of type LVC_T_SCOL.

  wa_fieldcat-fieldname = 'T_CELLCOLORS'.
  wa_fieldcat-ref_field = 'T_CELL_COLOR'.
  wa_fieldcat-ref_table = 'ZCDF_CELL_COLOR'.

  APPEND wa_fieldcat TO t_fieldcat1.

* Create dynamic table.

  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>.

    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.

  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.

    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.     "grids 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

0 Kudos

Hi Charles,

chapeau! and all respect,

this is the solution,

i didn't use an own structure for the color table, there are many SAPones in my system

thank you