Application Development and Automation 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: 
Read only

Dynamic Internal Tables

Former Member
0 Likes
728

Hi everybody,

I have a report in PS, in which based on the project I need to increase the number of columns. Thst is, I have to display the sheduled date, start date & its description under the porject name in one column. If the project is new , then I have to display the detailes in a new column. It may have n number of projects. How to do? Is it possible?

Thanks.

G.Vijayakumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
699

Hi Vijay,

Follow the steps to create a dynamic table.

1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE. Add more rows to the field catalog table (T_FIELDCAT) at run time.

2. Use the field catalog to create a table dynamically using the method below.

DATA: T_OUTPUT TYPE REF TO DATA

FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE

Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE

Exporting

IT_FIELDCATALOG = T_FIELDCAT

Importing

EP_TABLE = T_OUTPUT

ASSIGN T_OUTPUT->* TO <T_OUTPUT>.

Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime. Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.

Here is an example.


* the content of itab will be fields of the new table
loop at itab1 into wa1.
  Gs_FIELDCAT-TABNAME     = 'itab2'.
  GS_FIELDCAT-FIELDNAME = wa1-packid.
  GS_FIELDCAT-OUTPUTLEN = 2.
  GS_FIELDCAT-KEY         = space.
  GS_FIELDCAT-SELTEXT_L = wa1-packid.
  GS_FIELDCAT-COL_POS     =  1.
  GS_FIELDCAT-JUST        = 'L'.

  APPEND GS_FIELDCAT TO GT_FIELDCAT.
endloop.

LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.

    MOVE-CORRESPONDING GS_FIELDCAT TO ls_fcat.

    APPEND ls_fcat TO lt_fieldcat.

  ENDLOOP.



CALL METHOD cl_alv_table_create=>create_dynamic_table

                     EXPORTING it_fieldcatalog = lt_fieldcat

                     IMPORTING ep_table = t_output.

I hope this helps.

Regards,

Kinshuk

5 REPLIES 5
Read only

Former Member
0 Likes
699

Take a look at these weblogs which talk about dynamic internal tables

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

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

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Regards,

Ravi

Note : Please mark the helpful answers

Read only

hymavathi_oruganti
Active Contributor
0 Likes
699

to build a dynamic internal table,

see the following exmaple

suppose itab has fields A, B, C.

SO ITAB-C HAS THE VALUES OF C. NOW WE WANT A TABLE WITH VALUES OF C RIGHT!!.

NOW BUILD A FIELDCATALOG LIKE BELOW.

LOOP AT ITAB.

LS_FIELDCAT-FIELDNAME = ITAB-C.

LS_FIELDCAT-COL_TEXT = ITAB_C.

APPEND LS_FIELDCAT TO LT_FIELDCAT.

ENDLOOP.

DATA: DREF TYPE REF TO DATA.

FIELD-SYMBOLS: <TEMP_TAB> TYPE ANY.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVCFIELDCAT

IMPORTING

EP_TABLE = DREF.

ASSIGN dref->* TO <TEMP_TAB>.

<TEMP_TAB> IS THE REQUIRED DYNAMIC INTERNAL TABLE.

NOW IF U WANT TO FILL THE DYNAMIC INTERNAL TABLE.

DO AS BELOW..

DATA: WA_DREF TYPE REF TO DATA.

FIELD-SYMBOLS: <WA_TAB> TYPE ANY.

CREATE DATA WA_DREF LIKE LINE OF <TEMP_TAB>.

ASSIGN WA_DREF->* TO <WA_TAB>.

FIELD-SYMBOLS: <FS1>, <FS2>.

LOOP AT ITAB.

ASSIGN COMPONENT ITAB-C OF STRUCTURE <WA_TAB> TO <FS1>.

<FS1> = {SOME VALUE}.

APPEND <WA_TAB> TO <TEMP_TAB>.

ENDLOOP.

Read only

Former Member
0 Likes
699

Hi Vijaykumar,

follow these steps to create dynamic internal tables.

1. Declare an internal table (say lt_fcat) of type lvc_t_fcat.

2. populate lt_fcat with the information about the fields you want in your dynamic internal table.

3. declare a data reference fo type data (say lt_xtab).

4. call the following method:

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fcat

IMPORTING

ep_table = lt_xtab

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

5. Declare a field symbol <FS> and use the following statement :

ASSIGN LT_XTAB->* TO <FS>.

Now you can use the field symbol <FS> as an internal table with that many fields, as many records were there in lt_fcat.

Hope this solves your problem.

Rgds,

Deb.

Read only

Former Member
0 Likes
699

Hi Vijaykumar,

try this..

=====================================

REPORT zmaschl_create_data_dynamic .

TYPE-POOLS: slis.

DATA: it_fcat TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

  • Build fieldcat

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SYST'

CHANGING

ct_fieldcat = it_fcat[].

LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.

MOVE-CORRESPONDING is_fcat TO is_fieldcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

ENDLOOP.

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

  • Test it...

DO 30 TIMES.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

<l_field> = sy-index.

INSERT <l_line> INTO TABLE <l_table>.

ENDDO.

LOOP AT <l_table> ASSIGNING <l_line>.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

WRITE <l_field>.

ENDLOOP.

Change the fields as per your requirement.

Regards,

Mukesh Kumar

Read only

Former Member
0 Likes
700

Hi Vijay,

Follow the steps to create a dynamic table.

1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE. Add more rows to the field catalog table (T_FIELDCAT) at run time.

2. Use the field catalog to create a table dynamically using the method below.

DATA: T_OUTPUT TYPE REF TO DATA

FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE

Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE

Exporting

IT_FIELDCATALOG = T_FIELDCAT

Importing

EP_TABLE = T_OUTPUT

ASSIGN T_OUTPUT->* TO <T_OUTPUT>.

Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime. Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.

Here is an example.


* the content of itab will be fields of the new table
loop at itab1 into wa1.
  Gs_FIELDCAT-TABNAME     = 'itab2'.
  GS_FIELDCAT-FIELDNAME = wa1-packid.
  GS_FIELDCAT-OUTPUTLEN = 2.
  GS_FIELDCAT-KEY         = space.
  GS_FIELDCAT-SELTEXT_L = wa1-packid.
  GS_FIELDCAT-COL_POS     =  1.
  GS_FIELDCAT-JUST        = 'L'.

  APPEND GS_FIELDCAT TO GT_FIELDCAT.
endloop.

LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.

    MOVE-CORRESPONDING GS_FIELDCAT TO ls_fcat.

    APPEND ls_fcat TO lt_fieldcat.

  ENDLOOP.



CALL METHOD cl_alv_table_create=>create_dynamic_table

                     EXPORTING it_fieldcatalog = lt_fieldcat

                     IMPORTING ep_table = t_output.

I hope this helps.

Regards,

Kinshuk