Tải bản đầy đủ (.pdf) (18 trang)

Tài liệu Chapter 12: ABAP Report Templates docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (219.8 KB, 18 trang )


Report Development Tools 12–1
Chapter 12: ABAP Report Templates
Contents
First Things First ..................................................................................................12–2
ABAP Reporting Basics.......................................................................................12–3
Template Approach to Report Development .....................................................12–7
Working With Report Templates.........................................................................12–8
Getting the Most from ABAP Report Development: Tips & Tricks................12–17
Where to Learn More..........................................................................................12–18


12
In this chapter you will learn:
 The basic structure of an
ABAP report
 The difference between
traditional and interactive
reports
 How to build a traditional
report using the report
template
 How to build an
interactive report using the
report template
 Useful tips and tricks on
ABAP report development
Chapter 12: ABAP Report Templates
First Things First

Reporting Made Easy



12–2

First Things First
In the preceding chapters you learned about the different report development tools
available in the R/3 environment. This chapter introduces the basics of SAP’s programming
language, Advanced Business Application Program (ABAP), which can be used to build
custom reports. This chapter is structured differently than the others. It does not present all
the features of ABAP—we leave that to the online documentation. Instead, we focus on
helping you build an ABAP report using templates.
Before You Consider ABAP
The decision to use ABAP to create custom reports requires careful consideration. Writing
reports in ABAP can be costly, time-consuming, and in many cases unnecessary. While
ABAP provides numerous features to create excellent programs, it is not geared solely
toward report creation, as are the reporting tools outlined in the previous chapters. Thus,
the robust functionality of ABAP (combined with the programming styles of many
programmers) may make it cumbersome. The tactical approach to reporting (see chapter 2
in book 1, Fundamentals of Reporting of this guidebook series) recommends that you use
ABAP only after you have explored all other options.
Ideally, you should consider ABAP development only after you can answer “yes” to all of
the following questions:
< Did you do a thorough search of the standard reports to find the report you need?
< Did you survey available standard report development tools to determine if a certain
tool fits your report needs?
< Did you check other report resources (such as user groups and/or OSS—SAP’s Online
Support Service)?
Fundamentals of Reporting, the first book in the Reporting Made Easy series, outlines how to
approach the questions listed above. However, if you still do not have a solution for your
reporting requirement, it may be time to consider ABAP for custom development.
Before You Start

If you are an ABAP programmer, you should be aware of the following prerequisites and
assumptions:
< Your user account is registered as a developer in OSS. If your account is not classified as
a developer, then contact your system administrator to modify your account
classification.
< You need to be authorized to develop programs. Contact your system or security
administrator for the required authorization.
< You should have a basic understanding of ABAP. If you have prior programming
experience, you should be able to learn reporting-related ABAP commands.
Chapter 12: ABAP Report Templates
ABAP Reporting Basics

Report Development Tools
12–3

< You should have a basic knowledge of Structured Query Language (SQL). ABAP uses its
own set of SQL statements called “Open SQL” which are simplified but similar versions
of SQL.
< You should be familiar with ABAP event-triggering. Understanding which event
statement is relevant to which building block of a report helps speed up report
development.
< You should know how to create function modules in ABAP.
< ABAP report development must always be done in the development system . Do not use
the production (or any other) system to write ABAP reports.
ABAP Reporting Basics
Writing reports in ABAP is a matter of understanding the various commands relevant to
each basic block, and using them appropriately in the program to make the report produce
the desired results in an output list.
Basic Structure
An ABAP report consists of the following basic blocks (or sections):

1. Get the required data from the database.
2. Process the read-data as required.
3. Output the processed data as a formatted list on the screen or the printer.
ABAP code is written to perform certain functions that typically fall under one of the three
blocks listed above.
As shown in the graphic on the following page, these functions are performed in a linear
sequence and are dependent on each other. Think of these functions as the basic building
blocks of any report. Each block contains the necessary ABAP code to do its task. The ABAP
code within each block can be further modularized to perform the steps required for a given
block to function.
Chapter 12: ABAP Report Templates
ABAP Reporting Basics

Reporting Made Easy

12–4

Get required data
Process the
read data
Output processed
data as a list

Define data containers to store and output data

Define selection parameters as a basis for data retrieval

Read relevant data into selection parameters

Refine retrieved data (sorting, grouping, etc.)


Refine authorization filters

Perform desired calculations against the data

Prepare a list page layout (header, footer, comments, etc.)

Write and format the fields data (header, size, icon, color,
indentation, etc.)
Basic Block TasksBasic Report Blocks


Types of ABAP Reports
As shown in the graphic below, there are two types
of ABAP reports:
< Traditional reports
< Interactive reports
Both report types share the same basic structure and
functionality. An interactive report is an extension of
a traditional report.
With a traditional report, the execution of the report
is finished as soon as the output list is displayed. An
interactive report allows the user to interact with the
report list.
Traditional Reports
A traditional report, also called a “classic” report, allows the user to enter selection
parameters as key input for retrieving the data from the database. Then, the report processes
the read-data, and displays a list for output. Once the report list is displayed on the screen
or sent to a print spool, the report program execution concludes and no further interaction
or user input is possible. If the output is sent to the screen, a traditional report sends all

output data to a single list called a basic list.
Traditional
Report
Traditional
Report
Interactive Report

Chapter 12: ABAP Report Templates
ABAP Reporting Basics

Report Development Tools
12–5

Basic report list is generated
Basic report list is generated
Read data is processed
Read data is processed
User enters selection parameters
User enters selection parameters
Display
on screen
Traditional Report
OR
Send to
print spool
Basic report list is generated
Basic report list is generated
Read data is processed
Read data is processed
User enters selection parameters

User enters selection parameters
Display
on screen
Interactive Report
OR
Send to
print spool
• Download to desktop applications
• Control number of fields displayed
• Call up another report
• Jump to a system transaction
• Display summarized results or
totals in a new window
• Print selected fields
• Interactive sorting of fields
Plus
Secondary list
Traditional
Report
Traditional
Report
Interactive Report

Interactive Reports
Interactive reporting builds on the standard functionality of a traditional report. An
interactive report performs all the functions of a traditional report and provides the user
with the means to interact with the report even after the list is displayed on the screen.
As shown in the graphic above, this expanded functionality is particularly useful for reports
that require:
< Controlling the number of displayed fields on the screen

< Interactively sorting in any order of any field on the screen
< Calling up another report, or jumping to system transaction
< Displaying summarized results or totals in a new window
< Downloading to desktop applications
< Printing of selected fields on the displayed list
The first time an interactive report issues output, it sends data to the basic list just like a
traditional report. Any additional information is presented as a secondary list, which may
either completely replace the previous basic or secondary list, or appear in a secondary
window on the same screen.
To program the output list, a set of available ABAP commands is used. Typically, an
interactive report is written so that for every user input, an event is triggered, some source
code is executed, and the report responds back with either a new secondary list, or jumps to
a new screen.
Chapter 12: ABAP Report Templates
ABAP Reporting Basics

Reporting Made Easy

12–6


In Release 4.0 you can use a new tool called the ABAP List Viewer (ALV) and a set of
function modules to build interactive reporting functionality without having to program.
The ALV can help save time on display formatting. It also handles many basic interactive
features such as sorting, detailed line information, and total calculation. For more
information on ALV, refer to appendix A.
Traditional Versus Interactive Reports
We suggest using the following guidelines to decide whether to develop a traditional report
(basic list display) or an interactive report (interactive data retrieval).


Criteria Recommended Report Type
Frequency of report
use
If the report is run quarterly or annually, then a traditional
report is recommended. Even if the report is complex in nature,
or requires a multilayered output list, writing an interactive
report is probably not worth the development effort. If the report
is to be run more frequently, an interactive report (which allows
further analysis) is probably preferable.
Background
processing only
A traditional report is recommended since user interaction is
irrelevant in this case.
Ease of programming Traditional reports are typically easier to program, and faster to
develop and maintain. If needed, a traditional report can always
be enhanced to become an interactive report without significant
source code changes.
User interaction If the specifications require some form of user interaction, then
choose interactive reporting style.
Width of data fields If the report requires the simultaneous display of many large
data fields, an interactive report is useful. You can enhance the
displayed list visually by suppressing the output of lengthy
fields, and provide a menu button to view detailed line item
information as a secondary list in a new window.
Number of
calculations
If the report uses numerous mathematical calculations and
displays multitotaled field results, consider an interactive report.

Number of users Choose the interactive reporting style for any report that is used

by many users and is normally executed online for tracking
purposes on a daily, weekly, or monthly basis.
Presentation If the report is used for frequent presentation purposes, or for an
online demonstration of a successful project (such as employee
achievements), an interactive report carries a stronger impact.

Chapter 12: ABAP Report Templates
Template Approach to Report Development

Report Development Tools
12–7

Template Approach to Report Development
A report template is a generic program that contains all the necessary report elements
common to any report. It includes the ABAP statements and events, as they would typically
be placed in a report. The programmer then completes the detail.
Because each report has its own requirements, a template is not specific to any report. It
only serves as a roadmap for starting a report development project. It consists of many
empty placeholders for which custom source code is programmed.


The template itself cannot be generated. Consequently you cannot execute a template.
You must have basic ABAP knowledge to convert the template to executable code
.

Why Use a Report Template?
Report templates offer the following advantages:
< Modular structure: Reports in general are modular, which allows a template to be well
structured and highly customizable. A template can be easily expanded to include new
subroutines and new program code relevant to the report requirements.

< Eliminates cumbersome copying: For instance, templates eliminate the process of
copying an existing report, deleting many lines of source code, or modifying source code
that is relevant but uses different field names. These processes are awkward, and may
end up taking more time than starting a report from scratch.
< Saves time: A report template is a good way to jumpstart the development effort and
save time. Once the programmer identifies the database tables to work with, the
selection criteria, and the report functionality, the template can be instantly used to
insert the necessary source code in the various program sections.
< Consistency: Using templates ensures consistency of source code and structural
uniformity across many reports. This is especially helpful when other programmers
have to maintain the report in the future. (However, to help future programmers
understand report code, few things take the place of well-integrated comments.)
< Syntax: Even experienced programmers sometimes forget the exact syntax of a
command and have to look it up. Templates include frequently used program
statements in their correct syntax form. Any statement can have its parameter names
changed while still keeping it syntactically correct.


Note: A template approach to report development is a convenient and effective way to
start writing reports. We recommend that customers adopt a template approach for all of
their custom report development. If your company does not use templates, we suggest
designing a company standard report template for use by all programmers who write
reports. If needed, you can create your templates by refining the ones supplied with this
guidebook.

×