Singleton in ABAP

Hi,
1) I have created a class with its instantiation set to private.
2) Declared a static attribute 'instance' in the class with TYPE REF to same class.
3) In the class constructor checked if instance is initial if it is then created an object.
if instance initial.
    creat'e object instance.
endif.
4) Created a method get_instance which exports the 'instance' attribute of the class.
I suppose this is fine for implementing the Singleton class.
Created a sample program where I call get_instance of this class.
Open two sessions of SE80 and execute this program in debug mode. I see that each program is executing the class constructor and instance is initial every time.
If instance is initial in each execution (with two parllel executions) then what is the purpose of declaring it as static.
Since its initial create object is executed every time in
each execution. Then the instance is not unique and its not singleton.
Can somebody explain signleton in ABAP. Why is it different from JAVA.
Regards,
Sesh

Hi Sesh,
Your class object exists per default once per session. As of release 6.40 you can create objects in the shared memory (with addition AREA HANDLE), thus session-independent! For that, you need to mark the class as shared-memory enabled. This should create a singleton as in Java.
Best regards,
Georg

Similar Messages

  • Is abap thread safe? Some question in Singleton pattern in ABAP

    Hi Grus,
    I have a very basic question but really make me headache...
    Recently I am learning the design pattern in ABAP and as you know in JAVA there is a key word "Synchronized" to keep thread safe. But in ABAP, I didn't find any key words like that. So does that mean ABAP is always a single thread language? And I found that there is a way looks like "CALL FUNCTION Remotefunction STARTING NEW TASK Taskname DESTINATION dest" to make multi-thread works. As you can see it use the destination, so does that mean actually the function module is always executed in a remote system, and in every system, it is always single thread?
    Could you help me on the question? Thanks a lot, grus
    And here comes up to my mind another question...It's a little bit mad but I think it may works....What if I set every attribute and method as static in the singleton class...Since as you can see it is already a singleton so every attribute in it should be only one piece. So then I don't even need to implement a get_instance( ) method to return the instance. Just call "class_name=>some_method( )" directly then singleton is achieved...What do you think?
    BR,
    Steve

    Steve,
    I've the same question, few days ago I tried to use the singleton in ABAP. In Java programming is possible to use the same reference in two sessions or programs, sharing attributes, methods and all data, but I could not do in ABAP.
    In my test I created a program with one global class using the singleton pattern, so I expected that when I run my program and see the reference returned after the get_instance method it should be equal to the same program run in another session, but the ABAP will create a new reference and instantiate again.
    So I deduced that the only way to share it between sessions in ABAP is using the ABAP Shared Memory Objects.
    I can be wrong, but I think that ABAP use a thread by user session (Each window) and we can't change it.
    Best regards.

  • Hi! regarding the singleton property in webdynpro abap

    Hi experts ,
    Could anyone explain me in detail the property of singleton and wht r the conditions tht we should use wht will represents..
    plz explain me in detail......rather than sending links plz do explain me in detail....
    Regards,
    Sana...

    Cardinality : number of possible elements within the node.
    Singleton property means whether or not all instances of this node get created at runtime or not.
    Singleton property is mostly used to save memory & increase performance. we would go for singleton nodes in cases where UI needs only display from one-instance of data from my node.....
    What happens when you set singleton property to YES for a node??  Assume you have context structure like
    Context
         Vehicle( parent node )
           ( attribute veh-ID primary key for all types of vehicles, dealer, area )
              twowheeler( subnode of vehicle with cardinality-0..n singleton-NO)
                        ( attributes veh-ID, regno, model, color)
              fourwheeler( subnode of vehicle with cardinality-0..n singleton-YES)
                       ( attributes veh-ID, regno, model, color)
    At design time you fill the data within this context. Now you have 100 entries under the subnode  twowheeler & 90 entries under the subnode fourwheeler . You create UI elements to display the node twowheeler details in a View . At runtime when user selects the veh-ID and identifies that a twowheeler data needs to be fetched/displayed all the 100 entries for the twowheeler node get created in the background although you are displaying only the ONE corresponding to the veh-ID.
    if Veh-ID selected coresponded to fourwheeler( singleton property -yes) only ONE row of the data from the fourwheeler entries would have been fetched and ONLY Once instance of the fourwheeler would be created by background process!!
    thus saving memory & processing time.
    Scenarios singleton-YES
    If i were required to display details of only ONE vehicle based on the entered Veh-ID , i will make twowheeler & fourwheeler nodes singleton-YES.
    Scenario singleton-NO
    if i were required to show all the vehicles that belong to one particular Area.

  • Singleton in OOps ABAP

    Hello Experts,
                      I understand singleton means we can create only one instance of a class.But what exactly is the use of the singleton in OOPS.Can you provide me how to implement in OOPS.
    Thnaks and Regards,
    Vijay.

    Hi,
    Try this,
    1.Create a class ZCL_SINGLETON_TEST and select instantiation type private.
    2.Now, Create a Static private attribyte lr_ref type ref to  ZCL_SINGLETON_TEST.
    3.Create one public static method, get_instance with returning parameter r_ref type ref to  ZCL_SINGLETON_TEST.
    In method implementation write the below code,
    method get_instance.
    if lr_ref is initial.
    * as this is static instance only first time instance will be created.
    create object lr_ref.
    endif.
    *Return the reference.
    r_ref = lr_ref.
    endmethod.
    Now ,In your report call like this, as you cannot create object for private class.
    data lo_ref type ref to ZCL_SINGLETON_TEST.
    * get instance of single ton class
    lo_ref = ZCL_SINGLETON_TEST=>get_instance( ).
    Now using the lo_ref  instance you can access the methods of single ton class.
    Hope this helps u.,
    revert if you need some more clarifications,
    Thanks & Regards,
    Kiran.

  • Interactive form in web dynpro abap

    hi experts,
                   i am beginner to adobe interactive form in web dynpro using abap.
    my scenario:
                        To  use  interactive form ui element  and place all fields of lfa1 in view.
         my context look like
                       context:
                                    adobe(node 1, 1:n, singleton = true)
                                       lfa1(node2,1:n,singleton =true) with its fields.
                                       pdf_source(attribute)
                       layout type : zci layout and xml interface.
        my view look like:
                                    all fileds of lfa1.
                                    button-add.(to add to below table)
                                    table.
                                    button-submit to sap.
    i want to place all fields in view and get values from the user online and need to display the same in an table in same view and
    when the user click ok entered values should be displayed  in table  and after clicking submit to sap it should hit the database table.
    as i am beginner dont know how to do.pls i need ur help in finishing it.thanks in advance.
    cheers,
    vinoth.

    hi all,
             expecting reply from u all. pls help me and give some sugesstion.
    regards,
    vinoth.

  • ABAP Objects with Workflows / Classes and Instances

    Hello,
    I am currently designing a workflow using an ABAP-Objects. So far I have been been able to get my Workflow to run with my class, but I have a couple of problems:
    - I am using the Function 'SAP_WAPI_START_WORKFLOW' to start other subflows, which enables me to decide which subflow to start at runtime. All of the subflows have standart importing-parameters in their containers, such as the key of my class. In each workflow I instantiate my class using a self-written method, which checks the table T_INSTANCES in my object, and then either returns the object reference to an existing instance or creates a new one. Obviously all of the subflows that I call from my main workflow should be able to find the instance. As far as I can see in their protocolls, this happens without any problems. The problem starts when I make changes to the instance. For example the changing of attributes (with setter methods) seems not to work. After the subflows are finished, in my main workflow, I do not see (with getter methods) any changes that has been made to the object. Is local persistence really limited to one workflow ?
    - My second problem is basically about the workflow container in workflow protocoll. In the same workflow, I can change the attributes of my object. Nevertheless, the protocoll always show the initial attribute, even though, my task with the getter-method returns the new value of the attribute.
    I appreciate any help and thanks a lot in advance.

    Hello Pauls,
    Thank you for your answer. I think we are misunderstanding each other. The problem occurs (I think) because my class is not a singleton class. Or am I mistaken ?
    When I directly start a subflow from my main workflow, then the instance that I have created in my main workflow is also visible to the subflow. As well as the static table which actually keeps track of the instances. So, in this case the subflows finds the instance and then can use the object as is.
    When I start a subflow from my main workflow using the function I mentioned above, then even though the same object key is used, there is a new instance. And the static table (I assume that you mean a static variable from type table, when you say "class table") is completely empty. In this case, my "new" instance is created which overwrites every attribute that I have set in the main workflow, before I started the subflow. More interestingly, my main workflow instantiates another new object, as soon as the subflow has finished. (I am using an event to wait for the subflow to finish.)
    On the other hand, I am not quite sure that I understood your approach with refresh and how it could help me. This method is not well documented anywhere, and all of the examples that I have found are about "leave it empty"
    As far as I understood, this method is called by the workflow between the steps, when an object is used. I slowly start to think that I need advanced information about Workflows and Memory Management.
    Thanks a lot again. Apparently, I am the only person who came across such a problem
    Greetz
    G.Fendoglu

  • Solution Manager 7.0 Installation Error on Import ABAP  -Test DB connection

    Hi, SDN fellows.
    I am installing Solution Manager 7.0. In Step 16 of 44 - Import ABAP, I encountered an error when the installer was testing the database connection. It failed at this command:
    R3load.exe -testconnect
    Below is the error I copied from the log viewer. Thanks for all possible advices/suggestions to fix this issue. 
    =================
    WARNING 2011-07-12 03:51:49.188
    Execution of the command "C:\usr\sap\SM1\SYS\exe\uc\NTAMD64\R3load.exe -testconnect" finished with return code 2. Output:
    sapparam: sapargv( argc, argv) has not been called.
    sapparam(1c): No Profile used.
    sapparam: SAPSYSTEMNAME neither in Profile nor in Commandline
    C:\usr\sap\SM1\SYS\exe\uc\NTAMD64\R3load.exe: START OF LOG: 20110712035148
    (DB) ERROR: db_connect rc = 256
    (DB) ERROR: DbSlErrorMsg rc = 99
    WARNING[E] 2011-07-12 03:51:49.188
    CJS-30023  Process call 'C:\usr\sap\SM1\SYS\exe\uc\NTAMD64\R3load.exe -testconnect' exits with error code 2. For details see log file(s) R3load.exe.log.
    ERROR 2011-07-12 03:51:49.204
    FCO-00011  The step testDatabaseConnection with step key |NW_Onehost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|2|0|NW_CreateDBandLoad|ind|ind|ind|ind|10|0|NW_ABAP_Import_Dialog|ind|ind|ind|ind|5|0|NW_ABAP_Import|ind|ind|ind|ind|0|0|testDatabaseConnection was executed with status ERROR .
    =============
    KC

    cont....
    4 ETW000                                                                              33  1.576524
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:1 flag_fupd:0 use_cursor:0 chksum: 1112312
    4 ETW000                                                                              24  1.576548
    4 ETW000  [dev trc     ,00000]  DbSlRead - Error 103 (dbcode 208) on open             19  1.576567
    4 ETW000  [dev trc     ,00000]  DbSlRead - <##Y4ISBDCAPPsm100000045960000000001234118>
    4 ETW000                                                                              19  1.576586
    4 ETW000  [dev trc     ,00000]  DbSlRead - Error 103 (dbcode 208) on fetch            13  1.576599
    4 ETW000  [dev trc     ,00000]  DbSlRead - <##Y4ISBDCAPPsm100000045960000000001234118>
    4 ETW000                                                                              18  1.576617
    4 ETW000  [dblink      ,01299]  ***LOG BZA=>table SVERS      does not exist on database            [dblink#5 @ 1299]
    4 ETW000                                                                            8060  1.584677
    4 ETW000  [dev trc     ,00000]  Wed Jul 13 23:41:19 2011                           41342  1.626019
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000002234118
    4 ETW000                                                                              25  1.626044
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                            3649  1.629693
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              33  1.629726
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000002234118]
    4 ETW000                                                                              19  1.629745
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'DDNTT'.
    4 ETW000                                                                              27  1.629772
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000002234118]
    4 ETW000                                                                              19  1.629791
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 COMPCNT FROM "DDNTT" ]
    4 ETW000                                                                              28  1.629819
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              20  1.629839
    4 ETW000  [dev trc     ,00000]  NTAB: SELECT COMPCNT FROM DDNTT FAILED               277  1.630116
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000003234118
    4 ETW000                                                                              44  1.630160
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                             459  1.630619
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              33  1.630652
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000003234118]
    4 ETW000                                                                              18  1.630670
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'DDNTT'.
    4 ETW000                                                                              29  1.630699
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000003234118]
    4 ETW000                                                                              23  1.630722
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 VERSION FROM "DDNTT" ]
    4 ETW000                                                                              29  1.630751
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              20  1.630771
    4 ETW000  [dev trc     ,00000]  NTAB: SELECT VERSION FROM DDNTT FAILED               267  1.631038
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000004234118
    4 ETW000                                                                              43  1.631081
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                             436  1.631517
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              32  1.631549
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000004234118]
    4 ETW000                                                                              18  1.631567
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'DDNTT'.
    4 ETW000                                                                              58  1.631625
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000004234118]
    4 ETW000                                                                              19  1.631644
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 DBASE FROM "DDNTT" ]
    4 ETW000                                                                              28  1.631672
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              21  1.631693
    4 ETW000  [dbntab.c    ,00000]  *** ERROR => NTAB: SELECT VERSION/DBASE FROM DDNTT FAILED
    4 ETW000                                                                             284  1.631977
    4 ETW000  [dbntab      ,01276]  ***LOG BZY=>unexpected return code 103        calling NTAB       [dbntab#4 @ 12761]
    4 ETW000                                                                              31  1.632008
    4 ETW000  [twdydbacc.c ,00568]  i:0                                                 8690  1.640698
    4 ETW000  [twdydbacc.c ,00569]  db_fd_p<i>.fname:       PGMID                         20  1.640718
    4 ETW000  [twdydbacc.c ,00570]  db_fd_p<i>.is_key:      0                             11  1.640729
    4 ETW000  [twdydbacc.c ,00571]  db_fd_p<i>.offset:      0                             10  1.640739
    4 ETW000  [twdydbacc.c ,00572]  db_fd_p<i>.db_length:   0                             10  1.640749
    4 ETW000  [twdydbacc.c ,00573]  db_fd_p<i>.fixed_length:4                             10  1.640759
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000005234118
    4 ETW000                                                                              40  1.640799
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                             434  1.641233
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              32  1.641265
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000005234118]
    4 ETW000                                                                              75  1.641340
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'XXXXT'.
    4 ETW000                                                                              31  1.641371
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000005234118]
    4 ETW000                                                                              18  1.641389
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 COMPCNT FROM "XXXXT" ]
    4 ETW000                                                                              28  1.641417
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              21  1.641438
    4 ETW000  [dev trc     ,00000]  NTAB: SELECT COMPCNT FROM XXXXT FAILED               269  1.641707
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000006234118
    4 ETW000                                                                              44  1.641751
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                             437  1.642188
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              32  1.642220
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000006234118]
    4 ETW000                                                                              18  1.642238
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'XXXXT'.
    4 ETW000                                                                              28  1.642266
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000006234118]
    4 ETW000                                                                              19  1.642285
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 VERSION FROM "XXXXT" ]
    4 ETW000                                                                              27  1.642312
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              70  1.642382
    4 ETW000  [dev trc     ,00000]  NTAB: SELECT VERSION FROM XXXXT FAILED               273  1.642655
    4 ETW000  [dev trc     ,00000]  DbSlBegRead[1]: ##Y4ISBDCAPPsm100000045960000000007234118
    4 ETW000                                                                              44  1.642699
    4 ETW000  [dev trc     ,00000]  ParamStmtExec: line 13165. hr: 0x80040e14 Statement(s) could not be prepared.
    4 ETW000                                                                             435  1.643134
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 8180, sev 0), Statement(s) could not be prepared.
    4 ETW000                                                                              32  1.643166
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000007234118]
    4 ETW000                                                                              19  1.643185
    4 ETW000  [dev trc     ,00000]  sloledb.cpp [ParamStmtExec,line 13165]: Error/Message: (err 208, sev 16), Invalid object name 'XXXXT'.
    4 ETW000                                                                              28  1.643213
    4 ETW000  [dev trc     ,00000]  Procname: [##Y4ISBDCAPPsm100000045960000000007234118]
    4 ETW000                                                                              20  1.643233
    4 ETW000  [dev trc     ,00000]  ParamStmtExec failed.  HR 80040e14 DBSL retcode 103. stmt: [SELECT TOP      1 DBASE FROM "XXXXT" ]
    4 ETW000                                                                              30  1.643263
    4 ETW000  [dev trc     ,00000]  Conn_i:1 selection:1 singleton:0 flag_fupd:0 use_cursor:0 chksum: 1122000
    4 ETW000                                                                              21  1.643284
    4 ETW000  [dbntab.c    ,00000]  *** ERROR => NTAB: SELECT VERSION/DBASE FROM XXXXT FAILED
    4 ETW000                                                                             324  1.643608
    4 ETW000  [dbntab      ,01276]  ***LOG BZY=>unexpected return code 103        calling NTAB       [dbntab#4 @ 12761]
    4 ETW000                                                                              27  1.643635
    2EETW000 sap_dext called with msgnr "2":
    2EETW000 -
    db call info -
    2EETW000 function:   db_ntab
    2EETW000 fcode:      NT_RDTDESCR
    2EETW000 tabname:    TADIR
    2EETW000 len (char): 5
    2EETW000 key:        TADIR
    2EETW000 retcode:    2
    4 ETW000  [dev trc     ,00000]  db_con_rollback (con_da={R/3,0,0},th_rollback=1,tx=0)
    4 ETW000                                                                            9946  1.653581
    4 ETW000  [dev trc     ,00000]  Rollback: TestConnection(1) successful             36526  1.690107

  • WD ABAP performance tips and tricks

    Hi all,
    I was wondering if there is any good approach to build WD applications so performance does not have to suffer. Do you know of any good documentation on this topic?
    Thank you,
    Georgy

    Hello, Georgy,
    From my experience, I follow some guidelines. These can be correct or not, but from my researches across SDN and other sources (help.sap.com and Ulli's book), it's proven to be good guidelines. Of course, I'll be presenting here only those tips related to WDA, not ABAP. Here they are:
    1. Design your Context nodes carefully:
    - Avoid non-Singleton nodes;
    - Make your supply functions as simple as possible;
    2. Controllers:
    - If you use a component (such as ALV or MESSAGE_MANAGER) frequently, instantiate it at WDDOINIT and save it as a public attribute of the COMPONENTCONTROLLER. This way, whenever you need to call a method of the component, you can refer to wd_comp_controller->attribute->method.
    3. Views:
    - Instead of using dynamic programming to control properties of view elements (visibility, read-only, text, etc), use context attributes. This way, you can control, for instance, the visibility of an element in any method, not only inside WDDOMODIFYVIEW;
    4. Methods:
    - Use the WDA framework correctly: if you need to consist user entered data, use WDDOBEFOREACTION; if you need to control aspects of the view, use WDDOMODIFYVIEW;
    - Learn the Phase Model better than the back of your hands
    Well, that's some guidelines I use, and I'd like you to comment it also, or further expand this list.
    Regards,
    Andre

  • Automatic generation of ABAP-classes from Function Groups?

    Hey there,
    is there a way of having (SE24)-ABAP-Classes generatetd outomaticaly by providing an existing function group?
    I think, the following mapping shold be possible::
    - the function group is the class
    - its function modules are public (static) methods
    - any form-routines are private methods
    -> I don't want to to that boring work myself, some tool should be able to do that just fine, right? So, is there such a tool?
    Thanks, regards
    Joachim

    Sorry, sounds like the only two people who answered are not aware of such a tool...
    There is one additional point, which I hadn't thought about initially. With ABAP OO you also have a much stricter syntax and many more statement variants that are obsolete and thus cannot be used. This is another hindrance for writing such a tool (but of course not impossible, I just kind of doubt that any reasonable programmer would write such a thing).
    Anyhow, I never understood why SAP is pushing OO so much (declaring all non-OO as obsolete), even going as far as implementing stricter syntax checks for OO. In my opinion a much better option would've been to implement some flag that switches on the more strict syntax checks, similarly to the Unicode check they've introduced. Coding in OO or non-OO, both have its use. Rules from SAP to code everything in OO even in cases where OO doesn't work seems straight silly as a general recommendation: E.g. if I have to code an RFC module, why would I want to bloat my code by introducing a class for implementing the functionality so that the RFC is just a wrapper around the class (unless the additional class gives me some real benefit)?
    As much as I appreciate using OO classes supplied by SAP, I often have difficulties seeing objects in the requirements that I have to code (which might of course just be a reflection of my programming skills). A class with just some static methods is often an indication of poor OO design, i.e. there is no reasonable/tangible object and all you have is a utility class with a collection of various methods. To me it's important that the code is well structured, doesn't have any side effects, etc. This can be achieved with non-OO coding as well as OO, but switching from non-OO to OO doesn't guarantee at all that the code is any better.
    In the end, if you just have a single function group, I'd recommend to do the translation manually and try to apply good OO design principles (instead of a straightforward 1-to-1 translation). E.g. for a class with just static methods (which I'd expect an automated translation would result in) one might want to take a peek at [singletons are evil|http://www.c2.com/cgi/wiki?SingletonsAreEvil] versus [singletons are good|http://www.c2.com/cgi/wiki?SingletonsAreGood]. I know it's silly advice if you're a seasoned OO programmer; but if not, I think your time is much better spent by thinking about the design and then applying it instead of using some automated tools where you'd later have to anyhow do some refactoring...

  • ABAP objects design patterns

    hi all,
        can any one send me the Design patterns used for ABAP objects programming in ABAP. eg mvc and sample code which uses the design patterns
    cheers
    senthil

    Of course that program is not an object design pattern
    (Its just a little ABAP Objects syntax demo that I wrote  years ago
    I don't know about a list of OO design patterns implemented in ABAP Objects.
    A very simple one, a Singleton might look like this:
    <b>* cl_singleton: Eager Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS: class_constructor,
                       get_singleton RETURNING VALUE(singleton)
                                               TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD class_constructor.
        CREATE OBJECT singleton.
      ENDMETHOD.
      METHOD get_singleton.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.
    cl_singleton: Lazy Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS get_singleton RETURNING VALUE(singleton)
                                              TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD get_singleton.
        IF cl_singleton=>singleton IS INITIAL.
          CREATE OBJECT cl_singleton=>singleton.
        ENDIF.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.</b>

  • Is ABAP multi-threading safe?

    When implementing the Singleton design pattern in Java, we must use keyword <b>synchronized</b> with <b>getInstance()</b> method to ensure multi-threading safety, so that we can get the one and only instance.
        What shall I do in ABAP? or just leave it alone?  Would you help me find a example?
        thanks and regards,
      Davin,WANG

    Hi Davin,
    I do not understand fully what you are going to do in ABAP terms so I hope my comment will be of any value.
    Multithreading may be achieved in ABAB by calling a function with the addition STARTING NEW TASK IN GROUP.... See my sample program for <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/Easilyimplementparallelprocessinginonlineandbatchprocessing">Easily implement parallel processing in online and batch processing</a>
    The second question may be solved by help of SAP lock concept. This is used primarily to secure a consistent database by not allowing two processes to change data at the same time. Chose a lock object of your choice and set at start of first instance. At end, remove the lock. Before creating the second instance, try so set the same lock. If you get a foreign lock error, you know the process is running.
    See documentation on lock objects on how to lock/unlock.
    Regards,
    Clemens
    Hope your internet connection is broken no longer so you can read this.

  • About ABAP Object

    Hello All,
    i have some question about ABAP Object.
    What is the meaning of friend class and singleton?
    Regards,
    Luke

    Hi,
    The addition Friends makes class class a friend of classes classi and or interfaces ifaci.At the sam time, all subclasses of classes classi, all classes that implement one of the interfaces ifaci and all interfaces that have one of the interfaces ifaci as a component interface become friends of class. you have to specify at least one class or interface.
    The friends of a class have unrestricted access to the protected and private components of that class, and can generate unrestricted instances of the class.
    The friends of class are not automatically friends of subclasses of class. the addition Friends does not make class a friend of its friends.
    Thea ddition global is allowed only when you use the addition public for the global class of a class pool at the same time.You can list other global classes and interfaces from the class library after global friends.This addition is generated when the Class Builder creates a global class and you specified friends at the corresponding tab page of the class Builder.
    `
    In the example , classs c2 is a friend of interface i1, and therefore also of the implementing class c1. It can instantiate these objects and access their private component a1.
    interface i1.
    endinterface.
    class c1 definition create private friends i1.
    private section.
    data a1(10) type c value 'Class 1'.
    endclass.
    class c2 definition.
    public section.
    interfaces i1.
    methods m2.
    endclass.
    class c2 implementation.
    method m2.
    data oref type ref to c1.
    create object oref.
    write oref->a1.
    endmethod.
    enclass.
    Kindly Reward Points If You Found The Reply Helpful,
    Cheers,
    Chaitanya.

  • Coding standards for Web dynpro ABAP

    Hello all,
    Can anybody please help me by providing the code review checklist for Web dynpro ABAP?
    Thanks and Regards,
    Rohini Shankar

    Hello friend,
    WebDynpro     *
    1     Do not implement Data intensive operations in UI layer     
    2     Avoid database selects in the WebDynpro code.Use the corresponding BAPIs ,Methods     
    3     Are ABAP OO Classes like Assistance class are being used for application coding ?     
    4     Are Windows/Views only used for the sole purpose of hosting views and context?     
    5     Are a reasonable number of views put in a single WD Component instead of creating multiple WD Components ?     
    6     Unneccessary usage of dynamic programming and dynamic component avoided      
    7     Are singleton nodes used in case of nesting in the context ?     
    8     Is deep nesting of containers, Groups and Tabstrips avoided ?     
    9     Is the UI element TreeByKey or TreeByTableNestingColumn used instead of the Tree UI element ?     
    10     Is the checkbox "Accessibility Checks Active" ticked in the WD Component properties     
    11     Are the WD Component Instances deleted when no longer needed (IF_WD_COMPONENT_USAGE=>DELETE_COMPONENT)     
    12     Are the OTR texts defined  for all the labels, texts(where ever appropriate) in properties of all the UI elements      
    13     Has the Generation limit been checked for all the components developed     
    14     Sufficients commets are written at the beginning of every major block to explain the processing logic.     
    *Error Handling     *
    1     Is SY-SUBRC checked after CALL function modules      
    2     Use Assertions if you face unexpected errors which usually never ever occur!     
    Extended Check and Clean Up
    1     Have following been removed :     
         ·      Unused variables                       
         ·      Unused text elements                   
         ·      Unused tables from TABLES statement     
         ·      Commented out parts of the code     
         ·      Code segments which do nothing     
    2     Is extended program check completed  and all errors/warnings removed      
    These are the things which i used for my project.
    Thanks,
    Sri Hari

  • Instantiate a ABAP Object Dynamically

    I would like to get some guidance on Dynamically instantiating objects within ABAP.
    I have worked with Java.  Within Java I am able to instantiate a Java object through the use Class.forName (see example below):
    className = "com.vz.it.cleansheet.eFine.db.query.WBRDMTWKCNDATABEAN";
    try {
         singleton = (Object) Class.forName(classname).newInstance();
         } catch (ClassNotFoundException cnf) {
                   System.out.println("SingletonRegistry - Couldn't find class "}
    Is there a similar procedure in ABAP OO to enable dynamically instantiating a ABAP object?
    I would appreciate any advice.
    Thanks,
    Rick

    You can instantiate an object dynamically,  here is a sample program.  Notice that we are creating an object passed on what class is named in the selection screen.
    report zrich_0001.
    *       CLASS lcl_car DEFINITION
    class lcl_car definition.
      public section.
        data: car type string.
    endclass.
    *       CLASS lcl_car IMPLEMENTATION
    class lcl_car implementation.
    endclass.
    *       CLASS lcl_truck DEFINITION
    class lcl_truck definition.
      public section.
        data: truck type string.
    endclass.
    *       CLASS lcl_truck IMPLEMENTATION
    class lcl_truck implementation.
    endclass.
    data: r  type ref to object.
    parameters: p_class(20) type c default 'LCL_TRUCK'.
    start-of-selection.
      create object r type (p_class).
      check sy-subrc = 0.
    Regards,
    Rich Heilman

  • Child node attributes do not appear in ABAP WD

    Hi,
      I have the following context hierarchy (in ABAP WD):
    -Context
    ---Child_Node_A
    Sub_Child_NodeB
    AttributeE_of_Sub_Child_NodeB
    AttributeF_of_Sub_Child_NodeB
    AttributeG_of_Sub_Child_NodeB
    Sub_Child_NodeC
    AttributeH_of_Sub_Child_NodeC
    AttributeI_of_Sub_Child_NodeC
    AttributeJ_of_Sub_Child_NodeC
    AttributeA_of_Child_Node_A
    AttributeB_of_Child_Node_A
    AttributeC_of_Child_Node_A
    The attributes A, B, C of Child_Node_A are displayed in an ALV grid and the idea is that when the user selects a row in the ALV grid and clicks on a button, a popup is to be shown with additional details of the selected row in the ALV.  In this popup, I have some fields which are mapped to the attributes E, F, G of Sub_Child_NodeB and attributes H, I, J of Sub_Child_NodeC.  But when I show the popup the fields are empty.
    I use a supply function in the Component Controller to fill Child_Node_A and its children, so typically when the popup appears I should see the attributes of the Sub_Child_Node B and C which are linked to the lead selection of the ALV grid (i.e.: Child_Node_A), right?
    By the way, I have linked Child_Node_A from the Component Controller Context to the Context of my Main View and Popup View.  Also, I checked in the INIT method of my Main view to see if after the supply function has been called the Sub_Child_Nodes attributes were still there for a given lead selection in the ALV grid and they were.  But in my action handler to show the popup window from my Main view, I checked again to see if the Sub_Child_Nodes attributes were still there and they were not.
    I hope I was clear enough in my explanation.
    Thanks in advance for your help,
    Christian

    Hi Christian,
    We discussed this problem offline, but I would like to give some feedback on what we found out.
    (a) Since Child_Node_A had a supply function that also supplied Sub_Child_NodeB and since Sub_Child_NodeB was a singleton, it was not resupplied. The initial element originated from having Sub_Child_NodeB as 1..1 cardinality. In this case the runtime recreates an initial node element upon invalidation of the node.
    (b) The second problem might be related to the ALV. As the ALV does not support child nodes being present for the data displayed, the assumption is that Sub_Child_NodeB might have been invalidated once the data was copied back from the ALV to Child_Node_A.
    The solution is to have a supply function for Sub_Child_NodeB as well, which will counter any invalidation at any point in time and will restore the original data.
    I am curious if (b) is really the cause of the problem described.
    Best regards,
    Thomas

Maybe you are looking for

  • How to reinstall windows 7 on Satellite L505D-S598​3 when hard drive had to be replaced

    I recently had my Satellite L505D-S5983 laptop's hard drive die due to disk failures and had to replace the hard drive. Because the laptop is older I am not able to read the activation key from the laptop and do not have a recovery partition from the

  • Problem running web queries on machines with internet explorer 8 installed

    Hello All, We started noticing that a few of our users can no longer execute web queries in MS Excel spreadsheets created from .IQY files exported from Discoverer. The users get the following error when they attempt to refresh data on their excel wor

  • Exporting images to Iphoto libraries

    I am new to Apple and am probably trying to run before I can walk so apologies in advance if this is a "dumb blonde" question. I have happily been using Iphoto to store/manage and edit my images. I have recently started to shoot in RAW format, and ha

  • Reflection iCon like iPhone Apps

    Hi all, I'm wondering whether Keynote possible to create the icon like iPhone Apps' icons with the Reflection? How to do that?

  • Exception in getSessionCookieFactory

    Hi All, We have a application which exposes REST API and does not of ViewController. We are using ADF to access the data model. To initialize the adf context we added the following to the web.xml <filter-mapping>         <filter-name>adfBindings</fil