Downtime Announcement: Please note the SAP Community Wiki will be unavailable due to a system upgrade on Thursday, September 24th between 6 and 7 AM CEST
Skip to end of metadata
Go to start of metadata

Author: Marcelo Ramos
Submitted: 09/22/2008

Related Links:

Class Definition

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*---------------------------------------------------------------------*
*       CLASS main DEFINITION
*---------------------------------------------------------------------*
CLASS main DEFINITION.

  PUBLIC SECTION.

    "// Instance Methods ( Note we use the statement 'METHODS'
    "// to define an instance method )
    METHODS set_data IMPORTING i_data TYPE string.
    METHODS get_data RETURNING value(r_data) TYPE string.
    METHODS print_attribute IMPORTING i_data TYPE string.

    "// Instance Methods ( Note we use the statement 'CLASS-METHODS'
    "// to define a static method )
    CLASS-METHODS set_classdata IMPORTING i_data TYPE string.
    CLASS-METHODS get_classdata RETURNING value(r_data) TYPE string.
    CLASS-METHODS print_classattribute IMPORTING i_data TYPE string.

  PROTECTED SECTION.

    "// Instance Attribute ( Note we use the statement 'DATA'
    "// to define an instance attribute )
    DATA attribute TYPE string.
    "// Static Attribute ( Note we use the statement 'CLASS-DATA'
    "// to define a static attribute )
    CLASS-DATA classattribute TYPE string.

  PRIVATE SECTION.

    "// Instace event ( Note we use the statement 'EVENTS'
    "// to define aN instance event )
    EVENTS event EXPORTING value(e_data) TYPE string.

    "// Instace event ( Note we use the statement 'CLASS-EVENTS'
    "// to define a static event )
    CLASS-EVENTS classevent EXPORTING value(e_data) TYPE string.

    "// For more informations about events see the following example:
    "// ABAP Objects - Creating your First Local Class - Using Events

ENDCLASS.                    "main DEFINITION

Class Implementation

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*---------------------------------------------------------------------*
*       CLASS main IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS main IMPLEMENTATION.

  METHOD set_data.

    CONCATENATE 'Instance Attribute value' i_data
                               INTO attribute SEPARATED BY space.

  ENDMETHOD.                    "set_data

  METHOD get_data.

    MOVE attribute TO r_data.

  ENDMETHOD.                    "get_data

  METHOD set_classdata.

    CONCATENATE 'Static Attribute value' i_data
                               INTO classattribute SEPARATED BY space.

  ENDMETHOD.                    "set_classdata

  METHOD get_classdata.

    MOVE main=>classattribute TO r_data.

  ENDMETHOD.                    "get_classdata

  METHOD print_attribute.

    WRITE: i_data, /.

  ENDMETHOD.                    "print_attribute

  METHOD print_classattribute.

    WRITE: i_data, /.

  ENDMETHOD.                    "print_classattribute

ENDCLASS.                    "main IMPLEMENTATION

Data Definition

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: var type char20.

Calling Static Methods

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
START-OF-SELECTION.

  "// Calling a Static method (note we don't have a object )
  "// instead we use the <class name>=><method name>.
  main=>set_classdata( 'SDN' ).
  var = main=>get_classdata( ).
  "// Print the var value
  main=>print_classattribute( var ).

Object Definition

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: object_reference TYPE REF TO main.

Instance Creation

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
  CREATE OBJECT object_reference.

Calling Instance Methods

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
  "// - Calling a Instance Method( Note we have to use a object to
  "// access the insntace components of class main )
  "// - Note we're using the statment "CALL METHOD", see looking for
  "// functional & General methods for more informations
  CALL METHOD object_reference->set_data( 'BPX' ).
  var = object_reference->get_data(  ).
  object_reference->print_attribute( var ).

The result is

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
"Static Attribute value SDN
"Instance Attribute value BPX

3 Comments

  1. Unknown User (uanlq16)

    Hello Marcelo,

    I am neither an OO specialist nor an OO guru and most likely I don't want to become one. But occasionally I study some blogs regarding this matter. I very appreciate your Wiki even it's almost a year ago since it's published. The best idea studying something is without doubt testing and playing through given examples. So I did with ABAP Objects - Creating your First Local Class - Defining Components. Copying and pasting, I created a program and to my surprise your given coding doesn't work at all!
    Here is a list of all "inconsistencies":

    Error/Misspelling as is

    Has to be

    Remark

    METHODS get_data EXPORTING e_data TYPE char20.

    METHODS get_data returning value(e_data) type char30.

    1. The method get_data is used as a  functional instance method and therefore RETURNING VALUE is required.
    2. CHAR20 has to be extended to at least 26 Character to display the full length.

    METHODS print_attribute IMPORTING value TYPE char20.

    METHODS print_attribute IMPORTING value TYPE char30.

    Attribute value has to have at least 26 characters.

    WRITE value.

    WRITE / value.

    In METHOD print_attribute: to achieve the described line break.

    CONCATENATE 'Instance Attribute value' atribute
                                   INTO r_data SEPARATED BY space.

    CONCATENATE 'Instance Attribute value' atribute
                                   INTO e_data SEPARATED BY space.

    In METHOD get_data: r_data is not defined in Class main; instead e_data.

    DATA: var type char20.

    DATA: var type char30.

    In Program code: has to have at least 26 characters.

    main=>print_class_attribute( ).

    main=>print_class_attribute( ).

    This line has to be placed in an ABAP event, e.g. START-OF-SELECTION.

    Here is the complete ABAP code with the expected result:

    *&---------------------------------------------------------------------*
    *& Report  Z_OO_CREATE_FIRST_LOCAL_CLASS
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*

    REPORT  z_oo_create_first_local_class.

    *---------------------------------------------------------------------*
    *       CLASS main DEFINITION
    *---------------------------------------------------------------------*
    CLASS main DEFINITION.

      PUBLIC SECTION.

        "// Instance Methods
        METHODS add_data
                         IMPORTING i_data TYPE i.

        METHODS get_data returning value(e_data) type char30.
                        
        METHODS print_attribute IMPORTING value TYPE char30.

        "// Static Method
        CLASS-METHODS print_class_attribute.

      PRIVATE SECTION.

        "// Instance Attribute
        DATA atribute TYPE char01.

        "// Static Attribute
        CLASS-DATA classatribute TYPE char01.

    ENDCLASS.                    "main DEFINITION

    *---------------------------------------------------------------------*
    *       CLASS main IMPLEMENTATION
    *---------------------------------------------------------------------*
    CLASS main IMPLEMENTATION.

      METHOD add_data.

        ADD i_data TO atribute.

      ENDMETHOD.                    "add_data

      METHOD get_data.

        CONCATENATE 'Instance Attribute value' atribute
                                   INTO e_data SEPARATED BY space.

      ENDMETHOD.                    "get_data

      METHOD print_attribute.

        WRITE / value.

      ENDMETHOD.                    "print_attribute

      METHOD print_class_attribute.

        MOVE 'X' TO classatribute.
        WRITE'Static Attribute value', classatribute.

      ENDMETHOD.                    "print_class_attribute

    ENDCLASS.                    "main IMPLEMENTATION

    *Static Component Access
    start-of-selection.
      main=>print_class_attribute( ).

    * Object Definition
      DATA: object_reference TYPE REF TO main.
      DATA: var TYPE char30.

    **Instance Creation
      CREATE OBJECT object_reference.

    *Calling Methods
      CALL METHOD object_reference->add_data( i_data = 3 ).

    var = object_reference->get_data(  ).
    *
    CALL METHOD object_reference->print_attribute
      EXPORTING value = var.

    *the atribute value is printed:

    * Static Attribute value X"
    * Instance Atribute value 3"  

    That's my support!

    Cheers (smile) ,

    Heinz

  2. Unknown User (l8oh4bb)

    I got the program to work with just 1 change.

    DATA: var type char20. is not type compatable with i_data (type string - the compiler was complaining about it)
    so when I changed var to type string, everything worked and i got the expected results.
    Nice blog series. It is good for helping learn concepts and best practices.

  3. Former Member

    Nice article !