Tuesday, May 13, 2008

Working with Workflow container macros

Working with Workflow container macros:

Macros for accessing objects

Accessing objects in the business object repository is currently supported by a set of macros. These macros are described in more detail in the following.

All macros are comprised in the Include . This Include is contained in the Include , therefore making these macros automatically available in all object type implementations. Client programs which work with objects should use .

If the macros are used in ABAP Objects classes, use the includes and . contains the actual macro definitions; include it in the macro section of the class. Some attributes addressed from are defined in . must be included in the type section of the class.

Container

Containers are used for dynamic transfer of parameters and result values. The following macros are available for processing them:

Macro

Description

swc_container Declare a container

swc_create_container Create a new container

swc_release_container Release a container

swc_clear_container Clear a container

swc_create_element Create element in container

swc_set_element Insert element in container

swc_set_table Insert multiline element in container

swc_get_element Read element from container

swc_get_table Read multiline element from container

swc_delete_element Delete element from container

A detailed documentation of the container macros is provided in the SAP Library under: (Basis -> Business Management -> SAP Business Workflow Navigation -> Business Object Builder -> Programming in Implementation Program).

Object references

Declaration

DATA: TYPE SWC_OBJECT

Variables which contain object references are defined with the type SWC_OBJECT. A special case within the object implementation is the system variable SELF, which contains a reference to itself.

Create

SWC_CREATE_OBJECT

Object references are created using the macro SWC_CREATE_OBJECT. The first parameter received by the macro is the variable in which the reference is returned, the second parameter the type of object which is to be created, and the third parameter the key of the object.

Delete

SWC_FREE_OBJECT

The macro SWC_FREE_OBJECT can be used to release existing object references. The macro receives the reference to be released as input.

Read type and key

SWC_GET_OBJECT_TYPE

The macro SWC_GET_OBJECT_TYPE can be used to read the object type belonging to the object reference. The first parameter received by the macro is the object reference, the second parameter the return parameter containing the respective object type after the call. The field SWOTOBJID-OBJTYPE can be used as the data type reference for the object type.

SWC_GET_OBJECT_KEY

The macro SWC_GET_OBJECT_KEY can be used to read the key of an object. The macro is passed the reference of the object whose key is to be read as the first parameter and returns the key in the second parameter as the result. The field SWOTOBJID-OBJKEY can be used as the data type reference for the object type.

Method access

SWC_CALL_METHOD

The macro SWC_CALL_METHOD can be used to call methods of objects. The first parameter contains the object reference, the second the name of the method. The container holding all input values is passed in the third parameter. If the call is successful, the result (container element _RESULT) and the export parameters of the method call are stored in the container. If the invoked method raises an exception, the number of the exception is contained in the system variable SY-SUBRC and other values in the variables SY-MSGV1, ..., SY-MSGV4.

Attribute access

Read

SWC_GET_[TABLE_]PROPERTY

The macros SWC_GET_PROPERTY or SWC_GET_TABLE_PROPERTY can be used to access the attributes of an object. Both macros receive the object reference in the first parameter and the name of the attribute which is to be accessed in the second parameter. Both macros return the value of the attribute in the third parameter as the result. SWC_GET_PROPERTY returns single attribute values, SWC_GET_TABLE_PROPERTY returns multiline attribute values as internal tables.

Refresh

SWC_REFRESH_OBJECT

Attributes which are references to database fields are only read from the database for the first access. To refresh attribute values, the macro SWC_REFRESH_OBJECT can be called, causing the database to be read again the next time the attribute is accessed. The macro contains the object reference as an input parameter.

Trigger events

SWC_RAISE_EVENT

The macro SWC_RAISE_EVENT can be used to trigger events of object types. The reference to the object is passed to the macro as input in the first parameter, the name of the event in the second, and the container with the parameters for the event in the third parameter.

Special features within object type implementations

In addition to the macros listed above, contains macros which can be used within object type implementations.

Object reference to self

An own instance within the object type reference can be referenced with the variable SELF. This reference can be used to request attribute values of the current instance with SWC_GET_[TABLE_]PROPERTY.

Set object key

SWC_SET_OBJECTKEY

The macro SWC_SET_OBJECTKEY can be used to set the key of the object within method implementations. This is practical for methods such as create or find which link an object reference to a persistent object - which may be newly created.

Raise exceptions

EXIT_RETURN Publish Post

Within object type implementations, methods can raise exceptions which are defined in the method interface. To do this, the macro EXIT_RETURN is called which is passed the number of the exception and four result values as input. The result values can also be SPACE if they are empty.

Example

The following example is an extract from the example program RSWOCLNT. It uses the object types SCHEDULE, DOMINANT und APPOINTMENT from the SAP appointment calendar (transaction SSC1).

The program first lists the dominants (attribute DominantOfToday) and the appointments of the day (attribute AppointmentsOfToday), and then the appointments of the last and the next 5 days (method AppointmentsGet). Before the program is executed, appointments should be created in the calendar (SSC1).

REPORT RSWOCLNT.

***** use of container macros
INCLUDE .

***** object reference declaration
DATA: SCHEDULE TYPE SWC_OBJECT.

***** object reference creation
SWC_CREATE_OBJECT SCHEDULE 'SCHEDULE' SY-UNAME.
IF SY-SUBRC NE 0.
.....
ENDIF.

***** access to attribute
DATA: DOMINANT TYPE SWC_OBJECT.
SWC_GET_PROPERTY SCHEDULE 'DominantOfToday' DOMINANT.
IF SY-SUBRC NE 0.
.....
ENDIF.

***** access to mulitline attribute
DATA: APPOINTMENTS TYPE SWC_OBJECT OCCURS 0.
DATA: APP TYPE SWC_OBJECT.
SWC_GET_TABLE_PROPERTY SCHEDULE 'AppointmentsOfToday' APPOINTMENTS.
IF SY-SUBRC = 0.
LOOP AT APPOINTMENTS INTO APP.
.....
ENDLOOP.
ENDIF.

***** method invocation
DATEFROM = SY-DATUM - 5.
DATETO = SY-DATUM + 5.
* create container
SWC_CONTAINER CONTAINER.
* fill container
SWC_SET_ELEMENT CONTAINER 'DateFrom' DATEFROM.
SWC_SET_ELEMENT CONTAINER 'DateTo' DATETO.
* call method
SWC_CALL_METHOD SCHEDULE 'AppointmentsGet' CONTAINER.
IF SY-SUBRC = 0.
REFRESH APPOINTMENTS.
* read method result
SWC_GET_TABLE CONTAINER '_RESULT' APPOINTMENTS.
LOOP AT APPOINTMENTS INTO APP.
.....
ENDLOOP.
ENDIF.