cancel
Showing results for 
Search instead for 
Did you mean: 

define internal table as attribute in model

alberto_colonna
Participant
0 Kudos

Hi everybody,

I have to read out some data from a database and store it into an internal table.

The internal table is filled from the do_request method of a controller.

After this the internal table shall be passed to a view.

Now my problem is that I don't know how to define an internal table as an attribute

in the model class.

Can you help me?

Best regards

alberto

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Alberto,

One thing that you can do is declare an attribute as

I_TABLE TYPE TABLE

and then in the class declare an internal table say <b>gt_tab</b>, exactly of the same type as in the controller.....

Then just pass the table from the controller to I_TABLE, and the do

gt_tab = I_TABLE.

But you will have to use the exact same type, else it will give error stating that <b>Two internal tables are neither compatible nor convertible.</b>

Another way to do this is declare a structure and table type in the data dictionary and then use that table type in attributes......

Hope this helps.

<b><i>Do reward each useful answer..!</i></b>

Thanks,

Tatvagna.

alberto_colonna
Participant
0 Kudos

Now I tried this in the model class.

I have declared the internal table as an attribute and the line for teh internal table

as a type. But I get an error when I test the program.

Here is the code from the model class:

class ZCL_MODEL_DATA definition

public

inheriting from CL_BSP_MODEL

final

create public .

" public components of class ZCL_MODEL_DATA

" do not include other source files here!!!

public section.

types:

BEGIN OF line_spfli,

links type string,

carrid TYPE spfli-carrid,

END OF line_spfli..

data:

ITAB type TABLE of line_spfli .

Former Member
0 Kudos

Hi Alberto,

In the attributes of the MODEL create a reference table like..

itab type SPFLI_TAB.

This should resolve your problem.

Amandeep.