Implementing User-Defined Objects
This guide provides a comprehensive overview of implementing User-Defined Objects (UDOs) in SAP. It covers essential aspects such as database structure preparation, UDO types, class definitions, field management, collections, events, validations, formulas, and attributes. By following this structured approach, developers can efficiently create and manage custom objects tailored to business requirements. To begin implementing user-defined objects (UDOs), first prepare the Database Structure.
Class Inheritance Table
UDO implementation begins with selecting the appropriate UDO type. Each type is associated with specific base classes and interfaces, ensuring compatibility with SAP's framework.
SAP UDO Types | Base Class | Base Interface | Description |
---|---|---|---|
MasterData | MasterDataBean | IMasterDataBean | Code can be generated automatically or manually by setting AutoCodeGeneration = false . |
Master Data Lines | MasterDataChildBean | IMasterDataChildBean | Lines in master data object. |
Document | DocumentBean | IDocumentBean | Document header declaration. |
Document Lines | DocumentChildBean | IDocumentChildBean | Document lines declaration. |
No Object | NoObjectBean | INoObjectBean | Simple entry with code and name; no child objects supported. |
No Object - Autoincrement | AutoIncrementBean | IAutoIncrementBean | Simple entry with ID; no child objects supported. |
Basic Implementation
- Create an Interface: Define a public interface for the UDO, registered in dependency injection. The interface contains all fields and child collections.
- Implement the Class: The class should be
internal sealed partial
and implement business logic.
Fields
-
Getter and Setter: Use the setter according to business needs. To restrict certain fields, only add a getter.
int U_RedOnlyField { get; }
int U_IntegerField { get; set; } -
Supported Field Types:
.NET Type SAP Type Available Attributes int
numeric [DefaultValue]
double
price [DefaultValue]
string
alpha [DefaultValue]
DateTime
date - DateTime
time [TimeType]
enum
alpha [DefaultValue]
,[EnumType]
TimeSpan
numeric [TimeSpanType]
-
Enum Definition:
[EnumType(new int[] { 1, 2, 3, 4, 5 }, new string[] { "C", "B", "T", "M", "O" }, 1)]
public enum VehicleType
{
Car = 1,
Bus = 2,
Truck = 3,
Motorcycle = 4,
Other = 5
}
Child Collections
To enable LINQ support for collections, use a generic base interface:
public interface IVehiclePreviousOwners : IMasterDataChildBean<IVehiclePreviousOwners> { }
-
Specify Class Implementation:
internal sealed partial class VehiclePreviousOwners : MasterDataChildBean<IVehiclePreviousOwners>, IVehiclePreviousOwners
{
[GenerateUdoBeanProperties(typeof(IVehiclePreviousOwners))]
} -
Declare Child in Header Object:
public IVehiclePreviousOwners Owners { get; }
Events
UDO and its child classes can trigger and handle events:
this.RowAdded += rowAdded;
this.RowDeleted += rowDeleted;
this.ValueChanging += changing;
this.ValueChanged += changed;
private void rowDeleted(UdoEventArguments e) { }
private void rowAdded(UdoEventArguments e) { }
private void changed(object sender, PropertyChangedEventArgs e) { }
private void changing(object sender, PropertyChangingEventArgs e, out bool cancel) { cancel = false; }
Validations
Implement validations in BeforeAdd
, BeforeUpdate
, and BeforeDelete
methods:
protected override bool BeforeUpdate()
{
Validate();
return true;
}
private void Validate()
{
ValidateVIN();
ValidateRegistrationNumber();
}
Formulations
To add formula definitions:
-
Add
IFormulatedBean
to the interface. -
Implement
GetFormulaDefinition()
and define formulas.public UdoFormulaDefinition GetFormulaDefinition()
{
return new UdoFormulaDefinitionBuilder()
.AddDefinitionForCollection("Lines", __LinesTableName, nameof(TestMasterLines.U_Formula), nameof(TestMasterLines.U_Result))
.Build();
} -
Implement
RecalcFormulas()
to trigger calculations.public void RecalcFormulas(bool recalculateAll = true) { ... }
Additional Attributes on UDO
-
Bean Attribute - Required on UDO class:
- UdoCode: Code of the UDO.
- TableName: Table name.
- Description: Description of the UDO.
-
DefaultValue Attribute - Optional on the property to set a default value.
-
EnumType Attribute - Required on enum declarations for binding enum values to database representation.
AppEngine Attributes
-
AppEnginePropertyReadOnly - Marks a property as read-only in the web entity model.
-
AppEngineUDOBeanAttribute - Exposes UDO to the web entity model.
Example:
[AppEngineUDOBean(Ignore = false, ObjectType = "ManufacturingOrder", TableName = ManufacturingOrder.TABLENAME, ObjectCode = ManufacturingOrder.OBJECTCODE)]
-
AppEngineUDOChildBean - Applied on child beans to expose the collection to the web entity model.
-
AppEngineProperty - Defines custom order of fields to serialize between model and UDO.
-
AppEnginePropertyIgnore - When applied, omits the property in the web entity model.
This guide outlines the critical steps and best practices for implementing User-Defined Objects in SAP. With careful planning and execution, UDOs can significantly enhance application functionality and user experience.