Start of Content Area

This graphic is explained in the accompanying text Enumerations  Locate the document in its SAP Library structure

An enumeration is a facet that you can use to restrict the value range of a simple data type, attribute, or element to a predefined selection (more information: Data Types in the Enterprise Services Repository). Java proxy generation generates a Java class for accessing the values. This class provides a type and value secure mapping of the enumeration by generating constants for each value and only enabling access using methods:

      There are two constants for each value that, where possible, have the same name as the value itself (for example, in the case of string values). Otherwise, the constants have the names value1, value2,...., valueN (with or without an underscore):

       A value constant of the type of the simple data type, attribute, or element. The constant therefore has the value of a possible value in the enumeration. In addition, the constant name has an underscore as a prefix (for example,  _value1).

       A object constant of the type of the inner class. An object of the inner class is instantiated for the constant and the value constant is set for an attribute of the object.

      The internal class provides two methods for accessing the object constant or the value of the value constant:

       Both fromValue( <enumeration value> ) and fromString(<enumeration value (as a string)> ) return the object constant of an enumeration. fromValue()expects the value constant and fromString()expects the value in its string representation. If the values are incorrect, the respective method throws the runtime exception java.lang.IllegalArgumentException.

       getValue() and toString() get the value for an object constant.

Note

The enumeration classes are based on the JAX RPC specification that you can download from http://java.sun.com/xml/downloads/jaxrpc.html (see chapter 4.2.4 at this location).

Example

The element fruit is restricted to the value range “apple pear banana plum orange“. The element fruit is part of the data type Grocery. Java proxy generation generates a global class Grocery_Type with the inner class Grocery_Type.Fruit_Type. Within this inner class it also generates the following constants:

      A string constant for each value of the enumeration, for example
public static final java.lang.String _apple = "apple";

      A object constant for each value of the enumeration, for example
public static final Fruit_Type apple = new Fruit_Type(_apple);

If you instantiate the object g for the class Grocery_Type, the methods for the enumeration fetch the following values:

Method Call

Return Value

g.Fruit_Type.fromValue(_orange)

Object constant orange of type Fruit_Type

g.Fruit_Type.fromString(“orange“)

Object constant orange of type Fruit_Type

orange.getValue()

“orange“

orange.toString()

“orange“

 

 

 

 

 

 

End of Content Area