There are various reason why ABAP Developments don’t always run correctly, the first category is the errors are caused by the developer’s basic lack of ABAP skills. In this article allowed me to explain some of errors that may be occured.

The second category of errors can be characterized that wrong assumptions about the data from SAP system to be processed. These assumptions are often on a lack of understanding about customizing SAP settings, However you cannot develop ABAP Program without having basic knowledge of SAP Functionality.

The third category of errors has to do with common misunderstanding about ABAP language, several used ABAP statements and ABAP dictionary could occuring misunderstanding for ABAP developer such as how to selecting data and many more. In this Article of Enhancing your ABAP Code – Part 1 we will discuss only how to avoid errors when selecting data from SAP database.

  1. Selecting Unique and Correct Row Data.

We’ll show you an example of what can happen when you wrong assumptions about the organizational structure modeled in the SAP system. for example we may select data standard price from MBEW table, let’s assume that one company and two plant have been modeled in SAP System so the same materials are used in two plants, but the price are different. and this could produce wrong price when you select data from MBEW table without know SAP Organizational Structure.

Exactly that’s query should be selected one price per material, but the problem here is the data in MBEW could contain 2 same material with different price. A table row can be identified uniquely only by using all primary key fields.

So the solution you need to check your SAP Functionality, for this case you only need to passing MBEW-BWKEY on the WHERE condition. Don’t forget check table primary key before you select unique data.

2. WHERE Condition with complex combinations

SELECT statements can be complex, and you should avoid using combination of AND,OR, and NOT if possible for example you can check this following ABAP code.

Did you notice that’s code, that’s is a odd query after OR conditions. Although this query is syntactically correct but you will get wrong result data because SAP System will interpreted independently from the conditions placed before OR.

The solution is you need to use parentheses, the parentheses also to keep the syntax readable and to make the selection correct. Therefore keep SELECT statements simple,readable and as clear as possible and you may improve performance if you split complex statement too.

You can see the following ABAP Code for solution.

3. Validity of Selected Data.

As you know a lot of data in SAP System is valid only during a limited period of time. you have to more careful for selecting data with limited period of time, if you not you could get wrong data.

For example case, we will use SAP table contain limited period of time data such as A004 table.

The resulting internal table ta_a004 will contain all record with invalid date. so you need use the validity date to ( datbi)  valid on (datab) in the SELECT statement.

That code is still inaccurate, because if the value of Valid to date ( datbi ) or the valid on date ( datab ) exactly matches the selection date in parameter, the no entry is selected due to GT and LT operators used. some people use SELECT-OPTIONS to solve that’s problem, but please avoid SELECT-OPTIONS , SAP recommended you use parameter insted Select-Options.

The solution you need to separates parameter Valid On Date ( datab ) and Valid To date ( datbi ) and you have to use GE and LE. Please check following ABAP Code .

4. Please careful of the Delete Flag.

Delete flag and status fields are used for both master data and transaction data, selection data often include an explicit reference to such a field in order to prevent outdated data from being processed.

You can see the following ABAP Code, it’s selecting data on the material master with it’s delete flag ( MARA-LVORM ).

You need to know if master data and transaction data that will be processed contain Delete flag and status field. If the table containing delete flag and status flag you need more careful.

Incoming search terms: