Class in abap

 Class:

    *  Class is a collection of data members and member functions.

    *  Data members means variables and member function means functions.

    *  T-code -se24 and also se38.

    Syntax of class

        class < class_name> definiton.

            { visibility} - public,protected,private

            { declaration} - static / instance

            { events/interfaces}

        endclass.

        class <class_name> implementation.

            method <method_name>

            endmethod

        endclass.

    data obj_class type refer to<class_name>

    create object obj_class. or data(obj_class) = new <class_name> ().

    Example in se38 - local class 

         

    REPORT ZAJAY_CL_1.
    CLASS a DEFINITION.
      PUBLIC SECTION.
          data: text1 type string VALUE 'hello1'.
          METHODS meth.
      PROTECTED SECTION.
          data: text2 type string VALUE 'hello2'.
      PRIVATE SECTION.
           data: text3 type string VALUE 'hello3'.
      ENDCLASS.

    CLASS a IMPLEMENTATION.
          METHOD meth.
              write: / text1,
                    / text2 ,
                    / text3.
                        
            ENDMETHOD.
        ENDCLASS.

     START-OF-SELECTION.
    data obj TYPE REF TO a.
    create OBJECT obj.
    obj->meth( ).

         Example in se24 - Global class

      *  declare variables in attributes

     

    *  declare methods in methods and double click on method then write operation.


                                

Comments

Popular posts from this blog

Custom entity/Action dialog in RAP using Unmanaged scenario

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).