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

class contructor internal table

Former Member
0 Likes
1,736

Hi epert,

I am new for abap objects and i am trying to change the standard program.Please refer below.

CLASS a DEFINITION.
  CLASS-METHODS b.
  METHODS: constructor.
  METHODS: my,
           name.
ENDCLASS.                    "A DEFINITION

CLASS a IMPLEMENTATION.
  METHOD b.
    DATA screen TYPE REF TO a.
    CREATE OBJECT screen.
  ENDMETHOD.                    "B

  METHOD constructor.
    CALL METHOD : me->my.
  ENDMETHOD.                    "Constructor

ENDCLASS.                    "A IMPLEMENTATION

START-OF-SELECTION.
  CALL METHOD a=>b.

How it is possbile for me to pass a internal table to the method MY. I have internal table and i need to assign to the method MY.

Please guide me. standard program DEMO_ABAP_OBJECTS_SPLIT_SCREEN

Edited by: Matt on Sep 30, 2010 4:47 PM - added tags

Edited by: Matt on Sep 30, 2010 4:49 PM

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,261

>

> How it is possbile for me to pass a internal table to the method MY.

Hello,

You have to create a formal parameter for the method MY & pass your internal table to it:

Something like this:

Class A definition.
class-methods B.
methods: constructor.
methods: my IMPORTING im_itab TYPE <line type of your internal table>,
name.
Endclass.

In your CONSTRUCTOR pass the Internal Table value:

Method Constructor.
call method me->my EXPORTING im_tab = itab[].
endmethod.

BR,

Suhas

7 REPLIES 7
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,262

>

> How it is possbile for me to pass a internal table to the method MY.

Hello,

You have to create a formal parameter for the method MY & pass your internal table to it:

Something like this:

Class A definition.
class-methods B.
methods: constructor.
methods: my IMPORTING im_itab TYPE <line type of your internal table>,
name.
Endclass.

In your CONSTRUCTOR pass the Internal Table value:

Method Constructor.
call method me->my EXPORTING im_tab = itab[].
endmethod.

BR,

Suhas

Read only

0 Likes
1,261

>

> In your CONSTRUCTOR pass the Internal Table value:

>

Method Constructor.
> call method me->my EXPORTING im_tab = itab[].
> endmethod.

>

In classes, we don't have the header line. So, there is no need to pass the "body" by []. Internal table name is enough to pass the data... Specifying it without the brackets avoids the confusion...

Regards,

Naimesh Patel

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,261

Thanks for pointing it out Naimesh.

Read only

Former Member
0 Likes
1,261

Hi Suhas Saha.

Really thanks for your reply and i am trying my level best to try and error due i m new to this abap objects.

But i have question.

Is it possible to pass the itab[] from CALL METHOD a=>b.This is because my internal table is coming from other place.

I mean not in the class.

Basically it is coming from the screen 100 or main screen or previous screen.

Please advice if i am doing a mistake.

HI Matt. Thanks a lot and i will follow your guide.

Thank a lot everyone.

Read only

matt
Active Contributor
0 Likes
1,261

You define your CLASS-METHOD (also known as a static method) to have parameters, exactly in the way that Suhas showed you for method "my".

CLASS-METHODS b IMPORTING it_data TYPE <type of your internal table>.

I suggest your read carefully, again, the documentation on the various keywords - CLASS-METHODS, METHODS etc.

Read only

Former Member
0 Likes
1,261

HI Matt and Suhas Saha,

I have done it. I used Sahas Saha tips and i did some search in SDN.

I got. It is good start for me in abap objects.

Thanks a lot everyone Matt and Suhas Saha.

I will close this thread.

Read only

matt
Active Contributor
0 Likes
1,261

Can I suggest that you get into the habit, right now, of using meaningful class, method and attribute names.