Background documentationImplementation Program for a Virtual Attribute (BOR) Locate this document in the navigation structure

 

The extensions in the implementation program for a virtual attribute are located between the macro instructions GET_TABLE_PROPERTY and END_PROPERTY.

You must program how the value of the virtual attribute is generated at runtime. The value established or calculated is stored under its attribute ID in the container CONTAINER. Use the macro instruction SWC_SET_ELEMENT for single-line attributes or the macro instruction SWC_SET_TABLE for multiline attributes.

Syntax Syntax

  1. * Zugriff auf virtuelles Attribut
    ************************************************************
    GET_PROPERTY Attribut CHANGING CONTAINER.
    ...
        WC_SET_ELEMENT CONTAINER <Attribut> <Wert>.
    END_PROPERTY.
End of the code.

Caution Caution

The source text is generated automatically as a proposal from the entries you made in the object type definition. You must edit the source text for the implementation of virtual attributes.

End of the caution.
Virtual attribute as object reference and multiline virtual attribute

Virtual attributes are significant under the following circumstances in particular:

  • If the attribute is to supply a reference to an object at runtime, which has several key fields.

    Construct the key of the referenced object in the implementation program, create an object reference and return this to the caller.

  • If the attribute is defined as a multiline attribute.

Example

Implementation of the multiline, virtual attribute Items (sales document items) for the object type VBAK (sales document).

The key field of the object type VBAK is SalesDocument. This key field references the field VBAK-VBELN.

The attribute Items returns a multiline reference to an object of type VBAP (sales document item). The key fields of the object type VBAP are SalesDocumentNo (sales document) and ItemNo (sales document item). These key fields reference the fields VBAP-VBELN (or VBAK-VBELN) and VBAP-POSNR.

The system added the table Object-Items in the data declaration part automatically.

In the implementation program, define which information is used to construct this multiline object reference at runtime as well as how it is entered into the container.

The macro instruction SWC_CREATE_OBJECT can be used to construct an object reference from an object type and concatenated object key, and assign this object reference to the variable declared with SWC_OBJECT:

Syntax Syntax

  1. * virtuelles, mehrzeiliges Attribut Items GET_PROPERTY ITEMS CHANGING CONTAINER.
    * Datendeklarationen 
    ***********************************************************
    DATA ITEM TYPE SWC_OBJECT.
    DATA:
       BEGIN OF VBAP_KEY,
         VBELN LIKE VBAP-VBELN,
         POSNR LIKE VBAP-POSNR,
       END OF VBAP_KEY.
     DATA BEGIN OF VBAP_TAB OCCURS 0.
       INCLUDE STRUCTURE VBAP.
     DATA END OF VBAP_TAB.
    * Datenselektion
    ***********************************************************
      IF OBJECT-ITEMS IS INITIAL.
         SELECT * FROM VBAP INTO TABLE VBAP_TAB
           WHERE VBELN = OBJECT-KEY-SALESDOCUMENT.
         IF SY-SUBRC NE 0.
           EXIT.
         ENDIF.
         VBAP_KEY-VBELN = OBJECT-KEY-SALESDOCUMENT.
         LOOP AT VBAP_TAB.
           VBAP_KEY-POSNR = VBAP_TAB-POSNR.
    * Erzeugen einer Objektreferenz aus Objekttyp und Objektschlüssel
    ************************************************************
           SWC_CREATE_OBJECT ITEM 'VBAP' VBAP_KEY.
           APPEND ITEM TO OBJECT-ITEMS.
         ENDLOOP.
       ENDIF.
    * Zuweisung der Objektreferenz an Containerelement
    ************************************************************
      SWC_SET_TABLE CONTAINER 'Items' OBJECT-ITEMS.
     END_PROPERTY.
End of the code.