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 table declaration

Former Member
0 Likes
373

Hi

Is it possible to declare same internal table with different type of?, let me explain, I need to show data depends on interface name which users select, for example:

I have two interfaces, ZA and ZB ; if user select interface ZA I must declare one control and one detail internal table.

IF p_intf = 'ZA'.
    DATA: BEGIN OF it_output OCCURS 0.                          INCLUDE STRUCTURE zintf01.
    DATA:   sele(1),
          END OF it_output.

    DATA: BEGIN OF it_output_ctrl OCCURS 0.          
            INCLUDE STRUCTURE zintf01_ctrl.
    DATA:   name(1),
          END OF it_output_ctrl.

ELSEIF p_intf  = 'ZB'.
    DATA: BEGIN OF it_output OCCURS 0.                          INCLUDE STRUCTURE zintf02.
    DATA:   sele(1),
          END OF it_output.

    DATA: BEGIN OF it_output_ctrl OCCURS 0.          
            INCLUDE STRUCTURE zintf02_ctrl.
    DATA:   name(1),
          END OF it_output_ctrl.
ENDIF.

Thanks in advance.

2 REPLIES 2
Read only

Pawan_Kesari
Active Contributor
0 Likes
346

defining internal table dynamically is possible but not in this way.. on of the ways in which it can be done is using field-symbol and method cl_alv_table_create=create_dynamic_table.

see a sample code below



*** Tables
DATA: LT_DATA type ref to DATA.
DATA: LT_FIELDCATALOG type LVC_T_FCAT.

*** Structure
DATA: LS_FIELDCATALOG type LVC_S_FCAT.

*** Data References
DATA: NEW_LINE type ref to data.

*** Field Symbols
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
               <FS_1> type any table,
               <FS_2>,
               <FS_3>.



LS_FIELDCATALOG-FIELDNAME = 'MANDT'. 
append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname
LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character
append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CONNID'.
LS_FIELDCATALOG-INTTYPE = 'N'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.
LS_FIELDCATALOG-INTTYPE = 'D'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'PRICE'.
LS_FIELDCATALOG-INTTYPE = 'P'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.
LS_FIELDCATALOG-INTTYPE = 'C'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.


assign LT_DATA to <FS_DATA>.


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.



*** So <FS_1> now points to our dynamic internal table.

assign <FS_DATA>->* to <FS_1>.

*** Next step is to create a work area for our dynamic internal table.

create data NEW_LINE like line of <FS_1>.

*** A field-symbol to access that work area
assign NEW_LINE->*  to <FS_2>.

*** And to put the data in the internal table
select MANDT CARRID CONNID FLDATE PRICE CURRENCY
  from SFLIGHT
  into corresponding fields of table <FS_1>.

*** Access contents of internal table
loop at <FS_1> assigning <FS_2>.

assign component 1 of structure <FS_2> to <FS_3>.
write: / <FS_3>.
endloop.

this might give you some idea about dynamic internal tables

Read only

0 Likes
346

Thanks Pawan, I will check it.