Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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.

Tags:
Former Member
replied

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

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question