Writing a Multiline Object Reference into a Container (BOR)

Prerequisites

The following prerequisites must be fulfilled in order to write a multiline object reference of a classical object (BOR) 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


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

    DATA <Object list> TYPE SWC_OBJECT OCCURS 0.

    The internal table created does not have a table header. You fill it by creating each object reference individually and appending them to the table.

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

    DATA <Object> TYPE SWC_OBJECT.

  3. Create the first object reference. Use the following command to do this:

    SWC_CREATE_OBJECT <Object> <Objecttype> <Objectkey>.

  4. Append the object reference to the table. Use the following command to do this:

    APPEND <Object> TO <ObjectList>.

  5. Repeat the previous two steps until the table is full.

  6. Write the multiline object reference into the container. Use the following command to do this:

    SWC_SET_TABLE <Container> <ContainerElement> <ObjectList>.

  7. Make the object reference persistent. Use the following command to do this:

    SWC_CONTAINER_TO_PERSISTENT <Container>.

Results

The object references created are runtime references that only exist in the environment of the creating program. These object references are 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

The variable POSITIONLIST (item list) is declared as a multiline object reference.

* Type declarations for multiline object reference DATA POSITIONLIST TYPE SWC_OBJECT OCCURS 0.

The variable POSITION (item) is declared as an object reference. This variable serves as an auxiliary variable in the processing of the multiline object list.

* Type declarations for object reference DATA POSITION TYPE SWC_OBJECT.

Values are assigned to the internal table POSITIONKEY (item key). An object reference is created in the variable Position for each entry and written into the multiline object reference POSITIONLIST.

* Typdeklarationen für die Schlüsselfelder des
* Objektes "Position eines Auftrags"
DATA: BEGIN OF POSITIONKEY,
         DOCUMENT LIKE VBAP-VBELN,   "Verkaufsbeleg
         ITEM     LIKE VBAP-POSNR,   "Verkaufsbelegposition
       END OF POSITIONKEY.
* mehrzeilige Objektreferenz bearbeiten
SELECT * FROM VBAP
   WHERE VBELN BETWEEN '0000002500' AND '0000002600'.
* Schlüsselfelder füllen
   POSITIONKEY-DOCUMENT = VBAP-VBELN.
   POSITIONKEY-ITEM     = VBAP-POSNR.

  * Objektreferenz erzeugen
   SWC_CREATE_OBJECT POSITION 'VBAP' POSITIONKEY.

  * Objektreferenz in mehrzeilige Objektreferenz einfügen
   APPEND POSITION TO POSITIONS.
 ENDSELECT.
         

The multiline object reference POSITIONLIST is written into the container MY_CONTAINER in the container element Items.

* Write multiline object reference to container SWC_SET_TABLE MY_CONTAINER 'items' POSITIONLIST.

For a further example, see Implementation Program for a Virtual Attribute.