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

Former Member
0 Kudos

Hi...

"CL_ANY_TABLE_MM"

Somebody already use this class...??? How does it work...??

Thank's...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Flavio,

Look at this class CL_ALV_TABLE_CREATE.

Also clearly state, what you would like to do?

Probably we can help you then a little better.

Regards,

Subramanian V.

17 REPLIES 17

Former Member
0 Kudos

Hi Flavio,

Look at this class CL_ALV_TABLE_CREATE.

Also clearly state, what you would like to do?

Probably we can help you then a little better.

Regards,

Subramanian V.

0 Kudos

Hi...

I'm trying to build a function to create dynamic tables with a reference to DDIC fields, and use in dynamic reports...

Can you help me...???

0 Kudos

Hi Flavio,

Since you would like to "<i>create dynamic tables with a reference to DDIC fields and use in dynamic reports</i>", I assume that you would like to create dynamic internal tables.

Dynamic internal tables can be created using <b>CL_ALV_TABLE_CREATE</b> class and method CREATE_DYNAMIC_TABLE.

Just fill the field catalog(<b>IT_FIELDCATALOG</b>) in the parameter of method (like you do in normal ALV reports) and it creates a pointer to dynamic data table.

Let us know if this has been useful or you were looking at some other aspect.

Regards,

Subramanian V.

0 Kudos

It's just this...

I did but using the "cl_alv_table_create=>create_dynamic_table" method...

My doubt now is how to access a field in this table, like using the WRITE command... Do you know how...???

0 Kudos

Hi Flavio,

I wrote a small program and I hope everything is clear from that. ( I had no idea about data references and field-symbols before writing this program ).

<b>Assumption</b>: Structure of the dynamic table should be known before hand.(At least in this program, I am not sure how to do it otherwise. Probably the FIELD-SYMBOL stud programmers can help us out).


report  ytest.
data: lt_fieldcatalog type lvc_t_fcat.
data: ls_fieldcatalog type lvc_s_fcat.
field-symbols: <fs_data> type ref to data.
field-symbols: <fs_1>.
field-symbols: <fs_2> type any table.
field-symbols: <fs_3> type ypoll.


data: lt_data type ref to data.

assign lt_data to <fs_data>.

ls_fieldcatalog-fieldname = 'MANDT'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'POLLID'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'TEAM'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATOR'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'DESCRIPTION'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'APPROVED'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATED_DATE'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'END_DATE'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'WINNER'.
ls_fieldcatalog-tabname   = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.


call method cl_alv_table_create=>create_dynamic_table
  exporting
    it_fieldcatalog           = lt_fieldcatalog
  importing
    ep_table                  = <fs_data>
  exceptions
    generate_subpool_dir_full = 1
    others                    = 2
        .
if sy-subrc <> 0.
endif.

assign <fs_data>->* to <fs_1>.
assign <fs_1> to <fs_2>.

loop at <fs_2> assigning <fs_3>.
  write: <fs_3>-pollid.
endloop.

Let me know if this helps you.

Regards,

Subramanian V.

0 Kudos

Hi Flavio,

You had some good answers. Did they help? Could you assign points? It's a way to say "thanks" for the effort in the replies.

See: <u>/people/mark.finnern/blog/2004/08/10/spread-the-love for directions.

Click on the Yellow Star icon in each reply.

You can give:

1 - 10 pointer (marks it as a solved problem)

2 - 6 pointers (very helpful)

Lots of 2 pointers (helpful)

Cheers,

Joan (and Mark Finnern)

0 Kudos

Hi... Your code almost reach my solution... The problem that you point (don't know the fields that I want): Just it I do not want! I do this and it works fine to me:


REPORT ytrab03.

TABLES: mara, makt.

TYPE-POOLS: slis.

DATA: it_fcat   TYPE slis_t_fieldcat_alv,
      is_fcat   LIKE LINE OF it_fcat,
      ls_layout TYPE slis_layout_alv.

DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table      TYPE REF TO data,
      new_line       TYPE REF TO data,
      ob_cont_alv    TYPE REF TO cl_gui_custom_container,
      ob_alv         TYPE REF TO cl_gui_alv_grid,
      vg_campos(255) TYPE c,
      i_campos       LIKE TABLE OF vg_campos,
      vg_campo(30)   TYPE c,
      vg_tables(60)  TYPE c.

DATA: e_params LIKE zutsvga_alv_01.

FIELD-SYMBOLS: <l_table> TYPE table,
               <l_line>  TYPE ANY,
               <l_field> TYPE ANY.

PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

is_fcat-fieldname     = 'COL01'.
is_fcat-ref_fieldname = 'MATNR'.
is_fcat-ref_tabname   = 'MARA'.
APPEND is_fcat TO it_fcat.
is_fcat-fieldname     = 'COL02'.
is_fcat-ref_fieldname = 'MAKTX'.
is_fcat-ref_tabname   = 'MAKT'.
APPEND is_fcat TO it_fcat.

LOOP AT it_fcat INTO is_fcat.
  is_fieldcat-fieldname = is_fcat-fieldname.
  is_fieldcat-ref_field = is_fcat-ref_fieldname.
  is_fieldcat-ref_table = is_fcat-ref_tabname.
  APPEND is_fieldcat TO it_fieldcat.
  CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field
  INTO vg_campos SEPARATED BY '~'.
  APPEND vg_campos TO i_campos.
ENDLOOP.

*... Create the dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
 EXPORTING
   it_fieldcatalog = it_fieldcat
 IMPORTING
   ep_table        = new_table.

*... Create a new line
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.

SELECT (i_campos) FROM mara INNER JOIN makt
  ON mara~matnr = makt~matnr
  UP TO p_max ROWS
  INTO TABLE <l_table>.

LOOP AT <l_table> INTO <l_line>.

  LOOP AT  it_fcat INTO is_fcat.
    ASSIGN COMPONENT is_fcat-fieldname
           OF STRUCTURE <l_line> TO <l_field>.
    IF sy-tabix = 1.
      WRITE: /2 <l_field>.
    ELSE.
      WRITE: <l_field>.
    ENDIF.
  ENDLOOP.

ENDLOOP.

You help so much.. Thank's 4all...!!!

0 Kudos

Hi Flavio,

Amazing piece of code. That last bit, I think you deserve a pat for that. I couldn't think of using that field symbol for structure and thought one requires the structure type.


ASSIGN COMPONENT is_fcat-fieldname OF STRUCTURE <l_line> TO <l_field>.

Thank you very very much for sharing your code with us. I am glad, I could be of help to you.

Regards,

Subramanian V.

0 Kudos

There was a session at this year's TechEd that taught how to do just this - ABAP351 Advanced and Generic Programming. This session was taught on WAS 6.40 and I think some parts are only available on 6.40.

You can get the handouts from SAP's TechED website. There are two handouts, one has the slides and another with the code samples from the hands on examples.

Hope this helps,

Jerrod Baldauf

Former Member
0 Kudos

Hi Friends,

I need to create an Internal table at Run time...I was this discussion and crted an Internal Table. But there seems to be some limitation with this calss and method cl_alv_table_create=>create_dynamic_table . It can create only 36 subroutine pools and if by any chance the number of calls to this methods in the program exceeds 36 times...or your program gets called more than 36 times where this routione may be present only once thjen it throws a dump.

There is an OSS note regarding the error shown in the dump - 'GENERATE_SUBPOOL_DIR_FULL' (OSS505644).

Is there any other way of cretion of Dynamic tables...My table is not reference in the DDIC and is absolutely Local with respect to the program.

hence I am struck with this problem...The only way to ensutre problem doesnot occur is to ensure the calls dodnot exceed more than 36 times.

How can this be ensured or is there any other way of creation of Dynamic Internal Tables.

Regards,

Arunava

0 Kudos

The problem <b>does not lie</b> with the <b>creation of dynamic internal table</b>, but the <b>problem lies</b> with <b>generation of sub-routines</b>.

Subramanian V.

0 Kudos

Please refer to to see how to get around the 36 generation limit.

Cheers,

Scott

Former Member
0 Kudos

yes but these generation is happening inside a dynamic subroutine pool.

Regards

Venkat

Former Member
0 Kudos

Flavio,

If you haven't yet discovered how to address creating a dynamic table at runtime you should research the following class. CL_RS_STRUC. This class allows you to build a structure of your choosing at run time. You can then use the create data statement to build a table around that structure type.

Follow the example below:

data:

l_r_struc type ref to cl_rs_struc,

l_ref type ref to data.

field-symbols:

<line> type any,

<table> type standard table.

  • First create the object

create object l_r_struc.

  • Then add the elements to your structure as necessary

call method l_r_struc->add_element

exporting

i_sconame = "INSERT HERE

i_type = "INSERT HERE.

  • Add any additional elements

call method l_r_struc->add_element

exporting

i_sconame = "INSERT HERE

i_type = "INSERT HERE.

call method l_r_struc->create

exporting

i_dynamic = rs_c_false

receiving

r_r_data = l_ref

exceptions

wrong_struc_definition = 1

no_struc_definition = 2

others = 3.

assign l_ref->* to <line>.

create data l_ref like table of <line>.

assign l_ref->* to <table>.

Hope this helps....

Cheers,

Scott

Former Member
0 Kudos

Hello,

I want to create dynamic internal table but that in 4.5B , does anybody have anything on this?

Regards

Former Member
0 Kudos

Hi All,

If you want to create a dynamic table at run-time based on the table name passed, here is the answer!.

"p_tabname" is the table name passed.

Finally , <itab>[] would contain the structure and data of the table passed.

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <fcat> TYPE lvc_s_fcat.

FIELD-SYMBOLS: <ffield> TYPE lvc_s_fcat.

DATA: it_fcat TYPE lvc_t_fcat.

DATA: it_content TYPE REF TO data.

  • Table Fields, For Header Line in Download File.

TYPES: BEGIN OF ty_f,

fields type dd03l-FIELDNAME,

END OF ty_f.

DATA: it_fields TYPE STANDARD TABLE OF ty_f WITH HEADER LINE.

  • Get the table fields first

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = p_tabname

CHANGING

ct_fieldcat = it_fcat

EXCEPTIONS

OTHERS = 1.

IF sy-subrc = 0.

  • Complete field catalog

LOOP AT it_fcat ASSIGNING <fcat>.

<fcat>-tabname = p_tabname.

ENDLOOP.

  • Copy the table fields into it_fields.

LOOP AT it_fcat ASSIGNING <ffield>.

it_fields-fields = <ffield>-fieldname.

APPEND it_fields.

ENDLOOP.

CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'

CHANGING

ct_fieldcat = it_fcat

EXCEPTIONS

OTHERS = 1.

ELSE.

WRITE: text-e04. "Error building field catalog.

STOP.

ENDIF.

  • Create Dynamic Table for table dynamically

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat

IMPORTING

ep_table = it_content.

IF sy-subrc = 0.

ASSIGN it_content->* TO <itab>.

ELSE.

WRITE: text-e03. "Error creating internal table.

STOP.

ENDIF.

  • Select all the data from the table.

SELECT * FROM (p_tabname) INTO TABLE <itab> WHERE mandt = sy-mandt.

CHECK NOT <itab>[] is initial.

Hope this helps!.

Cheers,

Nameeth

Former Member
0 Kudos

Hi friends,

I'm facing new requirement here, i wanna to create function to read join table with tablename, tablefields, join conditions and where condition as table parameter.

ex : tablename : MARA,MAKT

tablefields : MARA~MATNR,

MARA~MTART,

MAKT~MATNR,

MAKT~MAKTX

join condition : MARAMATNR EQ MAKTMATNR

where condition : MAKT~SPRAS EQ 'E'

But there's a problem with FROM (dbtabname)clause and it makes me can not use [INNER] JOIN Clause.

So i have to read for each table and i use dynamic internal table(many thanx for all nice codes above)

it works..

DATA: new_table TYPE REF TO data,

...

*... Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

*... Create a new line

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

LOOP AT i_data

DO v_lines TIMES.

CLEAR v_index.

ADD sy-index TO v_index.

READ TABLE i_fields INDEX v_index.

IF sy-subrc EQ 0.

ASSIGN COMPONENT i_fields-fieldname OF STRUCTURE <l_line> TO

<l_field>.

READ TABLE i_split INDEX v_index.

IF sy-subrc EQ 0.

<l_field> = i_split-word.

ENDIF.

ENDIF.

ENDDO.

INSERT <l_line> INTO TABLE <l_table>.

ENDLOOP.

Untill here, i wanna to create dynamic field-symbol/intab to take data from <l_table> in depend on the name of each tablename,

like <l_mara> with MATNR and MTART fields header, <l_makt> with MATNR and MAKTX fields header, and last <l_join> with MATNR,MTART,MAKTX fields header.

Please help me.. Thank's

Regards,

Tjien