1. Trang chủ
  2. » Công Nghệ Thông Tin

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

18 445 2
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề ABAP report templates
Định dạng
Số trang 18
Dung lượng 219,8 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 usin

Trang 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

Trang 2

Chapter 12: ABAP Report Templates

First Things First

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

Trang 3

Chapter 12: ABAP Report Templates

ABAP Reporting Basics

< 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

Trang 4

Chapter 12: ABAP Report Templates

ABAP Reporting Basics

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 Tasks Basic 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

Trang 5

Chapter 12: ABAP Report Templates

ABAP Reporting Basics

Basic report list is generated Read data is processed User enters selection parameters

Display

on screen

Traditional Report

OR Send to

print spool

Basic report list is generated Read data is processed 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

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

Trang 6

Chapter 12: ABAP Report Templates

ABAP Reporting Basics

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

Trang 7

Chapter 12: ABAP Report Templates Template Approach to Report Development

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

Trang 8

Chapter 12: ABAP Report Templates

Working With Report Templates

Working With Report Templates

In this section you learn to work with the following types of report templates when writing

a report:

< Traditional report template

< Interactive report template

To work with a template, follow the steps and hints shown, and try to apply them according

to your report needs Sections that are common to both templates have been described only once in the traditional report template

In addition, parameters for the ABAP statements included in this template are shown in italics To illustrate in where particular report section parameters would be found, the descriptive names of the parameters have also been included Change the words in italics and insert new ABAP commands similar in functionality under those sections

Note: A ready-to-use template containing the necessary source code for an interactive and traditional report is included in the CD supplied with this guidebook

You can also download the templates from our website at: http://www.saplabs.com/rme

Report Specification Form and Report Templates

A report specification form serves as the starting point for ABAP report development It provides the developer with vital information about the reporting project A detailed and complete specification is important for efficient report development

To help customers and consultants streamline the process of developing reports, a

sample report specification form is shown in book 1, Fundamentals of Reporting, of this

guidebook series You can use the report specification form as is, or modify it to suit your requirements

Additionally, an electronic version (Microsoft Word document) of the specification form

is included on the companion CD supplied with this guidebook series You can also

download the specification form from www.saplabs.com/rme

We suggest making use of the report specification form to supply the information for some

of the blocks (for example, report name, database tables, etc.) in the report template As shown in the table on the next page, a developer can fill many of the placeholders in the report template simply by pulling related information blocks from the specification form

Trang 9

Chapter 12: ABAP Report Templates Working With Report Templates

Information a Developer Needs for the ABAP Report Blocks Where Found on the Report Specification Form (Filled out by the person requesting the report)

Title Item 1: What is the suggested name of the desired

report (Page 2)?

Documentation Item 2: Give a short description of the desired

report (Page 2)

Attributes or Application Item 4: Name the application(s) or data area(s) for

the report (Page 2)

Data declarations (Tables statement) Item 5: Please indicate any known tables or fields desired in the report (Page 2)

Traditional Report Template

To work with this template, enter the relevant information in each section as described here This template uses a prefix convention for each program object You could use subroutine names that are different from the ones shown in italics Also, modularize the source code using several subroutines if necessary

Guided Tour

1 From the SAP main menu, choose

Tools ABAP Workbench, then

Development ABAP editor

2 In the Program field, enter a name for

your report

3 Choose Create

If your user account does not have

developer status, the system will not let

you create an ABAP report Contact

your system administrator for more

information

Note: Although you will enter the source code in the ABAP Editor, the actual screens are not included here Instead, only the source code you would enter in ABAP Editor is shown

3 2

Trang 10

Chapter 12: ABAP Report Templates

Working With Report Templates

Enter:

< Report name and

width of the list

< Report attributes

such as program

name and title when

the report is first

saved

< Change history

including date, name

of person changing

the report, and the

change description

REPORT REPORTNAME LINE-SIZE XX LINE-COUNT YY

**************************************************************

*

* Program Info: (information IN ADDITION to what is already

* captured in program ATTRIBUTES and DOCUMENTATION)

*

**************************************************************

*

* Change History: (in addition to what is found in Version

* Management)

*

* Date/Author:

* Reason/Description of Change:

*

* Date/Author:

* Reason/Description of Change:

*

**************************************************************

< Enter all include

program names used

by the report (for

example, system

icons, symbols, or the

names of include

programs that

contain source code

the report uses)

**************************************************************

* DATA DECLARATIONS - BEGIN

**************************************************************

**************************************************************

* INCLUDES

**************************************************************

Include <icons>

Include <symbols>

Include <system include>

Include ProgramName

< Define report tables,

views, or structures

in this section, and

include the text

description of each

object Object names

are not always

descriptive

**************************************************************

* PROGRAM TABLES / STRUCTURES / VIEWS

**************************************************************

TABLES:

DDIC_tab1, “ Table description

DDIC_tab2 “ Table description

DDIC_View1 “ Table view description DDIC_Structure1 “ Structure description

< Define all the

necessary internal

tables where the

program needs to

store the data

**************************************************************

* DATA - INTERNAL TABLES (ITAB_tablename)

**************************************************************

DATA: BEGIN OF ITAB_tab1 OCCURS n,

Field1 LIKE table-field1,

Ngày đăng: 21/12/2013, 19:15

w