Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
SergioFerrari
Active Contributor
9,486

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.

 

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.

 

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.

 

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.

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

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:

DomainDescription
BUKRSCompany Code
WERKSPlant
EKORGPurchase Org.
VKORGSales Organization
VTWEGDistribution Channel
SPARTDivision
LGORTStorage Location
GSBERBusiness Areas
WAERSCurrency
LAND1Countries
MSHEIUnit of measurements
PARVWPartner Function
KTOKDCustomer account groups
KTOKKVendor account groups
MTARTMaterial Type
AUARTSales Document Type
LFARTDelivery Type
FKARTBilling Type
BSARTPurchasing Document Category
BWARTMovement Type
VSBEDShipping conditions
PSTYPItem Category in Purchasing Document
PSTYVSales document item category
KSCHLCondition Type
BLARTDocument Type (FI)
PLTYPPrice list type
MATNRMaterial
KUNNRCustomer account groups
LIFNRVendor
SKA1G/L Account Master (Chart of Accounts)
BELNRAccounting 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
5 Comments
Labels in this area