2008 Apr 30 11:15 PM
Hi all,
I am developing a program in object oriented abap.
i have defined a class and implementated, and we have to instantiate the class in start of selection.
now the problem is how to call a method at selection screen event.
i want to validate the inputs entered by users. so can i create a static method which can be called without instantiating a class?
please guide me
thanks
2008 Apr 30 11:39 PM
Hello,
Have you tryed to do it on INITIALIZATION stm?? This event runs before the START-OF-SELECTION.
Bye
2008 Apr 30 11:48 PM
yes, there also its saying "obj->method" not defined, check you spelling.
I am just trying a test program, the code is as follows.
class vendor definition.
public section.
methods validate_cc.
methods validate_po.
endclass.
class vendor implementation.
method validate_cc.
data : lv_bukrs type bukrs.
select single bukrs into lv_bukrs from t001 where bukrs in s_bukrs.
endmethod.
method validate_po.
data : lv_ekorg type ekorg.
select single ekorg into lv_ekorg from T024E where ekorg in s_ekorg.
endmethod.
endclass.
at selection-screen. .
obj->validata_cc.
obj->validata_po.
initialization.
data : obj type ref to vendor.
create object obj.
start-of-selection.
2008 May 01 12:05 AM
hi please see the fallwoing code.u can call the method for validate the some field in at selection-screen event.
data:v_name1 like kna1-name1.
parameters:name(30) type c.
class a definition.
public section.
methods:get_data.
endclass.
class a implementation.
method get_Data.
select single name1
from kna1
into v_name1
where name1 = name.
if sy-subrc <> 0.
message e000(z00) with 'Wrong Name'.
endif.
endmethod.
endclass.
at selection-screen.
data:obj type ref to a .
create object obj.
call method:obj->get_data.
start-of-selection.
write:/ v_name1.
2008 May 01 12:07 AM
yeah u may be right i havent tried ur method...
i tried in diff method its working thanks
class vendor definition.
public section.
*methods validate_cc.
*methods validate_po.
class-methods validate_cc.
class-methods validate_po.
endclass.
class vendor implementation.
method validate_cc.
data : lv_bukrs type bukrs.
select single bukrs into lv_bukrs from t001 where bukrs in s_bukrs.
if sy-subrc <> 0.
message i001(00).
exit.
endif.
endmethod.
method validate_po.
data : lv_ekorg type ekorg.
select single ekorg into lv_ekorg from T024E where ekorg in s_ekorg.
if sy-subrc <> 0.
message i001(00).
exit.
endif.
endmethod.
*method checkstatic.
*endmethod.
endclass.
at selection-screen. .
call method vendor=>validate_cc.
call method vendor=>validate_po.
initialization.
start-of-selection.
data : obj type ref to vendor.
create object obj.
This is working fine...
2008 May 01 12:27 AM
Hello Mr A,
Define the method as a Static Method and that will solve your problem. Static methods can be called directly and does not need the class to be instantiated before it can be called.
Data: my_class type ref to zcl_report_utilities.
At Selection-Screen.
Call Method zcl_report_utilities=>check_selections
exporting
iv_repnm = sy-cprog
importing
et_messages = lt_msgs.
.............
Start-Of-Selection.
Create Object my_class
exporting
im_pernr = ls_e1plogi-objid
im_begda = c_lowdate
im_endda = c_hidate.
Call Method my_class->read_infotypes
exporting
im_infty = c_org_assn
changing
et_infty = it_infty.
.......
Here you can see how the method check_selections is called before the class zcl_report_utilities is instantiated. The best part about the Static Methods is if you are writing the class in the Class Library (SE24), any other programs can call them directly (if they need to) without needing to instantiating the entire class before the call.
Also note the difference in syntax when calling the static method check_selections to when calling the Instance method read_infotypes.
Hope this solves your issue and please do not forget to reward points.
Cheers,
Sougata.
p.s. if you are defining your class locally (program specific) then use Class-Methods to define a static method.
Edited by: Sougata Chatterjee on May 1, 2008 9:53 AM
2008 May 02 12:33 AM
Hello Mr A,
You might not be aware of the reward point system here at the SDN. For replies to your question you reward points here to show your appreciation towards who answered them - after all most of us here have a job - its not like we have nothing else to do with our time than answer your "cutting-edge" technology questions such as this one
You have marked the thread as Answered without rewarding anyone! I think you may have forgotten to do so?
Cheers,
Sougata.