18
Best-Practices & Learning’s ON SAP ABAP – Hard coding Angels & Demons By Prammenthiran Rajendran [email protected] [email protected] 23-Dec-2010

Abap Hard Coding Angels and Demons

Embed Size (px)

Citation preview

Page 1: Abap Hard Coding Angels and Demons

Best-Practices & Learning’s

ON

SAP ABAP – Hard coding Angels & Demons

By

Prammenthiran Rajendran

[email protected]

[email protected]

23-Dec-2010

Page 2: Abap Hard Coding Angels and Demons

Introduction:

The word “hard-coding” will make any SAP consultant serious. Consultants always doubt the enhancement / reports / programs which has hard coded logic. Because they believe that it may work temporarily and not a permanent solution to the requirement. So, should it be avoided 100%? As per my SAP experience I can not say that hard coding has to be avoided 100%. Hard coding has to be used in most of the ABAP programming to meet the requirement. But the ABAP consultant has to understand what can be hard coded, how and why? I would like to differentiate good and bad practices of hard coding in this document.

ScopeThis document is intended for ABAP consultants. Also, will help the functional consultant to prepare a better functional specification to avoid reworking. The document will help the consultant to understand the hard coding concept with some samples which are taken from the SAP projects.

Best-Practices/Learning

Generally, ABAP consultants used to hard code the values as per the functional consultant’s input. But this does not mean that it is the complete responsibility of the functional consultants for hard coding any data. As a good ABAP consultant, we should know the impact of hard coding a custom data (a particular document type or item category or sales organization) in our ABAP programs. The best practice is to get the SAP configuration / master level information for the particular requirement which need hard coding. We can always ask this information to the functional consultant before starting the development. The functional consultant will definitely show the configuration (SPRO) path. This will give us the configuration level detail where we can get the requirement technical information by pressing F1 key.

The following pages have some samples which will help the consultant to understand the concept and apply in the SAP projects in a better way.

Page 3: Abap Hard Coding Angels and Demons

Sample requirements with good and bad hard coding practices:

1) Requirement: Update the Sales order billing block for Credit memo request, debit memo request and return orders through user exits.

Bad Practice: Hard coding all the required document types as below.

Impact: This will not work when we create a new document type. So, this enhancement needs code change whenever there is a new document type creation.

Good Practice: Hard code the SD document category (VBAK-VBTYP) which is the standard SAP configuration level data. This will cover all the custom document types which ever will be created in future as well.

Page 4: Abap Hard Coding Angels and Demons

Sample code for good practice:

We can also get the document type field data from the configuration table TVAK if required (Transaction code VOV8).

Page 5: Abap Hard Coding Angels and Demons

2) Requirement: Enable/disable a particular feature based on the sales organization and document type.

Bad practice: Hard coding the required sales organization and document type where ever required as below,

Good practice: Maintain a custom table with Sales organization and document types as primary key with separate flags as below. So that we can extend the required feature to other sales organization and document types in future. Or enable / disable whenever required.

Page 6: Abap Hard Coding Angels and Demons

3) Requirement: Print a particular detail for the sales order only when it has it’s domestic plant (Based on the company code country and Plant code country).

Bad practice: Hard code the sales order plant code and company codes to check the specific plants under the company codes.

Good practice: Compare the sales order’s company code country (T001-Land1) and plant code country (T001W-Land1). If both are same then it is a domestic plant.

Page 7: Abap Hard Coding Angels and Demons

4) Requirement: Identify the warehouse managed storage location and write the code as per the enhancement requirement.

Bad practice: Hard code all the required warehouse managed storage locations in the enhancement.

Good practice: Check the entries in configuration table T320 and identify the warehouse managed storage location if warehouse number found as below.

Page 8: Abap Hard Coding Angels and Demons

5) Requirement: Enhancement should exclude the sales order’s free goods or without price.

Bad practice: Hard code the material codes OR hard code item category OR check the sales order item net value field (NETWR) as zero OR write a complex logic to check the pricing condition type value of the sales order item.

Good practice: Check the configuration value (TVAP-PRSFD) for the sales order or invoice item category (VBAP-PSTYV) as below. This logic will take care the future item categories as well.

Page 9: Abap Hard Coding Angels and Demons

6) Requirement: Enhancement code should work only for Return deliveries (Delivery Document type ZLR).

Bad practice: Hard code the delivery document type ZLR as below,

Good practice: Hard code the required delivery document category LIKP-VBTYP which has been updated from the configuration table.

Return delivery document category = ‘T’

Normal delivery document category = ‘J’

etc.,

Page 10: Abap Hard Coding Angels and Demons

Conclusions

Hope you got some idea on good and bad practices in hard coding. The above samples are just to understand the concept. So, please ask your functional consultant to tell about the configuration level detail for the relevant hard coding area. Also, it is always good to understand the functional requirement though the consultant is an ABAP developer.

Useful Links:-

Program to find the hard coding in ABAP programshttp://www.abap-tutorials.com/2009/08/04/track-hard-coding-in-programs/#more-570

Thank you