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 internal table and work area

Former Member
0 Kudos

Hi,

I have a problem creating an internal table and work area at runtime:

My sample code is as follows:

&----


*& Report ZDKDDYNAMIC_TEST

*&

&----


*&

*&

&----


REPORT zdkddynamic_test.

TYPE-POOLS: abap.

TABLES:

zdk0005msgh_parm. " Parameters for the message handler

FIELD-SYMBOLS: <it_dyn_table> TYPE ANY TABLE.

FIELD-SYMBOLS: <wa_dyn_struc> TYPE ANY.

DATA:

wa_msgh_parm TYPE zdk0005msgh_parm.

DATA:

p_ident(4) TYPE n.

DATA:

struc_name TYPE abap_typename,

t_newtable TYPE REF TO data,

t_newline TYPE REF TO data.

START-OF-SELECTION.

p_ident = '0100'.

SELECT SINGLE *

INTO wa_msgh_parm

FROM zdk0005msgh_parm

WHERE id = p_ident.

struc_name = wa_msgh_parm-struct_name.

CREATE DATA t_newtable TYPE TABLE OF (struc_name).

ASSIGN t_newtable->* TO <it_dyn_table>.

CREATE DATA t_newline LIKE LINE OF <it_dyn_table>.

ASSIGN t_newline->* TO <wa_dyn_struc>.

SELECT *

FROM (struc_name)

INTO TABLE <it_dyn_table>.

END-OF-SELECTION.

When I try to select data to my <it_dyn_table> I get the following runtime error:

"SAPSQL_NO_DBTAB_OR_VIEW"

Hope that anyone can help,

Regards,

Morten

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

chk the below code and link.

very hlpful

REPORT zdynarjtry.

PARAMETERS: comp(80).

DATA: dref TYPE REF TO data.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE.

CREATE DATA dref TYPE TABLE OF (comp).

ASSIGN dref->* TO <dyn_table>.

SELECT * FROM (comp)

INTO TABLE <dyn_table>.

See the below links for more programs:-

http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html

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

<b>Reward points if useful</b>

Regards

AShu

4 REPLIES 4

Former Member
0 Kudos

hi,

chk the below code and link.

very hlpful

REPORT zdynarjtry.

PARAMETERS: comp(80).

DATA: dref TYPE REF TO data.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE.

CREATE DATA dref TYPE TABLE OF (comp).

ASSIGN dref->* TO <dyn_table>.

SELECT * FROM (comp)

INTO TABLE <dyn_table>.

See the below links for more programs:-

http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html

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

<b>Reward points if useful</b>

Regards

AShu

Former Member
0 Kudos

Hi

Use this code


*  FIELD-SYMBOLS: <fcat> TYPE lvc_s_fcat.
  data: wa_fcat like line of it_fcat.

  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_structure_name = in_tabname
    changing
      ct_fieldcat      = it_fcat
    exceptions
      others           = 1.
  if sy-subrc = 0.
    move: in_tabname to wa_fcat-tabname.
    modify it_fcat from wa_fcat transporting tabname where fieldname is
not initial.
  else.
    write: text-t01.
    leave program.
  endif.

*Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = it_fcat
    importing
      ep_table        = dy_table.

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

regards

Ravish Garg

<b>*reward if useful</b>

Former Member
0 Kudos

Hello,

Check this simple report.


PARAMETERS: P_COL1 TYPE I,
            P_COL2 TYPE I.
FIELD-SYMBOLS: <FS> TYPE ANY.
DATA: CHECK.
 
TYPES: BEGIN OF TYP_ITAB,
COL1 TYPE I,
COL2 TYPE I,
COL3 TYPE I,
COL4 TYPE I,
COL5 TYPE I,
COL6 TYPE I,
END OF TYP_ITAB.
DATA: ITAB TYPE TABLE OF TYP_ITAB, WA LIKE LINE OF ITAB.
 
WA-COL1 = 1.
WA-COL2 = 2.
WA-COL3 = 3.
WA-COL4 = 4.
WA-COL5 = 5.
WA-COL6 = 6.
 
APPEND WA TO ITAB.
WA-COL1 = 1.
WA-COL2 = 2.
WA-COL3 = 3.
WA-COL4 = 4.
WA-COL5 = 5.
WA-COL6 = 6.
 
APPEND WA TO ITAB.
 
DATA: COL1(20),
      COL2(20),
      CHAR,
      CHAR2.
WRITE P_COL1 TO CHAR.
CONCATENATE 'COL' CHAR INTO  COL1.
WRITE P_COL2 TO CHAR.
CONCATENATE 'COL' CHAR INTO  COL2.
*FIELD-SYMBOLS <F> TYPE ANY.
*ASSIGN (COL1) TO <F>.
DATA: BEGIN OF ITAB1 OCCURS 0,
 COL1 TYPE I,
COL2 TYPE I,
END OF ITAB1.
  FIELD-SYMBOLS: <FS1> TYPE ANY,
                 <FS2> TYPE ANY.
  DATA: VAR TYPE I.
 
LOOP AT ITAB ASSIGNING <FS>.
 
 
*  IF SY-TABIX = 1.
  ASSIGN COMPONENT COL1 OF STRUCTURE <FS> TO <FS1>.
*  ELSE.
  ASSIGN COMPONENT COL2 OF STRUCTURE <FS> TO <FS2>.
*  ENDIF.
 
*  APPEND <FS1> TO ITAB1.
  MOVE <FS1> TO ITAB1-COL1.
  MOVE <FS2> TO ITAB1-COL2.
  APPEND ITAB1.
*  WRITE:/  <FS1>,<FS2>.
ENDLOOP.
 
LOOP AT ITAB1.
  WRITE:/ ITAB1-COL1, ITAB1-COL2.
ENDLOOP.



Vasanth 

varma_narayana
Active Contributor
0 Kudos

Hi...

In the query below

SELECT *

FROM (struc_name)

INTO TABLE <it_dyn_table>.

The <b>struc_name</b> should contain an Existing DB talbe or View name.

Otherwise you will get the error SAPSQL_NO_DBTAB_OR_VIEW.

So you can check this in Table - DD02L (WHERE TABLES AND VIEWS ARE STORED) Before the query.

<b>SELECT SINGLE TABNAME FROM DD02L INTO STRUC_NAME

WHERE TABNAME = STRUC_NAME.

IF SY-SUBRC = 0.

SELECT *

FROM (struc_name)

INTO TABLE <it_dyn_table>.

ENDIF.</b>

<b>Reward if Helpful</b>