2015 Mar 16 5:18 PM
Hi All,
I have a question about OOP Abap;
How can i write (best way) inner of ZCML_USER=>LOGIN method for using like at doLogin method.
(There is a c# example under the Abap codes )
Thanks.
ABAP USER CLASS
class ZCMCL_USER definition
public
final
create public .
public section.
class-methods LOGIN
importing
value(USERNAME) type ZCM_DUS_USERNAME
value(PASSWORD) type ZCM_DUS_PASSWORD
returning
value(STATUS) type ref to ZCMCL_USER .
ABAP - STATIC METHOD OF USER CLASS
method LOGIN.
????????
endmethod.
ABAP - CALLING STATIC USER METHOD
method DOLOGIN.
DATA theUser TYPE REF TO ZCMCL_USER.
theUser = ZCMCL_USER=>LOGIN( USERNAME = 'kdr' password = '123' ).
endmethod.
C# EXAMPLE
C# - USER CLASS
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public static User Login(string username, string password)
{
//if.....
User usr = new User();
usr.Name = "Ahmet";
usr.Surname = "AKIN";
usr.Id = 1;
return usr;
}
}
C# - CALLING STATIC USER METHOD
public void doLogin()
{
User theUser = User.Login("ahmt", "123456");
Console.WriteLine(theUser.Name);
}
2015 Mar 17 5:08 AM
ABAP USER CLASS
ABAP - STATIC METHOD OF USER CLASS
Thanks,
Sharath
2015 Mar 17 5:08 AM
ABAP USER CLASS
ABAP - STATIC METHOD OF USER CLASS
Thanks,
Sharath
2015 Mar 18 3:40 AM
Hi Abdulkadir,
I believe you want to create a singleton class which can be accessible for all other places during runtime.
First you can create a singleton class. Here the sample code:
class yide_cl_fpm_singleton definition
public
final
create public .
public section.
data:
username type sy-uname.
class-methods get_instance
returning
value(re_instance) type ref to yide_cl_fpm_singleton .
protected section.
private section.
class-data mo_instance type ref to yide_cl_fpm_singleton .
endclass.
private section.
class-data mo_instance type ref to yide_cl_gaf_singleton .
method get_instance.
if mo_instance is initial.
create object mo_instance.
endif.
re_instance = mo_instance.
endmethod.
And then, in your program, you can call this singleton class by calling as static method get_instance. Once your instance has been instantiated, you can access your public data from this class. You can get or set via this singleton class.
Hope it's fit to your requirement.
Regards,
Indra