Skip to main content
Version: 3.0

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 TypesBase ClassBase InterfaceDescription
MasterDataMasterDataBeanIMasterDataBeanCode can be generated automatically or manually by setting AutoCodeGeneration = false.
Master Data LinesMasterDataChildBeanIMasterDataChildBeanLines in master data object.
DocumentDocumentBeanIDocumentBeanDocument header declaration.
Document LinesDocumentChildBeanIDocumentChildBeanDocument lines declaration.
No ObjectNoObjectBeanINoObjectBeanSimple entry with code and name; no child objects supported.
No Object - AutoincrementAutoIncrementBeanIAutoIncrementBeanSimple entry with ID; no child objects supported.

Basic Implementation

  1. Create an Interface: Define a public interface for the UDO, registered in dependency injection. The interface contains all fields and child collections.
  2. Implement the Class: The class should be internal sealed partial and implement business logic.

Fields

  1. 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; }
  2. Supported Field Types:

    .NET TypeSAP TypeAvailable Attributes
    intnumeric[DefaultValue]
    doubleprice[DefaultValue]
    stringalpha[DefaultValue]
    DateTimedate-
    DateTimetime[TimeType]
    enumalpha[DefaultValue], [EnumType]
    TimeSpannumeric[TimeSpanType]
  3. 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> { }
  1. Specify Class Implementation:

    internal sealed partial class VehiclePreviousOwners : MasterDataChildBean<IVehiclePreviousOwners>, IVehiclePreviousOwners
    {
    [GenerateUdoBeanProperties(typeof(IVehiclePreviousOwners))]
    }
  2. 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:

  1. Add IFormulatedBean to the interface.

  2. Implement GetFormulaDefinition() and define formulas.

    public UdoFormulaDefinition GetFormulaDefinition()
    {
    return new UdoFormulaDefinitionBuilder()
    .AddDefinitionForCollection("Lines", __LinesTableName, nameof(TestMasterLines.U_Formula), nameof(TestMasterLines.U_Result))
    .Build();
    }
  3. 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.