Sie sind auf Seite 1von 8

Business Objects A business object is a problem-domain entity that you model in the SAP system, such as SalesOrder, BillingDocument,

and Employee. The business objects integrate the functions of business applications with the workflow. Transaction SW01 - Business Object Builder can be used to display, create, change, delete, delegate business object. The business object access the data and the functionality of an application. Each object instance is a single runtime copy of its object type. The Business object has got the following components. Key The key defines each object instance uniquely. An example of this is object is the SalesArea (BUS000603) object type which has SalesOrganization (TVTA-VKORG), DistributionChannel (TVTA-VTWEG) and Division (TVTA-SPARTE) as key fields. Attributes A business object is primarily represented by its attributes. Attributes provides access to data. Attributes may reference to a single value or multiline.

The majority of attributes are data-dictionary fields.

Attributes can be defined without referencing data dictionary. These attributes are called virtual attributes.

Multi-line attributes these attributes define one-to-many relationships between an object and other fields. These objects can be defined in the data dictionary or can also be virtual attributes e.g. PIECEOFEQUIPMENT is a multilane attribute of BOR BUS1001

Methods Methods of an object represent the actions you take with objects attributes. Methods are similar to function modules and have importing and exporting parameters as well as exceptions. Methods can be created using function module, Transaction etc as is visible below

BOR programming BOR programming makes extensive use of macros. All the macros used in BOR programming are included in the include program <OBJECT>. Include <CNTN01> contains all the macros that can be used outside the object type program i.e. say for raising events in the business application program. The business object BUS1001 is referenced in this document to understand various concepts

Object declaration Each object type programming is bounded by the macros BEGIN_DATA and END_DATA. The object declaration is a complex structure that includes the key fields(OBJECTKEY-ID) and the attribute buffer e.g for attribute say costcenter attribute buffer is OBJECTCOSTCENTER. The attribute buffer is used to minimize recalculation. When the implementation

of the attribute is executed the attribute buffer is filled. When the attribute is again called instead of re-executing the whole code it can retrieve the previously calculated value. Key field is bounded by Begin of Key End of key begin of key, material like mara-matnr, end of key All object references have the data type definition as SWC_OBJECT DATA: Customer type SWC_OBJECT Single value attribute uses the macro SWC_GET_PROPERTY SWC_GET_PROPERTY <Object> <Attribute><Attribute Value> Multiple value attribute uses the macro SWC_GET_TABLE_PROPERTY SWC_GET_TABLE_PROPERTY <Object> <Attribute><Attribute Value> SWC_GET_TABLE_PROPERTY Customer SalesOrderList salesordertab Where salesordertab is an internal table. To fill object reference macro SWC_CREATE_OBJECT SWC_CREATE_OBJECT<Object> <ObjectType><ObjectKey> SWC_CREATE_OBJECT Customer KNA1 customer_number Programming Attributes in BOR Virtual attributes are bounded by macro BEGIN_PROPERTY anbgd END_PROPERTY. This creates a subroutine in which the value of the attribute can be calculated. SWC_SET_ELEMENT macro will be used to put the calculated value into the object container for the attribute id. GET_PROPERTY <AttributeID> Changing <Container> code for calculating the attribute value.. SWC_SET_ELEMENT CONTAINER <AttributeID> <value> END_PROPERTY Multiline attributes are always virtual attributes. Multiline attributes uses macro SWC_SET_TABLE GET_PROPERTY <AttributeID> Changing <Container> code for calculating the attribute value.. SWC_SET_TABLE CONTAINER <AttributeID> <InternalTable> END_PROPERTY E.G.: PIECEOFEQUIPMENT is a multilane attribute of BOR BUS1001

Example: Code GET_PROPERTY PIECEOFEQUIPMENT CHANGING CONTAINER. TABLES EQUI. DATA POE TYPE SWC_OBJECT. REFRESH OBJECT-PIECEOFEQUIPMENT. SELECT * FROM EQUI WHERE MATNR = OBJECT-KEY-MATERIAL. SWC_CREATE_OBJECT POE 'EQUI' EQUI-EQUNR. APPEND POE TO OBJECT-PIECEOFEQUIPMENT. ENDSELECT. SWC_SET_TABLE CONTAINER 'PIECEOFEQUIPMENT' OBJECT-PIECEOFEQUIPMENT. END_PROPERTY. Attributes containing object reference uses macro SWC_CREATE_OBJECT E.G.: OBJECTTYPE is a object type attribute of BOR BUS1001

Example: Code GET_PROPERTY OBJECTTYPE CHANGING CONTAINER. SWC_CREATE_OBJECT OBJECT-OBJECTTYPE 'TOJTB' OBJECT-_OBJECTTYPENAME.

SWC_SET_ELEMENT CONTAINER 'OBJECTTYPE' OBJECT-OBJECTTYPE. END_PROPERTY. If a number of attributes has reference to the same database table then the GET_TABLE _PROPERTY END-PROPERTY macro can be used to implement these attributes Example: Code GET_TABLE_PROPERTY MARA. DATA SUBRC LIKE SY-SUBRC. PERFORM SELECT_TABLE_MARA USING SUBRC. IF SY-SUBRC NE 0. EXIT_OBJECT_NOT_FOUND. ENDIF. END_PROPERTY. FORM SELECT_TABLE_MARA USING SUBRC LIKE SY-SUBRC. IF OBJECT-_MARA-MANDT IS INITIAL AND OBJECT-_MARA-MATNR IS INITIAL. SELECT SINGLE * FROM MARA CLIENT SPECIFIED WHERE MANDT = SY-MANDT AND MATNR = OBJECT-KEY-MATERIAL. SUBRC = SY-SUBRC. IF SUBRC NE 0. EXIT. ENDIF. OBJECT-_MARA = MARA. ELSE. SUBRC = 0. MARA = OBJECT-_MARA. ENDIF. ENDFORM. If database select fails then macro EXIT_OBJECT_NOT_FOUND can be used as this sends an error message object does not exist to the workflow. Programming Methods in a BOR Methods have one implementation per method. Methods make use of macro BEGIN METHOD END METHOD. This creates a subroutine where the code can be written. BEGIN METHOD <Method ID> CHANGING COINTAINER END METHOD Example: Code BEGIN_METHOD DISPLAY CHANGING CONTAINER. DATA: RETURN LIKE BAPIRET1. CALL FUNCTION 'BAPI_MATERIAL_DISPLAY' EXPORTING MATERIAL = OBJECT-KEY-MATERIAL IMPORTING RETURN = RETURN EXCEPTIONS OTHERS = 01. CASE SY-SUBRC. WHEN 0.

WHEN OTHERS EXIT_OBJECT_NOT_FOUND. ENDCASE. SWC_SET_ELEMENT CONTAINER 'RETURN' RETURN. END_METHOD. To call a method inside another method or to calculate an attributes value the macro SWC_CALL_METHOD can be used. Error handling In order to know detect the errors of a method say exceptions of FM or the messages of a call transactions the following macros can be used EXIT_RETURN can be used where the exception numbers and the parameters of the message can be specified. EXIT_RETURN <exception> <Var1><Var2><Var3><Var4> EXIT_RETURN 9001 object-key-id space space space In transaction SW01 has these three buttons.

Exceptions can be created by with button Exceptions

EXIT_CANCELLED can be used to tell the workflow that the user has chosen not the complete the activity in time. The work item will remain in the agents inbox with a status in Process. EXIT_OBJECT_NOT_FOUND tells the workflow that the object does not exist EXIT_PARAMETER_NOT_FOUND Tells the workflow that a mandatory parameter of the method is missing.

Das könnte Ihnen auch gefallen