Procedure documentationWriting an Object Reference into a Container Locate this document in the navigation structure

Prerequisites

The following prerequisites must be fulfilled in order to write an object reference of a BOR object into a container:

  • The container must have been created and initialized.

  • For function modules, the include file <CNTN01> must be incorporated in the program. For ABAP classes, the include files <CNTN02> and <CNTN03> must be incorporated. For more information, see Macro Instructions for Processing a Container.

    Note Note

    These prerequisites are always fulfilled if you are in the implementation program. The container is then addressed with the name CONTAINER.

    End of the note.
  • The concatenated key of the object must be available in a variable (designated as object key here).

Procedure

  1. Create a variable for the object reference. Use the following command to do this:

    DATA <Object> TYPE SWC_OBJECT.

  2. Create a variable for the object reference. Use the following command to do this:

    SWC_CREATE_OBJECT <Object> <Objecttype> <Objectkey>.

  3. Write the object reference into the container using the following macro instruction:

    SWC_GET_ELEMENT <Container> <ContainerElement> <Object>.

    Caution Caution

    Upper and lower case are not distinguished for the container element ID. If the container is used in the binding of a workflow, you must ensure that a container element of the same name is defined in the container definition.

    End of the caution.
  4. Repeat steps 2 and 3 until the container is filled.

  5. Make the object references of the container persistent using the following macro instruction:

    SWC_CONTAINER_TO_PERSISTENT <Container>.

    Note Note

    You need persistent object references if the container is also to be used in another program context. This applies if you pass the container as a parameter in a function call, for example if:

    • You want to evaluate or change the container as an event container in a check function module or receiver type function module

    • You prepare the container as an event container and use it as a parameter of the function modules SWE_EVENT_CREATE or SAP_WAPI_CREATE_EVENT.

    End of the note.

Result

The object reference created is a runtime reference that only exists in the environment of the creating program. This object reference is written into the container in a container element. If the container element with this ID is not yet in the container, it is inserted into the container with its value. If there is already a container element with this ID in the container, the old value is overwritten with the new value. If the container is needed in another program context, you must make the object references contained persistent.

Example

An object of the type KNA1 (customer) is described as a key field using the customer number. The customer number is under KUNNR in the table KNA1 (customer master: general section).

* Type declaration for key field * Object: Customer (debitor) DATA KUNNR LIKE KNA1-KUNNR. "Customer number

A value is assigned to the field KUNNR:

* Customer number KUNNR = '0000004711'.

The variable CUSTOMER is declared as an object reference.

* Type declarations for object DATA CUSTOMER TYPE SWC_OBJECT.

An object reference is created for the object type KNA1 (customer) mentioned above.

* Create object reference for object type KNA1 SWC_CREATE_OBJECT CUSTOMER 'KNA1' KUNNR.

The customer is entered into the container MY_CONTAINER in the container element Customer.

* Write object reference into container SWC_SET_ELEMENT MY_CONTAINER 'Customer' CUSTOMER.

The object references of the container are made persistent.

SWC_CONTAINER_TO_PERSISTENT MY_CONTAINER.