Monday, May 16, 2016

Macro Instructions for Accessing Objects, Attributes, Methods (BOR) - SAP Business Workflow

You can use these macros for simplifying access to Business Object Repository objects.

Prerequisites
The include file <cntain> (Container-Macros) 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_CONTAINER <Container>. SWC_CREATE_CONTAINER <Container>.
  • 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.
ExampleAttribute 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:
EXIT_RETURN <Exception> <Var1> <Var2> <Var3> <Var4>.

Pass the number of the exception in <Exception> and the four task parameters displayed in <Varn> . The parameters can be SPACE . <Exception> must be declared with LIKE SWOTINVOKE-CODE .

No comments:

Post a Comment

SAP giới thiệu mã hỗ trợ AI trong ngôn ngữ ABAP riêng của mình

SAP đã ra mắt một loạt tính năng mã hỗ trợ AI trong môi trường phát triển ứng dụng dựa trên đám mây của mình, đồng thời tham gia vào danh sá...