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.

  HardcodedCompanyCodes_sketch.jpg

Problem Domain

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.

Techedge@SCN ALM

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:

Download and install

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.

HardcodedInATC.jpg

 

Or if you prefer, here it is the result in ABAP in Eclipse (AiE):

ATC_AiE.jpg

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.

ZedGeHardCode.jpg

 

How it works?

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.

HardcodedCompanyCodes_sketch2.jpg

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:

HardcodedCompanyCodes_sketch3.jpg

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

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.

Statements:

In this version, the analysis considers the following statements that cover mostly of the scenarios:

  • CONSTANTS, DATA, STATICS or TYPES
  • COMPUTE including the implicit form like A = B
  • conditional statements IF, ELSEIF, CHECK or WHEN
  • MOVE or WRITE “for WRITE x TO y
  • CALL, PERFORM or SUBMIT
  • Open SQL statements SELECT, INSERT, UPDATE or DELETE

Known limitations

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:

  • it works only on workbench objects belonging to a custom main object. It can analyze BADIs and Customer Exits (CMOD) but cannot analyze ABAP code contained in user-exits includes (es. SAPMV45A is a SAP standard object thus MV45FZ01 cannot be analyzed that as from Best Practices should just call custom Customer Exits FUNCTION MODULEs or custom BADIs)
  • it works on PROGRAMs (PROG), FUNCTION MODULEs (FUGR) and CLASSEs (CLASS) but not on SAPScripts and SMARTForms.

What’s next?

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:

  • get weekly system certification in terms of Business Process standardization (no hidden different behaviors)
  • before starting a roll-out, get the list of Business hard code that will require adjustments
  • during handover phase, when the Project team describe to the AMS what has been realized, get list of Business hard code and evaluate accurately
  • to discourage the bad practice, you may want to add ABAP Test Cockpit during Change Request release
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Bjoern Panter

    Needed 10 minutes to implement the community version. Really cool and a nice demonstration how easy it is to enhance ABAP Code Inspector or ATC with new tests.

    (0) 

Leave a Reply