MichaelB.
7/25/2018 - 7:59 PM

Create a local CLASS (PUBLIC/PRIVATE SECTION)

To create a class we must have both DEFINITION (first) & IMPLEMENTATION (second). When we create a CLASS no object is created. We are just defining the blueprint for what objects based on this class contain and do. Classes can be defined locally, like below, or globally using SE24 (Class Builder). The Class Builder stores our class in the data dictionary. Object - is an instance of a class. We instantiate an object based on the blueprint. Allows us to store data and/or allow method execution.

CLASS student DEFINITION.

  PUBLIC SECTION.
    DATA: name   TYPE c LENGTH 40,
          age    TYPE i,
*         gender TYPE c LENGTH 1 READ-ONLY,
          status TYPE c LENGTH 1.
    CLASS-DATA: count TYPE i.
    
    METHODS setname
      IMPORTING namein TYPE c.
    
    METHODS getname
       EXPORTING nameout TYPE c.
    
    METHODS setstatus
      CHANGING newstatus TYPE c.

  PRIVATE SECTION.
    DATA: loginid TYPE c LENGTH 20,
          pwd     TYPE c LENGTH 15.

* Here you would declare methods that are PRIVATE just like in the PUBLIC section.

ENDCLASS.

CLASS student IMPLEMENTATION.
  
  METHOD setname.
    name = namein.
  ENDMETHOD.
  
  METHOD getname.
    nameout = name.
  ENDMETHOD.
  
  METHOD setstatus.
    IF newstatus CO 'MF'.
      status = newstatus.
      newstatus = '1'.            "Set the returning value to 1 = STATUS was set
    ELSE.
      newstatus = '2'.            "Set the returning value to 2 = STATUS was not set
    ENDIF.
  ENDMETHOD.
  
ENDCLASS.