Aggregate Attributes
BUS2105 (PurchaseRequisition) is the aggregate type of the object type BUS2009 (PurchaseReqItem).
BUS2105 has key PurchaseRequisition.Number
BUS2009 has key PurchaseReqItem.Number and PurchaseReqItem.Item
BUS2009 "is part of" BUS2105
PurchaseReqItem "is part of" PurchaseRequisition.
DB SalesOrder.DocumentDate (Object VBAK)
Code:
* get_table_property is a macro that is the start of a database attribute
* implementation either referencing a database field or a database field and
* an object reference
get_table_property vbak.
DATA subrc LIKE sy-subrc.
PERFORM select_table_vbak USING subrc.
IF sy-subrc NE 0.
exit_object_not_found.
ENDIF.
end_property.
FORM select_table_vbak USING subrc LIKE sy-subrc.
IF object-_vbak-mandt IS INITIAL
AND object-_vbak-vbeln IS INITIAL.
SELECT SINGLE * FROM vbak CLIENT SPECIFIED
WHERE mandt = sy-mandt
AND vbeln = object-key-salesdocument.
subrc = sy-subrc.
IF subrc NE 0.
EXIT.
ENDIF.
object-_vbak = vbak.
ELSE.
subrc = 0.
vbak = object-_vbak.
ENDIF.
ENDFORM.
DB/Object Ref SalesOrder.OrderingParty (Object VBAK)
Same as DB example. Since it is a database source, the only code is the code populating the database row. So all database references to an attribute within this table will reference this same code. The difference is in the definition of the attribute it references the Object, KNA1, with the reference table/field being VBAK-KUNNR. Since this is the value to the single key in the object KNA1, it works.
DATA : BEGIN OF verkaufsorganisation, " I don't think this is necessary
vkorg LIKE vbak-vkorg,
END OF verkaufsorganisation.
DATA: salesorganization TYPE swc_object.
* swc_get_property is a macro that retrieves a single value attribute of an object
* (This single value attribute can include another object)
swc_get_property self 'SalesOrganization' salesorganization. " self is an object
swc_get_property salesorganization " salesorganization is an object
'SalesOrganization' " SalesOrganization is an element
verkaufsorganisation-vkorg. " (actually it is the object key field)
* SalesOrganization is an object reference attribute in BUS2032
* "self" is a macro key word referring to the instantiation of
* the object within which this attribute is defined (BUS2032)
* The key for the object, SalesOrganization is
* SalesOrganization.SalesOrganization (vkorg)
SELECT SINGLE * FROM tvko WHERE vkorg = verkaufsorganisation-vkorg.
SELECT SINGLE * FROM t001 WHERE bukrs = tvko-bukrs.
object-companycodecurrency = t001-waers.
* swc_set_element <container> writes single value element from a
* variable to the container. The element is usually virtual but
* it can be database source
BEGIN_METHOD GETLIST CHANGING CONTAINER.
DATA:
REQUISITIONER LIKE BAPIMMPARA-PREQ_NAME,
...
* swc_get_element is a macro that reads a single value element from the container
* It can be either virtual or from a database source
* 'Requisitioner' is an attribute (source db) in the object BUS2009. GETLIST is a method
* in this object.
Macro Instructions for Accessing Objects, Attributes and Methods
You can use these macros for simplifying access to Business Object Repository objects.
Prerequisites
The include file <OBJECT> must be incorporated into the program in order to use these macros.
Features
You must declare variables in which an object reference is to be stored with the following instruction:
DATA: <Object> TYPE SWC_OBJECT.
General macros SWC_CREATE_OBJECT <Object> <ObjectType> <ObjectKey>.
Creates an object reference for an object key of an object type.
You must pass the object-specific key in <ObjectKey> and the ID of the object type in <ObjectType> . You must pass <ObjectType> either as a character string or as a variable declared with LIKE SWOTOBJID-OBJTYPE .
The object reference created is returned in the variable <Object> . You must declare <Object> with type SWC_OBJECT .
If the variable <ObjectKey> has the value SPACE , a reference to the object type is returned in <Object> . You can use this to query properties of the object type (attributes, methods, events).
SWC_REFRESH_OBJECT <Object>.
Object attributes that reference a database field are read from the database again when next accessed.
You must pass the object reference in <Object> . You must declare <Object> with type SWC_OBJECT .
You should use this macro instruction after execution of methods that can change attributes (for example Edit , Update , Change ).
SWC_GET_OBJECT_TYPE <Object> <ObjectType>.
The object type for the object reference is established.
You must pass the object reference in <Object> . You must declare <Object> with type SWC_OBJECT .
The object type is returned in the variable <ObjectType> . You can declare <ObjectType> with LIKE SWOTOBJID-OBJTYPE .
SWC_GET_OBJECT_KEY <Object> <ObjectKey>.
The object key for the object reference is established.
You must pass the object reference in <Object> . You must declare <Object> with type SWC_OBJECT .
The object key is returned in the variable <ObjectKey> . You can declare <ObjectKey> with LIKE SWOTOBJID-OBJKEY .
SWC_CALL_METHOD <Object> <Method> <Container>.
The method defined for an object type is executed on an object of this object type.
You must pass the object reference in <Object> and the method to be executed in <Method> . You must declare <Object> with type SWC_OBJECT .
The import parameters of the method are passed in the variable <Container> . The result and the export parameters of the method executed are also stored in <Container> . If the method called raises an exception, the number of the exception is stored in the system variable SY-SUBRC and any values in the variables SY-MSGV1 , ..., SY-MSGV4 .
An example of a call of this kind can be found in Programmed Call of Method.
If you pass SPACE for <Method> , the default method is executed.
You must pass a container even if no parameters are defined for the method called. Therefore you create and initialize an empty container with the following macro instructions:
SWC_GET_PROPERTY <Object> <Attribute> <AttributeValue>. SWC_GET_TABLE_PROPERTY <Object> <Attribute> <AttributeValue>.
The value of the specified attribute is established. If it is a virtual attribute, this is done dynamically.
You must pass the object reference in <Object> and the attribute or key field to be read in <Attribute> . You must declare <Object> with type SWC_OBJECT .
The value of the attribute or key field is returned in the variable <AttributeValue> . SWC_GET_PROPERTY returns a single value, SWC_GET_TABLE_PROPERTY returns a multiline value in an internal table.
An example of a call of this kind can be found in Programmed Access to an Attribute.
Executing macros on own object
All the macros in the section General macros can also be executed directly on the object itself in the implementation program. To do this, you replace <Object> with SELF in the macro calls.
Attribute values of the current object can be read by calling
SWC_GET_PROPERTY SELF <Attribute> <AttributeValue>.
Setting an object key
When implementing methods with which an object is created, the object key must be set. The typically applies to the methods Create and Find . Use the macro following macro instruction:
SWC_SET_OBJECTKEY <ObjectKey>.
The object key to be set is passed in the variable <ObjectKey> . An example of a call of this kind can be found in Programming Instance-Independent Methods.
Raising exceptions
Within the implementation program, you can raise the exceptions defined for a method. Use the macro following macro instruction:
Pass the number of the exception in <Exception> and the four task parameters displayed in <Var n> . The parameters can be SPACE . <Exception> must be declared with LIKE SWOTINVOKE-CODE .
INCLUDE <CNTN01>.
Code:
*************************** Macros *************************************
* Types
TYPES:
SWC_OBJECT LIKE OBJ_RECORD.
* DATA Container
DEFINE SWC_CONTAINER.
DATA BEGIN OF &1 OCCURS 0.
INCLUDE STRUCTURE SWCONT.
DATA END OF &1.
END-OF-DEFINITION.
*************************** Data Declaration ***************************
DATA BEGIN OF SWO_%RETURN.
INCLUDE STRUCTURE SWOTRETURN.
DATA END OF SWO_%RETURN.
DATA SWO_%OBJID LIKE SWOTOBJID.
DATA SWO_%VERB LIKE SWOTLV-VERB.
SWC_CONTAINER SWO_%CONTAINER.
************************* Error Handling *****************************
* set system error codes from structure SWOTRETURN
* P1 Returncode of structure SWOTRETURN
DEFINE SWC_%SYS_ERROR_SET.
IF &1-CODE NE 0.
SY-MSGID = &1-WORKAREA.
SY-MSGNO = &1-MESSAGE.
SY-MSGTY = 'E'.
SY-MSGV1 = &1-VARIABLE1.
SY-MSGV2 = &1-VARIABLE2.
SY-MSGV3 = &1-VARIABLE3.
SY-MSGV4 = &1-VARIABLE4.
ENDIF.
SY-SUBRC = &1-CODE.
END-OF-DEFINITION.
* Container Create Element
DEFINE SWC_CREATE_ELEMENT.
CALL FUNCTION 'SWC_ELEMENT_CREATE'
EXPORTING
ELEMENT = &2
TABLES
CONTAINER = &1
EXCEPTIONS ALREADY_EXISTS = 4
OTHERS = 1.
END-OF-DEFINITION.
* Container Set Element
DEFINE SWC_SET_ELEMENT.
CALL FUNCTION 'SWC_ELEMENT_SET'
EXPORTING
ELEMENT = &2
FIELD = &3
TABLES
CONTAINER = &1
EXCEPTIONS OTHERS = 1.
END-OF-DEFINITION.
* Container Set Table
DEFINE SWC_SET_TABLE.
CALL FUNCTION 'SWC_TABLE_SET'
EXPORTING
ELEMENT = &2
TABLES
CONTAINER = &1
TABLE = &3
EXCEPTIONS OTHERS = 1.
END-OF-DEFINITION.
* Container Get Element
DEFINE SWC_GET_ELEMENT.
CALL FUNCTION 'SWC_ELEMENT_GET'
EXPORTING
ELEMENT = &2
IMPORTING
FIELD = &3
TABLES
CONTAINER = &1
EXCEPTIONS NOT_FOUND = 8
IS_NULL = 4
OTHERS = 1.
END-OF-DEFINITION.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.