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

internal table

Former Member
0 Likes
622

wat is dynamic internal table?

wat is the use?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
572

Dynamic Internal table: The internal table you create during the runtime. Here you will know the field names only during the runtime.

Use : Let us consider a example that. You want to know the monthly value of the sales. The output should contain the material, <month_value>, <month_Qty>. Here the month ranges according to the input given by the user.. Let us consider from 01/2007 to 08/2007. Then your report should contain Material/ and 16 more fields.. If the user gives the input as 01/2007 to 02/2007 Then your report should contain Material/ and only 4 more fields.

In this case we go for the Dynamic internal table.

Just go thro the link to construct the dynamic internal table.

http://www.sap-img.com/ab030.htm

Regards

Rusidar S

5 REPLIES 5
Read only

Former Member
0 Likes
572

Creating the internal table at run time is called dynamic internal table

If you only know the fields at run time , then you cannot declare the internal table statically.. you have to go for dynamic internal table

also chk this

http://www.sap-img.com/ab030.htm

Message was edited by:

Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
572

Hi,

If you want to create a Internal table at runtime it is called a Dynamic internal table, some times we do not know how many fields will have a internal table, so at that time we can create a Dynamic internal table

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

Regards

Sudheer

Read only

Former Member
0 Likes
572

Hi Sheik,

Go through this program. we can understand clearly.

TABLES : tadir. " table in which the obj_name field stores all the

" database table names

TYPE-POOLS : slis.

TYPES ztab LIKE dcobjdef-name .

DATA : dyntab LIKE dntab OCCURS 0 WITH HEADER LINE,

dref TYPE REF TO data,

i_fcat TYPE lvc_t_fcat ,

wa_fcat TYPE lvc_s_fcat ,

w_pgm LIKE sy-repid,

count TYPE i VALUE 0,

w_obj_name LIKE tadir-obj_name.

DATA : wa_fieldcat TYPE slis_fieldcat_alv, "ALV FIELD CATALOG TABLE

i_fieldcat TYPE slis_t_fieldcat_alv, "ALV FIELD CATALOG STRUCTURE

i_event TYPE slis_t_event, "ALV EVENT HANDLING TABLE

wa_event TYPE slis_alv_event, "ALV EVENT HANDLING STRUCT

i_listheader TYPE slis_t_listheader, "ALV LIST HEADER TABLE

wa_listheader TYPE slis_listheader, "ALV LIST HEADER STRUCT

i_layout TYPE slis_layout_alv.

FIELD-SYMBOLS :<newtab> TYPE table.

INITIALIZATION.

w_pgm = sy-repid.

****************SELECTION-SCREEN 2000

SELECTION-SCREEN BEGIN OF SCREEN 2000 AS WINDOW.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE tit1.

PARAMETERS: tab_name TYPE ztab . " Enter database table name

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 2000.

***************END OF SELECTION-SCREEN 2000

tit1 = 'Enter Table Name?'.

START-OF-SELECTION.

CALL SELECTION-SCREEN 2000 STARTING AT 10 10.

PERFORM occurcheck.

*********CHECKING WHETHER THE DATABASE TABLE EXISTS

FORM occurcheck.

SELECT obj_name FROM tadir INTO w_obj_name WHERE obj_name = tab_name.

ENDSELECT.

IF sy-subrc <> 0.

MESSAGE i003."Table not found in the database .

CALL SELECTION-SCREEN 2000 STARTING AT 10 10.

PERFORM occurcheck.

ELSE.

PERFORM startprocess.

EXIT.

ENDIF.

ENDFORM.

**********GETTING THE FIELD NAMES OF THE INPUT DATABASE TABLE

FORM startprocess.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

langu = sy-langu

tabname = tab_name

TABLES

nametab = dyntab. "dntab now contains the field names

**********FILLING THE CATALOG OF NEW DYNAMIC INTERNAL TABLE

LOOP AT dyntab.

wa_fcat-fieldname = dyntab-fieldname.

wa_fcat-ref_field = dyntab-fieldname.

wa_fcat-ref_table = dyntab-tabname.

APPEND wa_fcat TO i_fcat .

ENDLOOP.

***********CREATING A POINTER (FIELD SYMBOL) TO THE INTERNAL TABLE

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_fcat

IMPORTING

ep_table = dref.

ASSIGN dref->* TO <newtab>.

SELECT * FROM (dyntab-tabname) INTO TABLE <newtab>.

**********CHECKING WHETHER DATA HAS BEEN UPLOADED.

DESCRIBE TABLE <newtab> LINES sy-tfill.

DESCRIBE TABLE <newtab> LINES count.

IF sy-tfill = 0 .

MESSAGE i001. "Internal table is not filled

ELSE.

MESSAGE i002 WITH count. "Internal table is filled

ENDIF.

****************EVENTS USED IN ALV

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0 " 0-simple list, 1-hierarchial list.

IMPORTING

et_events = i_event.

SORT i_event.

READ TABLE i_event

WITH KEY name = slis_ev_top_of_page "TOP_OF_PAGE event

INTO wa_event.

IF sy-subrc = 0.

MOVE 'IAM_TOP_OF_PAGE' TO wa_event-form. "IAM_TOP_OF_PAGE will

"call subroutine automatically

MODIFY i_event FROM wa_event INDEX sy-tabix.

ENDIF.

****************DISPLAYING ALV.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = w_pgm

i_structure_name = dyntab-tabname

it_events = i_event

TABLES

t_outtab = <newtab>.

ENDFORM.

**********FORM TOP_OF-PAGE.

******FILLING OF LIST HEADER TABLE

FORM iam_top_of_page.

CLEAR wa_listheader.

wa_listheader-typ = 'H'. "HEADING

wa_listheader-info = 'ALV CREATED DYNAMICALLY'.

APPEND wa_listheader TO i_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'S'. "SUB-HEADING

wa_listheader-key = 'PGM NAME:'.

wa_listheader-info = w_pgm.

APPEND wa_listheader TO i_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'S'.

wa_listheader-key = 'USER:'.

wa_listheader-info = sy-uname.

APPEND wa_listheader TO i_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'S'.

wa_listheader-key = 'DATE:'.

wa_listheader-info = sy-datum.

APPEND wa_listheader TO i_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'S'.

wa_listheader-key = 'TABLE NAME:'.

wa_listheader-info = dyntab-tabname.

APPEND wa_listheader TO i_listheader.

********FUNCTION TO WRITE THE TITLE AND SUB-TITLE OF THE ALV.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = i_listheader.

ENDFORM.

*********Rewards some points.

Rgds,

P.Naganjana Reddy

Read only

Former Member
0 Likes
572

Hi Sheik Rahimul,

Check this info.

REPORT zcdf_dynamic_table.

  • Dynamic ALV Grid with Cell Coloring.

  • Build a field catalog dynamically and provide the ability to color

  • the cells.

  • To test, copy this code to any program name and create screen 100

  • as described in the comments. After the screen is displayed, hit

  • enter to exit the screen.

  • Tested in 4.6C and 6.20

  • Charles Folwell - cfolwell@csc.com - Feb 2, 2005

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. The ALV call needs a fieldcatalog without

  • the internal table for cell coloring.

t_fieldcat2[] = t_fieldcat1[].

  • Add cell color table.

  • CALENDAR_TYPE is a structure in the dictionary with a

  • field called COLTAB of type LVC_T_SCOL. You can use

  • any structure and field that has the type LVC_T_SCOL.

wa_fieldcat-fieldname = 'T_CELLCOLORS'.

wa_fieldcat-ref_field = 'COLTAB'.

wa_fieldcat-ref_table = 'CALENDAR_TYPE'.

APPEND wa_fieldcat TO t_fieldcat1.

  • Create dynamic table including the internal table

  • for cell coloring.

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

  • Get access to internal table used to color cells.

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.

  • Display screen. Define screen 100 as empty, with next screen

  • set to 0 and flow logic of:

*

  • PROCESS BEFORE OUTPUT.

  • MODULE initialization.

*

  • PROCESS AFTER INPUT.

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 for cell coloring table.

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

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

Read only

Former Member
0 Likes
573

Dynamic Internal table: The internal table you create during the runtime. Here you will know the field names only during the runtime.

Use : Let us consider a example that. You want to know the monthly value of the sales. The output should contain the material, <month_value>, <month_Qty>. Here the month ranges according to the input given by the user.. Let us consider from 01/2007 to 08/2007. Then your report should contain Material/ and 16 more fields.. If the user gives the input as 01/2007 to 02/2007 Then your report should contain Material/ and only 4 more fields.

In this case we go for the Dynamic internal table.

Just go thro the link to construct the dynamic internal table.

http://www.sap-img.com/ab030.htm

Regards

Rusidar S