Hello Experts,
Gateway services internally generate four main classes.
- Model provider class
- Model provider Extension class
- Data provider class
- Data provider Extension class
My question is: what is the difference between the Model provider class and the data provider class?
Please share your valuable answer. Thanks in advance.
Solution
When creating an OData service in SAP, two important classes play key roles:
- Model Provider Class (MPC) – Defines what data is available.
- Data Provider Class (DPC) – Defines how the data will be fetched and managed.
What is Model Provider Class (MPC)?
The MPC is in charge of establishing the data's structure. It focuses on the information that the OData service will make available. Consider it the data model's design or blueprint.
Key Responsibilities of MPC:
- Define entities (like Employee or Product).
- Specify the properties (like name, ID, or price).
- Create associations and relationships between entities.
- Generate the metadata document (
/service/$metadata
).
Example of MPC:
For an Employee OData service, the MPC defines:
- Entity: Employee
- Properties: Employee ID, Name, Department
This tells the system what kind of data can be fetched through the service.
What is Data Provider Class (DPC)?
The DPC specifies how the data will be retrieved or modified and manages the business logic. It controls the communication between the SAP back-end system (such as SAP ECC or S/4HANA) and the OData service.
Key Responsibilities of DPC:
- Fetch data for GET requests (read operations).
- Handle POST, PUT, and DELETE operations (create, update, delete).
- Implement logic to query data from SAP tables.
Example of DPC:
In the Employee OData service, the DPC fetches the actual employee records when the service receives a GET
request.
Key Differences Between MPC and DPC
Aspect | Model Provider Class (MPC) | Data Provider Class (DPC) |
---|---|---|
Purpose | Defines the structure of the data | Implements business logic to fetch and manage data |
Focus | Which data will be made public | How data will be managed |
Generates | Metadata document ($metadata ) |
CRUD operations (GET, POST, PUT, DELETE) |
Example Role | Defines an Employee entity with ID and Name | Retrieves Employee records from the SAP system |
Conclusion
MPC and DPC are both crucial components of SAP OData services.
- The structure and available data are specified by MPC.
- DPC is in charge of the business logic and controls the retrieval or updating of data.
When combined, they guarantee seamless communication between SAP systems and external apps via OData services.
Model Provider Class
Model Provider class registers the metadata used in a service, it is nothing but base class and model provider extension class is nothing but derived class.
Model provider Extension class
Model provider Extension class is derived class of Module Provider Class
Data Provider Class
Data provider class provides the methods to Data provider Extension class, so developer can implement the functionalities for database interaction.
MPC is a Parent class and MPC_EXT->child class
MPC is used to define model you can use the method Define create entity and properties.
Model Provider class registers the metadata used in a service. Data provider class provides the methods to Data provider Extension class, so developer can implement the functionalities for database interaction.