cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a program defined internal table to an abap object

Former Member
0 Kudos

Hi. I have an internal table that was previously defined and created by SAP that I need to process in a user exit. The table is defined exactly as shown below.

Is it possible to pass a table that was defined in this manner (not in the ABAP dictionary) as an argument to a method of an ABAP object?

If so, what would the data type of the itab parameter have to be when defining the object's method parameter list? Is it necessary to somehow "cast it" to the KNA1 table type once I receive the table into the method? If so, what is the data type of the object's receiving variable/attribute?

data: begin of lkna1 occurs 0001.

include structure kna1 .

data:

end of lkna1 .

Just as one additional piece of information, I am using version 4.5B and I am trying to do this through se24.

Thanks so much!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Brendan,

I suppose your requirement is "how do I pass internal table as a parameter to a method of an object?".

If that is the requirement and if you are using global classes (using se24), I have just found the solution of it in 4.6C. Just try it in your version.

1) In the main program, you have defined your internal table as:

data: begin of itab occurs 0.

include structure kna1.

data: end of itab.

2) After creating and initializing the object , call the method of the class as:

call emp->get_table exporting int_table = itab.

3) Go to se11, create a table type of kna1 say ztabtype.

3) In se24, in the methods section, define the method get_table . In the parameters section,give

int_table importing type ztabtype.Give some description.

4) In the implementation, for accessing the values,

do as follows.

method get_table.

data: wa_itab type kna1.

loop at int_table into wa_itab.

now u can access the contents using wa_itab.

endmethod.

I suppose your query is satisfied.

Regards,

Sylendra.

Former Member
0 Kudos

Hi, Sylendra. Thank you for your help. I tried what you had said, but I think I may be doing something wrong in SE11.

In SE11, I selected "Table Type", named the type ZSDKNA1, clicked on CREATE, and then put KNA1 as the row type. I then specified ZSDKNA1 as the method's argument type (itab argument below). Then I try to pass the following table to the method:

data: begin of lkna1 occurs 0001.

include structure kna1.

data: end of lkna1.

data: testobj type ref to zsdtest.

create object testobj.

call method testobj->testreceive

exporting itab = lkna1.

But I get the following message on the source code check:

"LKNA1" is not type-compatible with formal parameter "ITAB":

Am I doing anything wrong in SE11 when I define the table type?

Thanks!

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

When you define an internal table with the OCCURS 0 extension, you are automatically creating a internal table with a HEADER LINE. Header lines in ABAP OO are not allow and hence the reason for your error.

Define your internal table like so.

Data: ikna1 type table of kna1.

Now you should be able to pass your table.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Brendan,

Sorry for a slightly wrong information.

Since you have declared itab as an internal table with header line,in your method call, do this change.

call method testobj->testreceive

exporting itab = lkna1[].

This will solve the issue.

Regards,

Sylendra.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Also you could have probably used TRCON_KNA1_TAB as your table type instead of creating a custom one. This table type exists in my 46c system.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi again,

<b>This kind of simple approach,

we can pass ANY KIND OF TABLE

WITHOUT HAVING TO DEFINE

LINE TYPE IN SE11.</b>

1. doing this simply u will achieve what u want.

( i just tried the same)

2. in se24,

give like this

ITAB Importing Type <b>STANDARD TABLE</b>

3. in the calling program,

call like this,

report abc.

data: begin of lkna1 occurs 0001.

include structure kna1.

data: end of lkna1.

data: testobj type ref to zsdtest.

select * from kna1

into table lkna1.

lkna1-kunnr = '000234'.

create object testobj.

<b>call method testobj->testreceive

exporting itab = lkna1[].</b>

4.

then in the class, source code,

just use like this

(so that u can accesss the fields of the itab,

using myitab)

<b>method TESTRECEIVE .

data : myitab type table of kna1.

myitab[] = itab[].

break-point.

endmethod.</b>

5. thats all !

regards,

amit m.

Former Member
0 Kudos

Hi Brendan,

I suppose your error is solved by now.The error was because the parameter is of table type of KNA1 and our internal table ie. lkna1 is an internal table with header line. So we have to give as

call testobj->testreceive

exporting itab = lkna1[].

If your problem is solved, kindly close the thread by awarding points to helpful answers.

Regards,

Sylendra.

Former Member
0 Kudos

Thank you SO MUCH Sylendra. Amit, you're last reply was great also.

I awarded points to both of you. Please let me know if you did not get them.

Thanks again!!!!!!!

Brendan

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Brendan,

In order to pass an internal table as a parameter to a method, you need to create a table type of the database table (say KNA1) and then in se24, goto the method's parameter give the type of internal table as table type you have created.

I think this should work. I haven't done like this before .So I will also do it from my system and will tell you the results . Meanwhile you may also try this out.

Regards,

Sylendra.

Former Member
0 Kudos

HI Brendan,

1. data type of the itab parameter

It can be KNA1.

2. bcos.

data: begin of lkna1 occurs 0001.

include structure kna1 .

data:

end of lkna1 .

is same as.

data : lkna1 like table of kna1 with header line.

regards,

amit m.

Former Member
0 Kudos

Hi, Amit. Thank you for replying...

I did try specifying KNA1 as the data type before I posted this, but the method only receives a KNA1 structure when I define the argument type as KNA1. The table is not passed.

Former Member
0 Kudos

Hi again,

1. STANDARD TABLE

In the class definition,

mention it as above.

2. eg. in class CL_GUI_ALV_GRID

the importing paramter (as table)

in the method

SET_TABLE_FOR_FIRST_DISPLAY

is

IT_OUTTAB Changing Type STANDARD TABLE

regards,

amit m.