Dynamically Generate a Formatted Representation of Internal Tables for Output

  • by David Duncombe, SAP Analyst, Powerlink Queensland
  • May 19, 2014
SAP Professional Journal
Use this table introspector utility class to dynamically generate a formatted representation of internal tables at run time, with support for subsequent output to various formats.
Learning Objectives

 By reading this article, you will be able to:

  • Develop a utility class to dynamically generate a formatted representation of internal tables with support for subsequent output to file, email, and SAP List Viewer (ALV) formats
  • Understand the benefits offered by the factory pattern and private instantiation
  • Understand the use of Run Time Type Services (RTTS) in supporting introspection of the underlying internal table at run time to determine attributes necessary to properly format and describe the data
  • Understand the elegance of using recursive algorithms to solve tree traversal when depth is unknown
  • Integrate the utility class into a client program to simplify common operations on internal tables
Key Concept

The ABAP Run Time Type Services (RTTS) library is an object-oriented framework that allows type information on existing objects to be deduced via Run Time Type Information (RTTI), as well as new data types to be defined via Run Time Type Creation (RTTC).

It is a common requirement to format internal tables for output to either a flat file or as an attachment to an email. To do this properly, however, the programmer is usually forced to statically define appropriate structures at development time in which to store the data. In addition, the programmer must spend time manipulating the data (i.e., creating and formatting a header line, enclosing string values in quotes, converting internal date and time formats to a suitable external representation, and inserting a delimiter between fields). These are all common operations.

In this article I present a table introspector utility class that I have developed to encapsulate behavior related to storing, manipulating, and formatting internal tables in preparation for output. The output table’s structure is created dynamically at runtime, and a header line with field descriptions is built through exploiting information stored in the Data Dictionary. Support is offered for subsequent output to file, email, and SAP List Viewer (ALV) formats.

David Duncombe

David Duncombe is an SAP Analyst at Powerlink Queensland. He has more than five years experience as a developer, and specializes in ABAP Objects and SAP NetWeaver Process Integration. He holds an honors degree in information technology from Queensland University of Technology.

See more by this author


Comments

No comments have been submitted on this article. 


Please log in to post a comment.

To learn more about subscription access to premium content, click here.