Home > SAP Tips > ABAP/Java developer tips > Data modeling and database design in SAP ABAP, part one
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ABAP/JAVA DEVELOPER TIPS

Data modeling and database design in SAP ABAP, part one


Tobias Trapp/SDN
11.20.2006
Rating: -4.25- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This weblog series is about database design and data modelling in ABAP. In this installment, I will discuss modelling techniques. In the next installment, I will introduce the structured entity relationship model designed by Elmar Sinz in 1990 and discuss some aspects of SAP SERM: hierarchical, aggregated referential and external relations between entities. The third part will deal with special aspects of database design in ABAP like NULL values in databases.

How to model data and design databases in ABAP

If I design an application, I start with object-oriented analysis and try to identify the main business objects. During the design phase, I create an object model and I use this to create a relational model. In my opinion, there are good reasons for doing this.

  • Object models correspond to data models -- like entity relationship models -- in a natural way: semantic models like SAP SERM have even notations for generalization/specialization. I have to admit that most of my ABAP object models are very pragmatic: in other programming languages people define all data types as objects -- and as the consequence object models get very complicated and deriving a relational model can more complicated than it ought to be.
  • Entity relationship models derived from object models often lead to database designs which are normalized (i.e., in third or even higher normal form).
  • If I have an object model in mind, I have to distinguish between attributes and methods. It is a common mistake that people try express processes in databases. If they do that the result will get more complicated as it should be.

There is another difficulty. In an object model there are sometimes complex relationships -- like higher order associations -- between objects. If I create a data model from an object model, I have to decide which relations must be represented in the database explicitly and which can be constructed implicitly while instantiating the ABAP object.

Last but not least, I have to create the relational data model: I have to define the transparent tables and foreign keys. During this design phase, I will have to cope with following problems:

  • What are my primary keys? Should I take technical keys -- perhaps GUIDs?
  • Is it possible to avoid (resp. does it make sense to use) composite keys?
  • What indexes do I need for fast access? Or is it better to use buffering -- in fact indexing and buffering are complementary concepts.
  • How do I realize derivation of objects in the data base?

Some people think that they don't need to define foreign keys in the ABAP dictionary because they are not represented in the underlying database. In my opinion, this is completely wrong. Foreign keys are necessary in Dynpro programming, for various DDIC-views, view clusters but the most important thing is that they make the data model easier to understand.

Usually I take pure technical keys -- number ranges, counter or even better: GUIDs -- to express object identity in the area of transparent tables. But sometimes it is necessary to define a so called value-based search key -- realized as a unique index -- to access the object in terms of its attributes. And sometimes I use composite keys but I will come back to the next point later.

As the result of my work I obtain a relational data model. Then I try to find out whether it is appropriate.

  • Is the database design normalized? Do I have to denormalize because of performance reasons?
  • Can the relational database model be extended easily?
  • Do I have to archive the data? Can I easily define an archive index? Can I read the archived data easily using the SAP standard?
  • It is easy to create a business information warehouse data extractor for the data model?
  • Do I allow customers do define APPENDs for transparent tables? Can this affect archiving?

In this phase, you can apply the usual techniques we know from database design. This takes a lot of time and must be done with care.

  • It is very difficult to change an existing data model; we don't have SQL DDL commands like ALTER TABLE. If a transparent table contains lots of data, its possible the database utility se14 won't work. And sometimes we even have to write XPRAs for changing the structure of transparent tables.
  • If the structure changes, it can affect archived data and of course archive objects.

And last but not least, I have to write documentation of my data model. But to be honest, most programmers don't like to write documentation and most documentation has poor quality. I know technical concepts that even contain huge lists of transparent tables together with their data elements, foreign keys and so on. Of course, that can be useful because it describes the DDIC at a certain point in time but this information can be easily generated from the DDIC. So in my opinion, it is better to write a program that extracts this information so that programmers don't have to rewrite and reformat documentation printed out in text files.

In some ABAP projects, chief designers think that it is helpful to write those concepts even before creating the transparent tables. Of course, this is possible and often necessary if the existence of an optimized and well reviewed relational model is crucial for the success of the whole development project. But as a consequence, we have to change those concepts every time we decide to modify parts of our relational model during design phase.

As a consequence, programmers create dozens of pages of documentation that has to be rewritten again and again. At the end nobody knows whether the documentation describes the current situation.

So here is my suggestion:

  • We define a data model -- perhaps derived from an object model -- perhaps with the help of the SAP Data Modeler.
  • At this time, we define the relational data model and link the semantic entities to the SAP DDIC.
  • Of course, we need guidelines for the design of the relational data model: it makes no sense if somebody uses GUIDs and another developer number ranges for primary keys at the same time (perhaps even in the same data model).

By using the SAP Data Modeler, we keep the documentation in the SAP system.

A first look at SAP-SERM and the Data Modeler

SAP decided to create database models on two layers. The semantic layer is defined in SAP-SERM and the logical model is defined in the data dictionary. Usually we don't work with the physical model (the underlying database) unless you are a database administrator. Only if there is serious trouble an ABAP developer will look at the physical database table -- this can be necessary if a transparent table is inconsistent (the database object doesn't correspond to the DDIC object) or we have serious problems to change the transparent table using the database utility (se14) or even with ABAP.

Semantic data models are really useful. Just imagine you want to understand internals of ABAP classes and how they are represented in the WAS itself. Just look at the package SEO and you will recognize data models and entity types:

Just select the first data model OR_COMPONE and press Ctrl. F3: the Data Modeler opens:

You can double click the entity type OR_REGMET: You will navigate to the entity type and by click the button dictionary you will see that this entity is represented by the view VSEORMETH. Furthermore this diagram says that a method can be a static class method or an instance method.

Suppose that you have to understand some parts of the CRM data model. Luckily most modern SAP applications are structured and divided into packages and sub-packages but usually this doesn't help you to understand the data model. (But just imagine a whole application would consist only of a single package -- you would have no chance to understand or to maintain it). Fortunately data models will help you. Just look at the data model CRM_BP0021 for example:

We all know entity relationship diagrams but what does this notation mean? It means that a business hour consists of several (time dependent) intervals. Furthermore, we can think of an business hour as a base class with some specializations (child classes): visiting hour, calling hours and receiving hours. This will be explained in the next installment of this blog series.

Summary

I briefly discussed the basics of data modelling and database design in ABAP and suggested some best practices. I shortly introduced the SAP Data Modeller. In the next installment. I will get into the details of SERM and SAP SERM.

Data modeling and database design in ABAP -- Part 2
Data modeling and database design in ABAP -- Part 3


This content is reposted from the SAP Developer Network.
Copyright 2006, SAP Developer Network

SAP Developer Network (SDN) is an active online community where ABAP, Java, .NET, and other cutting-edge technologies converge to form a resource and collaboration channel for SAP developers, consultants, integrators, and business analysts. SDN hosts a technical library, expert blogs, exclusive downloads and code samples, an extensive eLearning catalog, and active, moderated discussion forums. SDN membership is free.

Want to read more from this author? Click here to read Tobias Trapp's weblog. Click here to read more about ABAP on SDN.



Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ABAP/Java developer tips
Select Text fields: Case-insensitive
Finding BADIs you can use
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects
Find a BADI in a minute
Top 10 SAP tips of 2007
How to transport an SAP query in R/3 4.6x
How to switch off message determination in BAPI_PO_CREATE1

SAP ABAP
Getting started with a NetWeaver career
How to be a self-taught NetWeaver and ABAP expert
Is SAP BI knowledge advantageous to an ABAP user?
An ABAP user wants to learn XI
Select Text fields: Case-insensitive
Finding BADIs you can use
Is ABAP knowledge necessary for SAP BI?
Quiz: SAP ABAP development
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
SAP ABAP Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
ABAP  (SearchSAP.com)
ABAP Objects  (SearchSAP.com)
ABAP Workbench  (SearchSAP.com)
BAPI  (SearchSAP.com)
CATT  (SearchSAP.com)
R/3 Repository  (SearchSAP.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsBlogsTipsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts