Writing an Object Reference into a Container
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.
-
The concatenated key of the object must be available in a variable (designated as object key here).
Procedure
-
Create a variable for the object reference. Use the following command to do this:
DATA <Object> TYPE SWC_OBJECT.
-
Create a variable for the object reference. Use the following command to do this:
SWC_CREATE_OBJECT <Object> <Objecttype> <Objectkey>.
-
Write the object reference into the container using the following macro instruction:
SWC_GET_ELEMENT <Container> <ContainerElement> <Object>.
-
Repeat steps 2 and 3 until the container is filled.
-
Make the object references of the container persistent using the following macro instruction:
SWC_CONTAINER_TO_PERSISTENT <Container>.
Results
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.