<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: static attribute in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730675#M1110235</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Static variable is DEFINED by the key word CLASS-DATA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look at the following example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  ztest_zero_01.

*-- Employee - Definition
CLASS employee DEFINITION.

  PUBLIC SECTION.
    TYPES:
      BEGIN OF t_employee,
        no  TYPE i,
        name TYPE string,
     END OF t_employee.

    METHODS: constructor
        IMPORTING im_employee_no TYPE i
                  im_employee_name TYPE string.

    METHODS:  display_employee.

    METHODS: display_no_of_employees.

  PRIVATE SECTION.
    DATA: g_employee TYPE t_employee.
*   Class data(Static) are global for all instances
    CLASS-DATA: g_no_of_employees TYPE i.  " STATIC ATTRIBUTE

ENDCLASS.


*--- LCL Employee - Implementation
CLASS employee IMPLEMENTATION.

* Where ever you create object this constructor will be called
  METHOD constructor.
    g_employee-no = im_employee_no.
    g_employee-name = im_employee_name.
    g_no_of_employees = g_no_of_employees + 1.

    " Increasing the variable by 1 Since its a static variable it RETAINS the previous value

  ENDMETHOD.

  METHOD display_employee.
    WRITE:/ 'Employee', g_employee-no, g_employee-name.
  ENDMETHOD.

  METHOD display_no_of_employees.
    WRITE: / 'Number of employees is:', g_no_of_employees.
  ENDMETHOD.

ENDCLASS.

***********************************************************
* R E P O R T
***********************************************************
DATA: g_employee1 TYPE REF TO employee,
      g_employee2 TYPE REF TO employee,
      g_employee3 TYPE REF TO employee.


START-OF-SELECTION.

  CREATE OBJECT g_employee1
    EXPORTING im_employee_no = 101
              im_employee_name = 'ASIK'.    " Here g_no_of_employees = 1
  CREATE OBJECT g_employee2
    EXPORTING im_employee_no = 102
              im_employee_name = 'THOMAS'.  " Here g_no_of_employees = 2
  CREATE OBJECT g_employee3
    EXPORTING im_employee_no = 103
              im_employee_name = 'PRINCE'.  " Here g_no_of_employees = 3

  CALL METHOD g_employee1-&amp;gt;display_employee.
  CALL METHOD g_employee2-&amp;gt;display_employee.
  CALL METHOD g_employee3-&amp;gt;display_employee.

* since g_no_of_employees is a class-data (ie.STATIC data) where ever
* you create object this will be automatically increased. if u declared
* as normal data it cant be increased globally while creating object.

  CALL METHOD g_employee1-&amp;gt;display_no_of_employees.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Oct 2008 07:05:08 GMT</pubDate>
    <dc:creator>asik_shameem</dc:creator>
    <dc:date>2008-10-31T07:05:08Z</dc:date>
    <item>
      <title>static attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730673#M1110233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can anyone explain me with simple example what is static attribute in ABAP Objects. Eventhough i read the same, I am confused regarding the same. Is it same as constant. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 06:34:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730673#M1110233</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-31T06:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: static attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730674#M1110234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello John&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In principle (public) static attributes can be accessed without having an instance of the class. The same is true for public constants, e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  IF ( cl_gui_alv_grid=&amp;gt;GUI_IS_RUNNING( ) = abap_true ).
   ...
  ENDIF.

  ld_ucomm = cl_gui_alv_grid=&amp;gt;MC_EVT_ENTER.
   ...
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only major difference I am aware of (perhaps Klaus Ziegler will correct me) is that you can change static attributes whereas constants have a fixed value.&lt;/P&gt;&lt;P&gt;And that is the main distinction when to use the one or the other (at least for me).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 06:51:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730674#M1110234</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-10-31T06:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: static attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730675#M1110235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Static variable is DEFINED by the key word CLASS-DATA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look at the following example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  ztest_zero_01.

*-- Employee - Definition
CLASS employee DEFINITION.

  PUBLIC SECTION.
    TYPES:
      BEGIN OF t_employee,
        no  TYPE i,
        name TYPE string,
     END OF t_employee.

    METHODS: constructor
        IMPORTING im_employee_no TYPE i
                  im_employee_name TYPE string.

    METHODS:  display_employee.

    METHODS: display_no_of_employees.

  PRIVATE SECTION.
    DATA: g_employee TYPE t_employee.
*   Class data(Static) are global for all instances
    CLASS-DATA: g_no_of_employees TYPE i.  " STATIC ATTRIBUTE

ENDCLASS.


*--- LCL Employee - Implementation
CLASS employee IMPLEMENTATION.

* Where ever you create object this constructor will be called
  METHOD constructor.
    g_employee-no = im_employee_no.
    g_employee-name = im_employee_name.
    g_no_of_employees = g_no_of_employees + 1.

    " Increasing the variable by 1 Since its a static variable it RETAINS the previous value

  ENDMETHOD.

  METHOD display_employee.
    WRITE:/ 'Employee', g_employee-no, g_employee-name.
  ENDMETHOD.

  METHOD display_no_of_employees.
    WRITE: / 'Number of employees is:', g_no_of_employees.
  ENDMETHOD.

ENDCLASS.

***********************************************************
* R E P O R T
***********************************************************
DATA: g_employee1 TYPE REF TO employee,
      g_employee2 TYPE REF TO employee,
      g_employee3 TYPE REF TO employee.


START-OF-SELECTION.

  CREATE OBJECT g_employee1
    EXPORTING im_employee_no = 101
              im_employee_name = 'ASIK'.    " Here g_no_of_employees = 1
  CREATE OBJECT g_employee2
    EXPORTING im_employee_no = 102
              im_employee_name = 'THOMAS'.  " Here g_no_of_employees = 2
  CREATE OBJECT g_employee3
    EXPORTING im_employee_no = 103
              im_employee_name = 'PRINCE'.  " Here g_no_of_employees = 3

  CALL METHOD g_employee1-&amp;gt;display_employee.
  CALL METHOD g_employee2-&amp;gt;display_employee.
  CALL METHOD g_employee3-&amp;gt;display_employee.

* since g_no_of_employees is a class-data (ie.STATIC data) where ever
* you create object this will be automatically increased. if u declared
* as normal data it cant be increased globally while creating object.

  CALL METHOD g_employee1-&amp;gt;display_no_of_employees.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 07:05:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/static-attribute/m-p/4730675#M1110235</guid>
      <dc:creator>asik_shameem</dc:creator>
      <dc:date>2008-10-31T07:05:08Z</dc:date>
    </item>
  </channel>
</rss>

