SAP ABAP Tips and Tricks | Michael Management
7/7/2020 by Ronak Hingorani Posted in SAP

ABAPWith vast experience in SAP ABAP (Advanced Business Application Programming), we have come up with a few tips and tricks that an ABAP Developer can use in his day-to-day work with ABAP development tools (i.e. ABAP Workbench) to enhance the quality and speed of development.

Most SAP software is written in ABAP - it is the object -oriented programming language for SAP applications.

Below is a mix of tips that can be used for performance management, RICEF (Reports, Interfaces, Conversions, Enhancements, Forms) development, debugging, and analysis. 

 

ALV Consistency Check

ALV (Advanced List Viewer) programs sometimes have inconsistencies due to coding errors in the ALV field catalog and output table, which does not cause any visual issues but causes issues with code performance and maintenance. We can get a list of all these issues with this convenient and straightforward way, instead of reviewing the entire code line-by-line. 

The ALV consistency check can be used by pressing the Shift key and simultaneously double-clicking the right mouse button on an area in the ALV Grid Control in which no table rows are displayed (to do this, scroll to the right area of the output).

ABAP Demo Program

 

This action pops up an SAP standard screen with technical report details of the ALV. The consistency check function allows you to access:

  • The field catalogs
  • The layout structures
  • The sort tables
  • The filter tables
  • The structure for the layout (using the Variant pushbutton)
  • The field group table

ALV consistency check

 

SCI Configuration 

SCI stands for SAP Code Inspector. This SCI acts as the best tool for one's code review and peer review. Every project usually has a set of standards and naming conventions that developers are expected to use.

SCI checks the code for the naming convention and performance issues. It is possible to configure and enter the project-specific standards, as shown below. 

Go to SAP transaction code SCI and copy the DEFAULT Variant 

Code Inspector Initial Screen

 

Code Inspector Copy

 

Add Naming conventions

Code Inspector Naming Convention

 

Once configured, the same variant can be used to review a class, program, or any DDIC object.

 

CDS Code Exit 

If you have ever wondered if you can have a code exit in CDS, the answer is a resounding YES. A Virtual Element can be defined in an ABAP Method to implement a Code Exit for a CDS View. This exit and virtual element will not be visible for data preview in Eclipse or SE16N but will only be visible when the CDS is exposed as an OData service. 

This is very simple and can be done within the CDS view field definition, as shown below. The annotation @ObjectModel.virtualElement: true is used to mark it as a virtual element. 

CDS Code Exit

CDS Code Exit

   

The marked section shows the ABAP Class. ZCL_CDS_FUNCTION will be called to populate the text field below. The ABAP class must use the interface "if_sadl_exit_calc_element_read" and implement the methods "calculate".

Learn Access Control in ABAP Core Data Services.

 

Adobe LifeCycle Designer 

Before starting any ABAP programming development on ADOBE FORMS, it is imported to check the status and installation of the Adobe LifeCycle Designer in the SAP system. Follow the below steps to validate:

 

Report FP_TEST_00 checks if your system is configured correctly for processing forms in an ABAP environment.

 

  • Call transaction SA38 and enter the name FP_TEST_00 and Execute (F8)
  • Keep the defaulted options in the selection screen as-is with Form - FP_TEST_00, ADS Connection – ADS
         Form Processing
     
  • Execute and choose an output device with Print Preview.
         Print Preview

 

If the configuration is correct, a form containing several lines on two pages is displayed; otherwise, no form is displayed.

Print Preview

 

 

Display BAPI messages using BAPIRET 

SAP ABAP Developers use ABAP objects such as BAPIs frequently to access, create, change business objects. BAPIs provide a BAPIRET table that holds the success, error, and warning messages. In traditional ABAP code, the developer always loops over this table and build a pop-up ALV to show the user all relevant messages.

However, the SAP prebuilt function module RSCRMBW_DISPLAY_BAPIRET2 performs the same activity. This module accepts the BAPIRET as an input parameter and shows a pop-up display to the user. This reduces the number of code lines the ABAP developer needs to write and provides a consistent experience to users. Below is an example:

Function Module

 

Reference Code to call the FM:

Reference call

Error messages

 

Learn how to use Test Driven Development with ABAP in this training course.

 

BAPI Test Sequence

Whenever an ABAP developer looks for a solution to a problem, the first approach she uses is to test the solution before spending time on implementing it completely. The testing gets complicated when there is a need to test solutions in sequence. For example, if a BAPI is triggered, the output will only be seen when a BAPI_TRANSACTION_COMMIT is called. For such cases, SE37 way perform sequencing, shown below.

 

The test sequence can be built using SE37 > Function Module > Test > Test Sequences.

BAPI test sequence

 

Enter the required sequence of BAPIs to trigger them in the given order for testing.

Select function module

 

New Open SQL Syntax

SAP has come up with a new syntax for ABAP versions 7.4 or higher. This new syntax help developers reduce the number of code lines and write performance-optimized code. We are listing some important ones here, while an exhaustive list can be found here: ABAP 7.40 Quick Reference

Take this training course to learn more about Reading Data in ABAP with Open SQL.

 

Inline Declaration:

DATA(text) = `ABC`.

LOOP AT itab INTO DATA(wa).

LOOP AT itab ASSIGNING FIELD-SYMBOL().

READ TABLE itab ASSIGNING FIELD-SYMBOL().

SELECT * FROM dbtab INTO TABLE DATA(itab) WHERE fld1 = @lv_fld1.

oref->meth( IMPORTING p1 = DATA(a1) ).

 

Reading Table:

wa = itab[ index ].

wa = itab[ col1 = … col2 = … ].

IF line_exists( itab[ … ] ). ENDIF.

DATA(idx) = line_index( itab[ … ] ).

 

Data Type Conversion:

CONV dtype( … )

CONV #( … )

 

Value Operator to populate variables, structures or tables:      

Var = VALUE dtype( … ) or Var = VALUE #( … )

Structure = VALUE dtype( … ) or Structure = VALUE #( …)

itab = VALUE #( ( ) ( 1 ) ( 2 ) )

 

Similarly, there is another new syntax for REDUCE, FOR, COND, SWITCH, GROUP BY, etc. which can be used for effective coding. 

 


Author Photo

Ronak is an ABAP/UI5/FIORI Consultant with more than 8 years of experience, with a demonstrated history of working in the SAP consulting industry. He has worked across various SAP modules like MM, SD, FICO, P2P and has helped client by developing a scalable technical ABAP solution. Over the past 8 years he has built expertise in server-side ABAP technology and advanced ABAP skills like CDS, AMDP, OData and in client-side UX technology like UI5 Framework (HTML/CSS/ JavaScript) and FIORI. He also has experience in SAP Upgrade from ECC to HANA (1709/1909).
More Blogs by Ronak Hingorani:
full-stack webide
SAP WebIDE Full-Stack Edition Setup and Configuration

Introduction SAP WebIDE is a powerful, extensible, web-based integrated development tool that simplifies end-to-end full-stack application development. SAP WebIDE supports the entire application lifecycle, ...

sap webide
SAP WebIDE Personal Edition Setup and Configuration

Introduction SAP WebIDE is a web-based development tool to build SAPUI5 and FIORI applications. WebIDE is an open source code editor development environment for a single user. There are two kinds of ...

fiori elements
Application Development with FIORI Elements

Introduction SAP Fiori Elements, formerly known as smart templates, has been around since 2015 (when SAP S/4HANA come out) and provides a framework for the most common application patterns.  If ...