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

how to call methods at selection screen?

Former Member
0 Likes
3,045

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

6 REPLIES 6
Read only

Former Member
0 Likes
1,559

Hello,

Have you tryed to do it on INITIALIZATION stm?? This event runs before the START-OF-SELECTION.

Bye

Read only

0 Likes
1,559

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.

Read only

Former Member
0 Likes
1,559

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.

Read only

0 Likes
1,559

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...

Read only

Sougata
Active Contributor
0 Likes
1,559

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

Read only

Sougata
Active Contributor
0 Likes
1,559

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.