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 builder - attributes access in methods

Madhurivs23
Participant
0 Likes
1,245

Hi All,

I have created a class ZZ_CL_ABC and its methods :

ZZ_M1

ZZ_M2

in method ZZ_M1, one table gets filled up ITAB and I want to access this ITAB in the ZZ_M2.

These methods are getting called from one report



  DATA I_ZZ_CL_ABC     TYPE REF TO ZZ_CL_ABC .
  CREATE OBJECT I_ZZ_CL_ABC .


call method I_ZZ_CL_ABC->zz_M1
       exporting 
               imat = imat.

call method I_ZZ_CL_ABC->zz_M2.

Now I want to access the ITAB which gets filled up in method ZZ_M1 and I want to access that in ZZ_M2, when ZZ_M2 gets called through the program.

rgds,

Madhuri

Edited by: Matt on Sep 9, 2011 6:11 AM - changed tags to lower case

7 REPLIES 7
Read only

matt
Active Contributor
0 Likes
1,053

So what's the problem? Define ITAB as an attribute of the class.

Read only

0 Likes
1,053

the values of ITAB are getting cleared at the time I call the second method through program

Read only

matt
Active Contributor
0 Likes
1,053

You need to restate your issue. At the moment you simply haven't given sufficient information. Unless zz_m1 clears the table, or neglects to set it, it won't be cleared.

Have you tried debug?

Edited by: Matt on Sep 9, 2011 6:35 AM

Read only

0 Likes
1,053

I have created a class through class builder zcl_material.

in it I have written 2 methods:

get_material

get_quantity

in method get_material, the materials are getting stored in table it_material.

in method get_quantity, the quantity for materials in it_quantiry, for materials present in the it_material table is calculated

Now I am using this class in one report and calling its methods

get_material : select * from mara into it_material.

get_quantity : select * from mard in it_quantity for all entries in it_material.

The it_material table, I dont want to pass to the report. So what i did is, I declared this table in the attributes tab of the class builder with level instance and visibility as private.

after calling method get_material, the data is present in the it_material.

but when I am calling the method get_quantity, in the select query, the it_material is blank???

So how should I define any variable/ table so that it will be present till the class object is there????

is it possible through class builder->attribute?

Read only

matt
Active Contributor
0 Likes
1,053

Defining the attribute as instance/private is correct. Attributes do not get cleared between method calls. You must go through in debug and find out where the table is being cleared.

Is the instance of your object the same each time, for example? Have you declared in the method a local variable with the same name as the attribute?

Read only

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

after calling method get_material, the data is present in the it_material.

but when I am calling the method get_quantity, in the select query, the it_material is blank???

Can you post the code how you are calling the methods get_material( ) & get_quantity( ) ?

BR,

Suhas

Read only

0 Likes
1,053

thanks Matt,

It got solved. I was maintaing that table in 2 places . in the exporting parameter for method get_material and in the attribute also. So it was clearing out. Now I removed it_material from exporting parameter, and its storing values till the object persists.

thanks a lot for follow up of question.

thanks Suhas for reply, the doubt got solved.