Implementation Program for a Virtual Attribute

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.

* Access to virtual attribute
************************************************************
GET_PROPERTY Attribute CHANGING CONTAINER.
...
   SWC_SET_ELEMENT CONTAINER <Attribute> <Value>.
END_PROPERTY.

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.

Virtual attribute as object reference and multiline virtual attribute

Virtual attributes are significant under the following circumstances in particular:

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

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 :

* Virtual, multiline attribute Items
GET_PROPERTY ITEMS CHANGING CONTAINER.
* Data declarations
***********************************************************
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.
* Data selection
***********************************************************
  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.
* Create object reference from object type and object key
************************************************************
      SWC_CREATE_OBJECT ITEM 'VBAP' VBAP_KEY.
      APPEND ITEM TO OBJECT-ITEMS.
    ENDLOOP.
  ENDIF.
* Assignment of object reference to container element
************************************************************
  SWC_SET_TABLE CONTAINER 'Items' OBJECT-ITEMS.
END_PROPERTY.