Regarding Returning Parameter and Static method

Hi frnds,
I am learning oops ABAP. I want to use returning parameters in method and also STATIC METHOD.
If any example it will be more helpful
regards,
satya

Hi satya,
             Check this out ,Its helpful.
To get some values from a method , one can use the exporting, changing or returning parameters.If one uses RETURNING parameters, the following restrictions apply:-(1) No EXPORTING/CHANGING parameters can be used for the method.(2) Only one RETURNING parameter can be used.(3) RETURNING parameters are only passed by value.This program demonstrates the use of RETURNING parameters and the various ways   to call a method with RETURNING parameter to get the value into some variable.
Sample Program
</code>
report ysubdel1 message-id 00.
data : w_num type i.
class c1 definition .
public section. 
methods : m1 importing input1 type i
                        input2 type i
                        returning value(result) type i .
endclass.
class c1 implementation.
method  : m1.
result = input1 * 2 + input2.
endmethod.
endclass.
start-of-selection.
data : obj1 type ref to c1 . 
create object obj1.
Syntax 1     
call method obj1->m1 EXPORTING input1 = 5                                                        input2 = 4  
                               RECEIVING result = w_num.  
  write:/5 w_num .
Syntax 2
     w_num = obj1->m1( input1 = 10 input2 = 20 ).
  write:/5 w_num .
Syntax 3     
move obj1->m1( input1 = 2 input2 = 3 ) to w_num .  
write:/5 w_num .
</code>
Static method example
<code>
REPORT  zstatic.                              .
data : num type i.
class testclass definition.
public section.
  class-methods : testmethod.
endclass.
class testclass implementation.
method : testmethod.
  num = 5.
  write:/5 num.
endmethod.
endclass.
start-of-selection.
call method testclass=>testmethod.
</code>
Reward Points if u find helpful.
Thnks & Regards,
Rajesh

Similar Messages

  • Returning Parameter in OOPS method

    Hi frnds,
                   I am learning oops ABAP. I want to use returning parameters in method and also STATIC METHOD.
    If any example it will be more helpful

    http://help.sap.com/saphelp_nw2004s/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
    check this too,
    Reward points if helpful,
    Thank you,
    Regards,
    Jagrut BharatKumar Shukla

  • Regarding call transaction and session method???

    HI All,
    Cud u pls let me know
    1. differences between call transaction and session???
    2. Is it possible to schedule call transaction in background?? ( all are saying MODE N = background scheduling  in call transaction.......but i dont think so)
    3. Is it posible to handle multiple transactions in call transaction ? if so,how?
    4. Is it posible to handle multiple transactions in session ? if so,how?
    5. How can we see the log in session method????

    Hi ,
    Check this documentation.
    About Session method
    In this method you transfer data from internal table to database table through sessions.
    In this method, an ABAP/4 program reads the external data that is to be entered in the SAP System and stores the data in session. A session stores the actions that are required to enter your data using normal SAP transaction i.e., Data is transferred to session which in turn transfers data to database table.
    Session is intermediate step between internal table and database table. Data along with its action is stored in session i.e., data for screen fields, to which screen it is passed, the program name behind it, and how the next screen is processed.
    When the program has finished generating the session, you can run the session to execute the SAP transactions in it. You can either explicitly start and monitor a session or have the session run in the background processing system.
    Unless session is processed, the data is not transferred to database table.
    BDC_OPEN_GROUP
    You create the session through program by BDC_OPEN_GROUP function.
    Parameters to this function are:
    • User Name: User name
    • Group: Name of the session
    • Lock Date: The date on which you want to process the session.
    • Keep: This parameter is passed as ‘X’ when you want to retain session after
    processing it or ‘ ‘ to delete it after processing.
    BDC_INSERT
    This function creates the session & data is transferred to Session.
    Parameters to this function are:
    • Tcode: Transaction Name
    • Dynprotab: BDC Data
    BDC_CLOSE_GROUP
    This function closes the BDC Group. No Parameters.
    Some additional information for session processing
    When the session is generated using the KEEP option within the BDC_OPEN_GROUP, the system always keeps the sessions in the queue, whether it has been processed successfully or not.
    However, if the session is processed, you have to delete it manually. When session processing is completed successfully while KEEP option was not set, it will be removed automatically from the session queue. Log is not removed for that session.
    If the batch-input session is terminated with errors, then it appears in the list of INCORRECT session and it can be processed again. To correct incorrect session, you can analyze the session. The Analysis function allows to determine which screen and value has produced the error. If you find small errors in data, you can correct them interactively, otherwise you need to modify batch input program, which has generated the session or many times even the data file.
    CALL TRANSACTION
    About CALL TRANSACTION
    A technique similar to SESSION method, while batch input is a two-step procedure, Call Transaction does both steps online, one after the other. In this method, you call a transaction from your program by
    Call transaction <tcode> using <BDCTAB>
    Mode <A/N/E>
    Update <S/A>
    Messages into <MSGTAB>.
    Parameter – 1 is transaction code.
    Parameter – 2 is name of BDCTAB table.
    Parameter – 3 here you are specifying mode in which you execute transaction
    A is all screen mode. All the screen of transaction are displayed.
    N is no screen mode. No screen is displayed when you execute the transaction.
    E is error screen. Only those screens are displayed wherein you have error record.
    Parameter – 4 here you are specifying update type by which database table is updated.
    S is for Synchronous update in which if you change data of one table then all the related Tables gets updated. And sy-subrc is returned i.e., sy-subrc is returned for once and all.
    A is for Asynchronous update. When you change data of one table, the sy-subrc is returned. And then updating of other affected tables takes place. So if system fails to update other tables, still sy-subrc returned is 0 (i.e., when first table gets updated).
    Parameter – 5 when you update database table, operation is either successful or unsuccessful or operation is successful with some warning. These messages are stored in internal table, which you specify along with MESSAGE statement. This internal table should be declared like BDCMSGCOLL, a structure available in ABAP/4. It contains the following fields:
    1. Tcode: Transaction code
    2. Dyname: Batch point module name
    3. Dynumb: Batch input Dyn number
    4. Msgtyp: Batch input message type (A/E/W/I/S)
    5. Msgspra: Batch input Lang, id of message
    6. Msgid: Message id
    7. MsgvN: Message variables (N = 1 - 4)
    For each entry, which is updated in database, table message is available in BDCMSGCOLL. As BDCMSGCOLL is structure, you need to declare a internal table which can contain multiple records (unlike structure).
    Steps for CALL TRANSACTION method
    1. Internal table for the data (structure similar to your local file)
    2. BDCTAB like BDCDATA
    3. UPLOAD or WS_UPLOAD function to upload the data from local file to itab. (Considering file is local file)
    4. Loop at itab.
    Populate BDCTAB table.
    Call transaction <tcode> using <BDCTAB>
    Mode <A/N/E>
    Update <S/A>.
    Refresh BDCTAB.
    Endloop.
    (To populate BDCTAB, You need to transfer each and every field)
    The major differences between Session method and Call transaction are as follows:
    SESSION METHOD CALL TRANSACTION
    1. Data is not updated in database table unless Session is processed. Immediate updation in database table.
    2. No sy-subrc is returned. Sy-subrc is returned.
    3. Error log is created for error records. Errors need to be handled explicitly
    4. Updation in database table is always synchronous Updation in database table can be synchronous Or Asynchronous.
    Error Handling in CALL TRANSACTION
    When Session Method updates the records in database table, error records are stored in the log file. In Call transaction there is no such log file available and error record is lost unless handled. Usually you need to give report of all the error records i.e., records which are not inserted or updated in the database table. This can be done by the following method:
    Steps for the error handling in CALL TRANSACTION
    1. Internal table for the data (structure similar to your local file)
    2. BDCTAB like BDCDATA
    3. Internal table BDCMSG like BDCMSGCOLL
    4. Internal table similar to Ist internal table
    (Third and fourth steps are for error handling)
    5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)
    6. Loop at itab.
    Populate BDCTAB table.
    Call transaction <tr.code> using <Bdctab>
    Mode <A/N/E>
    Update <S/A>
    Messages <BDCMSG>.
    Perform check.
    Refresh BDCTAB.
    Endloop.
    7 Form check.
    IF sy-subrc <> 0. (Call transaction returns the sy-subrc if updating is not successful).
    Call function Format_message.
    (This function is called to store the message given by system and to display it along with record)
    Append itab2.
    Display the record and message.
    Check this program for session method using multiple transactions.
    Have one BDC_OPEN_GROUP, multiple BDC_INSERT s and one BDC_CLOSE_GROUP.
    You should have multiple BDC_INSERT s for multiple transactions.
    call function BDC_OPENGROUP.
    Build BDC data and cal lBDC_INSERT for transaction 1
    Build BDC data and cal lBDC_INSERT for transaction 2
    Build BDC data and cal lBDC_INSERT for transaction 3
    call function BDC_CLOSE_GROUP.
    Check out this sample program
    REPORT  ztest_report
    NO STANDARD PAGE HEADING
                            LINE-SIZE 255
                            MESSAGE-ID ZRASH.
                    Internal Table Declarations                          *
    *--Internal Table for Data Uploading.
    DATA : BEGIN OF IT_FFCUST OCCURS 0,
             KUNNR(10),
             BUKRS(4),
             KTOKD(4),
             ANRED(15),
             NAME1(35),
             SORTL(10),
             STRAS(35),
             ORT01(35),
             PSTLZ(10),
             LAND1(3),
             SPRAS(2),
             AKONT(10),
           END OF IT_FFCUST.
    *--Internal Table to Store Error Records.
    DATA : BEGIN OF IT_ERRCUST OCCURS 0,
             KUNNR(10),
             EMSG(255),
           END OF IT_ERRCUST.
    *--Internal Table to Store Successful Records.
    DATA : BEGIN OF IT_SUCCUST OCCURS 0,
             KUNNR(10),
             SMSG(255),
           END OF IT_SUCCUST.
    *--Internal Table for Storing the BDC data.
    DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    *--Internal Table for storing the messages.
    DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
    DATA : V_FLAG1(1) VALUE ' ',
    "Flag used for opening session.
           V_TLINES LIKE SY-TABIX,
           "For storing total records processed.
           V_ELINES LIKE SY-TABIX,
           "For storing the no of error records.
           V_SLINES LIKE SY-TABIX.
           "For storing the no of success records.
             Selection screen                                            *
    SELECTION-SCREEN BEGIN OF BLOCK B1.
    PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,
                 V_SESNAM  LIKE RLGRAP-FILENAME.
    SELECTION-SCREEN END OF BLOCK B1.
             Start-of-selection                                          *
    START-OF-SELECTION.
    *-- Form to upload flatfile data into the internal table.
      PERFORM FORM_UPLOADFF.
           TOP-OF-PAGE                                                   *
    TOP-OF-PAGE.
      WRITE:/ 'Details of the error and success records for the transaction'
      ULINE.
      SKIP.
             End of Selection                                            *
    END-OF-SELECTION.
    *-- Form to Generate a BDC from the Uploaded Internal table
      PERFORM FORM_BDCGENERATE.
    *--To write the totals and the session name.
      PERFORM FORM_WRITEOP.
    *&      Form  form_uploadff
        Form to upload flatfile data into the internal table.
    FORM FORM_UPLOADFF .
    *--Variable to change the type of the parameter file name.
      DATA : LV_FILE TYPE STRING.
      LV_FILE = V_FNAME.
    *--Function to upload the flat file to the internal table.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                      =  LV_FILE
        FILETYPE                      = 'ASC'
          HAS_FIELD_SEPARATOR           = 'X'
        HEADER_LENGTH                 = 0
        READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
      IMPORTING
        FILELENGTH                    =
        HEADER                        =
        TABLES
          DATA_TAB                      = IT_FFCUST
        EXCEPTIONS
          FILE_OPEN_ERROR               = 1
          FILE_READ_ERROR               = 2
          NO_BATCH                      = 3
          GUI_REFUSE_FILETRANSFER       = 4
          INVALID_TYPE                  = 5
          NO_AUTHORITY                  = 6
          UNKNOWN_ERROR                 = 7
          BAD_DATA_FORMAT               = 8
          HEADER_NOT_ALLOWED            = 9
          SEPARATOR_NOT_ALLOWED         = 10
          HEADER_TOO_LONG               = 11
          UNKNOWN_DP_ERROR              = 12
          ACCESS_DENIED                 = 13
          DP_OUT_OF_MEMORY              = 14
          DISK_FULL                     = 15
          DP_TIMEOUT                    = 16
          OTHERS                        = 17
      IF SY-SUBRC = 0.
    *--Deleting the headings from the internal table.
        DELETE IT_FFCUST INDEX 1.
    *--Getting the total number of records uploaded.
        DESCRIBE TABLE IT_FFCUST LINES V_TLINES.
      ENDIF.
    ENDFORM.                    " form_uploadff
    *&      Form  Form_bdcgenerate
        Form to Generate a BDC from the Uploaded Internal table
    FORM FORM_BDCGENERATE .
    *--Generating the BDC table for the fields of the internal table.
      LOOP AT IT_FFCUST.
        PERFORM POPULATEBDC USING :
                                    'X' 'SAPMF02D' '0105',
                                    ' ' 'BDC_OKCODE'  '/00' ,
                                    ' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,
                                    ' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,
                                    ' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,
                                    'X' 'SAPMF02D' '0110' ,
                                    ' ' 'BDC_OKCODE'  '/00',
                                    ' ' 'KNA1-ANRED'  IT_FFCUST-ANRED,
                                    ' ' 'KNA1-NAME1' IT_FFCUST-NAME1,
                                    ' ' 'KNA1-SORTL'  IT_FFCUST-SORTL,
                                    ' ' 'KNA1-STRAS' IT_FFCUST-STRAS,
                                    ' ' 'KNA1-ORT01' IT_FFCUST-ORT01,
                                    ' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,
                                    ' ' 'KNA1-LAND1' IT_FFCUST-LAND1,
                                    ' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,
                                    'X' 'SAPMFO2D' '0120',     
                                    ' ' 'BDC_OKCODE'  '/00',
                                    'X' 'SAPMF02D' '0125',     
                                    ' ' 'BDC_OKCODE'  '/00',
                                    'X' 'SAPMF02D' '0130',     
                                    ' ' 'BDC_OKCODE'  '=ENTR',
                                    'X' 'SAPMF02D' '0340',     
                                    ' ' 'BDC_OKCODE'  '=ENTR',
                                    'X' 'SAPMF02D' '0360',
                                    ' ' 'BDC_OKCODE'  '=ENTR',
                                    'X' 'SAPMF02D' '0210',     
                                    ' ' 'KNB1-AKONT'  IT_FFCUST-AKONT,
                                    ' ' 'BDC_OKCODE'  '/00',
                                    'X' 'SAPMF02D' '0215',
                                    ' ' 'BDC_OKCODE'  '/00',
                                    'X' 'SAPMF02D' '0220',     
                                    ' ' 'BDC_OKCODE'  '/00',
                                    'X' 'SAPMF02D' '0230',     
                                    ' ' 'BDC_OKCODE'  '=UPDA'.
    *--Calling the transaction 'fd01'.
        CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'
        MESSAGES INTO IT_CUSTMSG.
        IF SY-SUBRC <> 0.
    *--Populating the error records internal table.
          IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.
          APPEND IT_ERRCUST.
          CLEAR IT_ERRCUST.
    *--Opening a session if there is an error record.
          IF V_FLAG1 = ' '.
            PERFORM FORM_OPENSESSION.
            V_FLAG1 = 'X'.
          ENDIF.
    *--Inserting the error records into already open session.
          IF V_FLAG1 = 'X'.
            PERFORM FORM_INSERT.
          ENDIF.
    *--Populating the Success records internal table.
        ELSE.
          IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.
          APPEND IT_SUCCUST.
          CLEAR IT_SUCCUST.
        ENDIF.
    *--Displaying the messages.
        IF NOT IT_CUSTMSG[] IS INITIAL.
          PERFORM FORM_FORMATMSG.
        ENDIF.
    *--Clearing the message and bdc tables.
        CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].
      ENDLOOP.
    *--Getting the total no of error records.
      DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.
    *--Getting the total no of successful records.
      DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.
    *--Closing the session only if it is open.
      IF V_FLAG1 = 'X'.
        PERFORM FORM_CLOSESESS.
      ENDIF.
    ENDFORM.                    " Form_bdcgenerate
    *&      Form  populatebdc
          FOrm to Populate the BDC table.
    FORM POPULATEBDC  USING    VALUE(P_0178)
                               VALUE(P_0179)
                               VALUE(P_0180).
      IF P_0178 = 'X'.
        IT_CUSTBDC-PROGRAM = P_0179.
        IT_CUSTBDC-DYNPRO = P_0180.
        IT_CUSTBDC-DYNBEGIN = 'X'.
      ELSE.
        IT_CUSTBDC-FNAM = P_0179.
        IT_CUSTBDC-FVAL = P_0180.
      ENDIF.
      APPEND IT_CUSTBDC.
      CLEAR IT_CUSTBDC.
    ENDFORM.                    " populatebdc
    *&      Form  FORM_OPENSESSION
          Form to Open a session.
    FORM FORM_OPENSESSION .
    *--Variable to convert the given session name into reqd type.
      DATA : LV_SESNAM(12).
      LV_SESNAM = V_SESNAM.
    *--Opening a session.
      CALL FUNCTION 'BDC_OPEN_GROUP'
       EXPORTING
         CLIENT                    = SY-MANDT
         GROUP                     = LV_SESNAM
         HOLDDATE                  = '20040805'
         KEEP                      = 'X'
         USER                      = SY-UNAME
         PROG                      = SY-CPROG
    IMPORTING
       QID                       =
       EXCEPTIONS
         CLIENT_INVALID            = 1
         DESTINATION_INVALID       = 2
         GROUP_INVALID             = 3
         GROUP_IS_LOCKED           = 4
         HOLDDATE_INVALID          = 5
         INTERNAL_ERROR            = 6
         QUEUE_ERROR               = 7
         RUNNING                   = 8
         SYSTEM_LOCK_ERROR         = 9
         USER_INVALID              = 10
         OTHERS                    = 11
      IF SY-SUBRC <> 0.
        WRITE :/ 'Session not open'.
      ENDIF.
    ENDFORM.                    " FORM_OPENSESSION
    *&      Form  FORM_INSERT
          fORM TO INSERT ERROR RECOED INTO A SESSION.
    FORM FORM_INSERT .
    *--Inserting the record into session.
      CALL FUNCTION 'BDC_INSERT'
        EXPORTING
          TCODE                  = 'FD01'
        POST_LOCAL             = NOVBLOCAL
        PRINTING               = NOPRINT
        SIMUBATCH              = ' '
        CTUPARAMS              = ' '
        TABLES
          DYNPROTAB              = IT_CUSTBDC
        EXCEPTIONS
          INTERNAL_ERROR         = 1
          NOT_OPEN               = 2
          QUEUE_ERROR            = 3
          TCODE_INVALID          = 4
          PRINTING_INVALID       = 5
          POSTING_INVALID        = 6
          OTHERS                 = 7
      IF SY-SUBRC <> 0.
        WRITE :/ 'Unable to insert the record'.
      ENDIF.
    ENDFORM.                    " FORM_INSERT
    *&      Form  FORM_CLOSESESS
          Form to Close the Open Session.
    FORM FORM_CLOSESESS .
      CALL FUNCTION 'BDC_CLOSE_GROUP'
        EXCEPTIONS
          NOT_OPEN    = 1
          QUEUE_ERROR = 2
          OTHERS      = 3.
      IF SY-SUBRC <> 0.
      ENDIF.
    ENDFORM.                    " FORM_CLOSESESS
    *&      Form  FORM_FORMATMSG
          Form to format messages.
    FORM FORM_FORMATMSG .
    *--Var to store the formatted msg.
      DATA : LV_MSG(255).
      CALL FUNCTION 'FORMAT_MESSAGE'
        EXPORTING
          ID        = SY-MSGID
          LANG      = SY-LANGU
          NO        = SY-MSGNO
          V1        = SY-MSGV1
          V2        = SY-MSGV2
          V3        = SY-MSGV3
          V4        = SY-MSGV4
        IMPORTING
          MSG       = LV_MSG
        EXCEPTIONS
          NOT_FOUND = 1
          OTHERS    = 2.
      IF SY-SUBRC = 0.
        WRITE :/ LV_MSG.
      ENDIF.
      ULINE.
    ENDFORM.                    " FORM_FORMATMSG
    *&      Form  form_writeop
          To write the totals and the session name.
    FORM FORM_WRITEOP .
      WRITE :/ 'Total Records Uploaded :',V_TLINES,
               / 'No of Error Records :',V_ELINES,
               / 'No of Success Records :',V_SLINES,
               / 'Name of the Session :',V_SESNAM.
      ULINE.
    ENDFORM.                    " form_writeop
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Parameter or static method?

    (i'm braziliam, sorry for any english mistake..)
    Imagine a object A, that contains a object B, that contains a object C, and so on...
    Imagine that the object Z needs to use a table that A object contains.
    Now, imagine All the people, leaving for today!.. (kidding.. lol)
    Ok, my question is:
    What is most corret/secure/usual to do?
    Pass the A's table (or self A object) to B's constructor, and from B to C, and so on until Z get it.
    Or create a static method A.getTable()?
    I like the idea of the static method, but I hear to avoid static methods....
    What do you say?

    if starsCount is a static parameter of Universe then the static method works fine.... but notice, if you assume there are multiples universes (that is, if your class A can have multiple instances, and that each instance has its own parameters), it won't work.
    Since we are supposing there are only one universe we can take your analogy one level below: suppose your Planet class has a parameter double mass. And the planet has cities, etc.... and then the human wants to know his planet's mass. Your static method solution will definitely not work here, unless you (strangely) assume "mass" is a static parameter of Planet class.... right?
    By the way, I'm brazilian too.... nice to know there are other brazilians here :D Let's keep it in english though right?

  • Nested Classes and Static Methods

    I was perusing the Java Tutorials on Nested Classes and I came across this...
    [http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
    I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
    Static Nested Classes
    As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
    Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Abstract classes and static methods

    I have an abstract report class AbstractReportClass which I am extending in multiple report classes (one for each report, say ReportA, ReportB, ...). Each report class has its own static column definitions, title, etc., which I have to access through a static method getDataMeta() in a web application. Each report has the same exact code in getDataMeta, and no report may exist without these fields. My intuition tells me that AbstractReportClass should contain the code for getDataMeta, but I know that you can't mix abstract and static keywords.
    Am I missing a simple solution to unify the getDataMeta code in the abstract base class? or do I really need to have a static function getDataMeta with the same code in each of the base classes?
    My apologies if this has been discussed many times before.
    Thanks,
    -Andrew

    I'm not trying to be "right"; rather I just asked a question about whether I can do something that seems intuitive. Perhaps you might write code in a different way than I would or perhaps I wasn't clear about every little detail about my code? Do you regularly belittle people who ask questions here?
    I have a loadFromDB() member function in AbstractReport for which all sub classes have an overloaded version. All reports I'm displaying have 4 common fields (a database id and a name and a monetary value, for example), but then each other report has additional fields it loads from the database. Inside ReportX classes' loadFromDB(), I call the superclass loadFromDB() function and augment values to get a completely loaded object. In fact, the loadedData member object resides in AbstractReport.
    I can't use a report unless it has these common features. Every report is an AbstractReport. There is common functionality built on top of common objects. Isn't this the point of inheritance? I'm essentially saying that abstract class Shape has a getArea function and then I'm defining multiple types of Shapes (e.g. Rectangle and Circle) to work with...

  • Datacorruption and static methods

    public static void myMethod( String Argument)
         int i = 0 ;
    What are the chances of data corruption in this static method?
    IF there are chances of data corruption, am I corrupt in saying that chances of data corruption for argument and Variable i are same?
    Where is function state stored in static method stored? What will happen to this if one thread pre-empts other?
    public class a
         int j;
         public static void myMethod( String Argument)
              int i = 0 ;
    How is integer j different from integer i? Where will JVM keep these variables ?

    What are the chances of data corruption in this static
    method? None. As long as this static method only acts on local variables (variables declared inside the method) each call to the method is completely separate from any other call.
    Where is function state stored in static method
    stored? What will happen to this if one thread
    pre-empts other?I'm not sure what you mean by 'function state' but static methods are not associated with an Object, though they can modify and depend on the state of static (class) varaivbles.
    How is integer j different from integer i? Where will
    JVM keep these variables ? j is a member varaible. It is associated wth the instance of the class. i is a local variable and is created at the beginning of a method call and destroyed (eventually) after the method completes.

  • Generics and static methods

    Hi,
    I need a sanity check to make sure I have not missed design pattern.
    I believe that it is not possible to call a static method defined in a generic type.
    For example:
    public class Red extends Color
        public static Color getHue()
    public class Green extends Color
        public static Color getHue()
    public class GenericColorTest<C extends Color>
        public void fooBar()
             Color hue= C.getHue();  // Is this a valid method call ?
    }Since the base class Color can not define static methods, it seems resonable that a generic type can't make the call to get getHue(). Or am I missing something ? Is there a way for the class GenericColorTest's generic type C to call a static method ?
    Thanks
    HB

    I think I can be ever more specific than gafter on this.
    Your call, "C.getHue()", just plain makes no sense. C is "some kind of Color object", and the class "Color" has no function (static or not) called "getHue()". So calling "C.getHue()" is a simple case of you trying to call a function that isn't in the class.
    In fact you can call static functions, but only if they are in the base class require by the generic definition (erm, sorry can't remember the exact term right now). So, for example, if there was a "getHue()" static function in your class "Color", then sure, you can call "C.getHue()" in your code. But since static functions can't be overridden, the "C.getHue()" will do exactly the same thing no matter which actual class C was at the moment, which doesn't seem to be what you want.
    The right thing to do is just make "getHue()" non-static. Then things will work great.

  • Data Curruption and Static methods

    public static void myMethod( String Argument)
         int i = 0 ;
    What are the chances of data corruption in this static method?
    IF there are chances of data corruption, am I corrupt in saying that chances of data corruption for argument and Variable i are same?
    Where is function state stored in static method stored? What will happen to this if one thread pre-empts other?
    public class a
         int j;
         public static void myMethod( String Argument)
              int i = 0 ;
    How is integer j different from integer i? Where will JVM keep these variables ?

    Sorry The
    int j ;
    should have been
    static int j;
    I thought the behaviour of a variable in a static method will be same as static variable.

  • Regarding Call Transaction and Session Method in BDC.

    Hi,
    If there are 50 records and 25th row data is having error.
    What will happen when we run it in Call Transaction and Session Method in both Foreground and Background methods ? Can anybody explain me in details ?

    Hi Naresh,
    If you are using call transaction,
    if executed in Foreground, 24 records will be posted and for 25th you will have option to correct data or skip.
    if executed in background,
    if mode is N,  24 records are processed 25th is skipped and 26th onwards is processed again.
    if mode is E, 24 records will be posted and for 25th you will have option to correct data or skip.
    For Session also it should be same the difference is that the error would be there in sessionlog and you can re-process it.
    Hope it helps.
    Regards,
    Komal.

  • Synchronized and static methods

    I've got a doubt: is it possible to apply syncrhonized to a static method? I know that synchronized takes a lock on the current object, but in the case of a static method there could be no object.
    So how can I synchronize a static method?
    Thanks,
    Luca

    previous X POST(s) :
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411296
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411285
    http://forum.java.sun.com/thread.jsp?forum=31&thread=390499
    http://forum.java.sun.com/thread.jsp?forum=31&thread=374388
    http://forum.java.sun.com/thread.jsp?forum=31&thread=325358
    BOTTOM LINE : Search the forum b4 posting.
    rgds.

  • Interfaces and static methods

    Hi All,
    Does anyone know why you can't declare static methods in an interface? Is there a way round this problem?
    Cheers...

    But this won't:public class StijnsClass
      public static void aMethod()
        System.out.println("StijnsClass.aMethod()");
      public static void main(String[] arg)
        StijnsClass stijnsInstance = new StijnsSubClass();
        stijnsInstance.aMethod();
        System.out.println("Nothing else to say, here?");
    class StijnsSubClass extends StijnsClass
      public static void aMethod()
        System.out.println("StijnsSubClass.aMethod()");
        super.aMethod(); // Wrong!!!
    }You will get:
    "StijnsClass.java:21: non-static variable super cannot be referenced from a static context".
    If you remove static from the subclass method definition, you will get:
    "StijnsClass.java:18: aMethod() in StijnsSubClass cannot override aMethod() in StijnsClass; overridden method is static"
    That's the point. You aren't extending the method; you are only hiding it. To make it work, both methods must be instance methods, ergo, static methods cannot be extended.

  • Polymorphism and static methods

    Say I have classes A and B:
    public class A {
         public static A newInstance() {
              return new A();
    public class B
    extends A {
    }How can I write the newInstance method in A so that:
    B.newInstance();returns an object of class B instead of A? I know I can override the method in B to make an object of the right type - but is there a way to write the A method so that the correct type is created by any subclasses?

    I suppose this is cheating...
    class A {
       public static A newInstance(Class c)
       throws InstantiationException, IllegalAccessException {
          return (A) c.newInstance();
    class B extends A {
    class Testx {
       public static void main(String[] args)
       throws InstantiationException, IllegalAccessException {
          B b = (B)B.newInstance(B.class);
          System.out.println(b.getClass().getName());  //B

  • Completely stuck, get/set, Contructors and Static Methods

    Hi any help would be very appreciated on this one,
    import java.util.Scanner;
    import java.io.*;*
    *import java.util.*;
    public class Course extends Program {
         public Course(String Coursecode, String Coursename){
              Coursecode = stuinput.courseCode;
    public void getCoursecode(){
         return stuinput.courseCode;
    //public String getCourseCode(){
    //     return this.courseCode;
           public static void printCourses() throws Exception
                stuinput[] courseObjArray = new stuinput[18]; //Make sure this is the same as the ammount in the text
                   Scanner sc = new Scanner(new File("courses.txt"));
                   int i=0;
                   boolean found = false;
                   while(sc.hasNextLine())
                   //Delimit this line with scanner
                   Scanner sc1 = new Scanner(sc.nextLine());
                   sc1.useDelimiter(":");
                   courseObjArray[i] = new stuinput(sc1.next(),sc1.next());
                   i++;
                   }//while
                   for(int i1 = 0;i1 < courseObjArray.length;i1++)
                   System.out.println(courseObjArray[i1].courseCode);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println("-----------------");          
           //This print the indexOf what you want to search
              class stuinput
              String courseCode = null;
              String courseName = null;
              stuinput()
              stuinput(String courseCode,String courseName)
              this.courseCode = courseCode;
              this.courseName = courseName;
    import java.io.*;
    public class gradCheck {
         public static void main (String args[]) throws Exception {
                      Course.printCourses(); //Prints All Course but dont need that
    }This ^^^ Is basically the driver class, Im trying to run the printCourse() from the 1st Class I posted.....but it's giving me lots of errors with everything I try, I'm trying to get the values out of that text file and have them broken up so I can use them amoung various class's, I want to use those values inside the Course class, as well as the Program Class and other Class's that extend off of that,
    Any Ideas (im sure there are because im very new), as to how I might to that
    Thanks :-) would be much appreciated

    yes, I still have a lot to learn here I think, Thank you so much, that worked for me, I think I need to read a lot about all of this and understand it......thank you
    If I may, one more thing which I'm really stuck on and if I can get this right, I think my whole program and ideas will just fall into place...Ive been trying to a couple of weeks now and can't quit get it right
    in the above code,
    this bit,
              class stuinput
              String courseCode = null;
              String courseName = null;
              stuinput()
              stuinput(String courseCode,String courseName)
              this.courseCode = courseCode;
              this.courseName = courseName;
              }how do I pass this off to another class through the constructor
    public class Course extends Program {
         public Course(){
         }at the top....say If I want it to be used in the Program class.......or a student class that extends of the this current class above (Course Class)
    Thanks,

  • VB6 - Confusion regarding Acrobat Version and supported methods

    I've got an app, created in VB6, that uses the javascript method "addWatermarkFromFile".  It works fine on my machine(s) with Acrobat 7 and 9.0.  One of the machines that it has been installed on gets an "Object doesn't support this property or method" error.  The machine has had several version of Acrobat on it in the past, but is now running 9.4.1.  I added a chunk of code to create the AcroExch app and Show it, and the user reports that it launches Acrobat 9.4.1, so I know it's creating an app that should support "addWatermarkFromFile".  Is there anything else I can check?  I don't know much about the OLE mechanisms.  Could a stray acrobat.tlb file cause something like that?

    After further review the problem was NOT related to addWatermarkFromFile, but rather was caused when the app called a javascript function that was implemented by the placement of a .js file in the Javascripts directory.  The user is now, inconveniently, on vacation, but I'm guessing either the script is not being created (unlikely) or that Javascript (or some portion of the javascript functionality) is disabled. 

Maybe you are looking for