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

declaring data type dynamically

Former Member
0 Likes
361

Hi all

i am upgrading version 4.7 to 6.0.

In one of the program i came across following statements.

*Select * from (object_type-viewname) into work.*

object_type-viewname has some table name as value which changes with each loop pass.

Earlier in version 4.7 version the structure of work was flat,

but if i use the same in 6.0 it gives dump saying types not compatible.

So the only solution I was able to understand is every time *data type of work should be equal to contents of object_type-viewname.* But how do i achieve that

PLzzz help

2 REPLIES 2
Read only

RemiKaimal
Active Contributor
0 Likes
340

Hi,

Try making the work area Dynamic; Take this eg:-


DATA : 
it_tab TYPE TABLE OF pa0002,
wa_tab LIKE LINE OF it_tab,
record TYPE REF TO data.

FIELD-SYMBOLS: <fs> TYPE ANY.

GET REFERENCE OF wa_tab INTO record.
ASSIGN record->* TO <fs>.
SELECT SINGLE * FROM pa0002
              INTO <fs>
              WHERE pernr = '1'. "some criteria for selection

I guess in your case, the problem is with work and not with object_type-viewname .

So, all you need to do is make it dynamic based on the above eg:-

Cheers,

Remi

Read only

Former Member
0 Likes
340

Hi Shubhi,

Use the following code:

REPORT ZUPGRADE_BDC_ABAP1.


* Set of table names
DATA: IT_TABNAME TYPE TABLE OF DD03L-TABNAME,
      WA_TABNAME LIKE LINE OF IT_TABNAME.

* Field Symbols for the dynamic data creation
DATA LR_DATA TYPE REF TO DATA.

FIELD-SYMBOLS <FS> TYPE ANY TABLE.

CLEAR WA_TABNAME.

MOVE 'SPFLI' TO WA_TABNAME.
APPEND WA_TABNAME TO IT_TABNAME.

MOVE 'MARA' TO WA_TABNAME.
APPEND WA_TABNAME TO IT_TABNAME.


LOOP AT IT_TABNAME INTO WA_TABNAME.

*Dynamically creating the internal table
  IF <FS> IS ASSIGNED.
    UNASSIGN <FS>.
  ENDIF.

  CLEAR LR_DATA.

  CREATE DATA LR_DATA TYPE TABLE OF (WA_TABNAME).

  ASSIGN LR_DATA->* TO <FS>.

  SELECT * FROM (WA_TABNAME) INTO TABLE <FS> UP TO 10 ROWS.

ENDLOOP.