Application Development 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: 

Error while passing attribute from 1 class to another class

Former Member
0 Kudos

Hi,

I am not much into ABAP. Appreciate if u could help me with this. I am trying to pass an attribute from one class to another class. I am getting an error when accesing a class attribute from a method of another class.

I appreciate if anyone can atleast direct me to some good documentation on ABAP OO classes and methods.

Calling from

============

Super Class -


> SC1 = CL_RSR_WWW_HELP_WINDOW

CLASS -


> C1 (public) = Z_PRINT_HELP_SERVICE

METHOD----


> M1 (Instance Method, Private)

Class Attribute------> A1 (Instance Attribute, Private type STRING)

Method M1 needs Attribute A1 value.

Calling to

==========

Super Class -


> SC2 = CL_RSR_WWW_MODIFY_TABLE

CLASS -


> C2 (public) = Z_CL_RSR_WWW_MODIFY_TABLE

Class Attribute------> A2 (Instance Attribute, Public type STRING)

A2 has a value which has to be passsed to A1 of method M1 in Class C1.

here is the code for method M1.

method M1 .

DATA: A TYPE REF TO C2.

A1 = A->A2.

endmethod.

As I'm accessing these classes from Web, I am not sure what the error is except that browser says "page can't be displayed" without the values that are passed from A2 into A1.

there is no problem in the browser if i hard code the value in method 1 as follows.

method M1 .

A1 = 'value'.

endmethod.

hope it is clear.

thanks and appreciate any kinda help

2 REPLIES 2

olivergrande
Associate
Associate
0 Kudos

Hallo,

in your example method:

method M1 .

DATA: A TYPE REF TO C2.

A1 = A->A2.

the creation of the instance A is missing. You have to add something like:

create object A.

Hope this helps,

Oliver

0 Kudos

Hi,

thanks so much for your help. in my earlier post, I just asked to see if passing attribute works. but, my actual requirement is this. I appreciate if you could help me with this. I tried in all possible ways but of no luck so far.

am sure it might not be clear. but, I appreciate if you can be of any help to me.

Attribute A1 of class C1 needs a value that is passed from Method M2 of class C2.

Method M2 has 16 obligatory importing paramters and 4 changing parameters. one of the 4 "changing parameters of type STRING" is C_CELL_CONTENT.

Method M2 of Class C2

16 Parameters typeIMPORTING

4 parameters type CHANGING

C_CELL_CONTENT type CHANGING associated type STRING

class C2 has a public instance attribute A2 of type string.

I am trying to store C_CELL_CONTENT into A2 in method M2 and trying to access attribute A2 from method M1 of class c1.

I am not even sure if the path am going is right.

From method M2, I need to pass C_CELL_CONTENT value to A1 if I_Y = 1. (where I_Y is 1 of 9 importing parameters of method M2)

M2 method is as follows.

method M2 .

IF I_Y = 1.

A2 = C_CELL_CONTENT.

ENDIF.

endmethod.

M1 method is as follows.

method M1 .

DATA ClassA TYPE REF TO C2.

Create object ClassA.

A1 = ClassA->A2.

endmethod.

By above methods, I am getting blank value into A1. If i give initial value for attribute A2, Initial value of A2 is getting passed onto A1 using the above method M1 but not getting the value of C_CELL_CONTENT.

I thought method M2 is not being called.

I even called method M2 from M1 by passing blank parameters to all obligatory parameters and value 1 to I_Y as follows. As C_CELL_CONTENT is obligatory changing parameter, I had to pass some value and this value (thr' C_CELL_CONTENT_1 string in Method M1) is overwriting the value that i am looking for.

Method M1

Data ClassA type ref to C2.

create object A.

CALL METHOD A->CHARACTERISTIC_CELL

exporting

I_X = '' I_Y = '1' I_IOBJNM = ' ' I_AXIS = ' ' I_CHAVL_EXT = ' '

I_CHAVL = ' ' I_NODE_IOBJNM = ' ' I_TEXT = ' ' I_HRY_ACTIVE = ' '

I_DRILLSTATE = ' ' I_DISPLAY_LEVEL = '1' I_USE_TEXT = ' ' I_IS_SUM = ''

I_IS_REPETITION = ' ' I_CELLSPAN = ' ' I_CELLSPAN_ORT = ' '

changing

C_CELL_ID = C_CELL_ID_1

C_CELL_CONTENT = C_CELL_CONTENT_1

C_CELL_STYLE = C_CELL_STYLE_1

C_CELL_TD_EXTEND = C_CELL_TD_EXTEND_1.

A1 = ClassA->A2.

endmethod.

So, I am not successful in calling method M2 from M1. Can we somehow call method M2 without passing any parameters from method M1?

I thought of doing it in reverse. calling method M1 from M2. Still, value of A2 is not passed to A1.

M2 method is as follows.

method M2.

DATA ClassB type ref to C1.

create object ClassB.

A2 = C_CELL_CONTENT.

ClassB->A1 = A2.

endmethod.

I even tried to work around this problems using events. I am not sure if we can deal with events for this issue.

I raised an event E1 in method M2 to send C_CELL_CONTENT thr' export parameter.

method M2 contains the following code where title is instance public event and send_title is a parameter of type STRING.

RAISE EVENT title

exporting send_title = C_CELL_CONTENT.

Now, I need to handle (trigger) this event from M1 to get C_CELL_CONTENT into A1.

i used following code in method M1 and i get error "the statement for is not expected. A correct similar statement is FORM".

code in method M1 is as follows

for event title of C2 importing send_title.

thanks

hari