In previous blog STOP filling your Custom ABAP Code with Business hard coding I started a discussion about a popular coding bad practice that affects most of the SAP ERP systems.
In a week, the blog got more than 2.000 visits, 5 stars rating and the several interesting comments are even more valuable than the blog itself.
To get rid of Business hard code, I'm describing here a way scan your SAP system (e.g. SAP ECC) and get a clear picture of its occurrences.
With the term Business hard code, I'm referring to the practice of hard coding strings (literals) corresponding to codes (IDs) related to Organizational Units or Document Types and even Master Data. Examples are Company Codes, Purchase Organizations, Sales Organizations, Accounting document types and also Country Codes.
The ABAP workbench provides lot of tools to perform source code scanning.
Occurrences of a given literal (e.g. 'IT01' ) can be easily obtained via report RS_ABAP_SOURCE_SCAN or the Code Inspector check Scan for ABAP Tokens. In the real-life, this is the use case of Split & Merge when, for example, a Company Code is going to be merged with another.
Here I try to solve the problem of obtaining occurrences of any literal referred to business related domains without knowing the values to be found.
Before deep diving into the solution, let me confirm the attitude we have at TechedgeGroup to share stuff (for free) in SCN.
First, we are proud of the idea and first implementation of abap2xlsx by ivan.femia . I think it is one of the most popular SCN projects in terms of downloads, usage and software contributors.
Specifically in the domain of Application Lifecycle Management (ALM), it follows a short list of ideas and tools we shared in the years with the community:
This time Techedge is sharing with the SCN community the product Doctor ZedGe - Hard!Code that you can get for free without worrying about license or expiration time.
Doctor ZedGe - Hard!Code is the Community Edition of the larger product Doctor ZedGe that includes an advanced DashBoard to analyze ABAP Test Cockpit results and publish them in nice looking MS Excel reports and also a specific ABAP to download to MS Excel the ATC results including the statements with issues.
So, at the bottom of the page Doctor ZedGe | Techedge you will find instructions To order Doctor ZedGe . Simple ask for the Community Edition. You'll soon receive the comprehensive documentation and the complete source code simply installable via Copy & Paste .
This time we decided to distribute Doctor ZedGe - Hard!Code from our Techedge web site not only because Code Exchange has been closed.
Indeed since we are delivering the software, we can assure enterprises that the software is secure, is well developed and well documented. We'll also provide technical support in case of issues.
Thanks to the step-by-step guides you will get something like the following ATC result in less than an hour.
Or if you prefer, here it is the result in ABAP in Eclipse (AiE):
As you know, ABAP Test Cockpit provides an handy Statistics overview (top), the worklist (middle) and the finding detail (bottom). Navigation to the code (picture on the right) is a click-away.
The idea of this custom Code Inspector check is first to get the hard-coded string (literal), then discover the corresponding operand (context) and recognize if it refers to a Business entity.
As you know, ABAP syntax is very flexible and the challenge is to determining the context (the related operand) of a given literal. In the above example, the related operand of the literal '3000' is field LT_FILE-PLANT2. This time it is on the left of the operator '='.
In case of '3200' it is instead GT_FILE-WERKS that is on the right of the operator '='.
CASE and WHEN are even more challenging:
In the above example, the context of both 3000 and 3200 is to be found jumping back to the CASE statement to identify LT_FILE-PLANT2 as context (related operand).
Literals are strings and represent the hard coding Anti-pattern.
The Code Inspector check Doctor ZedGe - Hard!Code includes a Literal length parameter defaulted to consider those with length between 2 and 18.
In this version, the analysis considers the following statements that cover mostly of the scenarios:
It’s easy to catch hard coded strings (literals) but you'll get a huge number of false positives that make the scan unusable.
It’s not instead so easy to distinguish those related to business entities. After scanning millions of lines of code, we believe that Doctor ZedGe - Hard!Code can identify around 95% of the Business hard coding related to the following set of critical domains:
Domain | Description |
BUKRS | Company Code |
WERKS | Plant |
EKORG | Purchase Org. |
VKORG | Sales Organization |
VTWEG | Distribution Channel |
SPART | Division |
LGORT | Storage Location |
GSBER | Business Areas |
WAERS | Currency |
LAND1 | Countries |
MSHEI | Unit of measurements |
PARVW | Partner Function |
KTOKD | Customer account groups |
KTOKK | Vendor account groups |
MTART | Material Type |
AUART | Sales Document Type |
LFART | Delivery Type |
FKART | Billing Type |
BSART | Purchasing Document Category |
BWART | Movement Type |
VSBED | Shipping conditions |
PSTYP | Item Category in Purchasing Document |
PSTYV | Sales document item category |
KSCHL | Condition Type |
BLART | Document Type (FI) |
PLTYP | Price list type |
MATNR | Material |
KUNNR | Customer account groups |
LIFNR | Vendor |
SKA1 | G/L Account Master (Chart of Accounts) |
BELNR | Accounting Document Number BELNR |
Note that in case you need, I confirm it's very easy to extend the code to take into account other domains.
Keep in mind that, since we target an installation performed via one copy & paste (one ABAP class) we avoided in this version the use of tables to define the list of domains to be analyzed. We'll see in the future if it makes sense.
In add, since Doctor ZedGe - Hard!Code leverages the power of ABAP Test Cockpit and Code Inspector, it also suffers of the same known limitations:
Doctor ZedGe - Hard!Code could provide value not only to Developers and Quality Managers but also to Functional specialists, Team leaders, Project managers and even IT managers.
Follow a list of possible use cases:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |