BC400 ABAP Workbench Concepts and Tools

January 9, 2017 | Author: Nicole Johnson | Category: N/A
Share Embed Donate


Short Description

Download BC400 ABAP Workbench Concepts and Tools...

Description

BC400 ABAP Workbench Concepts and Tools BC400

Release 46D 26.03.2003

0 BC400 ABAP Workbench Concepts and Tools

BC400 ABAP Workbench: Foundations and Concepts 

   



SAP AG 2001 SAP AG

R/3 System Release 4.6D Material Number 5004 8586 October 2001

0.2

Copyright

Copyright 2002 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. All rights reserved.



SAP AG 2002

Trademarks:  Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.  Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered trademarks of Microsoft Corporation.  IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®, OS/390®, and OS/400® are registered trademarks of IBM Corporation.  ORACLE® is a registered trademark of ORACLE Corporation.  INFORMIX®-OnLine for SAP and INFORMIX® Dynamic ServerTM are registered trademarks of Informix Software Incorporated.  UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.  HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C ®, World Wide Web Consortium, Massachusetts Institute of Technology.  JAVA® is a registered trademark of Sun Microsystems, Inc.  JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.  SAP, SAP Logo, R/2, RIVA, R/3, ABAP, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo and mySAP.com are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other products mentioned are trademarks or registered trademarks of their respective companies.

0.3

ABAP Workbench Level 2

3 days BC402 ABAP Programming Techniques 3 days BC404 ABAP Objects: Object Oriented Programming in R/3 BC405 3 days Techniques of List Processing and InfoSet Query

BC400 5 days ABAP Workbench: Foundations and Concepts MBC40

2 days

Managing ABAP Developments Projects

BC410 Programming User Dialogs

5 days

BC420 Data Transfer

5 days

BC412 3 days Dialog Programming using EnjoySAP Controls

BC430 ABAP Dictionary

2 days

BC460 3 days SAPscript: Forms Design and Text Management

SAP AG 1999

CA610 (Rel. 4.0) 2 days CATT:Test Workbench and Computer Aided Test Tool

BC490 3 days ABAP Performance Tuning

2 days BC415 Communication Interfaces in ABAP BC425 3 days Enhancements and Modifications

BC470 2 days Form Printing Using SAP Smart Forms



Level 3 BC414 3 days Programming Database Updates

Recommended supplementary courses are: Business Process Technologies CA925, CA926, CA927 BC095 (Business Integ. Techn.) BC619 (ALE), BC620, BC621

0.4

ITS Level 3 Level 3

Level 2 Level 2

BC400 5 days ABAP Workbench: Foundation and Concepts

ITS100 2 days Developing EasyWebTransactions

ITS050 3 days SAP Internet Transaction Server: Foundations

2 days ITS110 Developing Web Scenarios and MiniApps using ITS Flow Logic ITS150

2 days

Corporate Identity Design



ITS070 2 days SAP Internet Transaction Server: Administration

SAP AG 1999

0.5

Course Prerequisites

 Programming knowledge



 Contents of SAP50 training course (Basis Technology)

SAP AG 2001

0.6

Target group

 Participants: Members of project team  Length: 5 days



SAP AG 2001

The training materials are not teach-yourself programs. They complement the course instructor's explanations. On the sheets, there is space for you to write down additional information.  There may not be time during the course itself for you to complete all the exercises. The exercises are intended as additional examples of the topics discussed during the course. Participants can also use them as an aid to enhancing their knowledge after the course has finished.

1 Course Overview

Contents:  Course Goals  Course Objectives  Course Content  Main Business Scenario  Important Database Tables for the Flight Data Model



SAP AG 2001

(C) SAP AG

BC400

1

1.2

Course Goals

At the conclusion of this unit, you will be able to:  Explain the basics of the ABAP programming language, including: 

Basic syntax elements



Different types of user dialogs



How to read database accesses

 Describe the various uses of the ABAP Workbench, including:





Support through development tools



Support in organization and transport

SAP AG 2001

(C) SAP AG

BC400

2

1.3

Course Objectives

At the conclusion of this course, you will be able to:

 Create an ABAP program containing user dialogs and database accesses  Describe the different types of development objects and their typical uses  Use appropriate tools to create basic examples for the Repository objects introduced in the course



SAP AG 2001

(C) SAP AG

BC400

3

1.4

Table of Contents I

Unit 1

Introduction

Unit 2

Program Flow in an ABAP Program

Unit 3

Introduction to the ABAP Workbench

Unit 4

Introduction to the ABAP Dictionary

Unit 5

Basic ABAP Language Elements

Unit 6

Data Retrieval

Unit 7

Internal Program Modularization with Subroutines

Unit 8

The ABAP Runtime System

Unit 9

User Dialog List

Unit 10

User Dialog Selection Screen



SAP AG 2001

(C) SAP AG

BC400

4

1.5

Table of Contents II

Unit 11

User Dialog Screen

Unit 12

User Interface

Unit 13

Perspective: Development of Internet Applications

Unit 14

Cross-Program Modularization

Unit 15

Software Logistics and Software Adjustment Appendix



SAP AG 2001

(C) SAP AG

BC400

5

1.6

Main Business Scenario

Departure airport

Destination airport In this course, you will develop several programs designed to assist travel agencies. Some of their typical needs include: Departure city



 Determining

flight connections on specific dates bookings for specific flights  Evaluating additional flight information, such as  Price  Capacity  Processing

Destination city

SAP AG 2001

(C) SAP AG

BC400

6

1.7

Important Database Tables for the Flight Data Model SCARR

CARRID: CARRNAME: CURRCODE:

Airline ID Airline name Local currency of airline

SPFLI

CARRID: CONNID: COUNTRYFR: CITYFROM: AIRPFROM: COUNTRYTO: CITYTO: AIRPTO:

Airline ID Flight connection ID Country key for departure city Departure city Departure airport Country key for arrival city Destination city Destination airport

SFLIGHT

CARRID: CONNID: FLDATE: PRICE: CURRENCY: SEATSMAX: SEATSOCC:

Airline ID Flight connection ID Flight date Price Currency Maximum number of seats on flight Current number of occupied seats on flight



SAP AG 2001

You will refer to this information as you do the exercises throughout this course.

(C) SAP AG

BC400

7

2 Program Flow in an ABAP Program

Contents:  System Architecture and ABAP Program  Sample Program with Selection Screen and List



SAP AG 2001

(C) SAP AG

BC400

1

2.2

Program Flow of an ABAP Program: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe the architecture of the R/3 System  Describe how to execute a simple dialog program using the ABAP runtime system



SAP AG 2001

(C) SAP AG

BC400

2

2.3

System Architecture and ABAP Program

System System Architecture Architecture and and ABAP ABAP Program Program Sample Sample Program Program with with Selection Selection Screen Screen and and List List



SAP AG 2001

(C) SAP AG

BC400

3

2.4

Client/Server Architecture

Presentation Server Layer

SAPGUI

SAPGUI

SAPGUI

Dispatcher

Application Server Layer

Database



SAPGUI

SAPGUI

SAPGUI

Dispatcher

Work Process

Work Process

Work Process

Work Process

Work Process

Work Process

Work Process

Work Process

SAP AG 2001

 The R/3 System has a modular software architecture that follows software-oriented client/server principles.  The R/3 System allocates the presentation, application logic, and data storage to different computers. This serves as the basis for the scalability of the R/3 System.  The lowest level is the database level. Here data is managed with a relational database management system (RDBMS). In addition to application data, the database contains the programs and the metadata that the R/3 System requires for self-management.  ABAP programs (both the applications provided by SAP and the ones you develop yourself) run at the application server level. The ABAP programs read data from the database level, process the data, and possibly store data there.  The presentation server level contains the user interface through which each user can access the program, enter new data, and display the results of a work process.  The technical distribution of software is independent of its physical location on the hardware. All levels can be installed vertically (on top of each other on one computer) or each level can be installed on a separate computer. The presentation and application servers can be divided horizontally among any number of computers. The horizontal distribution of database components, however, depends on the type of database installed.

(C) SAP AG

BC400

4

2.5

Excerpt for an ABAP Program

Presentation Server Layer

Work Process

ABAP Program

Application Server Layer

Database



SAP AG 2001

 This graphic can be simplified for most topics discussed during this course. The interaction between a single user and a single ABAP program will be of primary interest to us during this course.  The exact processes involved in user dispatching on an application server are secondary to understanding how to write an ABAP program. Therefore, we will work with a simplified graphic that does not explicitly show the dispatcher and the work process. Certain slides will, however, include these details whenever they are relevant to ABAP programming.  ABAP programs are processed on the application server. The design of user dialogs and database dialogs is, therefore, of particular importance when writing application programs.

(C) SAP AG

BC400

5

2.6

View for the User

Presentation Server Layer

Application Server Layer

Screen

Selection Screen

List

Black Box

Database



SAP AG 2001

 Most users are only interested in how a business transaction flows and how to enter data into and display data from a transaction. The technical aspects of programming are less interesting. The user does not need to know the precise flow of the ABAP program on the application server. To the average user, the SAP system is like a "black box."  Technically speaking, there are three different types of screens: dynamic screens or dynpros, selection screens, and lists. Each type of screen provides different services. The developer’s task is to select for each user dialog exactly those types that are most suitable for the accomplishment of the tasks concerned. For this reason, developers should have precise knowledge of the technical aspects.

(C) SAP AG

BC400

6

2.7

Interaction Between Server Layers

ABAP Program

Program Start

ABAP Processing Block

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time



Once the user performs a user action (selecting Enter, a function key, a menu function or a pushbutton, for example), control is passed from the presentation server to the application server.



Only certain parts of the ABAP program are processed.



If a further user dialog is triggered from within the ABAP program, the system transmits the screen and passes control once again to the presentation server.

(C) SAP AG

BC400

7

2.8

Sample Program with Selection Screen and List

System System Architecture Architecture and and ABAP ABAP Program Program Sample Sample Program Program with with Selection Selection Screen Screen and and List List



SAP AG 2001

(C) SAP AG

BC400

8

2.9

Program Start

Program Start

Repository

Database Table



SAP AG 2001

Time

 Whenever a user logs on to the system, a screen is displayed. From this screen, the user can start an ABAP program via a menu path or by entering a transaction code.

(C) SAP AG

BC400

9

2.10

System Loads Program Context

Program Start

ABAP Program

Repository

Selection Screen Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time

 The system first loads the program context onto the application server. The program context contains memory areas for variables and complex data objects, information on the screens for user dialogs, and ABAP processing blocks. The runtime system gets the program information from the Repository, which is a special part of the database.  The sample program has a selection screen as the user dialog, a variable and a structure as data objects, and one ABAP processing block. The list that is used to display the data is created dynamically at run time.  The ABAP runtime system controls the subsequent program flow.

(C) SAP AG

BC400

10

2.11

Runtime System Sends Selection Screen

Program Start

ABAP Program

Repository

Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time

Because the program contains a selection screen, the ABAP runtime system sends it to the presentation server. The presentation server controls the program flow for as long as the user enters data in the input fields.  Selection screens allow users to enter selection criteria required by the program. 

(C) SAP AG

BC400

11

2.12

Input Values Are Inserted into Data Objects

Program Start

ABAP Program

Repository

Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time

As soon as the user has finished entering data on the selection screen, he or she can trigger further processing of the program by selecting Execute.  The entered data is automatically placed in its corresponding data objects in the program and the ABAP runtime system resumes control of processing.  In our simple program example, there is only one ABAP processing block. The ABAP runtime system triggers sequential processing of this ABAP processing block.  If the entries made by the user do not have the correct type, an error message is triggered automatically. The user must correct the entries. 

(C) SAP AG

BC400

12

2.13

Program Requests Data Record from Database

Program Start

ABAP Program

Repository

Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time

 Within the ABAP processing block, a read access to the database is programmed. The program passes to the database information about which database table to access and which line in the table to read.

(C) SAP AG

BC400

13

2.14

Database Returns Data Record to Program

Program Start

ABAP Program

Repository

Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 

SAP AG 2001

Time

The database returns the requested data record to the program and the runtime system ensures that this data is stored in the appropriate data objects.  If a single record is accessed, this data object is usually a structure that contains components for all the required database fields. 

(C) SAP AG

BC400

14

2.15

Runtime System Sends List

Program Start

ABAP Program

Repository

Data Objects

Database Table ABAP Processing Block

ABAP Runtime System 



SAP AG 2001

Time

The layout of the subsequent list display was also programmed into the processing block. After completion, the runtime program sends this list as a screen to the presentation server.

(C) SAP AG

BC400

15

2.16

Course Content

System System Architecture Architecture and and ABAP ABAP Program Program Sample Sample Program Program with with Selection Selection Screen Screen and and List List



SAP AG 2001

(C) SAP AG

BC400

16

2.17

Assignment Overview I Which Components of an ABAP Program Are Discussed and in Which Chapter? Unit 1

Introduction

Unit 2

Program Flow in an ABAP Program

Unit 3

Introduction to the ABAP Workbench

Unit 4

Introduction to the ABAP Dictionary

Unit 5

Basic ABAP Language Elements

Unit 6

Data Retrieval

Unit 7

Internal Program Modularization with Subroutines

Unit 8

The ABAP Runtime System

Unit 9

User Dialog List

Unit 10

User Dialog Selection Screen



SAP AG 2001

(C) SAP AG

BC400

17

2.18

Assignment Overview II

Unit 11

User Dialog Screen

Unit 12

User Interface

Unit 13

Perspective: Development of Internet Applications

Unit 14

Cross-Program Modularization

Unit 15

Software Logistics and Software Adjustment Appendix



SAP AG 2001

(C) SAP AG

BC400

18

2.19

Program Flow of an ABAP Program: Unit Summary

You are now able to:  Describe in basic terms the architecture of the R/3 System  Describe in basic terms the execution of a simple dialog program using the ABAP runtime system



SAP AG 2001

(C) SAP AG

BC400

19

3 Introduction to the ABAP Workbench

Contents:  Introduction to the R/3 Repository  Working with the Object Navigator  Organizing Developments  Developing an ABAP Program



SAP AG 2001

(C) SAP AG

BC400

1

3.2

Introduction to the ABAP Workbench: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe the structure of the R/3 Repository and its search tools  Use the Object Navigator for your development work  Name and use the utilities for orderly software development  Create development classes, ABAP programs, and transaction codes



SAP AG 2001

(C) SAP AG

BC400

2

3.3

Introduction to the R/3 Repository

Introduction Introduction to to the the R/3 R/3 Repository Repository Working Working with with the the Object Object Navigator Navigator Organizing Organizing Developments Developments Developing Developing ABAP ABAP Programs Programs



SAP AG 2001

(C) SAP AG

BC400

3

3.4

The R/3 Repository

Presentation Server Layer

Application Server Layer

ABAP Program

Cross-client

Database



Client-specific

Repository

Customizing tables Application tables

SAP AG 2001

The database contains application and Customizing tables that are usually client-specific. The database also contains the R/3 Repository. The ABAP Dictionary is part of the R/3 Repository. The R/3 Repository contains all the development objects, for example, programs, definitions of database tables, or central data type definitions. Development objects are therefore also known as Repository objects.  Repository objects are never client-specific; therefore, they can be viewed and used in all clients.   

(C) SAP AG

BC400

4

3.5

Structure of the R/3 Repository

Repository Objects FI

HR

MM

SD

WM MM

MM M

M

Cust.

Development Classes Function Modules Programs Tables ... 

   

SAP AG 2001

The R/3 Repository is subdivided according to application components. Each application component is further divided into logical subdivisions called development classes. Repository objects are often made up of sub-objects that are themselves Repository objects. When you create a Repository object, you must assign it to a development class.

(C) SAP AG

BC400

5

3.6

SAP Application Hierarchy SAP

+ + +

+ + +

CA AC FI

Cross-Application Components Accounting - General Financial Accounting ... FBAS Financial Accounting Basis ...  + FI-GL General Ledger Acctg  + FI-LC Consolidation ... TR Treasury CO Controlling ...

Application component

Information System

Development class Selected subtree



SAP AG 2001

The structure of the application components is shown in the application hierarchy. From the SAP Easy Access menu, you access the application hierarchy by choosing Tools  ABAP Workbench  Overview  Application Hierarchy.  The application components are displayed in a tree structure in the application hierarchy. Expanding a component displays all the development classes that are assigned to that component.  You can select a subtree or branch and navigate from the application hierarchy to the R/3 Repository Information System. The system then collects all development classes for the branch selected and passes them to the Repository Information System. 

(C) SAP AG

BC400

6

3.7

R/3 Repository Information System Repository Information System Business engineering ABAP Dictionary Basic objects Database tables Views Data elements Structures Table types ... Other objects Fields Programming Function Builder Program Library Prog. environment Program sub-objects ABAP objects Class library Components of classes Components of interfaces Environment 

SAP AG 2001

You can use the Repository Information System to search for specific Repository objects. Suitable search criteria are available for the various Repository objects.  Which objects are to be found using the Repository Information System depends on how you get there:  From within the application hierachy, select the Information system (double-click the selected application component or development class). This filters the the respective Repository objects.  From the SAP Easy Access menu, choose Tools ABAP Workbench  Overview  Information system. The system lists all the Repository Objects available for searching. 

(C) SAP AG

BC400

7

3.8

Working With the Object Navigator

Introduction Introduction to to the the R/3 R/3 Repository Repository Working Working with with the the Object Object Navigator Navigator Organizing Organizing Developments Developments Developing Developing ABAP ABAP Programs Programs



SAP AG 2001

(C) SAP AG

BC400

8

3.9

ABAP Workbench Tools

Debugger

Screen Painter Menu Painter FI

HR

SD

MM WM

Object Navigator

MM Cust.

ABAP Editor

ABAP Dictionary Function Builder Class Builder





      

SAP AG 2001

The ABAP Workbench contains different tools for editing Repository objects. These tools can be used throughout the entire software development cycle. The most important tools for creating and editing Repository objects are as follows: The ABAP Editor for editing source text The ABAP Dictionary for processing database table definitions, central data types, and more The Screen Painter for configuring screens (screens with functions for user dialogs) Menu Painter for designing the user interface (menu bar, standard toolbar, application toolbar) (see Interfaces) The Function Builder for processing function modules The Class Builder for processing central classes You can start these tools in three ways:  Directly from the Easy Access menu.  Using the Object Navigator. This has a tree diagram of all objects within a development class or program. Double-click on an object to start the respective tool.  By double-clicking from one tool to the next, and back again.

(C) SAP AG

BC400

9

3.10

Screen Structure in the Object Navigator Full screen on/off

Tool area

Navigation area Right-click

Right-click

Context menu

Context menu

Size of display area can be changed



SAP AG 2001

The Object Navigator screen is divided into two areas:  A navigation area for displaying an object list as a hierarchy tree  A tool area for displaying and editing a development object using the correct tool  You can display or hide the hierarchy area.  You can select functions from a context menu in both screen areas. You are given a choice of only those functions that are provided for displaying or editing the object to which you are pointing. Right-click on the object to open the context menu. 

(C) SAP AG

BC400

10

3.11

Working with the Navigation Area Application Hierarchy Development Class Program Function Group Class / Interface Internet Service Local Objects

Development Class BC400

Display higher-level object list

Use of navigation history

Refresh object list

BC400

Favorites

Dictionary objects Programs SAPBC400WBD_GETTING_STA SAPBC400WBT_GETTING_STA Function groups BC400 Classes CL_BC400 



    

Double-click on a Repository object with subobjects: List of subobjects

SAP AG 2001

The Repository objects are organized in a hierarchy:  An application component can have different development classes.  A development class can contain different Repository objects: programs, function groups, ABAP Dictionary objects, and so on.  Each Repository object can have different subobjects assigned to it: Subobjects belonging to a program: global data, types, events, subprograms, and so on Subobjects belonging to a function group: global data, function modules, and so on You can enter the type of object list and the object name in the upper part of the navigation area. The object list is then displayed in the navigation area. To display the subobjects, double-click an object within the object list. If an object is not in an object list, you can display it by using the respective tool in the tool area. You can navigate between object lists either by either history or hierarchy. You can add object lists that you edit frequently to your favorites.

(C) SAP AG

BC400

11

3.12

Navigation in the Tool Area

Functions of the current tool

Show navigation window

Use of navigation history

Navigation stack



Hide navigation window

SAP AG 2001

In the tool area, you can display a window showing your navigation history, that is, a list of the objects you have displayed since you started the Object Navigator in the tool area.  The object currently displayed in the tool area is highlighted in a different color. 

(C) SAP AG

BC400

12

3.13

Synchronization of Navigation and Tool Areas

Display object list

Double-click on a Repository object without subobjects or choose context menu: Display/change in tool area Display Change ...



SAP AG 2001

Navigation in the navigation area is logically independent from navigation in the tool area. This allows for screens to be used in a flexible manner.  If you wish, you can synchronize the two areas:  You can display an object in the tool area by double-clicking it, or by selecting the context menu from within the navigation area. The system automatically selects the appropriate tool for processing the object you selected.  To display the object list that belongs to an object you are currently processing in the tool area, choose Display object list.  To create objects from an object list, you can use the context menu for that object type. If there is no entry in the object list for the required object type, you can create any number of objects using Edit object or Other object. 

(C) SAP AG

BC400

13

3.14

Organizing Developments

Introduction Introduction to to the the R/3 R/3 Repository Repository Working Working with with the the Object Object Navigator Navigator Organizing Organizing Developments Developments Developing Developing ABAP ABAP Programs Programs



SAP AG 2001

(C) SAP AG

BC400

14

3.15

Transporting Repository Objects

Change Request

FI

HR

MM FI

SD

HR

MM

WM MM

SD Cust.

WM MM Cust.

Development System 

Production System

SAP AG 2001

Development projects are always implemented in a development system and then transported to the next system.  Repository objects are automatically assigned to a transport route based on their belonging to a particular development class and on their actual function.  A decisive criterion for combining the development projects is, therefore, which Repository objects need to be transported together because of their dependencies.  You schedule the group transport of the Repository objects using a change request. 

(C) SAP AG

BC400

15

3.16

Scheduling a Development Project Schedule:

Monday

...

Friday

Locking Objects for Non-Project Non-Project Members Project Manager:

Request is released

FRY Team: FRY BC400-00 BC400-01 BC400-02 BC400-03 ...



SAP AG 2001

Scheduling a development project using a change request covers the following aspects: All employees in the project start their work on a defined date. Employees have the chance to follow up and check their activities separately. The respective Repository objects can be processed by all employees involved in the project. For those developers who do not belong to the team, the Repository objects remain locked until the project is completed.  The group triggers the transport of all the respective Repository objects.    

(C) SAP AG

BC400

16

3.17

Project Representation in the Workbench Organizer Project Manager: FRY Team:

Workbench Organizer: Change Requests Change requests involving user BC400-00

FRY BC400-00 BC400-01 BC400-02 BC400-03

Changeable

Request number

Transportable

Project Manager User

IT3K900051 CARSON

Task number

IT3K900052 CARSON IT3K900053 BC400-00

Repository objects created or corrected by employee

Report source ZBC400_00_FLIGHTLIST ABAP program IT3K900054 BC400-01

...

IT3K900055 BC400-02 IT3K900056 BC400-03 IT3K900057



...

SAP AG 2001

At the beginning of a development project, the project manager creates a change request in the Workbench Organizer. The project manager assigns all project team members to the change request. The Workbench Organizer then creates a task for each project developer.  From now on, whenever an employee assigns a Repository object to this change request, the Repository object is automatically entered in the employee's task. Thus all Repository objects that an employee works on during a development project are collected within his or her task folder. The Repository objects are therefore locked for all developers who do not belong to this particular project.  Unlike the logical functional divisions that separate Repository objects through the respective development class, change requests are project-related and, therefore, are limited to the time schedule involved. Thus, although a program always belongs to only one development class, it can belong to different change requests at different times. 

(C) SAP AG

BC400

17

3.18

Example: Creating Development Classes

Comply with customer namespace

Create Development Class Development Class

ZBC400_00

Short Text

Exercises group 00 Where should the development objects be transported to?

Transport Layer

ZDEV

Person Responsible

BC400-00

Software Component

HOME CA

Application Component

To which application component does the development class belong?





SAP AG 2001

You can create a development class in the Object Navigator.  As of Release 4.6C, you can choose the object type Development Class and enter the name of the development class in the input field. Make sure you comply with the customer namespace conventions. If the development class does not already exist, the system displays the Create Development Class dialog box.  For Release 4.6A and 4.6B, you must choose Edit object or Other object in the initial screen. Enter the name of the development class in the input field on Other tab page.



You should check the settings for the following attributes:  Transport layer - If you carry out your own developments, you must set up a transport layer for customer developments.  Person responsible - This person has full responsibility for the objects in this development class. The system automatically uses this user name as a default value.  Software component - For customer developments you should enter HOME as the software component. To get detailed information on the field, select F1 help.  Application component - Used to specify the location of the development class within the application hierarchy.

(C) SAP AG

BC400

18

3.19

Assignment to a Change Request Prompt for transportable Workbench request Development class/p..

ZBC400_00

Request

IT3K90051

Workbench request

Exercises for participants of BC400

My requests

Prompt for transportable Workbench request Change requests involving user BC400-00

Double-click request number

Changeable Transportable IT3K900051 FRY IT3K900052 FRY IT3K900053 BC400-00 IT3K900054 BC400-01



SAP AG 2001

All Repository objects that are created or changed must be assigned to the change request of the respective project. For this course, the trainer has created a change request for the project called "Exercises for Participants of BC400". Each group has a task within this change request.  To display all change requests in which you have a task, select Own requests.  When you assign all Repository objects (development classes, programs, and so on) to this change request, the system takes care of the exact assignment for your task. 

(C) SAP AG

BC400

19

3.20

Developing ABAP Programs

Introduction Introduction to to the the R/3 R/3 Repository Repository Working Working with with the the Object Object Navigator Navigator Organizing Organizing Developments Developments Developing Developing ABAP ABAP Programs Programs



SAP AG 2001

(C) SAP AG

BC400

20

3.21

Features of the ABAP Programming Language

The ABAP programming language ...  Has defined types  Enables multi-language applications  Has SQL embedded within it  Has been enhanced as an object-oriented language  Is platform-independent  Is downwards compatible

Therefore, it is designed for dialog-based, business applications.



     

SAP AG 2001

To support data processing by types, ABAP contains a systematic type hierarchy. Type conversions and type casting are supported. Using translatable text elements, you can develop multi-language applications. The OPEN SQL standard embedded in ABAP allows direct database accesses. ABAP Objects is the object-oriented enhancement of the ABAP programming language. The ABAP runtime system is one of the R/3 Basis components and is platform-independent. ABAP continues to evolve from release to release. If an old syntax statement is replaced by a better one, you can still run the old statement.

(C) SAP AG

BC400

21

3.22

General ABAP Syntax I

ABAP keyword

Additions and operands (dependent on keywords)

Period as symbol for closing the ABAP statement

DATA DATA wa_scarr TYPE scarr.. START-OF-SELECTION. START-OF-SELECTION. SELECT * FROM scarr INTO CORRESPONDING FIELDS OF wa_scarr.. NEW-LINE. WRITE wa_scarr-carrid.. WRITE wa_scarr-carrname.. WRITE wa_scarr-url.. ENDSELECT. ENDSELECT.



SAP AG 2001

ABAP programs consist up of individual statements. Each statement ends with a period. The first word in a statement is called a keyword. Words must always be separated by at least one space. Statements can be indented. Statements can take up more than one line. A single line can contain multiple statements.  The ABAP runtime system is not case sensitive; that is, it does not distinguish between lowercase and uppercase letters for keywords, additions, and operands. To make it easier to separate them visually, in this course all keywords and their additions are in uppercase and all operands are in lowercase.       



For indentations and for converting uppercase and lowercase letters, use the Pretty Painter function. Choose Utilities Settings  ABAP Editor  Pretty Printer

(C) SAP AG

BC400

22

3.23

General ABAP Syntax II

** comments ... ** comments ... ** comments ...

Comments

DATA wa_scarr TYPE scarr. START-OF-SELECTION. " comments ... SELECT * FROM scarr INTO CORRESPONDING FIELDS OF wa_scarr. NEW-LINE. WRITE : wa_scarr-carrid, , wa_scarr-carrname, , wa_scarr-url. .

Chained Statement

ENDSELECT.



SAP AG 2001

Use an asterisk (*) to introduce comment lines. The ABAP runtime system ignores the comment line.  If you want to enter a comment in the middle of a started line, enter double quotes.You can combine consecutive statements with an identical beginning into a single chained statement:  Close the identical beginning part with a colon.  Separate individual elements that come after the colon by commas.  Use blank spaces and line breaks before and after the separators (colons, commas, and periods).  The ABAP runtime system considers the individual parts of a chained statement to be single statements. 

(C) SAP AG

BC400

23

3.24

Return Value After ABAP Statements

PARAMETERS pa_carr TYPE scarr-carrid. DATA wa_scarr TYPE scarr. START-OF-SELECTION. SELECT SINGLE * FROM scarr INTO CORRESPONDING FIELDS OF wa_scarr WHERE carrid = pa_carr. syIF sy-subrc sy-subrc EQ 0. NEW-LINE. WRITE: wa_scarr-carrid, wa_scarr-carrname, wa_scarr-url. ELSE. WRITE 'Sorry, no data found!'. ENDIF.



SAP AG 2001

With several ABAP statements, the ABAP runtime system writes a return code into the system field sy-subrc to indicate how successfully the statement was executed  The return code zero (0) means that the statement was successful..  Read the documentation for the respective statements to find out whether and how this return code is set in individual cases. 

(C) SAP AG

BC400

24

3.25

Creating an ABAP Program Create Program Program

ZBC400_00_GS

With TOP Include

Comply with customer namespace! ABAP: Program Attributes ... Title

...

Attributes Type

Executable program

Status Application

Test program Fixed point arithmetic



SAP AG 2001

From the Object Navigator, you can create a program using one of the following options:  In the navigation area, choose Program as the object type and enter a program name. Be sure to comply with the customer namespace conventions. If the program does not exist, the system displays the dialog sequence that lets you create a program. (This procedure is possible only as of Release 4.6C.)  Display the development class for which you want to create the program. Start the dialog sequence for creating a program using the development class context menu or the Program node.  Select Other object... or Edit object. Select the Program objects tab and enter the name. Select Create.  In this course, deselect With Top Include (by removing the check mark from the checkbox). (If you don’t do this, your source text would be distributed to several programs.)  Change the title to a meaningful short text.  Choose Test program as the program status for all ABAP courses. 

(C) SAP AG

BC400

25

3.26

Keyword Documentation in the ABAP Editor

i Help START-OF-SELECTION. SELECT SINGLE * FROM scarr Editor Help INTO wa_scarr ABAP Overview WHERE carrid = pa_car. WRITE ABAP Term IF sy-subrc = 0. ABAP News MOVE-CORRESPONDING wa_scarr ABAP Docu and Examples TO sbc400_carrier. Keyword CALL SCREEN 100. Documentation MOVE-CORRESPONDING sbc400_carrier WRITE WRITE:

F1 TO wa_scarr. wa_scarr-carrid, wa_scarr-carrname, wa_scarr-currcode.

ENDIF. 

SAP AG 2001

 You can locate keyword documentation for an ABAP statement by:  Pointing to a statement and selecting F1 to go directly to the documentation for the statement  Selecting Information to go to a selection window for the various views of the keyword documentation.  Choose Help  SAP Library  BC Basis Components to access extensive online documentation on all the tools and topics that relate to the ABAP Workbench.

(C) SAP AG

BC400

26

3.27

Inactive and Active Development Objects Saved, for development and testing Activate Program 1, inactive version

Actively integrated, for system-wide usage Program 1, active version Program 2, active version

Program 3, inactive version



Program 3, active version

SAP AG 2001

Whenever you create a development object, or change and then save it, the system stores an inactive version only in the R/3 Repository.  Before a Repository object is available on a system-wide basis, it must first be available as an active version. This active version of your program will be used whenever a user wants to execute your program.  If your program is available in both versions, you can switch from one version to the other in display mode.  Whenever you activate a program, the system first displays a list of all inactive objects that you have processed. This is called the worklist. If you continue to activate the program, the following happens:  The system saves the program, that is, it stores or overwrites the inactive version.  The system performs a syntax check.  The system stores the active version or overwrites it. 

(C) SAP AG

BC400

27

3.28

Generating Runtime Objects

saved,

actively integrated,

for development/testing

for system-wide usage Program 1, active version Program 2, active version

Program 3, inactive version

Program 3, active version Generate (automatically)

Generate (automatically)

For system-wide usage Program 3, temporary generated version 



Program 3, generated version

SAP AG 2001

When you generate a development object, the system creates (compiles) a separate runtime object (LOAD) and stores it in the R/3 Repository.

This generated version is then the version that is executed (interpreted). Generation takes place automatically, but it can be triggered explicitly. If, for example, a user wants to execute your program and there is still no generated version, the system will use the active version for generation.  You can, however, determine which version you want to execute:  To execute the active version, start your program from the navigation area.  To execute the inactive version, test an executable program from the ABAP Editor. The system temporarily creates a generated version.  In this way, development can continue without changing the current system status. All changes to the development object become visible system wide only when the program is activated again. With inactive versions, you have a local, separate view of the R/3 Repository, which provides the basis for a local runtime system.   

(C) SAP AG

BC400

28

3.29

Creating Transaction Codes System

Help

Create Report Transaction ZBC400_00_GS

Transaction code Development class

Z00GS ZBC400_00

Transaction text

...

Program

ZBC400_00_GS

... Classification Professional User Transaction Easy Web transaction ... ...



     

SAP AG 2001

If you want to include a program in role menus or in the Favorites in your SAP Easy Access menu, you must assign a transaction code to it. In the Object Navigator, display the object list for your program. Right-click the program name and choose Create  Transaction. Comply with the customer namespace conventions. Choose Program and Selection Screen (Report Transaction) if the program is an executable program. On the next screen, enter the name of the program. Choose Professional User Transaction. Save the transaction code. Since each transaction code is a Repository object, you must assign it to a development class and to a change request on the following screens.

(C) SAP AG

BC400

29

3.30

Adding a Transaction Code to the SAP Easy Access Menu System

Help

SAP Easy Access Favorites Object Navigator SAP Menu Add transaction

Enter Transaction Manually Transaction code



Z00GS

SAP AG 2001

To include a transaction code in the your role menu favorites:  Display the initial screen (SAP Easy Access menu).  Choose Favorites  Insert transaction.  Enter a transaction code in the dialog box .  The transaction code short text appears under the Favorites node. You can start the appropriate program from the context menu for this new node. 

(C) SAP AG

BC400

30

3.31

Introduction to the ABAP Workbench: Unit Summary

You are now able to:  Describe the structure of the R/3 Repository and its search tools  Use the Object Navigator for your development work  Name and use the utilities for orderly software development  Create development classes, ABAP programs, and transaction codes



SAP AG 2001

(C) SAP AG

BC400

31

3.32ABAP Workbench Exercises

Unit: Introduction to the ABAP Workbench Topic:

Organizing Developments

At the conclusion of these exercises, you will be able to:  Create a development class  Assign changes in Repository objects to a change request As a developer for an airline group, you are given the task of developing evaluation programs for several airline companies. To group the Repository objects together logically and transport them, you must create a development class. User name:

Will be announced by the instructor.

Development class:

ZBC400_##

Change request:

Will be announced by the instructor.

## stands for the two-digit group number. 1-1

Log on to the operating system and then to the specified SAP R/3 training system using the user name the instructor has given you. Enter a new personal password.

1-2

Create the development class ZBC400_##. Assign it to the change request the instructor has given you.

1-3

From now on, assign all your Repository objects in the following exercises to this development class and this change request.

(C) SAP AG

BC400

32

Exercises Unit: Introduction to the ABAP Workbench Topic:

Developing ABAP Programs

At the conclusion of these exercises, you will be able to:  Create, edit, save, and process ABAP programs  Check ABAP programs for correct syntax  Test and activate ABAP programs Create an ABAP program that lists additional information on all existing flight departure times. Get the data from the database table SFLIGHT. Program:

ZBC400_##_GS_LIST

Model solution:

SAPBC400WBS_GS_LIST

## stands for the two-digit group number. 2-1

Create the executable program ZBC400_##_GS_LIST without TOP Include.

2-2

Define a work area for the data retrieval and data display (name suggestion: wa_flight): DATA wa_flight TYPE sflight.

2-3

Program a loop access to all the data records in the database table SFLIGHT: SELECT * FROM sflight INTO wa_flight. ... ENDSELECT.

2-4

For each data record, display the contents of the fields carrid, connid, fldate, seatsocc, and seatsmax in the list: NEW-LINE. WRITE wa_flight-carrid. WRITE ...

2-5

Check your program for syntax errors, test it, and activate it

(C) SAP AG

BC400

33

Exeercises Unit: Introduction to the ABAP Workbench Topic:

Transaction Codes

At the conclusion of these exercises, you will be able to:  Assign transaction codes to ABAP programs  Add transaction codes to your Favorites list in the SAP Easy Access menu Give your first ABAP program a transaction code, in addition to its technical name, which you use to execute it.

Transaction code:

ZBC400_##_GS

Program:

ZBC400_##_GS_LIST

Model solution:

SAPBC400WBS_GS LIST

## stands for the two-digit group number. 3-1

Create transaction code ZBC400_##_GS for the executable program ZBC400_##_GS_LIST. Initial object: program and selection screen (report transaction) Execute your program by entering the new transaction code.

3-2

Include the transaction code ZBC400_##_GS in your favorites in the SAP-EasyAccess-menu. Execute your program by double-clicking the new favorite entry. From now on, it is best if you always work with the Object Navigator. It provides you with an overview of all Repository objects in your development class. From here, you can edit each object directly by selecting it from this list.

(C) SAP AG

BC400

34

3.33ABAP Workbench Solutions

Unit: Introduction to the ABAP Workbench Topic:

1

Organizing Developments

Follow the instructions as given in the notes and figures on page 3-18 and 3-19, Creating Development Classes and Assignment to a Change Request.

Unit: Introduction to the ABAP Workbench Topic:

2

Developing ABAP Programs

Model solution:

REPORT sapbc400wbs_gs_list. DATA wa_flight TYPE sflight. SELECT * FROM sflight INTO wa_flight. NEW-LINE. WRITE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax. ENDSELECT.

Unit: Introduction to the ABAP Workbench Topic:

Transaction Codes

3-1

Follow the instructions as given in the notes and figure on page 3-29, Creating Transaction Codes.

3-2

Follow the instructions as given in the notes to the figure, Adding a Transaction Code to the SAP Easy Access Menu.

(C) SAP AG

BC400

35

4 Introduction to the ABAP Dictionary

Contents:  SAP Flight Data Model  Transparent Tables  Structures  Using Transparent Tables and Structures in an ABAP Program



SAP AG 2001

(C) SAP AG

BC400

1

4.2

Introduction to the ABAP Dictionary: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe the SAP flight data model  Describe the structure of a transparent table  Describe the structure of a structure  List the possible uses of transparent tables and structures in ABAP programs



SAP AG 2001

(C) SAP AG

BC400

2

4.3

Data Modeling

Real world

Data model

ABAP Dictionary

Relational database 

SAP AG 2001

 In the development of business application software, the real world must be partly mapped in the form of data. An entity represents a business unit.  Entities all relate to each other. The entities and relationships are contained in the data model or entity relationship model (ERM).  The conversion of the table definitions and their relationships in the ABAP Dictionary are based on this data model.  The actual application data is physically stored in the database itself.

(C) SAP AG

BC400

3

4.4

Flight Data Model for ABAP Training Courses

Departure city

Departure airport

Typical inquiries at the travel agency:  Suitable airports  Suitable flight connections  Suitable flight times  Additional flight information such as: price, availability



Destination airport

Destination city

SAP AG 2001

 ABAP training courses, online documentation, and ABAP keyword documentation all use the same flight data model. All Repository objects in the flight data model are located in the development class BC_DATAMODEL.  This training course demonstrates one simple excerpt from this data model, which the instructor can refine if necessary. If a person wants to travel from one place to another, she asks the travel agency the following questions: 

What connection offers me the best and most direct flight?



At what times are flights offered on the date when I want to travel?

 How can I optimize the travel conditions to find the best solution? What is the cheapest flight, the fastest connection, the connection that gets me there closest to the time when I want to arrive?  The passenger’s view differs from that of a travel agency. In the data model, which is tailored to suit management of the necessary data, all data is stored, organized by technical criteria, in tables on a central database. The amount of data stored far exceeds the demands of the passenger.  As a programmer, you must be able to compile the data in programs to suit the requirements of the travel agent.

(C) SAP AG

BC400

4

4.5

Relational Data Model BC_CARRIER T

BC_AIRPORT

Airline

Airport

T

City

H BC_PLANFLI

BC_GEOCITY T

A T

R R

A

BC_CITAIRP

T

City-airport assignment

Timetable H BC_SFLIGHT

T

Flight

BC_CUSTOM T

BC_COUNTER T

BC_TRAVLAG T

Customer

Sales office

Travel agency

H BC_BOOKING T

R

CR

CR

Flight booking



SAP AG 2001

The flight data model contains entities for all business information that is logically connected, such as:  Cities  Airports  Airlines  Flights  These entities all relate to each other in certain ways:  Each flight schedule contains exactly one airline, one departure airport, and one destination airport.  Bookable flights always belong to exactly one existing flight schedule each.  You can assign cities to nearby airports.  You can manage all necessary data without redundancies, using these relationships. At the same time, the travel agency is able to obtain all data requested by the customer. 

(C) SAP AG

BC400

5

4.6

Converting Using Transparent Tables BC_CARRIER T

Airline

SCARR MANDT

CARRID

CARRNAME

CURRCODE

URL

H BC_PLANFLI

T

Timetable

SPFLI MANDT

CARRID CONNID AIRPFROM

AIRPTO DEPTIME

...

H BC_SFLIGHT

T

Flight

SFLIGHT MANDT

CARRID CONNID FLDATE

SEATSMAX

SEATSOCC

...

H BC_BOOKING T

Flight booking



    

SBOOK MANDT

CARRID CONNID FLDATE BOOKID CUSTOMID

COUNTER

...

SAP AG 2001

A transparent table contains different columns, to allow you to manage data records in a structured way. You define transparent tables in the ABAP Dictionary. In this context, the table key is especially significant. The table key of a table combines key fields, which are also called primary key fields. The values in the key fields allow the system to identify all data records uniquely. Fields that link to other tables are called foreign key fields. With these foreign key relationships you can manage the data hierarchically and consistently.

(C) SAP AG

BC400

6

4.7

Technical Structure of a Transparent Table Transparent table Field uses Data element uses Domain

Table including data 

SAP AG 2001

You normally use a data element to assign a type to a table field. Semantic properties, such as field labels, are stored in the data element. You normally use a domain for the technical properties. The data type, among other things, is stored in the domain.  The ABAP Dictionary contains the platform-independent description of the relevant database table.  The database table has the same name as the transparent table in the ABAP Dictionary. The fields also have the same names in both the database and the ABAP Dictionary.   

(C) SAP AG

BC400

7

4.8

Transparent Tables in the ABAP Dictionary

Table

Edit

Goto

Utilities

Extras

Environment

System

Help

Dictionary: Display Table Indexes Transparent table

SPFLI

Short text

Flight schedule

Attributes Fields MANDT CARRID CONNID COUNTRYFR CITYFROM AIRPFROM COUNTRYTO CITYTO ... 

Fields Key   

Field type S_MANDT S_CARR_ID S_CONN_ID LAND_1 S_FROM_CIT S_FROMAIRP LAND_1 S_TO_CITY ...

Active

Currency/Quantity Fields Data type CLNT CHAR NUMC CHAR CHAR CHAR CHAR CHAR ...

Length 3 3 4 3 20 3 3 20 ...

Dec. places 0 0 0 0 0 0 0 0 ...

Short text Client for training Airline Carrier Flight connection Country key City of departure Airport of departure Country key Arrival city ...

SAP AG 2001

 The fields make up the columns of the transparent table. A check mark in the Key column indicates that the corresponding field is a key field.  You normally assign a type to a field using a data element (under Field type). The Short text stored with the data element is listed here. The technical attributes of the field are listed again under Data type, Length, and Dec. places. (A data element normally uses a domain.)  This is a logical view of the table. It is a purely technical description. When it is physically converted, the table is in the database, where you also find the table content or the actual application data.

(C) SAP AG

BC400

8

4.9

Structures in the ABAP Dictionary

Structure Edit Goto Utilities Extras Environment System Help

Dictionary: Display Structure

Structure

SBC400FOCC

Short text

Percentage Occupancy of Flights

Attributes Component CARRID CONNID FLDATE SEATSMAX SEATSOCC PERCENTAGE



Components

Active

Entry help/check

Component type S_CARR_ID S_CONN_ID S_DATE S_SEATSMAX S_SEATSMAX S_FLGHTOCC

DTyp CHAR NUMC DATS INT4 INT4 DEC

Length 3 4 8 10 10 5

Currency/quantity fields Dec. places 0 0 0 0 0 2

Short text Airline Flight connection Flight date Maximum capacity Occupied seats Flight Occupancy

SAP AG 2001

A flat structure is defined in almost the same way as a transparent table, except that you cannot convert fields to key fields. This would be pointless for structures. Structures do not represent a database table in the ABAP Dictionary, but are a pure type definition instead.  When defining a flat structure, however, we refer to component and component type as opposed to field and field type, because, in contrast to transparent tables, you can define complex structures. This means that, it is possible to store a structure or substructure under a component name. 

(C) SAP AG

BC400

9

4.10

Using Global Structures for Data Objects

DATA wa_focc TYPE sbc400focc sbc400focc. TABLES spfli spfli. PARAMETERS pa_carr TYPE spfli-carrid spfli-carrid.

carrid connid fldate wa_focc L H

400 20011231

seatsmax 450

mandt carrid connid countryfr cityfrom spfli 4 0 0 A A

64 US

seatsocc

New York

percentage

180

40

airpfrom countryto ... JFK

US

...

pa_carr L H



  

  

SAP AG 2001

A structure is used to centrally provide a data type in which fields from different tables are compiled. In the ABAP program, you can define data objects using the (Dictionary) structure. A transparent table merely represents a technical description in the ABAP Dictionary. Therefore you can use it as a central data type definition, as with a structure. This means that, similarly to the data object definitions listed above, the following variants are also possible: DATA wa_spfli TYPE spfli provides a data object, typed like the line in the transparent table SPFLI. TABLES sbc400focc provides a data object, typed like the structure SBC400FOCC. PARAMETERS pa_carr TYPE sbc400focc-carrid provides an input field, typed like the CARRID component of the structure SBC400FOCC.

(C) SAP AG

BC400

10

4.11

Using Global Structures for Dialogs TABLES spfli. Screen Painter PARAMETERS pa_carr TYPE spfli-carrid.

Dict/Program fields

Airline F1

Performance Assistant

Short description ...

Short description of the airline The field contains the ID of the airline.

Documentation 

ID AA AB AC AF

Airline American Airlines Air Berlin Air Canada Air France

Input help

SAP AG 2001

 If you use an elementary structure to define an input field on a selection screen, you can use semantic attributes or technical attributes. On request, the system automatically generates a documentation dialog and an input help dialog for the user. The necessary information for this is taken from the ABAP Dictionary.  The same applies to fields of transparent tables.  If you use an elementary structure component to assign a type to an input/output field on a screen, you can use the same attributes as with selection screens.  If you have defined a foreign key relationship, the resulting value combinations appear in the input help on the screen. If an error occurs, the system processes an automatic error dialog.  The same applies to fields of transparent tables.  Use the TABLES statement to define the data object for the data transport between screen and program.

(C) SAP AG

BC400

11

4.12

Introduction to the ABAP Dictionary: Unit Summary

You are now able to:  Describe the SAP flight data model  Describe the structure of a transparent table  Describe the structure of a structure  List the possible uses of transparent tables and structures in ABAP programs



SAP AG 2001

(C) SAP AG

BC400

12

4.13ABAP Dictionary Exercises

Unit: Introduction to the ABAP Dictionary Topic: Using Global Structures for Data Objects and Dialogs At the conclusion of these exercises, you will be able to:  Establish the technical names of data types and data objects that are used in user dialogs.  Run where-used lists within an ABAP program. You have to examine a specified ABAP program to see whether global data types are used in it, and if so, which ones.

Program:

SAPBC400WBT_GETTING_STARTED

1-1

Open the object list for development class BC400. Find the program SAPBC400WBT_GETTING_STARTED, and open its object list. Throughout the exercise, make sure that you remain in display mode.

1-2

Run the program to find out how it works.

1-3

There is an input field on the selection screen. 1-3-1 What information must you pass to the program? (Use for field help.) 1-3-2 What values can you enter? (Use for input help.) 1-3-3 What information does the program provide? 1-3-4 What is the technical name of the input field? (Use the Technical information in field help.)

(C) SAP AG

BC400

13

1-4

Two display fields appear on the screen. 1-4-1 Find out the screen number. (Choose System  Status.) 1-4-2 What information is displayed? (Use field help.) 1-4-3 What are the technical names of the display fields? Do the fields belong to a structure with a globally defined type? (Use the Technical information in field help.)

1-5

Use the object list to analyze the source code of the program. 1-5-1 What data objects are there? Where are they defined in the program? 1-5-2 Where in the program are they used? (Use the where-used list in the ABAP Editor.) 1-5-3 What data object corresponds to the input field on the selection screen? (Search the object list for a data object with the same name as the field that you found in step 1-3-4.)

(C) SAP AG

BC400

14

4.14ABAP Dictionary Solutions

Unit: Introduction to the ABAP Dictionary Topic: Using Global Structures for Data Objects and Dialogs 1-3

Analyzing by executing a program: 1-3-1 You need to enter an airline code. 1-3-2 The values permitted here depend on the contents of database table SCARR. 1-3-3 The program displays detailed information on the airline selected. This information is first displayed on a screen and then as a list. 1-3-4 The technical name of the input field is pa_car.

1-4

Analyzing by executing a program: 1-4-1 The screen number is 100. 1-4-2 The system again displays the airline code and the currency code. 1-4-3 The output fields are sbc400_carrier-carrid and sbc400_carrier-currcode. Double-click in the Structure field to go to the ABAP Dictionary and analyze the global type more closely.

1-5

Analyzing using the program's object list: 1-5-1 The program has the structures sbc400_carrier and wa_scarr and the elementary data object pa_car. 1-5-2 The elementary data object pa_car belongs to the input field, with the same name, on the selection screen.

(C) SAP AG

BC400

15

5 Basic ABAP Language Elements

Contents:  Data Types and Data Objects  Basic ABAP Statements  Using the ABAP Debugger  Working with Structures  Working with Internal Tables



SAP AG 2001

(C) SAP AG

BC400

1

5.2

Basic ABAP Language Elements: Unit Objectives

At the conclusion of this unit, you will be able to:  Define elementary and structured data objects  Use basic ABAP statements  Execute and analyze programs in debugging mode



SAP AG 2001

(C) SAP AG

BC400

2

5.3

Data Types and Data Objects

Data Data Types Types and and Data Data Objects Objects Basic Basic ABAP ABAP Statements Statements Using Using the the ABAP ABAP Debugger Debugger Working Working with with Structures Structures Working Working with with Internal Internal Tables Tables



SAP AG 2001

(C) SAP AG

BC400

3

5.4

Using Data Types Data types describe the attributes of:

ABAP program

… Input / output fields

… Data objects Object

Interface Subroutine

Interface Method

… ... Interface parameters 

SAP AG 2001

The type of a data object defines its technical attributes. The type of an interface parameter defines the type of the values (actual parameters) that are transferred when the modularization unit is called.  In addition to the technical attributes, the type of an input or output field can provide further information; for example, you can use it to control the value or input help.  

(C) SAP AG

BC400

4

5.5

Local and Global Data Types Local data types: Technical attributes only

Central data types: Technical and semantic attributes ABAP Dictionary

ABAP program

Object

Interface Subroutine



     

Interface Method

SAP AG 2001

You can define data types in an ABAP program (local, keyword TYPES) or in the ABAP Dictionary (global). Using global data types has several advantages: Global types are managed centrally and you can use them in all repository objects. This increases the consistency of the system and significantly reduces the amount of maintenance. In the ABAP Dictionary, you can perform an environment analysis (where-used list). Global data types can be linked to business variables by content, and therefore contain semantic and technical information. You can use global datat types to design screens. When searching for global data types, make sure you take both the technical and semantic attributes into account. Only then will you be able to make full use of the maintenance and robustness advantages of your program.

(C) SAP AG

BC400

5

5.6

Defining Data Objects

Local types TYPES type_name TYPE ...

Predefined ABAP types d t i f string xstring

DATA do_name TYPE type_name.

p n c x

Global types

DATA do_name_new LIKE do_name. 

SAP AG 2001

You can use a predefined ABAP type, a local, or a global type to type a data object. The following predefined ABAP types are complete:  d Date (format: YYYYMMDD)  t Time (format: HHMMSS)  i Integer  f Floating point number  string String (of variable length)  xstring Byte sequence (heXadecimal string, of variable length)  You must define the length for these predefined types:  c Character  n Numeric character  x Byte (heXadecimal)  p Packed number (= binary coded decimals). You must enter the number of decimal places.  For more information on predefined ABAP types, refer to the keyword documentation on TYPES or DATA.  You can use LIKE to refer to the type of a predefined data object.  

(C) SAP AG

BC400

6

5.7

Defining Elementary Data Objects

TYPES t_percentage(3) TYPE p DECIMALS 2. DATA: number percentage carrid connid

TYPE TYPE TYPE TYPE

i VALUE 17, t_percentage, s_carr_id, sbc400focc-connid.

S_CARR_ID

Data element Structure

SBC400FOCC 17

number percentage

+

carrid connid



SAP AG 2001

 The predefined ABAP types (d, t, i, f, string, and xstring) are complete. This means they can define an elementary data object of these types as follows: DATA do_name TYPE predefined_ABAP_type.  For the predefined ABAP types c, n, p, and x, you must define the length. This means you should first define an elementary type: TYPES type_name(length) TYPE predefined_ABAP_type. You use it to define the data object: DATA do_name TYPE type_name. For type p, you can also define the number of decimal places using the DECIMALS addition.  You can use the VALUE addition to pre-assign the value of an elementary data object.  For compatibility reasons, you can still construct data objects in the DATA statement without first having to define the type locally in the program with a TYPES statement.  In the case of incompletely predefined ABAP types, the system adds standard values to make up the missing type information.  If there is no type specification at all, the system defines a type c data object with a length of one.For the standard lengths and for more information, refer to the keyword documentation for TYPES and DATA.  The same syntax applies to global types as to user-defined types: DATA do_name TYPE global_type_name

(C) SAP AG

BC400

7

5.8

Fixed Data Objects Literal: Fixed data object without ID code

Text literal: literal Type c Character string: 'aBcdE' Decimal numbers: '123.45' Floating point numbers: '123.45E01'

Numeric literal: Type i or p Positive integers: 123 Negative integers: -123

Constant:

Fixed data object with ID code

CONSTANTS const_name TYPE type_name VALUE [ literal | IS INITIAL ]. CONSTANTS



SAP AG 2001

 You assign a value to each fixed data object in the source code. Therefore, it cannot be changed at run time.  You can use literals to transfer fixed values to ABAP statements. There are numeric literals and text literals. The latter are always enclosed in inverted commas:  You can display integers as numeric literals (in the case of negative numbers, with a preceding sign). The system then maps them onto the data type i, if they are within the value range of 4-byte integers. Higher numeric literals are mapped onto data type p.  You must display all other literals (such as character sets, numbers with decimal places, floating point numbers) as text literals. They are mapped onto data type c and converted later, if necessary. If you want to include an inverted comma in a text literal, you must enter it twice.  You define constants using the CONSTANTS statement. Their type is defined similarly to the type of an elementary data object with the DATA statement. The VALUE addition is required for constants 

Recommendation: Avoid literals when using statements. Create constants instead. This significantly improves program maintenance.

(C) SAP AG

BC400

8

5.9

Basic ABAP Statements

Data Data Types Types and and Data Data Objects Objects Basic Basic ABAP ABAP Statements Statements Using Using the the ABAP ABAP Debugger Debugger Working Working with with Structures Structures Working Working with with Internal Internal Tables Tables



SAP AG 2001

(C) SAP AG

BC400

9

5.10

Value Assignments Data declarations CONSTANTS c_qf TYPE s_carr_id VALUE 'QF'. DATA: carrid1 TYPE s_carr_id, carrid2 TYPE s_carr_id VALUE 'LH', counter TYPE i. Program start

carrid1

c_qf QF

carrid2

counter

LH

0

MOVE c_qf TO carrid1.

QF

LH

0

carrid2 = carrid1.

QF

QF

0

QF

QF

1

ADD 1 TO counter. CLEAR CLEAR: carrid1, carrid2, counter.

0

ABAP program ABAP runtime system Time 

SAP AG 2001

 When a program is started, the program context is loaded into a storage area of the application server and made available for all the data objects.  Every elementary data object is preassigned the type-related initial value, except if you preassigned a different value using the VALUE addition.  You can use the MOVE statement to copy the contents of data objects. Two statements are available for this purpose: 

MOVE source TO target.



target = source.

 If the two data objects have different types, the type is automatically converted if there is a conversion rule.  For detailed information about copying and the conversion rules, refer to the keyword documentation for the MOVE statement.  The CLEAR statement resets the contents of a data object to the type-related initial value. For detailed information about the initial values for a particular type, refer to the keyword documentation for the CLEAR statement.

(C) SAP AG

BC400

10

5.11

Calculations

Data declarations DATA: max TYPE sbc400focc-seatsmax, occ TYPE sbc400focc-seatsocc, percentage TYPE sbc400focc-percentage.

COMPUTE COMPUTE

percentage = occ * 100 / max.

The keyword is optional:

percentage = occ * 100 / max. ABAP program 

SAP AG 2001

In ABAP you can program arithmetic expressions nested to any depth. Note that parentheses and operators are keywords and must be separated by at least one blank character. The following are valid operators: + Addition Subtraction * Multiplication / Division ** Power DIV Integer division without remainder MOD Integer division with remainder  There are several functions for different data types in the ABAP runtime environment. For example, the following statement returns the current length of the contents of a character set: length = STRLEN( cityfrom ). With functions the opening parenthesis is part of the ID. The rest must again be separated by at least one space.  In general, the usual algebraic rules apply for the processing sequence: expressions in parentheses come first, then powers, then multiplication/division, and finally addition/subtraction.  For detailed information about the available operations and functions, refer to the keyword documentation for COMPUTE.. 

(C) SAP AG

BC400

11

5.12

Conditional Branching

CASE data_object_1. WHEN data_object_2. Statements

WHEN data_object_3 OR OR data_object_4. Statements

WHEN OTHERS OTHERS.

IF IF .

Statements

Statements

ENDCASE ENDCASE.

ELSEIF ELSEIF . Statements

ELSE ELSE. Statements

ENDIF ENDIF.



SAP AG 2001

 In ABAP you have two ways to execute different sequences of statements, depending on certain conditions.  With the CASE-ENDCASE construction the criterion for the execution of a statement block is the similarity of the data objects. If no comparison is successful, then the system executes the OTHERS branch, if it is available. Except for the first WHEN branch, all further additions are optional.  With the IF-ENDIF construction, you can use any logical expressions. If the condition is met, the system executes the relevant statement sequence. If no comparison is successful, then the system executes the OTHERS branch, if it is available. Except for the first query, all further branches are optional.  For both constructions, the system executes only one statement sequence and always for the first valid case.  Recommendation: If, in every condition, you check that a variable is equal to a given value, use the CASEENDCASE construction. It is clearer and less runtime intensive.  Outside of loops you can also use CHECK instead of IF. This query sets the execution of all statements up to the end of the current processing block under one condition. If this is unsuccessful, the system continues with the first statement in the next processing block.

(C) SAP AG

BC400

12

5.13

Loops DO [ n TIMES ] [...]. Statements

ENDDO. Loop Loop counter: counter: sy-index sy-index

WHILE . Statements

ENDWHILE. LOOP AT ... Statements

ENDLOOP.

DO. Statements

IF . EXIT. ENDIF. ENDDO.

SELECT ... Statements

ENDSELECT.



SAP AG 2001

 In ABAP there are four loop constructions, whereby LOOP-ENDLOOP and SELECTENDSELECT represent special cases. In the DO and WHILE loops, the system stores the number of the current loop pass in the sy-index field. If these loops are nested, sy-index contains the number of the current (that is, inner) loop.  Unconditional/index controlled loops The statements between DO and ENDDO are executed until the loop is left over other statements. You also have the option of specifying the maximum number of loop passes; otherwise, you may get an endless loop.  Header controlled loops The statements between WHILE and ENDWHILE are executed only if the condition has been met.  You can use the statements CHECK and EXIT for different effects on the way the loop is processed. For example, you can construct a footer-controlled loop.

(C) SAP AG

BC400

13

5.14

Dialog Messages MESSAGE tnnn(message_class) [ WITH v1 [ v2 ] [ v3 ] [ v4 ] ].

Meaning

Type

Behavior

Message appears in

t s

Status message

Program continues without interruption

Status line in next screen

i

Information

Program continues after interruption

Modal dialog box

w

Warning

Context dependent

Status bar

e

Error

Context dependent

Status bar

a

Termination

Program aborted

Modal dialog box

x

Short dump

Runtime error MESSAGE_TYPE_X is triggered

Short dump



SAP AG 2001

You can use the MESSAGE statement to send dialog messages. You must specify the three-digit message number and the message class.  Furthermore, you can use the WITH addition to include up to four values. The system, depending on the message text, inserts these values into the message text.  You control the dialog behavior using the type abbreviation “t”. There are six different types of message: a Abort The program is ended after a dialog box. x Exit The program ends in a short dump. e Error Runtime behavior is context dependent. w Warning Runtime behavior is context dependent. i Information The program continues after a dialog box. s Success The message appears in the status bar on the subsequent screen.  For further information about the syntactic alternatives of the MESSAGE statement, refer to the keyword documentation. 

(C) SAP AG

BC400

14

5.15

Runtime Behavior of Dialog Messages Help

i

Editor Help ABAP Overview ABAP Term ABAP News ABAP Docu and Examples

ABAP Documentation and Examples ? BC - ABAP Programming ? ABAP Introduction ? ABAP Programming Language ? ABAP User Dialogs ? Screens ? Selection Screens ? Lists ? Messages Simple example for messages Demonstration for all message types ? ... 

SAP AG 2001

 Depending on the context in which they appear, some message types show different dialog behavior.  You can find a program for testing the resulting options in the ABAP documentation. To access these example programs, choose Utilities  Help onABAP doc. and examples (in the following dialog box)

(C) SAP AG

BC400

15

5.16

Using the ABAP Debugger

Data Data Types Types and and Data Data Objects Objects Basic Basic ABAP ABAP Statements Statements Using Using the the ABAP ABAP Debugger Debugger Working Working with with Structures Structures Working Working with with Internal Internal Tables Tables



SAP AG 2001

(C) SAP AG

BC400

16

5.17

Executing a Program in Debugging Mode

Or: Set a breakpoint and execute the program Use the context menu Program ZBC400_00_GS ZBC400_00_GS Execute

REPORT sapbc400wbt_getting_started. TABLES sbc400_carrier. DATA wa_scarr TYPE scarr. PARAMETERS pa_car TYPE scarr-carrid. START-OF-SELECTION. SELECT SINGLE * FROM scarr Debugging INTO CORRESPONDING WHERE carrid = pa_car. IF sy-subrc = 0. MOVE-CORRESPONDING wa_scarr TO sbc4 CALL SCREEN 100. MOVE-CORRESPONDING sbc400_carrier T WRITE:/



wa_scarr-carrid, wa_scarr-carrname,

SAP AG 2001

 You can start a program in Debugging mode from the Object Navigator, without having to change the program in two ways: 

In the navigation area, choose Execute  Debugging for the selected program.

 In the editing area, select the desired program line and choose Set/delete breakpoint. Then start the program by choosing Execute Direct processing (F8)

(C) SAP AG

BC400

17

5.18

Switching to Debugging Mode at Runtime

System

Help Or: Choose menu System

/h Enter ‘/h’ into the command field and then select



Utilities

Debug screen Debug ABAP

SAP AG 2001

 If you want to debug only certain parts of a program, start the program first and then switch to debugging mode before a screen change. You can do this in two ways: 

Choose System Utilities Debug ABAP or Debug screen.



Enter /h in the command field and select Enter.

(C) SAP AG

BC400

18

5.19

Debugging Mode: Single Step and Field Contents X

SAP

ABAP Debugger



chws

Watchpoint r

SingleZJJ_FORMS step



Fixed point arithmetic 15 30 

SELECT SINGLE * FROM scarr INTO CORRESPONDING FIELDS OF wa_scarr Current statement WHERE carrid = pa_carr.  IF sy-subrc = 0. MOVE-CORRESPONDING wa_scarr TO sbc400_carrier. Double-click the CALL SCREEN 100. data object MOVE-CORRESPONDING sbc400_carrier TO wa_scarr. 1 - 4

Field Name

SY-SUBRC 

 

Field Value

 LH

pa_carr

0

SY-TABIX

0

SY-DBCNT

1

SAP AG 2001

In debugging mode, you can choose Single step to execute the program statement by statement. You can display the contents of up to eight data objects. Enter the names in the left input field or double-click the name in the displayed source code.

(C) SAP AG

BC400

19

5.20

Debugging Mode: Breakpoints X

SAP

ABAP Debugger



chws

Watchpoint

Continue



Fixed point arithmetic 15 30 

 SELECT SINGLE * FROM scarr INTO CORRESPONDING FIELDS OF wa_scarr WHERE carrid = pa_carr. IF sy-subrc = 0. MOVE-CORRESPONDING wa_scarr TO sbc400_carrier. CALL SCREEN 100. MOVE-CORRESPONDING sbc400_carrier TO wa_scarr. 1 - 4

Variant

SY-SUBRC 

0

Variant



SY-TABIX

0

SY-DBCNT

1

SAP AG 2001

 To set a breakpoint, double-click in front of a line of source code.  To set a breakpoint for a specific ABAP statement, choose: BreakpointBreakpoint at Statement.  If you choose Continue, the program is executed up to the next breakpoint.  If you Save the breakpoints, they remain intact while you are logged on to the system.  With breakpoints, the ABAP Workbench switches to debugging mode only for the developer who set the breakpoints. All other users can execute the program directly or set their own breakpoints

(C) SAP AG

BC400

20

5.21

Debugging Mode: Tracing Data Changes Watchpoint

Create/Change Watchpoint Local watchpoint (only in specified program) Program pa_carr Field name Relational operator = Comparison field (Comparison value if not selected) Comp. field/value

LH

Watchpoints No. Local Program Field name pa_carr 1 2 3 ... 10 Logical operator between watchpoints 

Operator Field Comp. field/value = LH

OR

AND

SAP AG 2001

Watchpoints are breakpoints that depend on the field content. You can create the following types of watchpoints:  Field name: The program is executed until the content of the field has changed.  Field name, relational operator, comparison value: The program is executed until the content of the field has changed so that the defined logical condition, relative to a value, is met.  Field name, relational operator, comparison value: The program is executed until the content of the field has changed so that the defined logical condition, relative to the content of a field, is met.  You can set up to 10 watchpoints and link them using the logical operators AND or OR. 

(C) SAP AG

BC400

21

5.22

Working with Structures

Data Data Types Types and and Data Data Objects Objects Basic Basic ABAP ABAP Statements Statements Using Using the the ABAP ABAP Debugger Debugger Working Working with with Structures Structures Working Working with with Internal Internal Tables Tables



SAP AG 2001

(C) SAP AG

BC400

22

5.23

Definition of Structures with Global Types

TABLES spfli. TABLES SPFLI

carrid connid fldate

seatsmax

Structure

SBC400FOCC

DATA wa_focc TYPE sbc400focc. DATA

seatsocc

Transparent table

percentage

wa_focc mandt carrid connid countryfr cityfrom

airpfrom countryto ...

spfli



SAP AG 2001

In ABAP, you can define structured data objects (simply called structures). This allows you to combine values that belong together logically into one object.  Structures can be nested. This means that components can consist of more structures or even tables.  There are two ways to define structures:  For DATA struc_name TYPE struc_type, you can use local or global types struc_type. 

 TABLES global_struc_type defines a structure that is technically managed in a special memory area. It has the same name as the global structure, global_struc_type. For this variant, the global structure must be flat, that is, all components must have an elementary type. Since Release 4.0, TABLES structures serve only as interfaces for screen fields..

(C) SAP AG

BC400

23

5.24

Definition of Structures with Local Types

OF st_flightinfo, TYPES: BEGIN BEGIN OF carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, seatsmax TYPE sflight-seatsmax, seatsocc TYPE sflight-seatsocc, percentage(3) TYPE p DECIMALS 2, END OF OF st_flightinfo . DATA wa_flightinfo TYPE st_flightinfo.

carrid connid fldate

seatsmax

seatsocc

percentage

wa_flightinfo



SAP AG 2001

 You can also define structure types locally using the TYPES statement. The components are enclosed by the following statements as shown in the graphic: BEGIN OF structure_type_name. ... END OF structure_type_name. Each individual component can in turn be assigned any type you wish.  For more information, refer to the keyword documentation for TYPES.  You define the data object itself in the usual way.  For compatibility reasons, you can also directly define a structured data object: DATA: BEGIN OF structure_name ... END OF structure_type_name

(C) SAP AG

BC400

24

5.25

Addressing Structure Components

DATA: wa_scarr TYPE scarr. wa_scarr --carrid = 'LH'. SELECT SINGLE * FROM scarr INTO wa_scarr WHERE carrid = wa_scarr --carrid. WRITE:/ wa_scarr wa_scarr wa_scarr

--carrid, --carrname, --url.

mandt carrid carrname currcode url wa_scarr



SAP AG 2001

Components of a structure are always addressed using a hyphen: structure_name-component_name.  For this reason, do not use hyphens in names. 

(C) SAP AG

BC400

25

5.26

Copying Structure Components with the Same Name

DATA: wa_sflight TYPE sflight, wa_focc TYPE sbc400focc. MOVE-CORRESPONDING wa_sflight TO wa_focc.

mandt carrid connid fldate

...

seatsmax seatsocc ...

wa_sflight

wa_focc carrid connid fldate



seatsmax seatsocc percentage

SAP AG 2001

 The statement MOVE-CORRESPONDING source_struc TO target_struc copies the contents of the structure source_struc into the structure target_struc component by component. The value assignment works only if the components have identical names.  All other components remain unchanged.

(C) SAP AG

BC400

26

5.27

Structures in Debugging Mode X

SAP

ABAP Debugger



chws

Watchpoint Fields Main program



Source code of

Fixed point arithmetic 

wa_sbc400 Structured field SELECT SINGLE * FROM scarr INTO CORRESPONDING Length (in bytes) 58 FIELDS OF wa_scarr WHERE carrid = pa_carr. 0.Component name Type Length Contents  IF sy-subrc =No. MOVE-CORRESPONDING wa_scarr TO sbc400_carrier. 1100. MANDT 100 C 3 Double-click the CALL SCREEN 2 CARRID AA C 3 data object MOVE-CORRESPONDING sbc400_carrier TO wa_scarr. 3 CARRNAME American Airlines C 20 Variant 4 CURRCODE USD C 5 wa_sbc400 5 MARK C 1 6 UNAME C 12 7 UZEIT 000000 T 6 8 DATE 00000000 D 8 SY-SUBRC 



0

SAP AG 2001

You can trace the field contents of a structure by entering the name of the structure in the left column. Double-click this entry to see the component display.

(C) SAP AG

BC400

27

5.28

Working with Internal Tables

Data Data Types Types and and Data Data Objects Objects Basic Basic ABAP ABAP Statements Statements Using Using the the ABAP ABAP Debugger Debugger Working Working with with Structures Structures Working Working with with Internal Internal Tables Tables



SAP AG 2001

(C) SAP AG

BC400

28

5.29

Internal Tables

Table can be extended dynamically



SAP AG 2001

 Internal tables are data objects that allow you to retain several data records with the same structure in memory. In principle, the number of data records is unlimited. It is restricted only by the capacity limits of specific system installations.  The ABAP runtime system dynamically manages the length of internal tables. This eliminates any work concerning working memory management.  The individual data records in an internal table are known as table lines or table entries. For this reason, the individual components in a line are referred to as columns of the internal table.  The line type of an internal table can be any ABAP data type, elementary or structured, or it can be another internal table.  Internal tables are a simple way of processing large data records in a structured form within a program. Typical uses include: •

Temporarily storing data from database tables for future processing



Structuring and formatting data for output



Formatting data for use by other services

(C) SAP AG

BC400

29

5.30

Attributes of Internal Tables

Line type

CARRID CONNID DISTANCE Line index

Key definition • Components • Sequence • Unique / non-unique key

4

AA 0017 LH 0400 LH 0400 QF 0005

2,572 6,162 7,273 10,000

5

SQ

0866

1,625

5

6

UA

0007

2,572

UA 0007

1 2 3

Index access Data access type

Key access



SAP AG 2001

The data type of an internal table is completely specified by the following attributes:  Line type This is the source of the attributes of the individual columns. You normally specify a structure type but any data types are possible.  Key definition The key columns and their order define the criteria by which the tables are identified. Depending on the access type, the key can be defined as unique or non-unique. With unique keys there are no multiple entries with identical values in the key.  Data access type  With a key access – as with database tables – you access using the field contents. Example: A read access using the search term 'UA 0007' to an internal table with the unique key CARRID CONNID and the data pictured above returns exactly one data record.  Index access: Unlike database tables, with internal tables the system may number the lines and give the line an index. You can use this idex to access a specific table line. Example: A read access to a data record with index 5 returns the fifth data record of the internal table

(C) SAP AG

BC400

30

5.31

Connection Between Table Kind and Access Type

Index tables Table type

STANDARD TABLE

Hashed table

SORTED TABLE

HASHED TABLE

Index access n Key access

Unique / NON- UNIQUE Non-Unique Key

UNIQUE | NON-UNIQUE

UNIQUE

Mainly keys

Keys only

n Access Using



Mainly index

SAP AG 2001

Another internal table attribute is the table type. Internal tables can be divided into three table types according to the respective access types: • With standard tables the line numbering is maintained internally. Both index and key accesses are possible. • With sorted tables the data records are always sorted according to key and saved. Here too, the index is maintained internally. Both index and key accesses are possible. • With hashed tables the data records are managed optimized at run time. A unique key is a requirement. With hashed tables only key accesses are possible.  Which table type you use in each case, depends on how that table's entries are generally going to be accessed: • For index accesses you should normally use standard tables. • Sorted tables are best for unique keys and fixed sorting. • With hashed tables the runtime optimization is noticeable only if the accesses are of the read type with a unique key.  This course deals with standard tables only. Apart from a few special cases, the syntax is identical for all three table types. 

(C) SAP AG

BC400

31

5.32

Definition of Internal Tables with Global Types SBC400_T_SBC400FOCC

Table type Line type and access Line type Data access type Key

Key definition Key category Key components

SBC400FOCC Standard table Key components Non-unique CARRID CONNID FLDATE

DATA itab_flightinfo TYPE sbc400_t_sbc400focc. DATA carrid connid fldate

seatsmax

seatsocc

percentage

itab_flightinfo



  

SAP AG 2001

Table types can be defined locally in a program or globally in the ABAP Dictionary. For DATA itab_name TYPE itab_type you can use local or global types itab_type. For detailed information on the definition of global table types in the ABAP Dictionary, refer to the SAP Library under Basis ABAP Workbench BC-ABAP Dictionary Types Table types.

(C) SAP AG

BC400

32

5.33

Definition of Internal Tables with Local Types

TYPES: tt_flightinfo TYPE STANDARD TABLE OF sbc400focc WITH NON-UNIQUE NON-UNIQUE KEY KEY carrid connid fldate. WITH DATA itab_flightinfo TYPE tt_flightinfo.

carrid connid fldate

seatsmax

seatsocc

percentage

itab_flightinfo



SAP AG 2001

 You can also define internal table types locally using the TYPE statement.  The table type is specified between TYPE and TABLE OF.  The line type comes after TABLE OF.  The key fields are listed after the WITH addition. Note that the order of the key fields plays a part here.  For detailed information about defining local table types, refer to the keyword documentation on TYPES.  You define the data object itself in the usual way.  For compatibility reasons, you can also directly define an internal table as follows: DATA itab_name TYPE table_kind TABLE OF struc_type WITH key_def.

(C) SAP AG

BC400

33

5.34

Overview: Typing Structured Data Objects ABAP program

ABAP Dictionary

DATA wa TYPE spfli. SELECT ... FROM spfli INTO wa ...

Transparent table

TABLES sbc400focc.

Structure

SPFLI

(Description)

Database AA AA ... LH LH

17 64 ... 400 402

... ... ... ... ...

SPFLI

SBC400FOCC DATA wa TYPE sbc400focc.

Structure

DATA it TYPE sbc400_t_sbc400focc.

Table type

AA AA ... LH LH



17 64 ... 400 402

... ... ... ... ...

SBC400FOCC

SBC400_T_SBC400FOCC

SAP AG 2001

(C) SAP AG

BC400

34

5.35

Overview: Accessing Single Records Append

APPEND wa TO itab. APPEND

Insert

INSERT INSERT

Read

READ TABLE TABLE itab INTO wa . READ

Change

MODIFY TABLE itab FROM wa [ ]. MODIFY

Delete

DELETE itab . DELETE



wa INTO TABLE itab .

SAP AG 2001

 The following single record operations are available for internal tables: In each case wa represents a structure that must have the same type as the line type of the internal table itab.  APPEND Appends the contents of a structure to an internal table. This operation should be used with standard tables only.  INSERT Inserts the contents of a structure into an internal table. In a standard table it is appended, in a sorted table it is inserted in the right place, and in a hashed table it is inserted according to the hash algorithm.  READ

Copies the contents of a line in an internal table to a structure.

 MODIFY

Overwrites a line in an internal table with the content of a structure.

 DELETE

Deletes a line of an internal table.

 COLLECT Accumulates the contents of a structure into an internal table. This statement may be used only for tables whose non-key fields are all numeric. The numeric values are summarized for identical keys  For detailed information about the ABAP statements described here, refer to the relevant keyword documentation.

(C) SAP AG

BC400

35

5.36

Overview: Processing Sets of Records LOOP AT itab INTO wa . LOOP

Loop: For all single record operations

ENDLOOP ENDLOOP..

Delete

DELETE itab .

Inserting several lines from another internal table

INSERT LINES OF itab2 INTO itab1 . APPEND LINES OF itab2 INSERT TO itab1.

Appending several lines from another internal table



SAP AG 2001

 The following set operations are available for internal tables: In each case wa represents a structure that must have the same type as the line type of the internal table itab.  LOOP ... ENDLOOP The LOOP places the lines of an internal table one by one into the structure specified in the INTO clause. All single record operations can be executed within the loop. In this case, for the single record operations, the system identifies the line to be processed.  DELETE Deletes the lines of the internal table that satisfy the condition .  INSERT Copies the contents of several lines of an internal table to another internal table.  APPEND Appends the contents of several lines of an internal table to another standard table. 

For detailed information about the ABAP statements described here, refer to the relevant keyword documentation.

(C) SAP AG

BC400

36

5.37

Syntax Example: Filling Line by Line

* define internal table and workarea: DATA: itab_flightinfo TYPE sbc400_t_sbc400focc, wa_flightinfo LIKE LINE OF itab_flightinfo. itab_flightinfo

wa_flightinfo * fill structure with values: wa_flightinfo-carrid = ... wa_flightinfo-connid = ... wa_flightinfo-fldate = ... wa_flightinfo-seatsmax = ... wa_flightinfo-seatsocc = ... wa_flightinfo-percentage = ...

. . . . . .

* insert structure into internal table: INSERT wa_flightinfo INTO TABLE itab_flightinfo. 

SAP AG 2001

You can insert lines into an internal table by first filling a structure with the required values and then inserting it into the internal table using the INSERT statement.  For standard tables, this means that the line is appended to the table. For sorted tables and hash tables, the system inserts the line after referring to the key. 

(C) SAP AG

BC400

37

5.38

Syntax Example: Reading Contents Using a Loop

* define internal table and workarea: DATA: itab_flightinfo TYPE sbc400_t_sbc400focc, wa_flightinfo LIKE LINE OF itab_flightinfo. itab_flightinfo

wa_flightinfo LOOP AT itab_flightinfo INTO wa_flightinfo. WRITE: / wa_flightinfo-carrid, wa_flightinfo-connid, wa_flightinfo-fldate, wa_flightinfo-seatsmax, wa_flightinfo-seatsocc, wa_flightinfo-percentage, '%'. ENDLOOP. 

SAP AG 2001

You can read and process the contents of an internal table using a LOOP by accessing the structure component within the loop.  In this example, the WRITE statement is used to create a list from the field contents.  If you want to change the contents of the internal table, first change the value of the components within the loop and then overwrite the line of the internal table using the MODIFY statement. 

(C) SAP AG

BC400

38

5.39

Syntax Example: Reading Using the Index LOOP AT itab_flightinfo INTO wa_flightinfo FROM 1 TO 5 5. WRITE: / wa_flightinfo-carrid, wa_flightinfo-connid, wa_flightinfo-fldate, wa_flightinfo-seatsmax, wa_flightinfo-seatsocc, wa_flightinfo-percentage, '%'. ENDLOOP. READ TABLE itab_flightinfo INTO wa_flightinfo 3. INDEX 3 WRITE: / wa_flightinfo-carrid, wa_flightinfo-connid, wa_flightinfo-fldate, wa_flightinfo-seatsmax, wa_flightinfo-seatsocc, wa_flightinfo-percentage, '%'. 

SAP AG 2001

 You can restrict access to certain line numbers using the INDEX addition. You may perform index operations on index tables only; therefore, these operations are supported for standard and sorted tables only.  In the first example, the system runs through only the first five lines in the internal table.  In the second example, the system reads the third line of the internal table

(C) SAP AG

BC400

39

5.40

Syntax Example: Reading Using the Key LOOP AT itab_flightinfo INTO wa_flightinfo WHERE carrid = 'LH' 'LH'. WRITE: /

wa_flightinfo-carrid, wa_flightinfo-connid, wa_flightinfo-fldate, wa_flightinfo-seatsmax, wa_flightinfo-seatsocc, wa_flightinfo-percentage, '%'.

ENDLOOP. READ TABLE itab_flightinfo INTO wa_flightinfo WITH TABLE KEY carrid = 'LH' connid = '0400' fldate = sy-datum sy-datum. IF sy-subrc = 0. WRITE: / wa_flightinfo-seatsmax, wa_flightinfo-seatsocc, wa_flightinfo-percentage, '%'. ENDIF. 

SAP AG 2001

 With the WHERE addition you can restrict access to lines with certain values. Key operations are supported for all table kinds.  With a completely specified key, key accesses to sorted and hashed tables are generally less runtime intensive than key accesses to standard tables.  In the first example, the system runs through only those lines in which the carrid field has the value 'LH'. (Performance aspect: The sorted table is most suited to this type of processing.)  The second example shows the syntax for reading a line in the internal table with a fully specified key. The return code sy-subrc is set to zero if a corresponding line is in the internal table. (Performance aspect: The hashed table is most suited to this type of single record access if the number of contained data records is very high.)  With single record accesses using a key, you must fill all key fields using the WITH TABLE KEY addition. If you want to define your selection criteria using any field values (not the entire table key), you must use the WITH KEY addition.

(C) SAP AG

BC400

40

5.41

Operations on the Whole Internal Table

Sort

SORT SORT

Delete the entire content of the internal table

REFRESH REFRESH



itab .

itab.

SAP AG 2001

The following operations affect the whole internal table.  SORT You can use this to sort any number of columns in a standard or hashed table in ascending or descending order. You may want to take culture-specific sort rules into account.  REFRESH This deletes the entire contents of an internal table. A part of the previously used working memory remains available for future insertions.  FREE This deletes the entire contents of the internal table and releases the previously used working memory.  CLEAR Unlike all other data objects, this statement has the same effect as the REFRESH statement on internal tables with no header line.

(C) SAP AG

BC400

41

5.42

Syntax Example: Sorting a Standard Table

* define internal table and workarea: DATA: itab_flightinfo TYPE sbc400_t_sbc400focc, wa_flightinfo LIKE LINE OF itab_flightinfo. itab_flightinfo

wa_flightinfo

SORT itab_flightinfo BY DESCENDING. BY percentage DESCENDING

Ascending or descending?

Name of column(s) by which to sort



SAP AG 2001

 You can sort standard tables by any column, simply by entering the column name after the BY addition to the SORT statement.  SORT itab [ ASCENDING | DESCENDING ] [ BY f1 [ ASCENDING | DESCENDING ] ... fn [ ASCENDING | DESCENDING ] ] [ AS TEXT ] [ STABLE ]. Sorting the internal table by the table key or specified field order: Without an addition the system sorts in ascending order. If you use the AS TEXT addition, the system will, while sorting by character-type fields, take the culture-specific sort rule into account. Only if you use the STABLE addition will the relative order of data records, which are identical in the sort key, remain intact during sorting.  In this example, the data records of the internal table are sorted in descending order by the percentage occupancy of flights.  For more details, refer to the keyword documentation for SORT.

(C) SAP AG

BC400

42

5.43

Internal Tables in Debugging Mode X

SAP

ABAP Debugger



chws

Watchpoint Table

Table



Fixed point arithmetic 15 30 

LOOP AT it_flightinfo INTO wa_flightinfo. WRITE: / wa_flightinfo-carrid,  wa_flightinfo-connid, it_flightinfo Internal table Double-click the data object Variant

it_flightinfo

SY-SUBRC 



0

1 2 3 4 5 6 7 8

Type STANDARD

CARRID

CONNID

FLDATE

...

PERCENTAGE

AA AA AA AA LH LH LH LH

0017 0017 0017 0017 0400 0400 0400 0400

20000512 20000724 20000828 20001224 20000626 20000715 20001113 20001212

... ... ... ... ... ... ... ...

66 120 560 470 240 123 273 280

SAP AG 2001

You can trace the line contents of an internal table by entering the name in the left column. To see the table display, double-click this entry.

(C) SAP AG

BC400

43

5.44

Comparison: Internal Tables with/without Header Lines DATA itab TYPE STANDARD TABLE OF scarr WITH NON-UNIQUE KEY carrid.

DATA itab TYPE WITH WITH

STANDARD TABLE OF scarr NON-UNIQUE KEY carrid HEADER LINE. LINE

DATA wa TYPE scarr. Work area

Header

wa

itab

Internal table

Internal table

itab

itab

INSERT wa INTO itab INDEX n.

INSERT itab INDEX n.

DELETE TABLE itab FROM wa.

DELETE TABLE itab.

READ TABLE itab INTO wa INDEX n. WRITE wa-carrid.

READ TABLE itab INDEX n. WRITE itab-carrid.

Explicit syntax: 

Implicit syntax:

SAP AG 2001

 You can define internal tables with or without a header line (WITH HEADER LINE addition). An internal table with header line consists of a work area (the header line) and the actual table body. Both objects are addressed with the same name. How this name is interpreted depends on the context. For example, with MOVE the name refers to the header line, while with SEARCH it is interpreted as the table body.  To avoid confusion, use internal tables without header lines. This is especially apparent in the case of nested tables.You can often use a shortened syntax (APPEND, INSERT, MODIFY, COLLECT, DELETE, READ, LOOP AT) for certain operations on internal tables with header line. Within ABAP objects, you can now only use internal tables without a header.  You can always uniquely address the body of an internal table itab by using the syntax itab[]. This is true regardless of whether the internal table has a header or not. Example: DATA itab1 TYPE TABLE OF i WITH HEADER LINE. DATA itab2 LIKE itab1. itab1 = itab2. itab1[] = itab2[].

(C) SAP AG

" only the headers are copied " the actual table content is copied

BC400

44

5.45

Basic ABAP Language Elements: Unit Summary

You are now able to:  Define elementary and structured data objects  Use basic ABAP statements  Execute and analyze programs in debugging mode



SAP AG 2001

(C) SAP AG

BC400

45

5.46ABAP Language Elements Exercises

Unit: Basic ABAP Language Elements Topic:

Basic ABAP Statements

At the conclusion of these exercises, you will be able to:  Define elementary data objects  Assign values  Implement conditional branching  Perform calculations Create an ABAP program for the four basic calculation types. You must be able to enter the values and arithmetic operator on a selection screen. Display the result in a list. Program:

ZBC400_##_COMPUTE

Model solution:

SAPBC400TSS_COMPUTE

## stands for the two-digit group number. 1-1

Create the executable program ZBC400_##_COMPUTE without "TOP Include".

1-2

Define the input parameters for two integers (name suggestion: pa_int1, pa_int2) and an arithmetic operator (name suggestion: pa_op). Additionally, define an elementary data object for the result type: packed number with two decimal places (name suggestion: result).

1-3

Execute the calculation in connection with the specified arithmetic operator. Use the CASE statement to do this.

1-4

Display the result in a list.

1-5

If the user has specified an invalid arithmetic operator on the selection screen, write an appropriate statement on the list screen.. Use the IF statement to do this.

(C) SAP AG

BC400

46

1-6

If the user tries to divide by zero, display an appropriate statement on the list screen. In a later unit you will learn how you can implement the error handling with a more elegant user dialog.

(C) SAP AG

BC400

47

Exercises Unit: Basic ABAP Language Elements Topic:

Working with Structures

At the conclusion of these exercises, you will be able to:  Use the Debugger to trace the data flow and understand the connections between processing blocks.  Use the MOVE-CORRESPONDING statement to assign values between structures. You have to examine a specified ABAP program to ascertain when and how certain data is transported between certain structured data objects.

Program:

SAPBC400WBS_GETTING_STARTED

2-1

Start the program SAPBC400WBS_GETTING_STARTED. On the selection screen, enter the airline code ‘LH’. In the command field, enter '/h' and then execute the program. You are now in debugging mode.

2-2

Make sure that all of the data objects are initial. Transfer all of the data objects defined in the program to the field view. Find out about the structure and type of the individual components.

2-3

Step through the program, one statement at a time, by choosing Single step (F5). Which fields of the structure wa_scarr does the SELECT statement fill? What is the value of system field sy-subrc after the statement?

2-4

Now observe how fields are copied from the structure wa_scarr to the structure sbc400_carrier. Which field values are copied?

2-5

The statement CALL SCREEN 100 processes screen 100. On the screen, enter appropriate values for the user name, date, and time, and continue with the program. Now observe how fields are copied from the structure sbc400_carrier to the structure wa_scarr.

2-6

Finally, observe how the WRITE statement constructs the list.

(C) SAP AG

BC400

48

After the first WRITE statement, an extra button appears in the application toolbar, which allows you to display the current contents of the list buffer at any time.

2-7

Restart the program in Debugging mode. Set a breakpoint at the MOVECORRESPONDING statement. Before the screen is processed, assign a name to the structure component sbc400_carrier-uname in the Debugger. The button used to change the field values at runtime is next to the input/output field.

2-8

(C) SAP AG

Repeat step 2-1. Now set a breakpoint at the CALL SCREEN statement. Additionally, set a field content-dependent watchpoint for the condition that a field value of the structure wa_scarr changes. Choose Continue (F8) to continue the program and check why the debugging of the program is stopped in each case.

BC400

49

Exercises Unit: Basic ABAP Language Elements Topic:

Working with Internal Tables

At the conclusion of these exercises, you will be able to:  Search for suitable table kinds in the ABAP Dictionary  Define internal tables based on a global table kind  Fill internal tables using array fetch  Process the content of internal tables using a loop. Create an ABAP program that lists additional information on all existing flight departure times. Get the data from the database table SPFLI. Program:

ZBC400_##_ITAB_LOOP

Model solution:

SAPBC400TSS_ITAB_LOOP

## stands for the two-digit group number. 3-1

Create the executable program ZBC400_##_ITAB_LOOP without "TOP-Include".

3-2

Buffer the data from the database table SPFLI in an internal table. Define an internal table with a line type that is compatible with the line structure of SPFLI. In the ABAP Dictionary, search for all internal table kinds that match this condition. (Use the Where-used list in the ABAP Editor.)

3-3

Define an internal table (name suggestion: it_spfli) based on one of the global table types you have found.

3-4

Define a work area that corresponds to the internal table (name suggestion: wa_spfli).

3-5

Program an array fetch access to all the data records in the database table SPFLI: SELECT * FROM spfli INTO TABLE it_spfli.

3-6

Display the buffered data in a list.

(C) SAP AG

BC400

50

Use the LOOP statement to do this.

(C) SAP AG

BC400

51

5.47ABAP Language Elements Solutions

Unit: Basic ABAP Language Elements Topic:

1

Basic ABAP Statements

Model solution:

REPORT sapbc400tss_compute. PARAMETERS: pa_int1 TYPE i, pa_op(1) TYPE c, pa_int2 TYPE i. DATA result TYPE p DECIMALS 2. IF NOT ( pa_op = '+' OR pa_op = '-' OR pa_op = '*' OR pa_op = '/' ). WRITE: 'Invalid operator!'(iop). ELSEIF pa_op = '/' AND pa_int2 = 0. WRITE: 'Division by zero!'(dbz). ELSE. CASE pa_op. WHEN '+'. result = pa_int1 + WHEN '-'. result = pa_int1 WHEN '*'. result = pa_int1 * WHEN '/'. result = pa_int1 / ENDCASE. WRITE: 'Result:'(res),

pa_int2. pa_int2. pa_int2. pa_int2. result.

ENDIF.

(C) SAP AG

BC400

52

Solutions Unit: Basic ABAP Language Elements Topic:

2-3

Working with Structures

Which components are filled by the SELECT statement C? mandt, carrid, carrname, currcode, url. What is the value of the system field sy-subrc after the SELECT statement? Because there is a data record for the airline LH (Lufthansa) in the database table SCARR, sy-subrc is set to zero.

2-4

(C) SAP AG

Which field values are copied? mandt, carrid, carrname, currcode.

BC400

53

Solutions Unit: Basic ABAP Language Elements Topic:

3

Working with Internal Tables

Model solution:

REPORT sapbc400tss_itab_loop. DATA: it_spfli TYPE sbc400_t_spfli. DATA: wa_spfli TYPE spfli. SELECT * FROM spfli INTO TABLE it_spfli. * at least one dataset selected IF sy-subrc = 0. * move each single dataset from internal table to * structure WA_SPFLI in order to write data on list LOOP AT it_spfli INTO wa_spfli. WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom, wa_spfli-cityto, wa_spfli-deptime, wa_spfli-arrtime. ENDLOOP. ENDIF.

(C) SAP AG

BC400

54

6 Data Retrieval

Contents:  Data Retrieval for Database Tables  Querying the Database  Reading Database Tables  Authorization Checks  Preview



SAP AG 2001

(C) SAP AG

BC400

1

6.2

Data Retrieval: Unit Objectives

At the conclusion of this unit, you will be able to:  List various ways of finding database tables  Program read access to specific columns and lines within a particular database table  Implement authorization checks  List the read access options for multiple database tables



SAP AG 2001

(C) SAP AG

BC400

2

6.3

Querying the Database

ABAP program pa_car

Data objects

Database table SCARR

wa_scarr ABAP Processing block SELECT SELECT ... FROM scarr

DatabaseDatabasespecific conversion

Open SQL

Database SQL

Database interface ABAP runtime system



SAP AG 2001

 Open SQL statements are a subset of Standard SQL that is fully integrated in the ABAP language. (SQL stands for standard query language.)  Open SQL statements allow you to access the database in a uniform way from your programs, regardless of the database system installed. The database interface converts Open SQL statements to database-specific SQL statements.

(C) SAP AG

BC400

3

6.4

Searching for Database Tables

Searching within a particular application component: Application hierarchy. Searching using a program :  Search in the ABAP Editor for the SELECT statement  Change to debugging mode during program execution and set breakpoint in the SELECT statement  If the program transmits a screen, display the structure field using F1 and technical information or navigate directly to the data element (double-click), or go directly to the data element (by double-clicking it) and open the where-used list in the tables



SAP AG 2001

 You can search for database tables via the Application Hierarchy or the Repository Information System.  If you have the name of a program that accesses the database table you are searching for:  Debugger: Start this program in debugging mode and set a breakpoint at the SELECT statement.  ABAP Editor: Search for the SELECT statement in the source text.  If you know a program that contains a screen with input fields connected to the table you are looking for, choose F1  Technical info. Double-click the technical name of the screen field to go to the ABAP Dictionary. This is often a structure field. Double-click the data element and then use the where-used list to search for transparent tables with the field type

(C) SAP AG

BC400

4

6.5

Reading Database Tables

Reading Reading Database Database Tables Tables Authorization Authorization Checks Checks Preview Preview



SAP AG 2001

(C) SAP AG

BC400

5

6.6

Programming Database Read Access

Which columns? SELECT

Which table(s)?

FROM

INTO

Whereto? Whereto?

WHERE

Which lines?

Single line

}

Multiple lines

} Particular column



SAP AG 2001

 To program database read access, use the Open SQL statement SELECT.  The SELECT statement contains a series of clauses, each of which has a different task:  The SELECT clause describes, among other things, whether the result of the selection will be several lines or a single data record and which fields of the table are to be read.  The FROM clause names the source (database table or view) from which the data is to be selected.  The INTO clause determines the internal data objects into which the selected data is to be placed.  The WHERE clause specifies the conditions that the selection results must fulfill. It thus determines the lines to be selected from the table.  For information about other clauses, refer to the keyword documentation for SELECT.

(C) SAP AG

BC400

6

6.7

Reading by Single Record Access

pa_car Database table SCARR

wa_scarr

SINGLE * SELECT SINGLE FROM scarr INTO INTO wa_scarr WHERE WHERE carrid = pa_car. IF sy-subrc = 0. ... Database interface



SAP AG 2001

 The SELECT SINGLE* statement allows you to read a single record from the database table. To ensure that you read a unique entry, all of the key fields must be filled by the WHERE clause. The asterisk * after SINGLE tells the database interface to read all columns in that line of the database table. If you want only a specific selection of columns, you can list the required fields instead.  In the INTO clause, enter the destination where the database interface is to copy the data. The target area should be structured left justified just like the required columns of the database table.  If you use the CORRESPONDING FIELDS OF addition in the INTO clause, you can fill the target area component by component. The system fills only those components that have identical names to columns in the database table. Note: If you do not use this addition, the system fills the target area left justified, irrespective of its structure.  If the system finds a table entry matching your conditions, SY-SUBRC has the value zero (0).  The SINGLE addition tells the database that only one line needs to be read. The database can then terminate the search as soon as it has found that line. Therefore, SELECT SINGLE produces better performance for single-record access than a SELECT loop if you supply values for all key fields

(C) SAP AG

BC400

7

6.8

Reading Several Lines Using a Loop

Database table SFLIGHT

pa_car wa_sbc400focc

SELECT SELECT carrid connid fldate seatsocc seatsmax FROM sflight INTO wa_sbc400focc WHERE carrid = pa_car. Statements for every record read

ENDSELECT ENDSELECT. IF sy-subrc = 0. ...



Database interface

SAP AG 2001

 If you do not use the addition SINGLE with the SELECT statement, the system reads multiple records from the database. The field list determines the columns whose data is to be read from the database.  The number of requested lines to be read can be restricted using the WHERE clause.  In the WHERE clause you may enter only the field names of the database table. The name of the database table you want to access is found in the FROM clause.  Multiple logical conditions can be added to the WHERE clause using AND, NOT or OR statements.  The database delivers data to the database interface in packages. The ABAP runtime system copies the data records to the target area line by line using a loop. It also enables sequential processing of all the statements between SELECT and ENDSELECT.  After the ENDSELECT statement, you can check the return code for the SELECT loop. sysubrc will have the value zero (0) if the database interface has found at least one record.  After the ENDSELECT statement, sy-dbcnt contains the total number of lines read.

(C) SAP AG

BC400

8

6.9

Reading Several Lines Using an Array Fetch

Database table SFLIGHT

pa_car itab_focc

SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO TABLE itab_focc WHERE carrid = pa_car. IF sy-subrc = 0. ...



Database interface

SAP AG 2001

The addition INTO TABLE itab causes the ABAP runtime system to copy the contents of the database interface directly to the internal table itab. This is called an array fetch.  Since the array fetch is not executed as a loop, do not program any ENDSELECT statement.  If you want to add lines to the end of an internal table that is already filled, instead of overwriting it, use the APPENDING TABLE itab addition.  sy-subrc has the value 0 if the system was able to read at least one record. 

(C) SAP AG

BC400

9

6.10

INTO Clause: Target Structure Suitable for Field List ABAP program DATA wa_sbc400focc TYPE sbc400focc. SELECT SINGLE carrid connid fldate seatsmax seatsocc FROM sflight INTO wa_sbc400focc wa_sbc400focc WHERE carrid = pa_car AND connid = pa_con AND fldate = pa_date. Same type as column read wa_sbc400focc



SAP AG 2001

 The program must contain a data object with a suitable type for each column that is required from a database table. For program maintenance reasons, you must use the corresponding Dictionary objects to assign types to the data objects. The INTO clause specifies the data object into which you want to place the data from the database table. You can use the INTO clause in two different ways:  Using a flat structure – You define a structure in your program that has the same fields in the same sequence as the field list in the SELECT clause. You can enter the name of the structure in the INTO clause. The contents are copied left justified. The field names of the structure are disregarded here.  Using individual data objects –You can enter a set of data objects in the INTO clause. For example: DATA: gd_carrid TYPE sflight-carrid, gd_connid TYPE sflight-connid, gd_fldate TYPE sflight-fldate, gd_seatsmax TYPE sflight-seatsmax, gd_seatsocc TYPE sflight-seatsocc. START-OF-SELECTION. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO (gd_carrid, gd_connid, gd_fldate, gd_seatsmax, gd_seatsocc) WHERE ...

(C) SAP AG

BC400

10

6.11

INTO Clause: Same-Name Fields of Field List in the Target Structure ABAP program DATA wa_sdyn_conn TYPE sdyn_conn. SELECT SINGLE carrid connid deptime FROM spfli wa_sdyn_conn INTO CORRESPONDING FIELDS OF wa_ _sdyn_ wa sdyn_conn WHERE carrid = pa_car AND connid = pa_con. Same type as column read mandt carrid connid

...

MANDT CARRID CONNID 

deptime

...

DEPTIME

SAP AG 2001

If you use the INTO CORRESPONDING FIELDS clause, the data is placed in the fields with the same name in the target structure.  Advantages of this construction:  The target structure does not have to be structured left justified in the identical way as the field list.  This construction is easy to maintain, because extending the field list does not require other changes to the program, as long as there is a field in the target structure that has the same name and type.  To place data in internal table columns of the same name using an array fetch, use the INTO CORRESPONDING FIELDS OF TABLE itab statement. 

(C) SAP AG

BC400

11

6.12

Selecting Data From Client-Specific Tables

Logged on in client 400:

SELECT * FROM spfli INTO ... WHERE carrid = 'AA'. ... ENDSELECT. SELECT * FROM spfli CLIENT SPECIFIED INTO ... WHERE mandt IN (401, 402) AND carrid EQ 'AA'. ... ENDSELECT.



Transparent table SPFLI MANDT 400 400 ... ... 401 401 ... ... 402 402

CARRID AA AA ... ... AA AA ... ... AA AA

CONNID

CITYFROM

0017 0064 ... ... 0017 0064 ... ... 0017 0064

NEW YORK FRANKFURT ... ... NEW YORK FRANKFURT ... ... NEW YORK FRANKFURT

SAP AG 2001



With client-specific database tables, the first keyword must always be MANDT or client (data type CLNT).



If you select data from client-specific tables, the system always reads the data records of the logon client, unless otherwise specified. (The ABAP runtime system automatically converts the SELECT statement.)



If you wish to explicitly include the client field in the WHERE clause, you must set the CLIENT SPECIFIED addition after the FROM clause.



Since this special case is not relevant for this course, the client field is generally omitted from the graphics.

(C) SAP AG

BC400

12

6.13

Performance: Secondary Index ... SELECT * FROM spfli INTO ... WHERE cityfrom = 'FRANKFURT'. ...

Secondary index CITYFROM BERLIN BERLIN ... FRANKFURT FRANKFURT FRANKFURT FRANKFURT ... NEW YORK NEW YORK ... 

Transparent table SPFLI CARRID AA AA ... ... LH LH ... ... UA UA ...

CONNID 0017 0064 ... ... 0400 0402 ... ... 0941 3504 ...

CITYFROM

CITYTO

NEW YORK FRANKFURT ... ... FRANKFURT FRANKFURT ... ... FRANKFURT SAN FRANCISCO ...

SAN FRANCISCO NEW YORK ... ... NEW YORK NEW YORK ... ... SAN FRANCISCO FRANKFURT ...

SAP AG 2001

 When you go to the definition of a database table in the ABAP Dictionary, you will see information on all the technical attributes of the database table.  The following information is useful for improving the performance of database accesses:  Key fields – If the lines requested from the database are retrieved according to key fields, the Database Optimizer can perform access using a primary index.  Secondary index – If the lines requested from the database are retrieved according to fields, the Database Optimizer can perform access using a secondary index. Secondary indexes are displayed in a dialog box whenever you select Indexes. You choose an index from the dialog box by double-clicking it. The system then displays a screen with additional information about that index.

(C) SAP AG

BC400

13

6.14

Authorization Checks

Reading Reading Database Database Tables Tables Authorization Authorization Checks Checks Preview Preview



SAP AG 2001

(C) SAP AG

BC400

14

6.15

Authorization Checks in ABAP Programs

User master records Selection screen

BC400-00

AUTHORITY CHECK

Profile 1 Profile 2

Note

No

Profile S_CARRID Authorization for authorization object S_CARRID Authorization for authorization object S_CARRID

SY-SUBRC = 0 ?

Yes SELECT

Profile 4 Authorization for authorization object S_TCODE



SAP AG 2001

 You should program an authorization check before accessing the database. The AUTHORITYCHECK statement first checks whether the user has the authorization containing all the required values. After the authorization check is completed, check the return code. If it is 0, the user has the required authorization and the program can be continued. If the value is not 0, the user does not have the required authorization and you should issue an appropriate message.  Later in this course, you will learn how to make fields on the selection screen ready for input again if you perform the authorization check right after the selection screen and how to send a message if the user does not have the required authorization

(C) SAP AG

BC400

15

6.16

Authorization Objects and Authorizations "Display" authorization for object S_CARRID

* 03

Object S_CARRID CARRID (Airline) ACTVT (Activity)

Activities: Create Change Display



= = =

"Change" authorization for object S_CARRID LH

01 02 03

02

SAP AG 2001

All data in the SAP system must be protected from unauthorized access by users who do not explicitly have permission to access it.  The system administrator assigns user authorizations when maintaining user master data. During this process, you should determine exactly which data users are allowed to access and what kind of access should be allowed. For example, you might want to allow users to display data for all airlines, but allow them to change data for only certain ones. In this case, the system must look for a combination of the activity (ACTVT) and airline carrier (CARRID) fields each time it performs an authorization check. Both fields must be filled with values during authorization creation as well (in this example, activity Change and airline carrier LH or activity Display and airline carrier *). You can ensure this by creating an authorization object composed of the ACTVT and CARRID fields that must be accessed both during the authorization assignment process and whenever your program performs an authorization check.  Authorization objects simply define the combination of fields that need to be addressed simultaneously and serve as templates for both authorizations and authorization checks. They are organized into object classes to make it easier to find and manage them. One or more object classes may be assigned to each application. 

(C) SAP AG

BC400

16

6.17

Syntax: Authorization Check

AUTHORITY_CHECK OBJECT 'S_CARRID' Check ID 'CARRID' FIELD 'LH' ID 'ACTVT' FIELD '02'. IF sysy-subrc NE 0.

Report results

Context-dependent reaction to missing authorization

ENDIF.



Authorizations for object S_CARRID

ACTVT 03 02

x

x

x

x

x

x

01

AA AZ DL LH UA

CARRID

SAP AG 2001

 When you check authorizations in programs, you specify the object and values the user needs in a particular authorization to be able to access the object in question.  In the above example, there is a check to determine whether the user has authorization for the object S_CARRID, which has the value 'LH' in the CARRID field and the value '02' (change) in the ACTVT field. The abbreviations for the possible activities are documented in the table TACT and also in the appropriate authorization objects.  The AUTHORITY-CHECK statement executes the authorization check for the user master record and also issues the return code. When evaluating the return code, you can specify the consequences of lacking authorization (for example, program terminates or skips some input lines).

(C) SAP AG

BC400

17

6.18

Implementing Authorization Checks Pattern Insert pattern ... ... AUTHORITY_CHECK S_CARRID ... ...

AUTHORITY-CHECK OBJECT 'S_CARRID'

Insert values

ID 'CARRID' FIELD '__________' ID 'ACTVT' FIELD '__________'. IF SY-SUBRC syNE 0. 0. sy-subrc NE IF Evaluate return code

ENDIF. 

SAP AG 2001

You must specify all fields of the object in an AUTHORITY-CHECK statement; otherwise you receive a return code not equal to zero. If you do not want to carry out a check for a particular field, enter DUMMY after the authorization field. Example: When a change transaction is called, it is a good idea to check whether the user may change the entries for a particular airline: AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' DUMMY ID 'ACTVT' FIELD '02'.  The most important return codes for AUTHORITY-CHECK are: 0: The user has authorization containing the required values. 4: The user does not have the required authorization. 8: The check was not successful because not all fields of the authorization object were specified.  The keyword documentation for AUTHORITY-CHECK contains a complete list of The check was not successful because not all fields of the authorization object were specifiedreturn codes. 

(C) SAP AG

BC400

18

6.19

Preview

Reading Reading Database Database Tables Tables Authorization Authorization Checks Checks Preview Preview



SAP AG 2001

(C) SAP AG

BC400

19

6.20

Reading Linkable Database Tables Which database tables should be taken into account? Which Whick link condition should apply to a common line?

SPFLI and SCARR

spfli-mandt = scarr-mandt spfli-carrid = scarr-carrid

SPFLI MANDT CARRID CONNID

...

SCARR CITYFROM

...

MANDT CARRID CARRNAME

...

...

...

...

...

...

...

...

...

...

Which columns are to be read, and from which database table? spfli-mandt spfli-carrid 



spfli-connid spfli-cityfrom scarr-carrname

SAP AG 2001

You can access several database tables using one database query, if the databse tables are logically related. To do so, you must specify the following information:  Which database tables should be accessed?  What should the link condition look like? In the graphic, columns from both database tables are linked. If all the field values of the linked columns match, a record is placed in a common line in the results table.  Which columns are to be read? If a column appears in more than one database table, you must specify the table from which this column is to be read.

(C) SAP AG

BC400

20

6.21

Dictionary View and ABAP Join Link in the Dictionary

ABAP Dictionary View

Link in the Program ABAP program

Link in the ABAP program using ABAP Join

SELECT SELECT

...

FROM spfli INNER JOIN scarr spfli~carrid = scarr~carrid ON WHERE ... 



SAP AG 2001

You can define the link conditions either statically or dynamically.  You define a static link or view in the ABAP Dictionary. There are several kinds of views. You can find information about views in the SAP Library under Basis Components  ABAP Workbench  BC ABAP Dictionary  Views.  You implement a dynamic link or an ABAP join using ABAP statements. The system generates an appropriate database query in the database interface at run time. For more information, see the keyword documentation for the SELECT statement.

(C) SAP AG

BC400

21

6.22

Preview: Reusable Components for Data Retrieval

Object

Business Object

Global class methods

BAPIs

Function group

Logical Database



SAP AG 2001

If reusable components that encapsulate complex data retrieval statements are available, you should use them. There are four techniques for reusing data retrieval components:.  Calling methods of global classes  Calling methods of business objects  Calling function modules  Including logical databases – Logical databases are data retrieval programs that return logicallyconnected data in a hierarchical sequence.  You can find information on these techniques in the appropriate units.  For detailed information on how to include logical databases, refer to the SAP Library under: Basis Components  ABAP Programming and Runtime Environment  ABAP Database Accesses  Logical Databases. 

(C) SAP AG

BC400

22

6.23

Preview: Database Accesses Initiating Changes

INSERT UPDATE SELECT DELETE MODIFY



SAP AG 2001

 In addition to the SELECT statement, Open SQL contains the UPDATE, INSERT, DELETE, and MODIFY statements.  Do not use these data base accesses, which initiate changes in the database, unless you understand the SAP transaction concept.  All Open SQL statements support the return code sy-subrc. If a database access was successful, the return code in the system field sy-subrc is 0; if it was not successful, the return code is not 0.  For more information about Open SQL statements, refer to the respective keyword documentation.

(C) SAP AG

BC400

23

6.24

Data Retrieval: Summary

Now you are able to:  List various ways of finding database tables  Program read access to specific columns and lines within a particular database table  Implement authorization checks  List the read access options for multiple database tables



SAP AG 2001

(C) SAP AG

BC400

24

6.25 Data Retrieval Exercises

Unit: Data Retrieval Topic: Reading Several Records Using a Loop At the conclusion of these exercises, you will be able to:  Program loop database accesses  Limit the quantity of selected data in accordance with an input parameter Enhance your ABAP program to issue flight schedules so that only the schedules of the airline carriers selected by the user are displayed. The list should also include the percentage occupancy of each flight scheduled. Template:

ZBC400_##_GS_LIST or SAPBC400WBS_GS_LIST

Program:

ZBC400_##_SELECT_SFLIGHT

Model solution:

SAPBC400DDS_SELECT_SFLIGHT

## stands for the two-digit group number.

1-1

Copy your executable program ZBC400_##_GS_LIST (solution for exercise 2 in unit 3, Introduction to the ABAP Workbench) or the template SAPBC400WBS_GS_LIST to the new name ZBC400_##_SELECT_SFLIGHT.

1-2

Change the work area type name (name suggestion: wa_flight). Now use the global structure SBC400FOCC. Find out information on the components (fields) of this structure.

1-3

Define an input parameter for the airline abbreviation.

1-4

Now select only the flights from the database table SFLIGHT that belong to the selected airline. Select only those fields that have a target field in the work area.

1-5

Within the loop statement, calculate the percentage occupancy for each flight. Assign the result to the PERCENTAGE field in your work area.

1-6

Extend your list output to include the percentage occupancy.

(C) SAP AG

BC400

25

1-7

(C) SAP AG

What is the first key field in the transparent table SFLIGHT? What is the first key field in your WHERE clause? Does the database interface still use the primary index?

BC400

26

Exercises Unit: Data Retrieval Topic:

Filling and Sorting an Internal Table

At the conclusion of these exercises, you will be able to:  Fill an internal table with data by appending data records  Sort the content of an internal table Enhance your ABAP program for the output of flight departure times so that the flights appear in the list sorted by percentage occupancy. For this purpose, append the read data records for the selected airline carrier to an internal table. Template:

ZBC400_##_SELECT_SFLIGHT or SAPBC400DDS_SELECT_SFLIGHT

Program:

ZBC400_##_SELECT_SFLIGHT_ITAB

Model solution:

SAPBC400DDS_SELECT_SFLIGHT_TAB

## stands for the two-digit group number. 2-1

Copy your executable program ZBC400_##_SELECT_SFLIGHT (solution for exercise 1 in this unit) or the template SAPBC400DDS_SELECT_SFLIGHT to the new name ZBC400_##_SELECT_SFLIGHT_ITAB.

2-2

Define an internal table (name proposal: it_flight) using a global table type as a basis that has the global structure SBC400FOCC as line type. Use the Where-used list in the ABAP Dictionary to find a suitable table type.

2-3

Fill this internal table line by line by using an INSERT statement in the SELECT loop. (Remove the statements for list output. You can use the source text again later.)

2-4

Sort the internal table by percentage occupancy and display the contents of the internal table in a loop on a list.

(C) SAP AG

BC400

27

Exercises Unit: Data Retrieval Topic:

Authorization Check

At the conclusion of these exercises, you will be able to:  Implement authorization checks  Set up the program flow in a variable manner depending on the outcome of the authorization check Enhance your ABAP program so that the flights can be read and displayed only if the user has display authorization for the selected airline. Templates:

ZBC400_##_SELECT_SFLIGHT and ZBC400_##_SELECT_SFLIGHT_ITAB SAPBC400DDS_SELECT_SFLIGHT and SAPBC400DDS_SELECT_SFLIGHT_TAB

Programs:

ZBC400_##_AUTHORITY_CHECK and ZBC400_##_AUTHORITY_CHECK_2

Model solutions:

SAPBC400DDS_AUTHORITY_CHECK and SAPBC400DDS_AUTHORITY_CHECK_2

## stands for the two-digit group number. 3-1

Copy your executable programs ZBC400_##_SELECT_SFLIGHT (solution for exercise 1 in this unit) and ZBC400_##_SELECT_SFLIGHT_ITAB (solution for exercise 2 in this unit) or the templates SAPBC400DDS_SELECT_SFLIGHT and SAPBC400DDS_SELECT_SFLIGHT_TAB to the new names ZBC400_##_AUTHORITY_CHECK and ZBC400_##_AUTHORITY_CHECK_2.

3-2

Program an authorization check for the authorization object S_CARRID. Check the combination of selected airline and activity Display. Use the respective Pattern statement in the ABAP Editor. Search for the correct abbreviation of the activity to be checked.

3-3

(C) SAP AG

Define a constant for the abbreviation of the activity “Display” (name proposal actvt_display). Use ACTIV_AUTH for typing the data element and use this constant during the authorization check.

BC400

28

3-4

Execute the database access only if the user has display authorization for the selected airline. If this is not the case, display an appropriate error message on the list.

3-5

Execute your programs; select the airline abbreviations ."AA" and "UA".

(C) SAP AG

BC400

29

6.26Data Retrival Solutions

Unit: Data Retrieval Topic: Reading Several Records Using a Loop

1-2

The global structure SBC400FOCC has the following components: CARRID with type S_CARR_ID CONNID with type S_CONN_ID FLDATE with type S_DATE SEATSMAX with type S_SEATSMAX SEATSOCC with type S_SEATSOCC PERCENTAGE with type S_FLGHTOCC.

1-7

The MANDT field in SFLIGHT is marked as a key field. The WHERE condition does not need this field. Despite this fact, the database interface can use the primary index in this case for selecting the data records. Reason: When the ABAP runtime system accesses a client-specific table, it assumes that data should be taken into account only if it belongs to the client under which the user is logged on. Thus, by default, the database interface enhances the WHERE condition with a WHERE mandt = sy-mandt condition.

(C) SAP AG

BC400

30

1

REPORT

Model solution:

sapbc400dds_select_sflight

.

DATA: wa_flight TYPE sbc400focc, PARAMETERS: pa_car TYPE s_carr_id. * Select all datasets from database table SFLIGHT * corresponding to carrier PA_CAR: SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. * Calculate occupation of each flight: wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. * Create List: WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsmax, wa_flight-seatsocc, wa_flight-percentage, '%'. ENDSELECT.

(C) SAP AG

BC400

31

Solutions Unit: Data Retrieval Topic:

2

Filling and sorting an internal table

Model solution:

REPORT sapbc400dds_select_sflight_tab. DATA: wa_flight TYPE sbc400focc, it_flight TYPE sbc400_t_sbc400focc. PARAMETERS: pa_car TYPE s_carr_id. * select all datasets from database table SFLIGHT * corresponding to carrier SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. * calculate occupation of each flight wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. * append single line into internal table INSERT wa_flight INTO TABLE it_flight. * alternatively, you could use the APPEND statement, * if you are using standard tables: * * APPEND wa_flight TO it_flight. ENDSELECT. * sort internal table SORT it_flight BY percentage. * create list from sorted internal table LOOP AT it_flight INTO wa_flight. WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,'%'. ENDLOOP.

(C) SAP AG

BC400

32

Solutions Unit: Data Retrieval Topic:

3

Authorization Checks

Model solution:

REPORT sapbc400dds_authority_check. CONSTANTS actvt_display TYPE activ_auth VALUE '03'. DATA wa_flight TYPE sbc400focc. PARAMETERS pa_car TYPE s_carr_id. * authority-check: * Is user authorized to display data for carrier PA_CAR? AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. CASE sy-subrc. * user is authorized WHEN 0. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. WRITE: / wa_flight-carrid COLOR COL_KEY, wa_flight-connid COLOR COL_KEY, wa_flight-fldate COLOR COL_KEY, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,'%'. ENDSELECT. * user is not authorized or * other error of authority-check WHEN OTHERS. WRITE: / 'Authority-Check Error'(001). ENDCASE. (REPORT sapbc400dds_authority_check_2 analog).

(C) SAP AG

BC400

33

7 Internal Program Modularization with Subroutines

Contents:  Defining Subroutines  Interface Parameters  Visibility  Calling Subroutines  Subroutines in Debugging Mode



SAP AG 2001

(C) SAP AG

BC400

1

7.2

Internal Program Modularization with Subroutines: Unit Objectives

At the conclusion of this unit, you will be able to:  Define subroutines  Call subroutines  Analyze the execution of subroutines in debugging mode



SAP AG 2001

(C) SAP AG

BC400

2

7.3

Calls and Interfaces ABAP program

Actual parameters

PERFORM ...

Total seats 200

PERFORM ...

Inquiries 1000

FORM ...

Occupied seats 60

Bookings 555

Percentage occupied 30.00

Sales ratio 55.50

Interface Formal parameters

* .................... calculate percentage ... ENDFORM. 

Subroutine

SAP AG 2001

 A subroutine is an internal module within a program. In a subroutine, you lift parts of a program out of the main programming block and put them somewhere else. This makes your program easier to read and allows you to use these code segments more than once.  You can pass data to the subroutine and back through its interface. This allows you to call the same function for different data objects. The example in the graphic shows a subroutine that calculates a percentage. This subroutine is called several times, even though different data objects are passed to the interface in each case.  Using subroutines makes your program more function oriented: it splits the program's task into subfunctions so that each subroutine is responsible for one subfunction.  This generally makes programs easier to maintain. In the Debugger, you can execute the subroutines in background so that you see only the result. This usually makes it easier to find the source of the error.  The structure of a subroutine includes the following: 

Each subroutine starts with FORM and ends with ENDFORM.



The name of the subroutine is followed by the interface definition.

 The statements that the subroutine executes come between FORM and ENDFORM.

(C) SAP AG

BC400

3

7.4

Ways of Passing Interface Parameters

Call-by-value

Call-by-reference

Call-by-value-and-result

Passes a value Passes an address Passes and returns a value



SAP AG 2001

 You specify how the data is passed from the main program (actual parameters) to the subroutine (formal parameters) in the interface of the subroutine. You can do this in three ways:  Call-by-value – A local copy of the actual parameter is passed to the subroutine. This means that value assignments to the formal parameter have absolutely no effect on the actual parameter.  Call-by-reference – A dereferenced address of the actual parameter is passed to the subroutine. This means that value assignments to the formal parameter directly affect the actual parameter. The value of the actual parameter is physically changed by the subroutine through the address.  Call-by-value-and-result – A local copy of the actual parameter is passed to the subroutine and a value is passed back to the main program only if the ENDFORM statement is executed. This means that value assignments to the formal parameter affect the actual parameter only after they have left the subroutine. Choose this option if you want to make sure that the actual parameter is not changed if the subroutine is terminated prematurely.

(C) SAP AG

BC400

4

7.5

Passing Interface Parameters: Syntax

PERFORM subroutine_name USING a1 CHANGING a2 a3. a1

a2

a3

f1

f2

f3

FORM subroutine_name USING value(f1) value( ( ) ... value CHANGING f2 ... value( ( ) ... . value value(f3) ... ENDFORM. 

SAP AG 2001

 In the interface definition, you list the formal parameters of the different sorts and assign a type to each one. The sequence of parameters is fixed: first you name all the USING parameters, then you name all the CHANGING parameters. Within the subroutine, you address the data that has been passed using the formal parameters.  The actual parameters are grouped by USING and CHANGING when the subroutine is called.  You specify the way in which the parameters are to be passed in the interface definition:  Call-by-value (f1) – You list these parameters after the USING keyword and complete them with the value(f1) addition.  Call-by-reference (f2) – You list these parameters after the CHANGING keyword. (For documentation purposes, you can also list a pass-by-reference parameter after USING. Technically, USING and CHANGING have exactly the same effect. (However, if you change a parameter listed after USING in the subroutine, you receive a warning in the Extended Program Check.)  Call-by-value-and-result (f3) – You list these parameters after the CHANGING keyword and complete them with the value(f3) addition

(C) SAP AG

BC400

5

7.6

Interface Parameters: Specified and Inherited Types TYPES t_perc TYPE p DECIMALS 2. DATA: a1 TYPE ..., a2 TYPE ..., a3 TYPE ... . ...

DATA: a1 TYPE ..., a2 TYPE ..., a3 TYPE ... . ...

PERFORM calc_perc USING

PERFORM calc_perc USING

Specified type FORM calc_perc USING value(f_part) TYPE TYPE ii value(f_all) TYPE TYPE ii CHANGING value(f_pc) TYPE TYPE t_perc. t_perc t_perc

Inherited type FORM calc_perc USING value(f_part) TYPE ANY value(f_all) TYPE ANY CHANGING value(f_pc) TYPE ANY.

a1 a2 CHANGING a3.

a1 a2 CHANGING a3.

CHECK f_all 0. f_pc = f_part * 100 / f_all. ENDFORM. 

CHECK f_all 0. f_pc = f_part * 100 / f_all. ENDFORM.

Risk of type conflicts

SAP AG 2001

 The data objects passed to a subroutine (that is, the actual parameters) can be of any type. If you use elementary types, you can decide whether or not you want to specify the type of the formal parameters.  By specifying the type of the formal parameters, you ensure that only actual parameters of that type can be passed to the subroutine. This makes your program more stable because the syntax check will find any type conflicts.  If you use the TYPE ANY addition, you leave the type unspecified. (For compatibility reasons, you can also omit this addition.) In this case, the formal parameter inherits the type from the actual parameter at run time. If the statements in the subroutine are not suited to the inherited type, a runtime error may occur.  If you assign the types p, n, c or x, the missing type attributes are similarly "inherited" at run time. If you want to specify a type completely, you must use a user-defined type. If you use string or xstring, the type is not fully specified until run time.  Conversely, the types i, f, d, and t are fully typed.

(C) SAP AG

BC400

6

7.7

Interface Parameters: Specifying Types for Structures and Internal Tables DATA wa_flightinfo TYPE sbc400focc.

DATA it_flightinfo TYPE sbc400_t_sbc400focc.

...

...

PERFORM fill_wa CHANGING wa_flightinfo.

PERFORM fill_itab CHANGING it_flightinfo.

FORM fill_wa Structure type CHANGING f_wa TYPE sbc400focc sbc400focc.

Table type FORM fill_itab CHANGING sbc400_t_sbc400focc f_itab TYPE sbc400_t_sbc400focc.

f_wa-carrid = ... . f_wa-connid = ... . ENDFORM. 

Address the structure components

LOOP AT f_itab ... . ... ENDLOOP. Address the parameter as an internal table ENDFORM.

SAP AG 2001

If you use structures or internal tables as formal parameters, you must type them fully. This allows you to access these formal parameters within the subroutine.  The components of structures are known in the subroutine, as a result of the assigned type, so that you can address these components with the usual syntax.  If you use internal tables, the assigned type allows you to address the formal parameter as an internal table with the usual syntax.  Note on performance: If you use internal tables as parameters, you should generally pass them using pass-by-reference. Otherwise, the system can use considerable resources simply copying them to the subroutine. 

(C) SAP AG

BC400

7

7.8

Visibility of Global and Local Data Objects

DATA: it_flightinfo TYPE sbc400_t_sbc400focc, wa_flightinfo TYPE sbc400focc, ... .

Visible globally

... PERFORM fill_itab CHANGING it_flightinfo. FORM fill_itab CHANGING f_itab TYPE sbc400_t_sbc400focc. DATA DATA l_wa LIKE LINE OF f_itab.

Visible locally

LOOP AT f_itab INTO l_wa. ... ENDLOOP. ENDFORM. 

SAP AG 2001

 You can define local data within a subroutine.  Both the formal parameters and the local data objects are active only at the run time of the subroutine. This means that memory is allocated only when the subroutine is called and is released as soon as the subroutine has been executed. Thus these parameters and data objects can be addressed only from within the subroutine.  The global data objects from the main program can also be addressed from the subroutine. However, you should avoid doing this wherever possible. Otherwise, you bypass the interface, which makes the program more prone to errors.  If a local data object or formal parameter has the same name as a global data object, the ABAP runtime system addresses the local data object in the subroutine and the global one outside it. These objects are then known as locally obscured objects.  Summary of hints about gobal and local data objects:  Address the global data objects in the main program and pass them to the subroutine using the interface. 

Address only formal parameters and local data objects in the subroutine.

 For clarity, avoid using identically named global and local variables. Instead, use a simple prefix, such as f_ for formal parameters and l_ for local data objects.

(C) SAP AG

BC400

8

7.9

Syntax Example: Passing an Internal Table DATA: it_flightinfo TYPE sbc400_t_sbc400focc, wa_flightinfo TYPE sbc400focc, lines TYPE i. ... PERFORM count_lines USING

it_flightinfo 'LH' CHANGING lines.

FORM count_lines USING

f_itab TYPE sbc400_t_sbc400focc f_carr TYPE sbc400focc-carrid CHANGING value(f_lines) TYPE i.

DATA l_wa LIKE LINE OF f_itab. CLEAR f_lines. LOOP AT f_itab INTO l_wa WHERE carrid = f_carr. ADD 1 TO f_lines. ENDLOOP. ENDFORM. 

SAP AG 2001

 The example in the graphic shows a main program calling a subroutine, which specifies the number of lines of an internal table needed to fulfill a specific criterion.  The internal table, f_itab, and the comparison value, f_carr, are passed by reference to improve performance. The number of lines, f_lines, is passed by value-and-result.  To loop through the internal table, you need a work area with a compatible line type, which you define locally in the subroutine, by making a reference to the formal parameter.

(C) SAP AG

BC400

9

7.10

Calling Subroutines System

Help

ABAP Editor: Changing the Report Z00_FORM Z00_FORM

Subroutines COUNT_LINES

1: "drag-and-drop"



PERFORM count_lines USING f_itab + f_carr CHANGING f_lines. 2: Adapt the actual parameters FORM count_lines USING f_itab TYPE ... f_carr TYPE ... CHANGING value(f_lines) TYPE ... . ... ENDFORM.

SAP AG 2001

 A subroutine is called using the PERFORM statement.  When the subroutine is called, parameters are passed to it in strict sequence.  For this reason, you should define the subroutine first and then call it. The Object Navigator supports you in this respect: You can generate the PERFORM statement by dragging the subroutine from the navigation area to the editor area.  Alternatively, you can generate the call using the Pattern function in the ABAP Editor.  This prevents you from mixing up or forgetting any parameters. However, you must remember to replace the formal parameters with actual parameters.

(C) SAP AG

BC400

10

7.11

Subroutines in Debugging Mode X

SAP

ABAP Debugger



chws

Watchpoint ZJJ_KURS_000 ZJJ_FORMS

Return



Fixed point arithmetic 15 30 

FORM count_lines USING

Execute



DATA l_wa LIKE LINE OF f_itab.

1 - 4

Variant

SY-SUBRC

Variant

 LH

f_carr



f_itab TYPE ... f_carr TYPE ... CHANGING value(f_lines) TYPE ... .

0

SY-TABIX

0

SY-DBCNT

1

SAP AG 2001

 In debugging mode, you can make a subroutine run without stopping. The execution of the main program does not stop until after the subroutine has been executed.  Alternatively, you can execute the subroutine statement by statement using Single Step.  If the current statement is located in a subroutine, you can run the rest of the subroutine without it stopping by selecting Return (F7). Execution of the main program does not stop until after the subroutine is executed.

(C) SAP AG

BC400

11

7.12

Internal Program Modularization with Subroutines: Unit Summary

You are now able to:  Define subroutines  Call subroutines  Analyze the execution of subroutines in debugging mode



SAP AG 2001

(C) SAP AG

BC400

12

7.13Modularization Exercises

Unit: Internal Program Modularization Topic: Subroutines

At the conclusion of these exercises, you will be able to:  Create subroutines  Use the subroutine interface to pass data

Change your program ZBC400_##_SELECT_SFLIGHT_ITAB (or the corresponding model solution) so that the display of the data in a list is encapsulated in a subroutine.

Template:

ZBC400_##_AUTHORITY_CHECK_2 or SAPBC400DDS_AUTHORITY_CHECK_2

Program:

ZBC400_##_SUBROUTINE

Model solution: SAPBC400PBS_SUBROUTINE

1-1

Copy your program ZBC400_##_AUTHORITY_CHECK_2 or the corresponding model solution SAPBC400DDS_AUTHORITY_CHECK_2 to the new program ZBC400_##_SUBROUTINE.

1-2

Encapsulate the display of data in a list in a subroutine. Call the subroutine (suggested name: WRITE_LIST) after the SELECT loop. Pass the internal table containing the data that has been read using the interface.

1-3

Define the subroutine and specify types for the interface parameters.

1-4

Display the data from the subroutine using a LOOP… ENDLOOP structure. To do this, create the required table work area as a local data object in the subroutine. To specify the type of the local structure, use the ABAP statement DATA LIKE LINE OF .

(C) SAP AG

BC400

13

7.14Modularization Solutions

Unit: Internal Program Modularization Topic: Subroutines

Model solution SAPBC400PBS_SUBROUTINE *&--------------------------------------------------------------* *& Report SAPBC400PBS_SUBROUTINE * *& * *&--------------------------------------------------------------* REPORT sapbc400pbs_subroutine. CONSTANTS actvt_display TYPE activ_auth VALUE '03'. DATA: wa_flight TYPE sbc400focc, it_flight TYPE sbc400_t_sbc400focc. PARAMETERS: pa_car TYPE sflight-carrid.

START-OF-SELECTION. * Authority-Check: AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. CASE sy-subrc. * User is authorized WHEN 0. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. APPEND wa_flight TO it_flight. ENDSELECT. PERFORM write_list USING it_flight. * User is not authorized or other error of authority-check WHEN OTHERS. WRITE: / 'Authority-Check Error'(001). ENDCASE. *&--------------------------------------------------------------* *& Form WRITE_LIST *&--------------------------------------------------------------* * text *---------------------------------------------------------------* * -->P_IT_FLIGHT text *---------------------------------------------------------------* FORM write_list USING p_it_flight TYPE sbc400_t_sbc400focc. DATA: wa LIKE LINE OF p_it_flight. LOOP AT p_it_flight INTO wa. (C) SAP AG

BC400

14

WRITE: / wa-carrid COLOR COL_KEY, wa-connid COLOR COL_KEY, wa-fldate COLOR COL_KEY, wa-seatsocc, wa-seatsmax, wa-percentage,'%'. ENDLOOP. ENDFORM.

(C) SAP AG

BC400

" WRITE_LIST

15

8 The ABAP Runtime System

Contents:  Execution of Event Blocks by the ABAP Runtime System  Event Block LOAD-OF-PROGRAM (INITIALIZATION)  Event Block START-OF-SELECTION



SAP AG 2001

(C) SAP AG

BC400

1

8.2

The ABAP Runtime System: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe the event-controlled processes for executing an ABAP program  Use the event block LOAD-OF-PROGRAM (INITIALIZATION)  Use the event block START-OF-SELECTION



SAP AG 2001

(C) SAP AG

BC400

2

8.3

Possible Elements in an ABAP Program

Event block

Local type and field definitions

Event block Selection screen

Event block Event block



Module Interface

Module

Subroutine program

Process Before Output Process After Input

Screen

SAP AG 2001

 An ABAP program is a collection of processing blocks. A processing block consists of passive source code sections that are processed sequentially when called.  Processing blocks are the smallest units in ABAP. They cannot be split, which also means that they cannot be nested.  There are various kinds of ABAP processing blocks:  Event blocks are processing blocks that are called by the ABAP runtime system whenever the respective event is initiated. Such events can be initiated by the ABAP runtime system itself or by the user.  Subroutines are processing blocks that are called by ABAP statements. The developer controls subroutines.  Modules are special ABAP processing blocks that are called by screen statements. These are required for screen processing.  Whenever a program is started, all the global data objects of the program are created in the working memory first. Declarative ABAP statements are not components of ABAP processing blocks; instead, they are collected by the ABAP runtime system when the overall source code is generated. For the sake of clarity, however, you should place all declarative statements together at the beginning of the source code. Exceptions to this are local declarations within subroutines.

(C) SAP AG

BC400

3

8.4

Example: ABAP Program with Several Event Blocks and a Selection Screen

Local Type and Field Definitions

Selection screen (generated by the runtime system)

PARAMETERS pa_date LIKE sy-datum [ DEFAULT sy-datum ].

LOAD-OF-PROGRAM.

Event block Default settings for selection screen

pa_date = sy-datum - 7. START-OF-SELECTION.

Event block

Start of list creation

WRITE pa_date.



SAP AG 2001

 In all of the programs we have seen so far in this course, only one processing block has been programmed in addition to declarative statements. In this case, there is no need to declare the processing block explicitly. In more complex programs, however, several different processing blocks are required.  The example in the graphic contains a selection screen with an input field for a date. The date of the same weekday in the previous week should appear as a default value. The PARAMETERS statement is a declarative language element. The system requires a calculation to preset the date dynamically. The DEFAULT addition to the PARAMETERS statement ensures that the data object is filled with a default value. The ABAP runtime system fills the sy-datum field with the current date at the start of the program. To change variables at run time, therefore, you must program a processing block. Because this should be processed before the standard selection screen is transmitted, use the respective event block called LOAD-OF-PROGRAM.  Use the standard event block, START-OF-SELECTION, to create the list

(C) SAP AG

BC400

4

8.5

Sample Program Runtime Behavior

ABAP program

pa_date

Program start

LOAD-OF-PROGRAM. pa_date = sy-datum - 7. 19991225

??? START-OF-SELECTION. WRITE pa_date.

List buffer for basic list

ABAP runtime system Time 



SAP AG 2001

In the flow diagram in the graphic, you can easily follow the sequence of processing steps by the ABAP runtime system. Event blocks are called in a fixed sequence designed for list processing:  The first event block to be called is LOAD-OF-PROGRAM. In the example, the date "A week ago" is calculated and placed into the pa_date input field. Next the system sends the selection screen with this new value to the presentation server. The user can change the value.  Next the selection screen is sent to the presentation server.  After the user leaves the selection screen, START-OF-SELECTION is called.  If the START-OF-SELECTION event block contains the ABAP statements WRITE, SKIP or ULINE, a list buffer is filled.  As soon as START-OF-SELECTION is processed completely, the list buffer is sent to the presentation server as a list.



Both events presented here are initiated by the ABAP runtime system exactly once each time a program is executed.

(C) SAP AG

BC400

5

8.6

Event Block Characteristics

 Introduced by an event keyword ABAP program

 Ended by the next processing block  Event block for different tasks  Processing sequence for event blocks is determined by the runtime system Event block sequence in source code unimportant

PARAMETERS pa_date LIKE sy-datum [ DEFAULT sy-datum ]. LOAD-OF-PROGRAM. LOAD-OF-PROGRAM. pa_date = sy-datum - 7. START-OF-SELECTION. START-OF-SELECTION. WRITE pa_date.

 Standard event block in executable program:



SAP AG 2001



An event block is introduced with an event keyword. It ends implicitly when the next processing block starts.



Event blocks are called by the ABAP runtime system. Therefore, the sequence in which the event blocks are written in the program is unimportant.



LOAD-OF-PROGRAM is the first event block called in all ABAP program types. This event block allows you to set default values that can only be determined at runtime.



For compatibility reasons, the event block INITIALIZATION is available as an alternative. However, it is available for executable programs only.



START-OF-SELECTION is the first event block for creating a list. It is called by the ABAP runtime system as soon as you leave the standard selection screen. It is available for executable programs only.



In executable programs, additional event blocks are available for different tasks and are designed for creating lists. You can obtain a complete list of event blocks from the ABAP documentation: choose ABAP Overview  ABAP - Overview Diagrams  Classification of Keywords by Type Event keywords.

(C) SAP AG

BC400

6

8.7

The ABAP Runtime System: Unit Summary

You are now able to:  Describe the event-controlled processes for executing an ABAP program  Use the event block LOAD-OF-PROGRAM (INITIALIZATION)  Use the event block START-OF-SELECTION



SAP AG 2001

(C) SAP AG

BC400

7

9 User Dialog List

Contents:  List attributes and strengths  Basic list  List events  Interactive lists  Example with syntax: Detail list



SAP AG 2001

(C) SAP AG

BC400

1

9.2

User Dialog List: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe list attributes and strengths  Write a program that displays the detail of a specific line from your basic list to an interactive list whenever the user double-clicks that particular line  Explain the runtime behavior of your program during the AT LINE-SELECTION event



SAP AG 2001

(C) SAP AG

BC400

2

9.3

List Attributes Screen CA ID PRICE AA 2602 2400 AA 2602 2500 Total

Display languagespecific texts in logon language Formatted output: 20010821 Date

7800

08/21/2001

According to fixed user settings Print

Formatted output: Amounts according to their currency Lengths according to their unit





SAP AG 2001

The main purpose of a list is to display data while involving a minimum amount of programming. Special business data requirements are taken into account:  Lists are language-independent. Texts and headers appear in the logon language whenever a translation is available.  Lists can display monetary values in numerous currencies.



The following options are available to the user for lists:  Displaying on screens: you can add colors and icons  Printing  Publishing on Internet or intranet: The system automatically converts lists to HTML.  Saving: You can save lists within the R/3 System as well as outside for further processing, for example, using spreadsheet programs

(C) SAP AG

BC400

3

9.4

Standard List Functions:

Back / Exit / Cancel Scroll Print Find (in list) System ...

Save

: List :



SAP AG 2001

The standard list interface offers the user several navigation features:  Back  Exit  Cancel  Print  Find (in list)  Save as a file, in the menu, or to a buffer  Send the list in e-mail form  You can use the Menu Painter to adjust the standard list interface to fit your individual needs. 

(C) SAP AG

BC400

4

9.5

List Headers in the Default Page Header

From within the list: System ... : List :

From the ABAP Editor: Text elements Titles/headers

List header

Save

Column header



SAP AG 2001

Each list can have a list header and up to four lines of column headers. You can use these tools in two ways:  From the ABAP Editor: Use the text element maintenance functions. A ruler is available.  From the list: If you save your program, activate it, and then execute it to create the list, you can access the maintenance screen by choosing System  List  List header. The main advantage of using this method is that the list is still displayed on the screen. This makes it easier to position column headers.  The next time you start the program, the new headers will appear in the list automatically.  If no header text is entered, the program title is inserted in the header. 

(C) SAP AG

BC400

5

9.6

Multilingual Capability of Lists

ABAP program Text elements Titles/headers List header

WRITE: /15 text-001, text-001 35 sy-datum, /15 text-002 text-002, 35 sy-uname.

DE creation date EN creation date FR ...

Text symbols 001

002

DE Anlegen Datum EN Creation date FR ... : EN Created by

Creation date: 01/01/2001 Created by: WALTERS



SAP AG 2001

Titles and headers are part of the program's text elements. You can translate all text elements into other languages. The logon language setting on the logon screen determines in which language text elements will be displayed.  Text symbols are another kind of text element. Text symbols are text literals that can be translated and are assigned to the program. They are frequently used to create lists independent of language.  You can write text symbols into your program in either of the following ways:  TEXT-ccc (ccc is a three-byte character string)  '...'(ccc) (... is any text, ccc is a three-digit character string)  From the Editor, you can access the maintenance screen for the text symbols by choosing Goto Text elements Text symbols or by double-clicking the number of a text symbol. 

(C) SAP AG

BC400

6

9.7

Lists in Executable Programs

Program start

ABAP program

Database tables

Data objects START-OF-SELECTION. SELECT ... List buffer

WRITE ...

ABAP runtime system 

SAP AG 2001

Time

 In executable programs, lists are automatically displayed after their corresponding event blocks have been processed. These processing blocks must, however, contain a statement that writes to the list buffer. These are WRITE, SKIP, and ULINE.  Event blocks are called in a sequence designed for list processing: 

Before the selection screen: LOAD-OF-PROGRAM.



After the user leaves the selection screen: START-OF-SELECTION.

 All output from the event blocks that create the lists (here only START-OF-SELECTION) and from the modularization units called there, which is processed before a list is sent, is temporarily stored in the list buffer.  Once all list creation event blocks (here only START-OF-SELECTION) have been processed, all data from the list buffer is displayed in the form of a list.

(C) SAP AG

BC400

7

9.8

Creating Detail Lists

START-OF-SELECTION.

Database tables

Basic list buffer

AT LINE-SELECTION. Detail list buffer



SAP AG 2001

Time

 In executable programs, you can use the event block AT LINE-SELECTION to create detail lists.  The ABAP runtime system ensures that:  The basic list is sent after the event blocks responsible for creating the basic list have been processed (for example, after START-OF-SELECTION). In this case, the system field sy-lsind contains the value 0.  The event block AT LINE-SELECTION is processed using the function code PICK each time you double-click an entry or choose an action for the system to perform. If you are not using a user-defined status, this happens automatically every time you choose Detail list (icon looks like a magnifying glass), the menu function Choose, or the function key F2.  The detail list is sent after the AT LINE-SELECTION event block is processed and the value contained in sy-lsind is increased by one.  After every user action with the function code BACK, the system displays the list at the previous detail level (that is, it goes from level n to n-1).

(C) SAP AG

BC400

8

9.9

Detail Lists: Navigation Basic list

Basic list sy-lsind

0

First detail list

Detail list sy-lsind

1

Detail list sy-lsind

2 Second detail list





SAP AG 2001

The lists in the example program should function as follows:  The basic list should display the text Basic list and the system field sy-lsind.  The user can navigate to a detail list by using any of the following: Double-clicking on the basic list Choosing Detail list (icon looks like a magnifying glass) in the application toolbar Choosing a menu function Using function key F2. The Detail list appears and the system field sy-lsind has the value 1.  Repeating this action calls the second detail list, where system field sy-lsind contains the value 2 instead (representing the current detail list level).  Repeating this action increases the sy-lsind value by one every time. This is possible up to the twentieth detail list.  Choosing Back takes the user back one single detail list level at a time until the basic list is reached..

(C) SAP AG

BC400

9

9.10

Syntax Example: Simple Detail List

... START-OF-SELECTION. WRITE: / text-001 COLOR col_heading, / 'sy-lsind', sy-lsind color 2. AT AT LINE-SELECTION. LINE-SELECTION. WRITE: / text-002 COLOR col_heading. ULINE. WRITE: / 'sy-lsind', sy-lsind color 4.





Text symbols: 001

Basic list

002

Detail list

SAP AG 2001

A detail list is programmed as follows:  You create a basic list by filling the basic list buffer at an appropriate event block (here STARTOF-SELECTION) using either WRITE, SKIP, or ULINE.  Use the event block AT LINE-SELECTION when programming detail lists. Whenever you use WRITE, SKIP, or ULINE with this event block, you fill the detail list buffer for the next level (the detail list buffer with a level value one greater than the level on which the user performed the action).  You can pre-determine navigation between detail lists by querying system field sy-lsind at the event block AT LINE-SELECTION.

(C) SAP AG

BC400

10

9.11

Example: Detail List

Timetable Airl. LH LH ... SQ

Flight From 0400 FRA Frankfurt 0400 FRA Frankfurt 0002 SIN

To New York New York

JFK JFK

Singapore SFO San Francisco 09:30:00

Detail: Flights

You have chosen LH Flight date 19.12.2001 20.12.2001 24.12.2001



Departing at 10:10:00 13:30:00

0402 Max.

Occ.

380 380 380

240 270 380

SAP AG 2001

You will now write a program using both basic lists and detail lists. The basic list in your program should contain flight data such as carrier ID and flight numbers, departure city and airport, destination city and airport, and departure and arrival times. This data can be found in the database table SPFLI.  The user should be able to access information about any particular flight by double-clicking its carrier ID and flight number. Flight date and occupancy should be displayed. This data can be found in the database table SFLIGHT. You must use the SPFLI key fields in this detail list in order to read the appropriate data in SFLIGHT. The following graphics demonstrate how this is done.  The example program is SAPBC400UDD_DETAIL_LIST and it is part of development class BC400.  

(C) SAP AG

BC400

11

9.12

Buffering Global Data in the Hide Area Current list buffer HIDE fieldname. SELECT carrid connid airpfrom airpto deptime FROM spfli INTO CORRESPONDING FIELDS OF wa_spfli. WRITE: /

HIDE :

1 2 3 4 55

CAR

:

:

AA LH LH

ID

From

0017 JFK 0400 FRA 0402 FRA :

:

To

Departing at

SFO JFK JFK

13:30:00 10:10:00 13:30:00

:

:

Hide area

wa_spfli-carrid, wa_spfli-connid, wa_spfli-airpfrom, wa_spfli-airpto, wa_spfli-deptime. wa_spfli-carrid, wa_spfli-connid.

ENDSELECT.

Line

Field name

Value

3 3 4 4 5 5 :

wa_spfli-carrid wa_spfli-connid wa_spfli-carrid wa_spfli-connid wa_spfli-carrid wa_spfli-connid :

AA 0017 LH 0400 LH 0402 :

AT LINE-SELECTION. 



SAP AG 2001

When the event AT LINE-SELECTION is processed, a program's data objects contain the same values as before basic list display. A detail list, however, often needs data selected within the basic list itself. You can use the HIDE area to store certain data from the line that you have selected and then automatically insert it where you need it in the corresponding data object for a detail list.

To predetermine which information is classified by its line position when you create a basic list, use the ABAP keyword HIDE followed by a list of the data objects you require. The runtime system automatically records the name and contents of the data object in relation to its line position in the list currently being created.  The HIDE global_field statement buffers the content of the global data field global_field with reference to the current display line. You do not have to display the field beforehand using the WRITE statement. You merely have to program the HIDE statements after the last WRITE statement in the current line.  The data field can also be a flat structure. 

(C) SAP AG

BC400

12

9.13

Line Selection Hide area

CAR ID From From CAR ID

To To

AA 0017 JFK LH 0400 FRA LH 0402 FRA ... SQ 0002 SIN

SFO JFK JFK

13:30:00 10:10:00 13:30:00

SFO

09:30:00

Line

Field name

Value

3 3 4 4 5 5 : 14 14

wa_spfli-carrid wa_spfli-connid wa_spfli-carrid wa_spfli-connid wa_spfli-carrid wa_spfli-connid : wa_spfli-carrid wa_spfli-connid

AA 0017 LH 0400 LH 0402 : SQ 0002

Departingatat Departing

?? LH 0400 ??

??

??

wa_spfli

... AT LINE-SELECTION. WRITE: text-001, wa_spfli-carrid, wa_spfli-connid. 

Text symbols: 001

Flights for connection

SAP AG 2001



When you select a line (by pointing to it followed by PICK or double-click), this triggers the event AT LINE-SELECTION.



First the values for this line buffered in the HIDE area are inserted back into the corresponding global data objects.



Then the system processes the relevant event block in the ABAP program.

(C) SAP AG

BC400

13

9.14

Syntax Example: Additional Data for Selected Line

... Text symbols:

AT LINE-SELECTION. IF sy-lsind = 1. WRITE: text-001, wa_spfli-carrid, wa_spfli-connid.

001

Flights for connection

SELECT fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_sflight WHERE carrid = wa_spfli-carrid AND connid = wa_spfli-connid. WRITE:/ wa_sflight-fldate, wa_sflight-seatsmax, wa_sflight-seatsocc. ENDSELECT. ENDIF. 

SAP AG 2001



You create a detail list by filling the detail list buffer at the AT LINE-SELECTION event block using either WRITE, SKIP, or ULINE.



In the example program, the key fields of the airline will be displayed. The flights available for this airline in the database table SFLIGHT are read using a SELECT loop.



Note that the line-specific information on the airline is only available by double-clicking in the data objects if the relevant data objects have been placed in the HIDE area when the basic list was created.

(C) SAP AG

BC400

14

9.15

User Dialog List: Unit Summary

You are now able to:  Describe list attributes and strengths  Write a program that displays the details of a specific line from your basic list to an interactive list whenever the user double-clicks that particular line  Explain the runtime behavior of your program during the AT LINE-SELECTION event



SAP AG 2001

(C) SAP AG

BC400

15

9.16User Dialog List Exercises

Unit: User Dialog List Topic: Detail Lists At the conclusion of these exercises, you will be able to:  Create a detail list in a program

Extend the program ZBC400_##_SELECT_SFLIGHT or the corresponding model solution as follows: Once the user has selected a flight on the basic list (double-click or F2 on the relevant list line), display a detail list containing all of the bookings for the selected flight. Template:

ZBC400_##_SELECT_SFLIGHT or SAPBC400DDS_AUTHORITY_CHECK

Program:

ZBC400_##_DETAIL_LIST

Model solution: SAPBC400UDS_DETAIL_LIST

1-1

Copy your program ZBC400_##_SELECT_SFLIGHT or the corresponding template SAPBC400DDS_AUTHORITY_CHECK to the new program ZBC400_##_DETAIL_LIST.

1-2

Make sure that the key fields of the database table SFLIGHT are available to you for creating the detail list when the user selects a flight from the basic list (doubleclick or F2 on the corresponding list line).

1-3

Add the AT LINE-SELECTION event to your program to allow you to construct a detail list.

1-4

In the first line of the detail list, display key information from the selected flight. Under this line, display a horizontal line and a blank line.

1-5

Read all of the bookings from database table SBOOK for the selected flight. Make sure that you read only those fields from the database table that you want to display in the list. Display the following fields from the database table SBOOK on the detail list: BOOKID, CUSTOMID, CUSTTYPE CLASS,

(C) SAP AG

BC400

16

ORDER_DATE, SMOKER, CANCELLED.

1-6

Optional: Display the fields LOCCURAM and LOCCURKEY on the detail list: Ensure that the currency amount LOCCURAM is displayed with the appropriate formatting for the currency LOCCURKEY. Use the addition CURRENCY in the WRITE statement. Example: WRITE: wa_sflight-price CURRENCY wa_sflight-currency, wa_sflight-currency.

1-7

(C) SAP AG

Optional: Display the BOOKID field in the color COL_KEY.

BC400

17

9.17User Dialog List Solutions

Unit: User Dialog List Topic: Detail Lists

Model solution without optional exercises: SAPBC400UDS_DETAIL_LIST *&--------------------------------------------------------------* *& Report SAPBC400UDS_DETAIL_LIST * *& * *&--------------------------------------------------------------* REPORT

sapbc400uds_detail_list.

CONSTANTS: actvt_display TYPE activ_auth VALUE '03'. DATA: wa_flight TYPE sbc400focc, wa_sbook TYPE sbook. PARAMETERS: pa_car TYPE s_carr_id. START-OF-SELECTION. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. CASE sy-subrc. WHEN 0. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,'%'. * Hide key field values corresponding to the actual line HIDE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ENDSELECT. WHEN OTHERS. WRITE: / 'Authority-Check Error'(001). ENDCASE. CLEAR wa_flight. * Program continues here, if a line is selected on basic list AT LINE-SELECTION. IF sy-lsind = 1. (C) SAP AG

BC400

18

* Key fields transported back from hide area to ABAP data objects WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ULINE. SKIP. * Selection of bookings, which depend on selected flight SELECT bookid customid custtype class order_date smoker cancelled loccuram loccurkey FROM sbook INTO CORRESPONDING FIELDS OF wa_sbook WHERE carrid = wa_flight-carrid AND connid = wa_flight-connid AND fldate = wa_flight-fldate. * Creation of detail list WRITE: / wa_sbook-bookid, wa_sbook-customid, wa_sbook-custtype, wa_sbook-class, wa_sbook-order_date, wa_sbook-smoker, wa_sbook-cancelled. ENDSELECT. ENDIF. CLEAR wa_flight.

(C) SAP AG

BC400

19

Model solution with optional exercises: SAPBC400UDS_DETAIL_LIST1 *&--------------------------------------------------------------* *& Report SAPBC400UDS_DETAIL_LIST1 * *& * *&--------------------------------------------------------------* REPORT sapbc400uds_detail_list1. CONSTANTS: actvt_display TYPE activ_auth VALUE '03'. DATA: wa_flight TYPE sbc400focc, wa_sbook TYPE sbook. PARAMETERS: pa_car TYPE s_carr_id. START-OF-SELECTION. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. CASE sy-subrc. WHEN 0. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car. wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,'%'. * Hide key field values corresponding to the actual line HIDE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ENDSELECT. WHEN OTHERS. WRITE: / 'Authority-Check Error'(001). ENDCASE. CLEAR wa_flight. * Program continues here, if a line is selected on basic list AT LINE-SELECTION. IF sy-lsind = 1. * Key fields transported back from hide area to ABAP data objects WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ULINE. SKIP. * Selection of bookings, which depend on selected flight SELECT bookid customid custtype class order_date smoker cancelled loccuram loccurkey FROM sbook INTO CORRESPONDING FIELDS OF wa_sbook WHERE carrid = wa_flight-carrid AND connid = wa_flight-connid AND fldate = wa_flight-fldate. * Creation of detail list WRITE: / wa_sbook-bookid COLOR COL_KEY, wa_sbook-customid, wa_sbook-custtype, (C) SAP AG

BC400

20

wa_sbook-class, wa_sbook-order_date, wa_sbook-smoker, wa_sbook-cancelled, wa_sbook-loccuram CURRENCY wa_sbook-loccurkey, wa_sbook-loccurkey. ENDSELECT. ENDIF. CLEAR wa_flight.

(C) SAP AG

BC400

21

10 User Dialog Selection Screen

Contents:  Selection screen attributes and strengths  Defining selection screens  Evaluating user input to restrict database selection  Selection screen events  Syntax examples: Additional input checks with error dialog



SAP AG 2001

(C) SAP AG

BC400

1

10.2

User Dialog List: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe selection screen attributes and strengths  Write a program that allows you to enter intervals on a selection screen and that can be used to restrict the number of data records retrieved from the database  Write a program that contains additional input checks for the selection screen and returns to the selection screen if an error occurs



SAP AG 2001

(C) SAP AG

BC400

2

10.3

Use of Selection Screens

ABAP program

Selection criteria

Database table

ABAP processing block

ABAP runtime system 

 

SAP AG 2001

Selection screens allow users to enter selection criteria required by the program for it to continue. For example, if you create a list containing data from a very large database table, you can use a selection screen to restrict the amount of data that is selected. At runtime, the user can select intervals for one of the key fields, and only data that corresponds to this selection is read from the database and displayed in the list. This considerably reduces the load on the database and network.

(C) SAP AG

BC400

3

10.4

Overview: Selection Screen Attributes

Selection Selection Screen Screen Attributes Attributes Single Single Fields Fields (PARAMETERS) (PARAMETERS) Value Value Sets Sets (SELECT-OPTIONS) (SELECT-OPTIONS) Selection Selection Screen Screen Events Events



SAP AG 2001

(C) SAP AG

BC400

4

10.5

Selection Screen Attributes

Type checks Multilingual Capacity

Value entry

Variants

?



Input help Possible entries help

SAP AG 2001

Selection screens are input masks for value sets that restrict the amount of data read from the database. The following possibilities are available to the user:  Entries in single fields  Complex entries: Intervals, operations, patterns  Saving filled selection fields as variants  Input help and search helps are available by choosing the F4 function key or the possible entries pushbutton  You can translate selection texts into other languages so that they are then displayed in the language in which the user is logged on.  The system checks the type: If you enter a value with an incorrect type, the system displays an error message and makes the field ready for new input. 

(C) SAP AG

BC400

5

10.6

Entering Value Sets

SELECT-OPTIONS ...

Airline

PARAMETERS ...

Departure city

LH

to

Maintain selection options Airline Single value Greater than or equal Less than or equal Greater than Less than Not equal Select



Exclude from selection

Multiple single values Intervals Single value exclusion Interval exclusion

SAP AG 2001

Selection screens allow you to define selection options for complex entries as well as simple input fields.  Setting selection options  Entering multiple values or intervals  Defining a value set that is not to be selected and is to be subtracted from the value set to be selected at the end.  Every selection screen contains an information icon. Choose this icon to display additional information. 

(C) SAP AG

BC400

6

10.7

Using the Semantic Information of Global Types

Structure

Airline

Global types Data element

Formatting rules

Selection screen

Semantic information

[Search help]

• Field label • Input help • Search help

Technical information:

• Technical type

ABAP program PARAMETERS pa_carr TYPE spfli-carrid.



SAP AG 2001

If an input field is typed with a data element, the following additional semantic information is available:  You can use a field name as a selection text  Input help (F1 help) from the data element is available automatically  Possible entries help (F4 help) is available automatically, provided the data element has been linked with a search help. A search help is a standalone object defined in the Dictionary, which controls the dialog with the user and data retrieval for the possible entries help.  If an input field is typed with a structure field that uses a data element, the following semantic information is available:  Field names and input help (F1 help) are copied from the data element that has been used to type the Dictionary structure field.  If a structure field is coupled with a search help, then this is the search help that is used for the possible entries help (F4 help) - that is, it obscures the data element search help. If there is no search help coupled with the structure field, the system uses the data element search help.  Bear in mind that the global type you choose to provide a type for an input field affects the semantic information available to the user.  For more information, refer to the online documentation for the ABAP Dictionary. 

(C) SAP AG

BC400

7

10.8

Selection Texts

Multilingual capacity ABAP program Text elements Source code

...

Titles/headers Text symbols

SELECT-OPTIONS so_carr FOR ... PARAMETERS pa_city TYPE ...

Airline

LH

SO_CARR

DE EN Airline

PA_CITY

DE EN Departure city

to

Departure city



Selection texts

Dictionary reference

SAP AG 2001

On the selection screen, the field names appear as text next to the input fields. However, you can replace these with selection texts, which you can then translate into any further languages you require. Selection texts are displayed in the user's logon language.  If the input field is typed directly or indirectly with a data element, you can copy the field name from one of the texts stored in the Dictionary. 

(C) SAP AG

BC400

8

10.9

Variants

Airline

LH

to

Departure city

Createaavariant: variant: Create • Fill out the selection screen • Save as a variant • Enter a variant name • Meaning: Enter a descriptive short text • You can also choose other attributes Use the variant: Create a variant: • Start the program • Choose the

icon on the selection screen

• Choose a variant by name • The system copies the values to the input fields 



 

  

SAP AG 2001

If you want to save the values (or some of the values) on a selection screen that you have filled out, you can do so by creating a variant. When you start the program again later, you can get these values from the variant and display them in the selection screen. You can define and save variants for any program that contains a selection screen. You do this by starting the program and then creating a variant by choosing Goto  Variants  Save as variant. Variants allow you to tailor selection screens to suit your needs. You can:  Preassign values for input fields  Hide input fields A single variant can refer to more than one selection screen in the same program. Variants are client-specific. Every selection screen contains an information icon. Choose this icon to display additional information.

(C) SAP AG

BC400

9

10.10

Single Fields (PARAMETERS)

Selection Selection Screen Screen Attributes Attributes Single Single Fields Fields (PARAMETERS) (PARAMETERS) Value Value Sets Sets (SELECT-OPTIONS) (SELECT-OPTIONS) Selection Selection Screen Screen Events Events



SAP AG 2001

(C) SAP AG

BC400

10

10.11

Effect of the PARAMETERS Statement

ABAP program pa_car Declarative statements PARAMETERS PARAMETERS pa_car TYPE s_carr_id.

S_CARR_ID

Selection screen



Reference to ABAP Dictionary

SAP AG 2001

 In an executable program, a single PARAMETERS statement is sufficient to generate a standard selection screen.  The PARAMETERS TYPE statement and the PARAMETERS LIKE statement both generate an elementary input field on the selection screen, and a data object with the same type. 

If the user enters a value and chooses Execute, that value is placed in the internal data object in the program. The system permits only entries with the correct type.

(C) SAP AG

BC400

11

10.12

Runtime Behavior and Data Transport: Parameters

ABAP program Description of selection screen

pa_car Selection screen

ABAP processing block

ABAP runtime system 

SAP AG 2001

Time

Once the LOAD-OF-PROGRAM event block has been processed, the selection screen is sent to the presentation server. The runtime system transports the data object values that are defined using PARAMETERS to the selection screen input fields of the same name.  The user can then change the values in the input fields. If the user then clicks on the Execute function, the input field values are transported to the program data objects with the same name and can be evaluated in the ABAP processing blocks. 

(C) SAP AG

BC400

12

10.13

Using Parameters When Accessing the Database

REPORT ... DATA wa_spfli TYPE spfli. PARAMETERS pa_car TYPE s_carr_id. ... SELECT SELECT carrid connid cityfrom cityto ... FROM spfli INTO CORRESPONDING FIELDS OF wa_spfli pa_ WHERE carrid carrid == pa_car pa_car . WHERE WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-fldate, ... . ENDSELECT . ENDSELECT



SAP AG 2001

If you have used the PARAMETERS statement to program an input field as a key field for a database table, you can use a WHERE clause at the SELECT statement to limit data selection to this value.  In the example above only those data records are read from database table SPFLI whose key field CARRID has the same value as is contained in data object pa_car at runtime. 

(C) SAP AG

BC400

13

10.14

Value Sets (SELECT-OPTIONS)

Selection Selection Screen Screen Attributes Attributes Single Single Fields Fields (PARAMETERS) (PARAMETERS) Value Value Sets Sets (SELECT-OPTIONS) (SELECT-OPTIONS) Selection Selection Screen Screen Events Events



SAP AG 2001

(C) SAP AG

BC400

14

10.15

Effect of the SELECT-OPTIONS Statement

Option sign low high

ABAP program Reference to ABAP Dictionary

so_carr gd_carrid

Selection screen



Declarative statements DATA gd_carrid TYPE s_carr_id. SELECT-OPTIONS SELECT-OPTIONS so_carr FOR gd gd_carrid.

S_CARR_ID

SAP AG 2001

You use the SELECT-OPTIONS name FOR data_object statement to define selection options: Two input fields with the same type as the data object appear on the selection screen, allowing you to enter interval limits. Additionally, a button appears that allows you to realize complex set limits.  The statement also declares an internal table name within the program, with the following four columns:  sign: This field designates whether the value or interval should be included (I) in or excluded (E) from the selection.  option for the operator (BT, ...): For a list of possible operators, refer to the keyword documentation for the SELECT-OPTIONS statement.  low: This field contains the lower limit of an interval or single value.  high: This field contains the upper limit of an interval.  This selection table name always refers to a data object that has already been defined. The data object is used as a target field during database selection, while the selection table is a set of possible values. For this reason a special version of the WHERE clause exists for database selection. It determines whether or not the database contains the corresponding field within the value set.  Note: Similarly, an inclusion test is also defined for the IF statement. 

(C) SAP AG

BC400

15

10.16

Runtime Behavior and Data Transport: Selection Options

ABAP program Description of selection screen

gd_carrid

so_carr Selection screen

ABAP processing block

ABAP runtime system 



SAP AG 2001

Time

If the user enters several values or intervals for a selection option and chooses Execute, the system places them in the internal table.

(C) SAP AG

BC400

16

10.17

Using Selection Options When Accessing the Database

REPORT ... DATA wa_spfli TYPE spfli. SELECT-OPTIONS so_carr FOR wa_spfli-carrid. ... SELECT carrid connid cityfrom cityto ... FROM spfli INTO CORRESPONDING FIELDS OF wa_spfli WHERE carrid IN so_carr carr so_carr. so_ WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom, wa_spfli-cityto, ... ENDSELECT ENDSELECT.



.

SAP AG 2001

The above example shows how you can restrict database selection to a certain range using a selection table.  Conditions in an internal table declared using SELECT-OPTIONS are interpreted as follows:  If the internal table is empty, the condition field IN selname is always true.  If the internal table only contains inclusive elementary conditions, such as i_1, or i_n, the result is the composite condition (i_1 OR ... OR i_n ).  If the internal table only contains exclusive elementary conditions such as e1 or em, the result is the composite condition ( NOT e_1) AND ... AND (NOT e_m)  If the internal table contains inclusive elementary conditions, such as i_1 or i_n, and exclusive elementary conditions, such as e_1 or e_m, the result is the composite condition ( i_1 OR ... OR i_n ) AND ( NOT e_1 ) AND ... AND ( NOT e_m ). 

(C) SAP AG

BC400

17

10.18

Selection Screen Events

Selection Selection Screen Screen Attributes Attributes Single Single Fields Fields (PARAMETERS) (PARAMETERS) Value Value Sets Sets (SELECT-OPTIONS) (SELECT-OPTIONS) Selection Selection Screen Screen Events Events



SAP AG 2001

(C) SAP AG

BC400

18

10.19

Selection Screen Events Program start

LOAD-OF-PROGRAM.

AT SELECTION-SCREEN.

No Yes



SAP AG 2001

START-OF-SELECTION.

Time

In an executable program, the ABAP runtime system generates a standard selection screen as long as you have written at least one PARAMETERS or SELECT-OPTIONS statement. The event block AT SELECTION-SCREEN belongs to the selection screen.  The selection screen is sent after the event block LOAD-OF-PROGRAM.  Each time the user presses , a pushbutton, a function key, or chooses a menu function, the system initially carries out a type check. If the entries do not have the correct type, the system displays an error message, and makes the fields ready for input again. When the entries have the correct type, the system processes the event block AT SELECTION-SCREEN.  Subsequent program flow depends on the user action:  If the user chooses or Execute the next event block is called: in this case START-OFSELECTION.  If the user chose any other function, the selection screen is displayed again. 

(C) SAP AG

BC400

19

10.20

Error Dialogs in AT SELECTION-SCREEN Program start

LOAD-OF-PROGRAM.

No authorization...

AT SELECTION-SCREEN. IF ... Error check

Message text

Error message

START-OF-SELECTION.



SAP AG 2001

Time

Use the event block AT SELECTION-SCREEN if you want to program additional input checks for a standard selection screen.  The event block AT SELECTION-SCREEN is triggered by each user action. If an error dialog is triggered by the MESSAGE statement, the system resends the selection screen and automatically resets all input fields to ready for input.  For more detailed information on the MESSAGE statement, refer to the keyword documentation.  Additional information can be found in the keyword documentation for AT SELECTION-SCREEN. 

(C) SAP AG

BC400

20

10.21

Syntax Example: Selection Screen Authorization Check

PARAMETERS pa_car TYPE s_carr_id. * event processed after leaving the selection screen AT SELECTION-SCREEN. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. IF sy-subrc NE 0. * show selection screen again with message in status bar MESSAGE MESSAGE ee045(bc400) WITH pa_car. ENDIF.



SAP AG 2001

As an example of an additional input check with error dialog, an input field for the airline ID needs to be added to the program.  An authorization check is to be carried out on the selection screen.  If the user has authorization to display the specified airline, the program continues.  If the user does not have display authorization, then the selection screen is displayed again and an error message appears in the status bar. 

(C) SAP AG

BC400

21

10.22

User Dialog List: Unit Summary

You are now able to:  Describe selection screen attributes and strengths  Write a program that allows you to enter intervals on a selection screen and that can be used to restrict the number of data records retrieved from the database  Write a program that contains additional input checks for the selection screen and returns to the selection screen if an error occurs



SAP AG 2001

(C) SAP AG

BC400

22

10.23 Selection Screen Exercises

Unit: Selection Screen

At the conclusion of these exercises, you will be able to:  Use the ABAP statement SELECT-OPTIONS to enter complex values on a standard selection screen.  Take account of complex values in a database selection.  Program an error message for a standard selection screen Extend your program ZBC400_##_DETAIL_LIST or the corresponding model solution as follows: Extend the standard selection screen to allow you to define a complex value set for limiting the connecting flight number. The value set is to be taken into account when selecting flights. Additionally, change your program so that the user can only progress from the selection screen if the authorization check for the desired airline is successful. Program:

ZBC400_##_SEL_SCREEN

Model solution: SAPBC400UDS_SEL_SCREEN Template:

SAPBC400UDS_DETAIL_LIST

1-1

Copy your program ZBC400_##_DETAIL_LIST or the corresponding template SAPBC400UDS_DETAIL_LIST to the new program ZBC400_##_SEL_SCREEN.

1-2

Extend your selection screen to allow the user to enter a complex value range for the flight number CONNID. When you are typing the airline and flight number, make sure you refer to the same structure so that the search helps are context-dependent.

1-3

Use the complex value set to restrict the amount of data selected from the database table SFLIGHT.

1-4

Change your program so that the user cannot progress from the selection screen if the authorization check against the authorization object S_CARRID fails. If the

(C) SAP AG

BC400

23

authorization check fails, display a suitable error message from message class BC400, and allow the user to enter a different value on the selection screen.

(C) SAP AG

BC400

24

10.24Selection Screen Solutions

Unit: Selection Screen

Model solution: Program SAPBC400UDS_SEL_SCREEN *&--------------------------------------------------------------* *& Report SAPBC400UDS_SEL_SCREEN * *& * *&--------------------------------------------------------------* REPORT

sapbc400uds_sel_screen.

CONSTANTS: actvt_display TYPE activ_auth VALUE '03'. DATA: wa_flight TYPE sbc400focc, wa_sbook TYPE sbook. PARAMETERS: pa_car LIKE wa_flight-carrid. * Data field for complex restrictions applied to connection id SELECT-OPTIONS: so_con FOR wa_flight-connid. * First event processed after leaving the selection screen AT SELECTION-SCREEN. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD pa_car ID 'ACTVT' FIELD actvt_display. IF sy-subrc 0. * Return to selection screen again and display message in status * bar MESSAGE ID 'BC400' TYPE 'E' NUMBER '045' WITH pa_car. ENDIF. START-OF-SELECTION. SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF wa_flight WHERE carrid = pa_car AND connid IN so_con. wa_flight-percentage = 100 * wa_flight-seatsocc / wa_flight-seatsmax. WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,'%'. HIDE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ENDSELECT. (C) SAP AG

BC400

25

AT LINE-SELECTION. IF sy-lsind = 1. WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate. ULINE. SKIP. SELECT bookid customid custtype class order_date smoker cancelled loccuram loccurkey FROM sbook INTO CORRESPONDING FIELDS OF wa_sbook WHERE carrid = wa_flight-carrid AND connid = wa_flight-connid AND fldate = wa_flight-fldate. WRITE: / wa_sbook-bookid, wa_sbook-customid, wa_sbook-custtype, wa_sbook-class, wa_sbook-order_date, wa_sbook-smoker, wa_sbook-cancelled, wa_sbook-loccuram CURRENCY wa_sbook-loccurkey, wa_sbook-loccurkey. ENDSELECT. ENDIF.

(C) SAP AG

BC400

26

11 User Dialogs: Screens

Contents:  Screen Attributes and Strengths  Creating Screens Layout Field Attributes Flow Logic  Data Transport  Using Pushbuttons and Evaluating User Actions



SAP AG 2001

(C) SAP AG

BC400

1

11.2

User Dialog Screen: Unit Objectives

At the conclusion of this unit, you will be able to:  Describe screen attributes and strengths  Write a program that: Displays data on a screen Allows the user to change some of that data Allows the user to influence further program processing using pushbuttons



SAP AG 2001

(C) SAP AG

BC400

2

11.3

Screen Attributes

Editing options

?

Input help Possible entries help

Flexible program flow 100

120

200

140

Consistency check during data entry

300

Type checks



SAP AG 2001

 Screens are made up of more than just a screen layout with input and output fields. They also have their own processing logic.  The fact that the ABAP Dictionary is integrated in the system means that automatic consistency checks for screen input fields are provided. These checks include type checks, foreign key checks, and fixed value checks. All of these checks are automatically supplied with information from the ABAP Dictionary.  Checks like the ones above can be complemented by other program-specific checks. With the techniques available for screens , you can control the order in which checks are performed and, if errors occur, make the fields input ready again, where appropriate.  You can also set up screen layout in a very flexible way. Input fields, output fields, radio buttons, checkboxes, and even pushbuttons can be placed on screens. These features allow users to determine the direction in which the program will proceed.  The same editing options are available for the screen as for list display and the selection screen: the fixed point numbers and the date are set according to the user default values, the time in format hh:mm:ss, amounts according to the setting in a currency field, and lengths and weights according to the content of a unit-of-measure field.

(C) SAP AG

BC400

3

11.4

Options for Calling Screens

Transaction code 100

200

120

140

CALL SCREEN 100. 300





SAP AG 2001

To start a screen sequence:  Specify the first screen as the start screen of a transaction code of the type dialog transaction  Call a screen from any one ABAP processing block in the program



This unit concentrates on the latter option.

(C) SAP AG

BC400

4

11.5

Application Example: Destination

Timetable Flgt LH LH ... SQ

Conn. Dept Conn. 0400 FRA Frankfurt 0400 FRA Frankfurt 0002 SIN

JFK JFK

Dest. Dest. New York New York

Singapore SFO San Francisco Change flight data Airline Flight number

Screen

LH 0400

Departure airport FRA Destination airport JFK Change in database

Flight duration Departure time Save





8:24 10:10:00 Back

SAP AG 2001

In the following units, you will develop a program, in several steps, that enables the user to change the master data of the flight timetable.  Double-clicking on an entry in the basic list containing the flight timetable calls a screen, which displays data from the line you selected, and additional information about the flight connection. You can change the flight duration and the departure time.  Choosing Back takes the user back to the basic list without changing any data.  Choosing Save changes the data in the database.



There is a function module for database changes that is implemented later on (see the unit about Cross-Program Modularization).

(C) SAP AG

BC400

5

11.6

Components for Screen Processing

Screen Painter

Attributes Screen number Short text Screen type Next screen ...





Layout Departure City

Element list Attributes: CHAR20 Required entry field ...

Flow control PROCESS BEFORE OUTPUT. MODULE clear_ok_code. PROCESS AFTER INPUT. MODULE user_command.

SAP AG 2001

Each screen has the following information:  Attributes: Include a four-digit number as the screen name, designation, and a short text information on the screen type (for example, normal for full size screen).  Layout: Includes elements you can place on the screen. Elements that are displayed on the screen are called screen elements.  Element list: Contains the attributes of the screen elements, such as the position, size, and data type.



Flow control: Contains the processing logic that is to be processed before the screen is sent to the presentation server (PBO) and the processing logic that is to be processed after a user action has taken place.

(C) SAP AG

BC400

6

11.7

Editing Window in the Graphical Layout Editor

Graphical Layout Editor Element attributes

Toolbar

Layout area

Create fields with reference to the Dictionary

Element list





SAP AG 2001

From the Graphical Layout Editor, you can start other functions:  Element attributes: All the attributes of a screen element are displayed in this dialog box. You can change some of the attributes in the box. Example: you can specify whether or not an input/output field is to be input ready.  Get from ABAP Dictionary / Get from program: This dialog box allows you to generate fields that have either a global type or the same type as a data object in the program.  Element list: Shows all the elements displayed on the screen with their attributes. You can also change attributes here..

(C) SAP AG

BC400

7

11.8

Example of Level 1: Create Screen

Timetable Flgt LH LH ... SQ

Conn. Dept Conn. 0400 FRA Frankfurt 0400 FRA Frankfurt 0002 SIN

JFK JFK

Dest. Dest. New York New York

Singapore SFO San Francisco Change flight data

Screen

Airline Flight number Departure airport Destination airport Flight duration Departure time



SAP AG 2001

Your first step is to create a screen, specify its layout, and define its field attributes. The fields Airline, Flight number, Departure airport, and Destination airport are to appear as output fields. The fields Flight duration and Departure time are available as input-ready fields.  The user should be able to call the screen by double-clicking a line within the basic list and return to the basic list by choosing the appropriate function on the screen. 

(C) SAP AG

BC400

8

11.9

Creating a Screen: Screen Attributes

ABAP

Create object

: AT LINE-SELECTION. : CALL SCREEN 100 100. Double-click :

Screen Painter

Screen 100 does not exist. Do you want to create the object? Yes

No

Cancel

Screen Attributes Short text

Supplemental data display

Screen type Normal Subscreen Modal dialog box Next screen 



0

SAP AG 2001

There are several ways to create screens:  Through forward navigation: You can create screens from within the ABAP Editor by doubleclicking on the screen number. This transfers you to Screen Painter automatically.  Using Object Navigator: You can create a new program object screen for your program directly from the object list in the navigation area.



When you create a screen, the system will ask you to enter screen attributes. Enter a short description of the screen, select screen type Normal, and enter the number of the subsequent screen.



If you enter 0 for the subsequent screen, the system first processes your screen completely and then returns to processing at the point where the screen call is set. (Note that "0" in the entry field for the subsequent dynpro is not displayed because this is actually the inital value.)



In the example in the graphic, the screen the user creates is called from within the basic list. Therefore, CALL SCREEN 100 must belong to the AT LINE-SELECTION event block.

(C) SAP AG

BC400

9

11.10

Input Fields with Reference to Fields of a Dictionary Structure

T

X

SDYN_CONN

Airline Flight number Departure airport Destination airport Flight duration Departure time



SAP AG 2001

There are two ways of assigning field attributes to the required screen fields:  Copying data from the Dictionary: You can copy types and field attributes from existing ABAP Dictionary structures. This makes all information about the object available to you, including semantic information about its data elements and foreign key dependencies. The name of the Dictionary field is automatically adopted as a field name.  Copying data from the program: You can copy field attributes from data objects already defined within your program to the screen. In order to do this, however, an activated copy of the program must already exist. The name of the data object is automatically taken as the field name.  The Graphical Screen Painter allows you to define different screen elements (for example, input and output fields, keyword texts, borders, and so on) with relative ease. Choose the desired screen element and then place it on the screen using the mouse. 



You can delete screen elements simply by pointing to them and choosing Delete.



You can move screen elements by selecting them and dragging them to a new position.

(C) SAP AG

BC400

10

11.11

Changing the Element Attributes of a Field: Attribute Window

Attributes T

Name Text Line

Airline Flight number X

Departure airport Destination airport Flight duration Departure time



SDYN_CONN-CARRID

Colu mn

FCode

FTyp e Dict Prog Disp

Input field Output field Required field ...

SAP AG 2001



To maintain the attributes of a screen field, select the field and choose Attributes.



You can assign the attribute mandatory (Required field) to a screen field. At run time, the field will be marked accordingly if it is set to initial value.



If not all required fields have been filled at run time and a user action is performed, an error dialog is triggered by the ABAP run time system and all input fields are once again displayed ready for input.

(C) SAP AG

BC400

11

11.12

Example Level 2: Displaying Data

Timetable Flgt LH LH ... SQ

Conn. Dept Conn. 0400 FRA Frankfurt 0400 FRA Frankfurt 0002 SIN

JFK JFK

Dest. Dest. New York New York

Singapore SFO San Francisco Change flight data Airline Flight number

Screen

LH 0400

Departure airport FRA Destination airport JFK Flight duration Departure time



8:24 10:10:00

SAP AG 2001



In step two you learn how to display data on a screen by programming data transport from the basic list to the screen.



For the user, the program works in the following manner:  By double-clicking on a line in the basic list, the user branches to the screen where the most important items of information for the flight connection he or she has chosen are displayed. The flight duration and departure time are displayed in a field that is ready for input and hence can be changed.  The user returns to the basic list in one of several ways.



With this in mind, this part of the unit will deal with:  Setting up prerequisites for automatic data transport between the program and screen fields  Defining the screen interface and programming data transport to the data objects of the interface

(C) SAP AG

BC400

12

11.13

Screen Interface

Data objects

ABAP program wa_spfli sdyn_conn Declarative statements DATA wa_spfli TYPE spfli. TABLES sdyn_conn. TABLES SDYN_CONN

Process Before Output Process After Input



ABAP processing block Screen

SAP AG 2001



The TABLES statement defines an internal data object that serves as an interface for the screen. The TABLES statement always refers to an ABAP Dictionary object (for example, transparent table or structure).



If the screen fields and the TABLES statement refer to the same ABAP Dictionary object, this data object's data is automatically transported to the screen fields every time the screen is transmitted. Any new entries or changes that the user makes on the screen are then transferred back into this data object.



As a rule, structures that contain fields of the same type for the different tables are created in the ABAP Dictionary. The flight data programs being created in this course use one structure for master data maintenance (sdyn_conn) and another for bookings data (sdyn_book). Using your own structures as interfaces usually helps make a program easier to understand and helps to avoid errors as well.

(C) SAP AG

BC400

13

11.14

Data Transport from the Program to the Screen

ABAP program wa_spfli sdyn_conn

DATA wa_spfli TYPE spfli. TABLES sdyn_conn. Process Before Output

CALL SCREEN 100.

Process After Input

Screen 100 ABAP runtime system 

SAP AG 2001

Time

Data transport between program data objects and screen fields with the same name takes place automatically: Immediately before the screen is sent to the presentation server, that is, after the PBO event has been fully processed, the contents from fields with the same names are copied from the ABAP work area into the screen fields.  ABAP statements facilitate data transport between ABAP program data objects and the work area designated as the screen interface. 

(C) SAP AG

BC400

14

11.15

Data Transport from the Screen to the Program

wa_spfli sdyn_conn

Process Before Output

CALL SCREEN 100.

Process After Input

Screen 100



SAP AG 2001

Time

Data transport between screen fields and program data objects with the same name takes place automatically: Immediately after a user performs an action on the screen, that is, before the PAI event is fully processed, the contents of the fields with the same name are copied from the screen fields into the ABAP work area.  ABAP statements facilitate data transport between jects the work area designated as the screen interface and program data objects.. 

(C) SAP AG

BC400

15

11.16

Data Transport in the Program Example

Automatic data transport HIDE area in data objects AT LINE-SELECTION. Fill the TABLES structure with current data for selected line TABLES structure in screen fields

CALL SCREEN 100.

Screen fields in TABLES structure ABAP runtime system 

SAP AG 2001

Time



The sample program should display screen data that matches the line selected in the basic list.



If data objects and their values were stored in the HIDE area when the basic list was created, the data belonging to the selected line will be placed in the corresponding data objects.



You must copy the data to be displayed on the screen to a TABLES structure. You can do this in any ABAP processing block that is processed before the screen is sent to the presentation server. There are various ways of doing this:  You start by reading all the data to be displayed on the screen before retrieving the basic list from the database. You then place all the necessary data in the HIDE area. Then, at the AT LINESELECTION event, you have to copy the data into the TABLES structure only. Disadvantage: You have to read data from the database that the user may not even look at. If detailed data has changed between creating the basic list and displaying the screen, the system will display the wrong data.  Before the screen is called using the SELECT SINGLE statement, you read the additional data for the selected key (HIDE area) from the database. Advantage: You reduce the volume of data you need to read from the database when you create the basic list. The detailed list is up-to-date. Disadvantage: The system sends a query to the database every time the user double-clicks the list.

(C) SAP AG

BC400

16

11.17

Implementing the Sample Program Structure: Fields:

wa_spfli Basic HIDE Area List

MANDT CARRID CONNID COUNTRYFR CITYFROM AIRPFROM COUNTRYTO CITYTO AIRPTO FLTIME DEPTIME ARRTIME DISTANCE DISTID FLTYPE

 

 

sdyn_conn Screen: Output Field Input Field  







  

 

Before calling the screen: screen: SELECT SINGLE * FROM spfli ... 

SAP AG 2001



On the last development level, the program should allow the user to change data in the database. The user should be able to change the fields FLTIME and DEPTIME. To enable the user to change data for several airlines, a basic list of the airlines for which the user is allowed to change data should be displayed. The user reaches the change screen by double-clicking in the basic list. Once the changes are made successfully, the user returns to the basic list. However, a new basic list is not created. Therefore, the data that can be changed should not appear on the basic list.



To ensure that the database data displayed on the screen is up-to-date, the record is read again from the database at the beginning of AT LINE-SELECTION.



Advantages of this method:  For the basic list, only those columns of the database table that are displayed on the list need to be read. This can improve performance with large lists.  The data that is displayed on the screen is always up-to-date, even if the data record selected has just been changed using this program.  Changes made to the database using the screen do not lead to incorrect values in the basic list because the modifiable fields are not contained in the basic list.

(C) SAP AG

BC400

17

11.18

Syntax: Sample Program with Data Transport START-OF-SELECTION. SELECT carrid connid airpfrom cityfrom airpto cityto INTO CORRESPONDING FIELDS OF wa_spfli FROM spfli. WRITE: / wa_spfli-carrid COLOR COL_KEY, wa_spfli-connid COLOR COL_KEY, ... * buffering key fields wa_ wa_ HIDE: wa_spfli-carrid, wa_spflispfli-carrid, carrid, wa_spfli-connid. wa_spflispfli-connid. connid. ENDSELECT. AT LINE-SELECTION. SELECT SINGLE SINGLE ** FROM FROM spfli spfli SELECT INTO wa_spfli wa_ INTO wa_spfli WHERE carrid carrid == wa_spfli-carrid wa_ WHERE wa_spflispfli-carrid AND connid connid == wa_spfli-connid. wa_ AND wa_spflispfli-connid. connid. MOVE-CORRESPONDING wa_ wa_spfli to sdyn_ sdyn_conn. conn. CALL SCREEN 100. 

SAP AG 2001



To display data on the screen, the TABLES structure must be filled with current data before the screen is sent to the presentation server. The example in the graphic shows one way of doing this.



The HIDE statement is used to place key fields of database tables with reference to the list line in the HIDE area. Then the current data for the line selected is available in fields wa_spfli-carrid and wa_spfli-connid at event AT LINE-SELECTION.



The data record is read from the database using SELECT SINGLE. This ensures that the data is upto-date.



The corresponding fields of the wa_spfli work area are copied to the TABLES structure sdyn_conn using MOVE-CORRESPONDING. The system transports the structure data to the screen fields automatically.



Alternatively, you can place the data into the TABLES structure directly when the database is accessed, using the INTO CORRESPONDING FIELDS addition.

(C) SAP AG

BC400

18

11.19

Example Level 3: Assigning Pushbuttons

Timetable Flgt LH LH ... SQ

Conn. Dept Conn. 0400 FRA Frankfurt 0400 FRA Frankfurt 0002 SIN

JFK JFK

Dest. Dest. New York New York

Message 1 in status line

Singapore SFO San Francisco Change flight data Airline Flight number

Message 2in status line

Screen

LH 0400

Departure airport FRA Destination airport JFK Flight duration Departure time Save 

8:24 10:10:00 Back

SAP AG 2001

In step three you learn how to assign pushbutton functions. These functions allow different kinds of program logic to be processed according to user choice.  For the user, the program works in the following manner:  By double-clicking on a line, the user branches to a screen where the most important items of information for the connection the user chose are displayed. The flight duration and departure time can be changed.  By choosing the Back pushbutton, the user returns to the basic list without writing any changes to the database. The message "Screen was left without any changes being made" is displayed in the status bar of the basic list.  Choose Save to write all of your changes to the database. The changes take effect in the program only at a later time. The pushbutton is already prepared in the following section. The user returns to the basic list after choosing the pushbutton and a message is displayed in the status bar. .  After each other user activity, the screen is displayed once again.  With this in mind, this part of the unit deals with:  Flow logic in PBO and PAI event blocks  Using PBO and PAI modules as ABAP processing blocks for screen programming  Evaluating information on which pushbutton was selected at the time of PAI 

(C) SAP AG

BC400

19

11.20

Runtime Behavior When User Chooses a Pushbutton

ABAP program Global data object Back BACK

ok_code

Function code BACK CASE ok_code. WHEN 'BACK'. ... ENDCASE.

ABAP runtime system 

SAP AG 2001

Time



If the user chooses a pushbutton, the run time system copies the associated function code to a special screen field. This screen field is usually called the ok_code.



The content of this screen field is then automatically transported if there is an ABAP data object of the same name.



The content of this ok_code field can then be evaluated in an ABAP processing block.



This mechanism allows you to create a program flow that depends on the user's actions. The following slides deal with how you declare the ok_code field, how you create pushbuttons and assign function codes to them, and how you can change the screen sequence.

(C) SAP AG

BC400

20

11.21

Defining Pushbuttons / Assigning Function Codes

Attributes T

Name Text Line

Airline Flight number X

Departure airport Destination airport

FCode BACK FType

Flight time Departure time Save





BUTTON2 Back Colum n

Dict Prog Disp

Back

Input field Output field ...

SAP AG 2001

To be able to transport information as to which pushbutton was chosen, you must assign a function code to each pushbutton. You can do this either in the Graphical Layout Editor using the maintenance function for field attributes or from the element list.

(C) SAP AG

BC400

21

11.22

Making the Command Field Usable ABAP Editor 2

TABLES sdyn_conn. DATA: ok_code like sysy-ucomm. DATA ok_ _code LIKE -ucomm. ok sy ucomm.

Screen Painter

Screen Painter: Painter: List of Elements General attributes

OK

Field name

Field text

BUTTON1 BUTTON2 OK_CODE

Save Back

...

Function code ...

SAVE BACK

1 

SAP AG 2001

The command field serves as a special field into which corresponding function codes are placed after every user action.  This field must be given a name in the last line of the list of elements on each screen. Generally, you use the name OK_CODE.  In the declaration part of the program, define a corresponding data object with the same name. At run time, whenever a user action is triggered, the function code of the pushbutton chosen is placed into the data object. You can use the system field sy-ucomm as a reference field for the type. 

(C) SAP AG

BC400

22

11.23

Calling Modules

100

CALL SCREEN 100.

PBO

MODULE name.

MODULE name OUTPUT. ENDMODULE.

PAI

MODULE name.



MODULE name INPUT. ENDMODULE.

SAP AG 2001 Time

The ABAP statement CALL SCREEN interrupts the processing of the processing block and calls a screen.  Each screen has two event blocks:  PROCESS BEFORE OUTPUT (PBO) is processed immediately before a screen is displayed. At this time, modules are called that take care of tasks such as presetting values in screen fields.  PROCESS AFTER INPUT (PAI) is processed immediately after a user action. All program logic that is influenced by user action must be processed at PAI. 



Note: The code for the events PBO and PAI is written using the Screen Painter, not with the ABAP Editor. These two event blocks make up the flow logic of a screen. A special small set of commands (not ABAP statements) is available for programming flow logic. The most important statement here is called: MODULE module_name. This calls the module_name ABAP processing block. Within this block you can code in ABAP as usual.



Modules are ABAP processing blocks with no interface that can be called only from within the flow logic. Modules are enclosed within the ABAP statements MODULE and ENDMODULE.

(C) SAP AG

BC400

23

11.24

Evaluating the Function Code for PAI

Screen Painter

ABAP Editor

PROCESS BEFORE OUTPUT.

Save

Back

user_ MODULE user_command_0100 user_command_0100 command_0100 INPUT.

PROCESS AFTER INPUT. MODULE _command_0100. user command_0100. MODULE user_ user_command_0100.

CASE CASE ok_code. WHEN 'BACK'. ... WHEN 'SAVE'. ... ENDCASE. ENDMODULE.



SAP AG 2001



You can evaluate user actions in a PAI module. Usually, this PAI module is called user_command_nnnn, where nnnn stands for the screen number. In this module, evaluate the function code in the ok_code field.



Note: For historical reasons, modules have no interface and no local variables. You can access all the ABAP program's global data in modules.

(C) SAP AG

BC400

24

11.25

Creating Modules Using Forward Navigation Screen Painter PROCESS AFTER INPUT. MODULE user_command_100.

Create object PAI module USER_COMMAND_100 does not exist. Do you want to create the object?

Yes

No

Cancel

Create PAI module PAI module

USER_COMMAND_0100

Include selection

ABAP Editor

ZBC400_00_DYNPRO

New include Main program

MODULE user_command_100 INPUT. ENDMODULE. 

SAP AG 2001

As a rule, you implement MODULE calls within a screen's flow control (PBO and PAI events). The modules themselves are created using ABAP.  There are two ways to create a module:  Forward navigation: To create a module, double-click on the module name in the flow logic from within the Screen Painter.  Navigation area: If you want to create a module from within the object list of the program, choose a new program object PBO module or PAI module.  A module can be called from more than one screen (reusability).  Make sure that modules called at PBO events are defined using the statement MODULE ... OUTPUT, whereas modules defined using the statement MODULE ... INPUT can be called only at PAI events. 

(C) SAP AG

BC400

25

11.26

Next Screen: CALL SCREEN Statement

100

CALL SCREEN 100.

PBO

PAI

Screen attributes Next screen





0

Next screen 0

SAP AG 2001 Time

If you enter 0 for the next screen, the system first processes your screen completely and then continues processing the program from the point where the screen was called.

(C) SAP AG

BC400

26

11.27

Next Screen: Set Statically

100

CALL SCREEN 100. ...

PBO

PAI

Screen attributes Next screen





100

Next screen 100

SAP AG 2001 Time

If you set the next screen for screen 100 to 100, the system processes the screen again after it has finished processing the PAI module.

(C) SAP AG

BC400

27

11.28

Next Screen: Set Dynamically

100

CALL SCREEN 100. ...

PBO

PAI

SET SCREEN 0. SET SCREEN 0. 0

Screen attributes Next screen



100

Next screen 0

SAP AG 2001 Time

Using the ABAP statement SET SCREEN nnnn from within a PAI module, you can have the next screen set dynamically. The static entry is then suppressed.  The number of the current screen is entered by the system as the standard entry for the next screen. This ensures that the Enter key or the green checkmark lead to a field check only; afterwards the screen is transmitted once again, possibly with a respective error message. To leave the screen, an appropriate pushbutton must be defined that triggers a screen change within the PAI module. 



Note: If the system processes the same screen again, it also runs through all the PBO modules again. If you decide to fill the TABLES structure in a PBO module, make sure that data changes made by the user are not overwritten on the screen if the module gets called twice

(C) SAP AG

BC400

28

11.29

Syntax Example: Evaluating the Function Codes

DATA ok_code LIKE sy-ucomm. . . MODULE user_command_0100 INPUT. CASE ok_ ok_code. code. ok_code. WHEN WHEN 'BACK'. 'BACK'. SET SCREEN 0. MESSAGE s057(BC400). WHEN WHEN 'SAVE'. 'SAVE'. * calling a function module to save changes * is left out for didactical reasons SET SCREEN 0. MESSAGE s057(BC400). ENDCASE. ENDMODULE.





SAP AG 2001

For the example for evaluating function codes, two pushbuttons are discussed:  Choosing BACK dynamically sets this value to 0. This sends the user back to the callpoint. In our case, this means the user returns to the basic list. Message 057 appears in the status bar of the next screen.  With SAVE, the program behaves in the same way as BACK. The user returns to the basic list; however, there is a new message in the status bar. In the unit about Cross-Program Modularization, the program is enhanced with a data record change.

(C) SAP AG

BC400

29

11.30

Runtime Behavior for Special Situation: No Function Code Is Assigned to the ENTER Key Basic list

Screen 100 Screen field

OK_CODE Double-click

Data object

ok_code Transmit screen 100

BACK

BACK

Double-click BACK

BACK 

SAP AG 2001

BACK

BACK

Back to basic list Transmit screen 100

Back to basic list?

Time



This section walks through a particular scenario to point out the necessity of an additional program step.



The user starts the program and double-clicks to display detailed information on the screen. After determining that all the data is correct the user returns to the basic list by choosing the green arrow. In this way, the function code BACK, which is assigned to this standard pushbutton, is placed in the command field and then it is transported automatically to the global data object ok_code of the ABAP program. This function code is then evaluated in a PAI module. The next screen is set to 0.



Then AT LINE-SELECTION is processed further. If there is no WRITE statement there, the system displays the basic list again.



The user then displays details for another record by double-clicking it. Through automatic field transport, the content of the global data object ok_code is transported into the screen field with the same name and the screen is displayed.



If the user now chooses Enter, the screen is displayed once again, provided no function code has been assigned to the Enter key. (Standard case!) Therefore, the command field is not overwritten. The function code BACK remains in the command field and is copied to the global data object ok_code at the beginning of the PAI event.



This function code is then evaluated in a PAI module. Consequently, as described above, the system goes back to the basic list, instead of displaying the screen again.

(C) SAP AG

BC400

30

11.31

Solution Option: Deleting the Command Field for PBO Screen Painter

ABAP Editor

PROCESS BEFORE OUTPUT. MODULE _ok_ clear ok_code. code. MODULE clear_ clear_ok_code.

Save

clear_ MODULE clear_ok_code clear_ok_ ok_code OUTPUT. ok_code. CLEAR ok_ ok_code. code. ENDMODULE. ENDMODULE.

Back

PROCESS AFTER INPUT. MODULE user_command_0100.





MODULE user_command_0100 INPUT. CASE ok_code. ... ENDMODULE.

SAP AG 2001

If the command field is not initialized, errors can occur since not every pushbutton must have a function code assigned to it. There are two ways to initialize a command field:  Initialize the ok_code field in a PBO module. Then it is set to the initial value at PAI, unless the user has carried out a user action to which a function code is assigned. In this case, the ok_code field contains the current function code.  Use an auxiliary field and copy the content of the ok_code field into the auxiliary field in a PAI module, then initialize the ok_code field. In this case, the auxiliary field must be queried in the PAI module for the function code evaluation.

(C) SAP AG

BC400

31

11.32

User Dialog Screen: Unit Summary

You are now able to:  Describe screen attributes and strengths  Write a program that: Displays data on a screen Allows the user to change some of that data Allows the user to influence further program processing using pushbuttons



SAP AG 2001

(C) SAP AG

BC400

32

11.33Screen Exercises

Unit: Screen Topic: Creating Screens At the conclusion of these exercises, you will be able to:  Create screens  Call existing screens from the program The program SAPBC400UDT_DYNPRO_A enables you to display all bookings made by one travel agency as a list. As a first step, change the program as follows: A screen is to be called whenever the user double-clicks a line in the basic list. This screen should contain input fields for specific booking data that is not displayed on the list. This screen should also contain output fields for booking information that is already displayed on the list. Any user action should result in the basic list being displayed again Program:

ZBC400_##_DYNPRO

Model solution:

SAPBC400UDS_DYNPRO_A

Template:

SAPBC400UDT_DYNPRO_A

1-1

Copy the template SAPBC400UDT_DYNPRO_A to your new program ZBC400_##_DYNPRO.

1-2

Become familiar with the program. Test the program using the travel agency number 1## (## is your group number).

1-3

Selecting a line on the basic list (by double-clicking or using F2) should call a screen. Create this screen (screen number 100) using forward navigation.

1-4

For the attributes, assign screen number 0 as the number of the next screen, so that after any user action on screen 100, the user returns to the basic list.

1-5

Create input/output fields on the screen. When you are assigning field types, refer to ABAP ABAP Dictionary structure SDYN_BOOK.



Copy booking table key fields CARRID, CONNID, FLDATE, and BOOKID with their field labels.



The customer name NAME should be copied without a field label and should be displayed next to the customer number.

(C) SAP AG

BC400

33



The fields CUSTOMID, CUSTTYPE, SMOKER, CLASS, LOCCURAM, and LOCCURKEY should be copied with field labels.

1-6

Maintain the screen field attributes:



Fields CARRID, CONNID, FLDATE, BOOKID, and CUSTOMID should be displayed as output fields (Output field attribute).



The customer name NAME should be displayed next to the customer number without text (Output only attribute).



The fields CUSTTYPE, SMOKER, CLASS, LOCCURAM, and LOCCURKEY are input/output fields (Input field/Output field attributes).

(C) SAP AG

BC400

34

Exercises Unit: Screen Topic: Data Transport At the conclusion of these exercises, you will be able to:  Fill the screen fields with data from the program

Change your program ZBC400_##_DYNPRO: Double-clicking on a line of the basic list displays details of the selected booking on the screen. If the user changes data on the screen, then these changes should be available in the program once the user has left the screen.

2.1 2.2 2-3

2-4

2-5

(C) SAP AG

Program:

ZBC400_##_DYNPRO

Model solution:

SAPBC400UDS_DYNPRO_B

Change your program ZBC400_##_DYNPRO or copy the template SAPBC400UDS_DYNPRO_A to the new program ZBC400_##_DYNPRO_B. In your program, use the TABLES statement to create a work area with the same name. This work area will then serve as the screen interface. Ensure that the key fields of the SBOOK database table and the customer name are still available (HIDE: ...) in the AT LINE-SELECTION event block after a line has been selected on the basic list (double click or F2). Change your program accordingly so that data in the database can be changed. Make sure that the screen can be processed only if the user has change authorization for the airline selected. Before the screen is called, retrieve the data of the selected posting from the SBOOK database table into a suitable work area (name proposal: wa_sbook) To make sure that the data is up-to-date. If the data record cannot be read, the system must display information message 176 from message class BC400. If the data is read successfully, call the screen. Immediately before the screen is called, copy the relevant data into the TABLES work area.

BC400

35

Exercises Unit: Screen Topic: Field Transports and Subsequent Screen Processing At the conclusion of these exercises, you will be able to:  Create pushbuttons on screens  Process the system code triggered when the user clicks on a pushbutton and thus control the program flow  Set the next screen dynamically Change your program ZBC400_##_DYNPRO: On the screen, the user should be able to control program flow through two pushbuttons. Program:

ZBC400_##_DYNPRO

Model solution:

SAPBC400UDS_DYNPRO_C

3-1

Change your program ZBC400_##_DYNPRO or copy the template SAPBC400UDS_DYNPRO_B to the new program ZBC400_##_DYNPRO_C.

3-2

Define two pushbuttons on the screen that allow the user to either return to the basic list (PUSH_BACK) or to save the changed data (PUSH_SAVE):

Name of pushbutton PUSH_BACK PUSH_SAVE

Text Back Save

Function code BACK SAVE

or icon ICON_SYSTEM_SAVE 3-3 3-4

Name the OK_CODE field on the screen and define a data object of the same name (and corresponding type) in the program. Navigate in the flow logic. Create a module for function code processing (using forward navigation) at PROCESS AFTER INPUT:

Function code BACK SAVE (C) SAP AG

Action None First: BC400

Next screen List List 36

Function code

Action

Next screen

Information message no. All others 3-5

(C) SAP AG

060(BC400) None

Screen 100

Ensure that pressing Enter always displays screen 100, regardless of the navigation history. Initialize the OK_CODE field in a PBO module.

BC400

37

11.34Screens Solutions

Unit: Screens Topic: Creating Screens

Model Solution: Program SAPBC400UDS_DYNPRO_A *&--------------------------------------------------------------* *& Report SAPBC400UDS_DYNPRO_A * *& * *& * *&--------------------------------------------------------------* REPORT sapbc400uds_dynpro_a. CONSTANTS actvt_display TYPE activ_auth VALUE '03'. * Definition of selection screen PARAMETERS pa_anum TYPE sbook-agencynum. * workarea for select DATA: wa_booking TYPE sbc400_booking. START-OF-SELECTION. * selecting data using an ABAP dictionary view to get the data from * sbook and the customer name from scustom SELECT carrid connid fldate bookid customid name FROM sbc400_booking INTO CORRESPONDING FIELDS OF wa_booking WHERE agencynum = pa_anum. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_display. IF sy-subrc = 0. * Output WRITE: / wa_booking-carrid COLOR col_key, wa_booking-connid COLOR col_key, wa_booking-fldate COLOR col_key, wa_booking-bookid COLOR col_key, wa_booking-name. ENDIF. ENDSELECT. AT LINE-SELECTION. CALL SCREEN 100.

1-3 (C) SAP AG

Create a screen using forward navigation BC400

38

(double-click 100 in the CALL SCREEN 100 statement). 1-4

Maintain screen attributes - Enter a descriptive short text - Set the next screen to 0

1-5

Layout - Navigate to the Graphical Layout Editor - Choose the Dict/Program fields icon - Enter SDYN_BOOK - Choose the Get from Dictionary icon - Select the fields you want choose Enter to confirm, and drag these fields to the screen - 1st Block: Copy key fields: CARRID, CONNID, FLDATE, and BOOKID with field names - 2nd Block: Copy customer name NAME without a field name (choose the Without text radio button) - 3rd Block: Copy the fields: CUSTOMID, CUSTTYPE, SMOKER, CLASS, LOCCURAM, and LOCCURKEY with field names

1-6

Change the field attributes for example, by double-clicking the input field - Change the attributes: - The fields CARRID, CONNID, FLDATE, BOOKID, and CUSTOMID should be displayed as output fields (Output field attribute). - The customer name NAME should be displayed next to the customer number without text (Output only attribute). - The fields CUSTTYPE, SMOKER, CLASS, LOCCURAM, and LOCCURKEY should be both input-ready and output-ready (the Input/Output field attribute). .

(C) SAP AG

BC400

39

Solutions Unit: Screens Topic: Data Transport

Model Solution: Program SAPBC400UDS_DYNPRO_B *&--------------------------------------------------------------* *& Report SAPBC400UDS_DYNPRO_B * *& * *& * *&--------------------------------------------------------------* REPORT sapbc400uds_dynpro_b. CONSTANTS: actvt_display TYPE activ_auth VALUE '03', actvt_change TYPE activ_auth VALUE '02'. * Definition of selection screen PARAMETERS pa_anum TYPE sbook-agencynum. * workarea for list DATA wa_booking TYPE sbc400_booking. * workarea for single booking to be changed DATA wa_sbook TYPE sbook. * workarea for dynpro TABLES sdyn_book. START-OF-SELECTION. * selecting data using an Adictionary view to get the data from * sbook and the customer name from scustom SELECT carrid connid fldate bookid customid name FROM sbc400_booking INTO CORRESPONDING FIELDS OF wa_booking WHERE agencynum = pa_anum. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_display. IF sy-subrc = 0. * Output WRITE: / wa_booking-carrid COLOR col_key, wa_booking-connid COLOR col_key, wa_booking-fldate COLOR col_key, wa_booking-bookid COLOR col_key, wa_booking-name. HIDE:

(C) SAP AG

wa_booking-carrid, wa_booking-connid, wa_booking-fldate, wa_booking-bookid, wa_booking-name. BC400

40

ENDIF. ENDSELECT. AT LINE-SELECTION. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_change. IF sy-subrc = 0. SELECT SINGLE * FROM sbook INTO wa_sbook WHERE carrid = wa_booking-carrid AND connid = wa_booking-connid AND fldate = wa_booking-fldate AND bookid = wa_booking-bookid. IF sy-subrc = 0. MOVE-CORRESPONDING wa_sbook TO sdyn_book. MOVE wa_booking-name TO sdyn_book-name. CALL SCREEN 100. ENDIF. ELSE . MESSAGE ID 'BC400' TYPE 'S' NUMBER '047' WITH wa_booking-carrid. ENDIF.

(C) SAP AG

BC400

41

Unit: Screens Topic: Field Transports and Subsequent Screen Processing

Model Solution: Program SAPBC400UDS_DYNPRO_C *&--------------------------------------------------------------* *& Report SAPBC400UDS_DYNPRO_C * *& * *& * *&--------------------------------------------------------------* REPORT sapbc400uds_dynpro_c. CONSTANTS: actvt_display TYPE activ_auth VALUE '03', actvt_change TYPE activ_auth VALUE '02'. * Definition of selection screen PARAMETERS pa_anum TYPE sbook-agencynum. * workarea for list DATA wa_booking TYPE sbc400_booking. * workarea for single booking to be changed DATA wa_sbook TYPE sbook. * workarea for dynpro TABLES sdyn_book. * variable for function code of user action DATA ok_code LIKE sy-ucomm. START-OF-SELECTION. * selecting data using a dictionary view to get the data from * sbook and the customer name from scustom SELECT carrid connid fldate bookid customid name FROM sbc400_booking INTO CORRESPONDING FIELDS OF wa_booking WHERE agencynum = pa_anum. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_display. IF sy-subrc = 0. * Output WRITE: / wa_booking-carrid COLOR col_key, wa_booking-connid COLOR col_key, wa_booking-fldate COLOR col_key, wa_booking-bookid COLOR col_key, wa_booking-name. HIDE: (C) SAP AG

wa_booking-carrid, wa_booking-connid, BC400

42

wa_booking-fldate, wa_booking-bookid, wa_booking-name. ENDIF. ENDSELECT. CLEAR wa_booking. AT LINE-SELECTION. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_change. IF sy-subrc = 0. SELECT SINGLE * FROM sbook INTO wa_sbook WHERE carrid = wa_booking-carrid AND connid = wa_booking-connid AND fldate = wa_booking-fldate AND bookid = wa_booking-bookid. IF sy-subrc = 0. MOVE-CORRESPONDING wa_sbook TO sdyn_book. MOVE wa_booking-name TO sdyn_book-name. CALL SCREEN 100. ENDIF. ELSE . MESSAGE ID 'BC400' TYPE 'S' NUMBER '047' WITH wa_booking-carrid. ENDIF. CLEAR: wa_sbook, wa_booking. *&--------------------------------------------------------------* *& Module CLEAR_OK_CODE OUTPUT * *&--------------------------------------------------------------* *& text * *&--------------------------------------------------------------* MODULE clear_ok_code OUTPUT. CLEAR ok_code. ENDMODULE. " CLEAR_OK_CODE OUTPUT

*&--------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT * *&--------------------------------------------------------------* *& text * *&--------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN 'SAVE'. MOVE-CORRESPONDING sdyn_book TO wa_sbook. MESSAGE ID 'BC400' TYPE 'I' NUMBER '060'. LEAVE TO SCREEN 0. (C) SAP AG

BC400

43

ENDCASE. ENDMODULE.

(C) SAP AG

" USER_COMMAND_0100

BC400

INPUT

44

12 Interfaces

Contents:  Creating interfaces using the Menu Painter with the subobjects:

Title Menu bar Standard toolbar Application toolbar Function key assignment



SAP AG 2001

(C) SAP AG

BC400

1

12.2

Interfaces: Unit Objectives

At the conclusion of this unit, you will be able to:  Create a GUI title  Create a GUI status for a list and a screen that contains the following subobjects: Menu bar Standard toolbar Application toolbar Function key assignment



SAP AG 2001

(C) SAP AG

BC400

2

12.3

Overview: Screen Flight data

Edit

Goto

System

Help GUI title SET TITLEBAR .

Help Choose Back . . .



   



  

F1 F2 F3

Menu bar Standard toolbar Application toolbar Key assignment

GUI status SET PF-STATUS .

SAP AG 2001

The screen contains the following elements: The title bar contains the title of the current screen. The menu bar contains expandable menus. The menus contain the executable functions for the current program. Menus can also contain submenus (cascading menus). The menus System and Help can be found on every screen in R/3 and always contain the same functions. Neither of these menus may be changed or hidden. The standard toolbar contains icons for frequently used functions. The R/3 standard toolbar always contains the same icons with standard functions assigned to them. Functions that cannot be executed on the current screen are grayed out. The function key assignment can be displayed by right-clicking. Ideally, you should be able to execute all menu functions using function keys as well. The application toolbar contains icons and pushbuttons for frequently used functions on a particular screen. Each program is created with an interface containing all of the above tools and objects. Different views of this interface are then created for individual screens: GUI status.

(C) SAP AG

BC400

3

12.4

Objective: Example Program Interface Flight data Edit Print Save / send Save Exit

Goto

 

Ctrl+S

Flight data Edit Print Save / send Save Exit



System

Help 

 



Office Report tree File...

Goto

System  

Ctrl+S

List

Help  

Office Report tree File...

 

Screen 0100

SAP AG 2001

You will define an interface for the entire example program. The various statuses will have the following attributes:  The same menu bar will be available on both the list and the screen. Only those menu functions that can be executed will appear in black.  In the standard toolbar, only those functions that can be executed will appear in color. Screen functionality will not be altered in any way.  The screen will have its own title. 

(C) SAP AG

BC400

4

12.5

Create Status

SET PF-STATUS 'LIST_STATUS'.

Flight data Edit

Goto

System

Help

Flight data Edit

List



Goto

System

Help

Screen

SAP AG 2001

 You set a status using the SET PF-STATUS statement before the display of the screen.  This status remains valid for all subsequent screens provided you do not set a new status.

(C) SAP AG

BC400

5

12.6

Setting a Status for Each Screen

SET PF-STATUS 'LIST_STATUS'.

Flight data Edit

Goto

System

Help

Flight data Edit

List



SET PF-STATUS 'DYNP_100'.

Goto

System

Help

Screen

SAP AG 2001



In the example, a separate status is set for each screen. However, the same functions are to be available in every status.



Not all functions are appropriate on both screens; for example the print function is useful only on the list.



Depending on whether it is a list or a screen, the functions should be black (active or executable) or gray (inactive or not executable).

(C) SAP AG

BC400

6

12.7

References to Subobjects

Menu bar Standard toolbar/function key assignment Application toolbar

SET PF-STATUS 'LIST_STATUS'.

Flight data Edit



Goto

System

SET PF-STATUS 'DYNP_100'.

Flight data Edit

Help

Goto

System

Help

SAP AG 2001

For the sake of simple maintenance, we do not want to create the subobjects menu bar and standard toolbar with function keys and application toolbars for the screen status again.  Therefore we simply reference the subobjects already created in the context of the list status and define, from the point of view of the status, which functions are active or inactive. 

(C) SAP AG

BC400

7

12.8

Creating GUI Statuses for Lists START-OF-SELECTION. SET PF-STATUS 'LIST_STATUS' . Create object GUI interface: Status LIST_STATUS does not exist. Do you want to create the object? Yes

Create status No Cancel Program xxxxx Status

LIST_STATUS

Status attributes Short text Status type



Status for flight list Online status Dialog box Context menu

SAP AG 2001

You can create or maintain statuses in three different ways:  By using the object list in the Object Navigator  By using forward navigation in the ABAP Editor,  By using the Menu Painter.  When creating a status you can create a new menu bar, application toolbar, and key assignment (top down), adopt existing objects (bottom up), or use a combination of both methods.  GUI status names can have a maximum of 20 characters.  By choosing a status type, you determine whether, for instance, a status refers to a normal screen or a dialog box. Depending on the status type, you have a choice of different types of functions. 

(C) SAP AG

BC400

8

12.9

Adjusting Statuses Adjust status template • Standard Standard list list functions functions are copied

Include template in

• Standard Standard description description for menu bar and key settings is entered

status

LIST_STATUS

Template status... List status Selection screen ...

List of Functions

i

Menu bar List

Application toolbar Function keys 

Line selection list

Edit

Goto

i i

You can change the description

Line selection list

SAP AG 2001

The Adjust template function in the Extras menu allows you to include standardized function codes in your status. This function also allows you to include objects from a status of your choice in the existing status. You can choose norms for list statuses and selection screens or use any status you want from another ABAP program.  If you choose Adjust status  List status, the system generates standard list functions and the standard entries for the menu and application toolbar, and the assignment of functions to function keys. Each menu bar, application toolbar, and function key setting is also given a default name, which you should replace with an explanatory short text.  You can display the generated functions by choosing the Information icon. 

(C) SAP AG

BC400

9

12.10

Status in the Menu Painter: Function Keys

i i i

Menu bar Application toolbar Function keys Standard toolbar BACK %EX

RW

Flight data menu bar Flight data application toolbar Flight data function keys

%PRI

%SC

%SC+ P- 

P-

P+

 

P++  

?

Recommended function key assignments PICK

F2 F9 ...

Choose Select

Freely assignable function keys F5 F6 ... 

SAP AG 2001

Key assignment can be divided into three areas:  Standard toolbar: Certain function codes are predefined for the functions Save, Back, Exit program, Cancel, Print, for the Scroll icons, and for the Enter pushbutton. Simply assign these codes to the standard toolbar icon and they will be automatically assigned to their corresponding standard function keys.  Recommended function key assignment: The system proposes the functions that you should generally assign to specific function keys.  Freely assignable function keys: The system lists all the remaining function codes that are not assigned by standards. From this list, you can choose appropriate function keys for programspecific functions.  You can also define buttons on an application toolbar for frequently used function keys. These pushbuttons can have icons or text. 

(C) SAP AG

BC400

10

12.11

Statuses in the Menu Painter: Menu Bar

i

Menu bar Flight data Code

PRI

%EX

Text

Exit

Application toolbar Function keys



 

Edit

Print Save/send

Flight data menu bar

>

Goto

Code

Text

Code

Text

PICK

Choose

BACK

Back

%SC

Find

%SC+

Find next

RW

Cancel

i i

Flight data application toolbar Flight data function keys

SAP AG 2001

If so desired, the system will suggest standards for your menu bar. These can also be modified. Menu bars can contain up to eight menus. You can define up to six of these yourself, but the System and Help menus are standard and are added automatically by the system.

(C) SAP AG

BC400

11

12.12

Including Existing Elements

Menu bar Application toolbar Function keys

List of Functions



i i i

SCREEN SCREEN SCREEN

Displays existing objects and allows you to select them

SAP AG 2001

Create a new status for the screen and use the icon shown in the figure to display all the menu bars and function key assignments already defined. The example program displays only one menu bar or function key assignment.  Double-click this to reference the same menu bar and function key assignment for the screen status as for the list status. 

(C) SAP AG

BC400

12

12.13

Setting Functions to Active or Inactive in the Status 2: Toggle between active and inactive using the button Function code

i

Menu bar Flight data

Flight data menu bar

Edit

Goto

1: Select function code

Application toolbar Function keys 



i i

Code

Text

BACK

Back

Flight data application toolbar Flight data function keys

SAP AG 2001

To set status functions to active or inactive, proceed as follows:  Switch to the change mode of the status.  Point to the function code you want to activate and choose Active  Inactive on the application toolbar.



In the example in the graphic, we are adding the SAVE function, which is not a standard list function, to the standard toolbar and the Flight data menu. The system informs us that we are referencing the menu bar and standard toolbar. If we confirm the dialog box, the system automatically adds the SAVE function to the menu bar and standard toolbar in the list status and sets it to inactive.



The BACK and SAVE functions in our example are evaluated in the PAI module user_command_0100.

(C) SAP AG

BC400

13

12.14

Creating a GUI Title for a Screen MODULE status_0100 OUTPUT. SET PF-STATUS 'DYNP_100'. SET TITLEBAR '100' '100'. ENDMODULE. Create object GUI interface: Title 100 does not exist. Do you want to create the object? Yes

No

Cancel

Create title

Title code

Program

xxxxx

Title code

100

Title

Save Change flight times

Title Flight connections

Continue 

SAP AG 2001

You can create or maintain titles in three different ways:  By using the object list in the Repository Browser  By using forward navigation from the ABAP Editor  By using the Menu Painter  A GUI title-name can have a maximum of 20 characters.  Note: If you create the suggested PBO module status_nnnn using forward navigation, the SET TITLEBAR 'XXX' statement is automatically generated in the module. It is inactive. You can use this suggestion by erasing the star and entering the number of the title. Now you can create the title using forward navigation. 

(C) SAP AG

BC400

14

12.15

Interfaces: Unit Summary

You are now able to:  Create a GUI title  Create a GUI status for a list and a screen that contains the following subobjects: Menu bar Standard toolbar Application toolbar Function key assignment



SAP AG 2001

(C) SAP AG

BC400

15

12.16Interfaces Exercises

Unit: Interfaces

At the conclusion of these exercises, you will be able to:  Create user interfaces for a program  Include a GUI status and GUI title in a program Extend your program ZBC400_##_DYNPRO: The system is to display texts corresponding to the list and screen in the title bar. You must specify the correct status for the list and screen. Program:

ZBC400_##_DYNPRO

Model solution:

SAPBC400UDS_DYNPRO_D

Template:

SAPBC400UDS_DYNPRO_C

1-1

Extend your program ZBC400_##_DYNPRO or copy the template SAPBC400UDS_DYNPRO_C to the new program ZBC400_##_DYNPRO_D.

1-2

List status: 1-2-1

First define a status for the list. Create the status (type: dialog status) using forward navigation. Include the relevant ABAP statement in the processing block START-OF-SELECTION. The status you create must correspond to the standard list status. Create a suitable function key assignment, application toolbar and menu bar. Choose Extras  Adjust templates  List status to add the standard function codes. Change the name of the left menu list from List to Bookings.

1-2-2 Add the function code SAVE, which you must be able to access using the Save icon in the standard toolbar, to the function key assignment. You must also be able to choose SAVE using an entry in the Bookings menu list. Deactivate the SAVE function in this status.

1-3

Screen status: 1-3-1 Assign a status (type: dialog status) to the screen. To do so, include the relevant ABAP statement in a module at the point of the PROCESS BEFORE OUTPUT. Do not create the function key assignment, application toolbar, and menu

(C) SAP AG

BC400

16

bar again, but instead reference the objects created in the last step (1-2-2). Activate the function codes BACK and SAVE in this status and activate the interface. 1-4

(C) SAP AG

Optional: Assign a GUI title to the basic list and screen (using forward navigation).

BC400

17

12.17Interfaces Solutions

Unit: Interfaces

1-2-1 In the program source code, add the SET PF-STATUS 'LIST' statement to the START-OF-SELECTION event. (Note: Text between the two apostrophes must be in uppercase). In the program line SET PF-STATUS 'LIST', double-click the LIST status name. The system displays a dialog box containing the words “The GUI interface status ‘LIST’ does not exist. Do you want to create it?” Choose Yes to confirm. Enter the short text. Choose the status type Dialog status. Choose Extras Adjust template List status Adjust the name of the menu bar and function key assignment to suit your own needs. Change the name of the menu List to Bookings. 1-2-2 In the standard toolbar, enter the function code SAVE above the Save icon and choose Enter. Double-click to open the Bookings menu, enter SAVE as a function code, and assign the text Save bookings to it. Choose Active  Inactive to deactivate SAVE for this status. Activate the status. 1-3

Goto the change mode of screen 100. (Right-click on the screen number in the object list of the program.) In the flow logic, add the MODULE set_status_0100 statement to the PROCESS BEFORE OUTPUT event. Double-click the name of the module to create the module (using forward navigation), confirm the dialog box by choosing Yes, choose Main program in the subsequent dialog box, and add the following source code: *&--------------------------------------------* *& Module SET_STATUS_0100 OUTPUT *&--------------------------------------------* MODULE set_status_0100 OUTPUT. SET PF-STATUS 'DYNPRO'. ENDMODULE. Create the status using forward navigation. Double-click 'DYNPRO' in the SET PF-STATUS 'DYNPRO' statement. Choose Yes to confirm the dialog box. In the next dialog box, enter a short text and choose Dialog status. Place the cursor on the menu bar and choose the reference icon. Create the reference to the existing menu bar by double-clicking.

(C) SAP AG

BC400

18

Point to Function keys and choose the reference icon. Create the reference to the existing function key assignment by double-clicking. Activate the two functions SAVE and BACK by pointing to the function code in the menu or on the function key assignment and choosing the Activate icon Activate the status. Activate the screen. 1-4

Extend the program source code in the event START-OF-SELECTION.: SET PF-STATUS 'LIST'. SET TITLEBAR 'LIST'. Create the title using forward navigation and enter the text in the dialog box. Extend the source code of the SET_STATUS_0100 module: *&------------------------------------------* *&

Module

SET_STATUS_0100

OUTPUT

*&------------------------------------------* MODULE set_status_0100 OUTPUT. SET PF-STATUS 'DYNPRO'. SET TITLEBAR 'DYNPRO'. ENDMODULE. Create the title using forward navigation and enter the text in the dialog box. Activate the status and the program.

(C) SAP AG

BC400

19

Source code for the program SAPBC400UDS_DYNPRO_D *&--------------------------------------------------------------* *& Report SAPBC400UDS_DYNPRO_D * *& * *&--------------------------------------------------------------* REPORT sapbc400uds_dynpro_d. CONSTANTS: actvt_display TYPE activ_auth VALUE '03', actvt_change TYPE activ_auth VALUE '02'. * Definition of selection screen PARAMETERS pa_anum TYPE sbook-agencynum. * workarea for list DATA wa_booking TYPE sbc400_booking. * workarea for single booking to be changed DATA wa_sbook TYPE sbook. * workarea for dynpro TABLES sdyn_book. * variable for function code of user action DATA: ok_code LIKE sy-ucomm. START-OF-SELECTION. SET PF-STATUS 'LIST'. SET TITLEBAR 'LIST'. * selecting data using a dictionary view to get the data from * sbook and the customer name from scustom SELECT carrid connid fldate bookid customid name FROM sbc400_booking INTO CORRESPONDING FIELDS OF wa_booking WHERE agencynum = pa_anum. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_display. IF sy-subrc = 0. * Output WRITE: / wa_booking-carrid COLOR col_key, wa_booking-connid COLOR col_key, wa_booking-fldate COLOR col_key, wa_booking-bookid COLOR col_key, wa_booking-name. HIDE:

wa_booking-carrid, wa_booking-connid, wa_booking-fldate, wa_booking-bookid, wa_booking-name.

ENDIF. ENDSELECT. CLEAR wa_booking. AT LINE-SELECTION. AUTHORITY-CHECK OBJECT 'S_CARRID' ID 'CARRID' FIELD wa_booking-carrid ID 'ACTVT' FIELD actvt_change. IF sy-subrc = 0. (C) SAP AG

BC400

20

SELECT SINGLE * FROM sbook INTO wa_sbook WHERE carrid = wa_booking-carrid AND connid = wa_booking-connid AND fldate = wa_booking-fldate AND bookid = wa_booking-bookid. IF sy-subrc = 0. MOVE-CORRESPONDING wa_sbook TO sdyn_book. MOVE wa_booking-name TO sdyn_book-name. CALL SCREEN 100. ENDIF. ELSE . MESSAGE ID 'BC400' TYPE 'S' NUMBER '047' WITH wa_booking-carrid. ENDIF. CLEAR: wa_sbook, wa_booking. *&--------------------------------------------------------------* *& Module STATUS_0100 OUTPUT * *&--------------------------------------------------------------* * text * *---------------------------------------------------------------* MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'DYNPRO'. SET TITLEBAR 'DYNPRO'. "optional ENDMODULE.

" STATUS_0100

OUTPUT

*&--------------------------------------------------------------* *& Module CLEAR_OK_CODE OUTPUT * *&--------------------------------------------------------------* *& text * *---------------------------------------------------------------* MODULE clear_ok_code OUTPUT. CLEAR ok_code. ENDMODULE. " CLEAR_OK_CODE OUTPUT

(C) SAP AG

BC400

21

*&--------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT * *&--------------------------------------------------------------* *& text * *&--------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN 'SAVE'. MOVE-CORRESPONDING sdyn_book TO wa_sbook. MESSAGE ID 'BC400' TYPE 'I' NUMBER '060'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE.

(C) SAP AG

" USER_COMMAND_0100

BC400

INPUT

22

13 Outlook: Developing Internet Applications

Contents:  SAPGUI for HTML and Easy Web Transaction  Making selected transactions available for the Web  Making functions available in a Web-specific layout



SAP AG 2001

(C) SAP AG

BC400

1

13.2

Outlook: Developing Internet Applications

At the conclusion of this unit, you will be able to:  Create a transaction code for an Easy Web Transaction  Create an Internet service  Publish an Internet service  Test an Easy Web Transaction using a Web browser



SAP AG 2001

(C) SAP AG

BC400

2

13.3

Aim: ABAP Program User Dialogs in a Web Browser

?

Web Browser

Program start

ABAP program

html

Action

html

html

... ABAP runtime system



 

SAP AG 2001

To launch an SAP program from a Web browser, you have to generate HTML pages for the screens. You can generate these automatically.

(C) SAP AG

BC400

3

13.4

Internet Transaction Server Web Browser

ITS

Program start

ABAP program

html

html

html

... ABAP runtime system





SAP AG 2001

The Internet Transaction Server carries out this task.

(C) SAP AG

BC400

4

13.5

ITS Programming Models

Screen layout

SAPGUI for HTML

HTMLBUSINESS-

ITS Flow Logic

HTMLBUSINESSTemplate

Business logic

ABAP program • Module • Function module • BAPI

Screen

Easy Web Transaction



Dialog logic

Screen

ABAP program • Module • Function module • BAPI

ITS flow file

• RFC-compatible function module • BAPI

Template

SAP AG 2001

There are three programming models for creating internet applications:  SAPGUI for HTML: Here an ABAP program with user dialogs provides the basis for the display, dialog logic, and business logic. The layout is generated automatically from the screen information. The appearance in the Web browser contains exactly the same elements as the screen.  Easy Web Transaction: Only the business logic and the dialog logic are copied from the ABAP program. You can then change the layout of the page.  ITS Flow Logic: Only the pure business logic is executed in an ABAP program, which can be called externally - this is usually a BAPI or an RFC-compatible function module. The dialog logic and layout are defined on the ITS.  The following pages discuss the programming models SAPGUI for HTML and Easy Web Transaction in more detail. 

(C) SAP AG

BC400

5

13.6

SAPGUI for HTML and Easy Web Transaction

SAP System

SAPGUI for HTML: The ITS generates a HTMLBUSINESS template dynamically

Publish

ITS

ITS

Web browser

Web browser



Easy Web Transaction: The developer generates a static HTMLBUSINESS template

SAP AG 2001

SAP GUI for HTML generates HTML dynamically from the relevant SAP screens. Features of this process are:  Simple, SAP screen-based layout  SAP screen elements (such as text or input fields) are mapped 1:1 to the fields on the generated HTML page  No other HTML elements are available  No further development is necessary  In the Web browser, the user must enter the folowing path: http://://wgate//  With Easy Web Transaction the developer creates static HTMLBUSINESS templates. Features of this process are:  Flexible design of the layout. The screen information serves as a basis for the template; however, you can adjust the template to suit individual needs (for example, hide complex functions or include additional MIME objects).  You can add additional functions.  Further development necessary: You need to create, edit, and publish HTML templates. You also need to implement additional functions yourself. 

(C) SAP AG

BC400

6

13.7

Creating EWT Transaction Codes Customer namespace Transaction code Short text Initial object: Program and screen (dialog transaction) Program and selection screen (report transaction)

Program name

ZBC400_XXXXXXXXXX

Transaction classification: Professional User Transaction Easy Web Transaction

Service Save

Development class

ZBC400_XX

Change request 



   

SAP AG 2001

In the Object Navigator, open the object list of the program for which you want to create an Easy Web Transaction. In the appropriate context menu, choose Create  Transaction. Enter a transaction code. Comply with the customer namespace conventions. Enter a short text. If the program is an executable program, choose Program and selection screen (Report Transaction). On the next screen, enter the name of the program. Choose Easy Web Transaction followed by Save. On the next screen, enter the name of the development class to which the transaction code is to be assigned. On the next screen, assign the change request.

(C) SAP AG

BC400

7

13.8

Creating an Internet Service for EWT Object Navigator Internet Service ZBC400_EWT

Display

Service ZBC400_EWT does not exist. Do you want to create the object? Yes

Web-Application Builder: Create service Internet Service

ZBC400_EWT

Easy Web Transaction Transaction code ITS mixed mode Web application start template



SAP AG 2001

One way of making a transaction available over the ITS directly is to create a service file. The service file contains the information indicating which transaction is to be started.  You can create a service for a transaction in the Object Navigator. Choose Internet Services and enter a name for your service. Make sure you comply with the customer namespace conventions. Internet services are often given the same name as the transaction associated with them. You could, however, use a different name, particularly if you are creating several services for the same transaction.  Choose Enter or the Display icon. If there is no service saved under the name you have entered, you can confirm the query with Enter.  In the dialog box that appears, choose Easy Web Transaction and enter the transaction code.  Save the service.  Note: If you choose ITS mixed mode, you do not need to generate a static HTML page for each screen. If a screen is not associated with an HTML page, the SAPGUI for HTML generates the page dynamically at runtime. 

(C) SAP AG

BC400

8

13.9

Creating Templates Object Navigator Internet Service ZBC400_EWT ZBC400_EWT Theme 99

Create ...

... Template ... Web Application Builder: Create template ZBC400_EWT Internet Service Theme Create HTML from screen Program name Screen number ... HTML template name



Save SAP AG 2001

To create templates for a service, choose Create  Template in the context menu for a theme. In the dialog box for your service and the selected theme, enter the program name and screen number, which will serve as a basis for the template.  Save the template.  

(C) SAP AG

BC400

9

13.10

Publishing an Internet Service

Easy Web Transaction

Object Navigator Internet Service

SAP Library

ZBC400_EWT ZBC400_EWT Theme 99

ITS

... Publish



SAP System

Service file HTMLBUSINESS template

Service file Complete service

SAP AG 2001

You must save the Internet service in a file the ITS can access. You can publish the service in the Web Application Builder in the Object Navigator:  In the Object Navigator, open the object list for the Internet service.  In the context menu for the service, choose Publish  Complete service.  Note: Your user-specific ITS settings must be correct before you can publish a service. You can check the settings in the Object Navigator by choosing Utilities Settings ITS (tab in the dialog box). 

(C) SAP AG

BC400

10

13.11

Testing the Web Transaction http://igt70.wdf.sap-ag.de:1080/scripts/wgate/zbc400_ewt/! Web server

Path

Service name

Web browser Object Navigator Internet Service ZBC400_EWT ZBC400_EWT Theme 99

... Publish Start service





SAP AG 2001

To test a transaction after publishing it:  Choose Start service from the context menu (in the Internet service object list)  Enter http://[:]//wgate// as the path in a Web browser.

(C) SAP AG

BC400

11

13.12

Outlook: Developing Internet Applications

You are now able to:  Create a transaction code for an Easy Web Transaction  Create an Internet service  Publish an Internet service  Test an Easy Web Transaction using a Web browser



SAP AG 2001

(C) SAP AG

BC400

12

14 Cross-Program Modularization

Contents:  Working with Function Modules  Working with Methods  Working with BAPIs



SAP AG 2001

(C) SAP AG

BC400

1

14.2

Cross-Program Modularization: Unit Objectives

At the conclusion of this unit, you will be able to:  Acquire information on function modules  Include function module calls in your program  Include object instances and method calls in your program  Include the ALV grid control for displaying data in a fixed screen area  Acquire information on BAPIs  Include BAPI calls in your program



SAP AG 2001

(C) SAP AG

BC400

2

14.3

Working with Function Modules

Working Working with with Function Function Modules Modules Working Working with with Methods Methods Working Working with with BAPIs BAPIs



SAP AG 2001

(C) SAP AG

BC400

3

14.4

Function Module

Function Module Attributes Local data objects Source code Interface Import Import parameters parameters

Export parameters

Changing parameters

Exceptions

sy-subrc 

SAP AG 2001



Function modules are actively integrated modularization units with an interface.



Function modules can, therefore, be called specifically from within programs or function modules.



The interface of a function module can contain the following elements:  Import parameters are passed to the function module. In general, these parameters are assigned standard ABAP Dictionary types. Import parameters can also be optional.  Export parameters are received from the function modules. Export parameters are always optional.  Changing parameters are passed to the function module and can be changed by it.

 Exceptions provide information about error situations. If a function module initiates an exception, processing of the function module is interrupted. It is possible to set a return code, if necessary, in the calling program.  As is the case with subroutines, a function module can contain local type and data object definitions.

(C) SAP AG

BC400

4

14.5

Function Group

Global data objects Subroutine Interface

Screen

Function Module FM4

Interface



SAP AG 2001

A function group represents the main program for function modules. Several function modules that operate on the same data content are combined to form a function group.  The function group remains active for as long as the calling program is active. For example, if an executable program calls a function module, its entire function group is loaded as well. It remains active until the executable program is completed.  A function group can contain the same components as an executable program. These include:  Data Objects These are then global in relation to the function group, that is, they are visible to and changeable by all function modules within the group. The validity period is the same as for the function group.  Subroutines These can be called from all function modules in the group.  Screens These can be called from all function modules in the group. 

(C) SAP AG

BC400

5

14.6

Data Flow Within a Function Group

Function Module FM4

Interface 

SAP AG 2001

The global data of a function module is retained until the program that contained the first call of a function module in the function group is finished.  Thus, if a function module that writes values to the global data is called, other function modules in the same function group can access this data when the program calls them.  Seen from the outside, the global data is encapsulated, that is, it is not possible to access it directly. Therefore, you must have function modules that allow orderly access from the outside.  The same applies to all the other components of the function group (screens, subroutines). 

(C) SAP AG

BC400

6

14.7

Example: Transmitting a Standard Dialog System

SAP R/3

Help

Cancel



!

Data will be lost

Yes



 

No

SAP AG 2001

In several ABAP programs, a standard dialog is transmitted as soon as the user selects Cancel. The processed screen always contains the sentence: " Data will be lost." The title and the two lines following it are context-specific. The user can choose one of two options: Yes or No.

(C) SAP AG

BC400

7

14.8

Integration of the Standard Dialog

Function group

!

Addit. text Title Call

< ... >

!

Yes No

Reply

Reaction

ABAP program 

SAP AG 2001

This dialog box is encapsulated in a function module. If you call this function module, the system can pass the additional and title texts to the function module using the import parameters.  The function module transmits a screen of the function group that displays the text lines and the title, and contains the Yes and No buttons.  An export parameter then contains the information regarding which button the user has chosen.  You can integrate this dialog in your program as follows:  

 Call the function module as soon as the user has chosen Cancel.  After the call, evaluate the answer and react accordingly.

(C) SAP AG

BC400

8

14.9

Searching for Function Modules

Searching within a particular application component: Application hierarchy Searching with the help of a program that uses the function module being searched for:  Search in the ABAP Editor for the CALL FUNCTION statement  Change to debugging mode during program execution and set breakpoint in the CALL FUNCTION statement  If the function module transmits a screen, display the program name and the screen number using F1 and technical information or navigate directly (double-click)



SAP AG 2001



During your search for function modules (and all other Repository objects), you will be supported by the ABAP Workbench in many ways.



In the Repository Information System, you can use parts of the technical name, for example, CONFIRM, or parts of the short text, for example, Confirmation prompt, during your search.



If you know the application component, you should always use the Application hierarchy. You use this to call the development classes in question.



If you know a program that already uses the function module, you can search in this program for the call using the CALL FUNCTION statement.



In the case of a modal dialog box, you do not have the standard navigation method (System  Status) at your disposal to be able to find screen and program names. In such cases, point to a text field and select F1F Technical information.



In all cases, before you integrate the funtion module in your program, you must make sure that it is released.

(C) SAP AG

BC400

9

14.10

Analysis of a Function Module Interface

Function Module Attributes

Parameters TEXTLINE1 TEXTLINE2 TITLE START_COLUMN START_ROW



POPUP_TO_CONFIRM_LOSS_OF_DATA Import

...

Export

Ref. type

Changing

...

Exceptions

Optional Value

Source code

Description



Required function module parameters must be passed









during the call





SAP AG 2001

Once you have found a function module, you must find out more about its interface. Under the Attributes section , you will find out whether the function module is released. The required parameters in the function module must be “supplied with data” during the call. To find out which additional parameters are to be passed and when, refer to the documentation of the function module and to the documentation on interface parameters.  You can also navigate directly to the source code of the function module.   

(C) SAP AG

BC400

10

14.11

Documentation and Testing

Documentation • Short text • • • • • • •

Function Example Notes Additional information Parameters Exceptions Function group

Test Environment Export parameters

Import parameters





 

 

Function module

Exceptions

SAP AG 2001

You can test function modules using the test environment. An input template allows you to specify the IMPORT and CHANGING parameters. You can also switch to debugging mode. The values in the EXPORT and CHANGING parameters are listed after execution. If an exception situation occurs, the system records the exception, and also displays a message text, if available. The time required for executing the function module is displayed. These values are subject to the same limitations as the Runtime analysis function. You should therefore repeat the test several times using the same data. You can store test data in a test data directory. You can create test sequences.

(C) SAP AG

BC400

11

14.12

Calling a Function Module

PAI

textline title answer

MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'. CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA' EXPORTING EXPORTING textline = text-001 title = text-002 IMPORTING IMPORTING answer = pop_answer. CASE pop_answer. when 'J'. ... when 'N'. ... ENDCASE. ... ENDCASE. ABAP program



SAP AG 2001



You call function modules using the ABAP statement CALL FUNCTION. The name of the function module follows in capital letters enclosed in single quotation marks.



After EXPORTING has taken place, the system passes values to the Import parameters of the function module.



After IMPORTING has taken place, the function module returns the result through its Export parameter.



Looking at this from the calling program's side, we see that the parameters passed to the function module are exported, and those passed from the function module to the program are imported.



On the Parameter assignment screen, the system displays the names of the interface parameters of the function module (formal parameters) to the left of the equal sign. The system displays the calling program's data objects (actual parameters) to the right of the equal sign.

(C) SAP AG

BC400

12

14.13

Implementation of a Function Module Call System

Help

ABAP Editor: Changing the Report Z00_FB Pattern Insert pattern

SPO1 Function modules

CALL FUNCTION POPUP_TO_CONFIRM_LOSS_OF_DATA

POPUP_TO_CONFIRM_

... ...

or: "drag-and-drop"

+ CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA' EXPORTING textline = ... title = ... Fill in actual IMPORTING parameters answer = ...



SAP AG 2001



To program the function module call, always use the Pattern function.



Alternatively, you can display the function group in the navigation area and then pull the function module call into the ABAP Editor area using drag-and-drop.



The ABAP statement CALL FUNCTION 'FUNCTION_MODULE_NAME' is thus inserted, together with the entire list of interface parameters and exceptions, at the current cursor position in the source code of the program. Optional parameters and exceptions are inserted as comments. In this way, you avoid typing errors and omissions.



After programming the funtion module call, you must fill in the current actual parameters and, if necessary, program the exception handling.

(C) SAP AG

BC400

13

14.14

Handling of Exceptions CALL FUNCTION 'BC400_UPDATE_FLTIME' EXPORTING iv_carrid = wa_spfli-carrid iv_carrid iv_connid = wa_spfli-connid iv_connid iv_fltime = wa_spfli-fltime iv_fltime iv_deptime = wa_spfli-deptime iv_deptime EXCEPTIONS flight_not_found = 1 ... = ... OTHERS = 4.

Database table

-subrc CASE sysy sy-subrc. WHEN 0. MESSAGE s148(bc400). WHEN 1. MESSAGE i007(bc400). WHEN ... ... WHEN 4. MESSAGE i149(bc400). ENDCASE. 

SAP AG 2001



With most function modules, exceptions are triggered in error situations. In such cases, the exceptions are assigned to the number values after EXCEPTIONS.



If the function module triggered such an exception, the respective value is placed into the system field sy-subrc.



If you do not want to list the triggered exception under EXCEPTIONS or you cannot do so, the exception is assigned to the OTHERS case, provided this addition is listed.



By evaluating this field, you can then react accordingly. In the example shown in the graphic, suitable messages are transmitted.



If no exception was triggered or neither the exception nor OTHERS was listed under EXCEPTIONS, the system sets the sy-subrc field to 0.

(C) SAP AG

BC400

14

14.15

Working with Methods

Working Working with with Function Function Modules Modules Working Working with with Methods Methods Working Working with with BAPIs BAPIs



SAP AG 2001

(C) SAP AG

BC400

15

14.16

Classes and Objects

Name meth1

Attributes (data objects):

8 attr1 attr2 ... meth2

• attr1 • attr2 • ... Methods (functions): meth1

• meth1 • meth2 • ...

123 attr1 attr2 ... meth2

meth1 Class: technical description of objects 

4711 attr1 attr2 ... meth2

Objects: Runtime instances in a class

SAP AG 2001



At first glance, a class is very much like a function group since it contains data objects (attributes) and functions (methods). These components can be protected from access by components of other programs. Then they can be accessed only by methods belonging to the class.



In contrast to function groups, classes can have multiple instances, that is, more than one runtime object can be created for each program in a class. In other words, a class contains the technical description of objects (instances). All these objects, therefore, have the same attributes and provide the same methods. However, they can be distinguished physically. Their attributes can have different features.



Classes can be defined either locally within an executable program or globally in the Class Builder.



The ABAP runtime system provides support for standard object-oriented syntax elements as of Release 4.6A. For more details, refer to the SAP online library.

(C) SAP AG

BC400

16

14.17

Creating Objects and Calling Methods ref1

ref2

DATA ref1 TYPE REF TO class. DATA ref2 TYPE REF TO class. meth1

CREATE OBJECT ref1 ...

meth1

CREATE OBJECT ref2 ... CALL METHOD ref1->meth1 EXPORTING ... IMPORTING ... EXCEPTIONS ... CALL METHOD ref2->meth1 EXPORTING ... IMPORTING ... EXCEPTIONS ... ... 

ABAP program

SAP AG 2001



To create instances of classes and to be able to access them, you need reference variables, which are pointers to these instances. You define these reference variables using DATA reference_name TYPE REF TO class_name.



At program start, the data objects are created in memory. However, since no instances have been created yet, the reference variables are still empty.



At runtime, you can create as many instances of classes as you wish using CREATE OBJECT reference_name. If necessary, the import parameters of the special method CONSTRUCTOR must be filled with values. This special method is executed immediately after the instance is created. As a rule, basic settings for the actual instance are thus created.



You can call methods of an instance using CALL METHOD reference_name->method_name. In contrast to a function module call, the method name is not sufficient here because, generally, several instances of a class exist for each program. Using the reference variable, followed by the object component selector ->, you instruct a particular instance to execute its method.

(C) SAP AG

BC400

17

14.18

Examples of Standard Classes: EnjoySAP Controls

Picture Control

Airlines AA 0017 0064 LH 0400 0402



http://www.sap.com

Tree Control

HTML Viewer Control

SAP AG 2001



As of Release 4.6A, the ABAP Workbench offers several new EnjoySAP controls in order to move dialog functions from the application server to the presentation server. These controls are called on an object-oriented basis using classes, that is, the SAP Control Framework.



For each method call, you select the controls from your ABAP program. The Control Framework sends your requests to the presentation server where they are converted on a platform-specific basis.



You can give the user the option of triggering events on the presentation server. The Control Framework then converts these events and you can react to them in your ABAP program.



For more details on the EnjoySAP controls and the Control Framework, refer to the SAP online library.

(C) SAP AG

BC400

18

14.19

Example of Usage: ALV Grid Control Details

Find Sort

Sum

Filter

Download

Print

Display variant

Toolbar

AA AA AA AA LH LH LH LH LH



 

   

 

17 17 17 64 400 400 400 402 402

2000-01-17 2000-02-20 2000-03-11 2000-05-19 2000-01-13 2000-02-26 2000-03-21 2000-03-04 2000-05-28

USD USD USD USD DEM DEM DEM DEM DEM

513.69 513.69 513.69 369.00 1234.56 1234.56 1234.56 1234.56 1234.56

A321 A321 747-400 747-400 A310-300 A310-300 A310-300 A319 A319

SAP AG 2001

The ALV grid control is used for displaying non-hierarchical data in table form. Several user functions are already implemented. In the control, you can adjust the column width by dragging, or use the Optimum width function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position. Standard functions are available in the control toolbar. The Details pushbutton displays the fields in the line on which the cursor is positioned in a modal dialog box. The Sort function in the ALV control is available for as many columns as required. You can set complex sort criteria and sort columns in either ascending or descending order. You can use the Search function to search for a string (generic search without *) in lines or columns within a selected area. You can use the Sum function to request totals for one or more numeric columns. You can use the Subtotal function to structure control level lists: select the columns (non-numeric fields only) that you want to use and the corresponding control level totals are displayed. For Print and Download the whole list is always processed, not just the sections displayed on the screen. You can also display variants.

(C) SAP AG

BC400

19

14.20

Programs Using ALV Grid Control

Process Before Output

Area Screen 100

Process After Input

START-OFSELECTION.

Custom Container Control

ALV Grid Control



SAP AG 2001



An Enjoy SAP control must always be embedded in an SAP container control. This manages the embedded controls and provides a physical area for visualization.



A container becomes the parent of the embedded control.



Because containers are themselves controls, they can be nested within one another. In this way, you can work flexibly and modularly with controls.



To be able to use an ALV grid control in your program, you require at least one container and one ALV grid instance.

(C) SAP AG

BC400

20

14.21

Objects and Classes for ALV Grid Control

Area

CL_GUI_CUSTOM_CONTAINER CL_GUI_ALV_GRID

Custom Container Control

Custom Container

ALV Grid

Class Builder ALV Grid Control





SAP AG 2001

You can use the following global classes (object types) in the Class Builder to call the custom container controls and the ALV Grid Control:  CL_GUI_CUSTOM_CONTAINER  CL_GUI_ALV_GRID

(C) SAP AG

BC400

21

14.22

Custom Control Container: Constructor Method CL_GUI_CUSTOM_CONTAINER Superclasses Methods CONSTRUCTOR

Class Attributes

CL_GUI_CUSTOM_CONTAINER Interfaces

Parameters for method Parameters PARENT CONTAINER_NAME ...



Attributes

Methods

Events

Int. Types

CONSTRUCTOR

Value 

Optional 

 







...

Ref. type

...

Description

Required parameters of the Constructor method must be passed at CREATE OBJECT

SAP AG 2001



For more detailed information on the global class CL_GUI_CUSTOM_CONTAINER, you can navigate in the Class Builder. Display the object list for the class in the navigation area of the Object Navigator. Then display the entire class or individual components in the ABAP Editor. Alternatively, you can also go to the Class Builder by double-clicking the class names from within an ABAP program. Depending on the display mode, you can then display the interface parameters through Parameters or Signature.



The global class CL_GUI_CUSTOM_CONTAINER contains the CONSTRUCTOR method. When you create an instance in a program using CREATE OBJECT, you must pass at least the required parameter CONTAINER_NAME. The name of a custom container area on a screen must be passed to this parameter.

(C) SAP AG

BC400

22

14.23

ALV Grid Control: Important Methods CL_GUI_ALV_GRID Superclasses Interfaces Attributes Methods ... CONSTRUCTOR

Required parameter: i_parent (Reference to CL_GUI_CONTAINER)

... REFRESH_TABLE_DISPLAY ...

Required parameter: it_outtab (internal standard table with data for display)

SET_TABLE_FOR_FIRST_DISPLAY Optional parameter: i_structure_name (global line type of internal table)

... Redefinitions Events



SAP AG 2001



The global class CL_GUI_ALV_GRID contains several methods. To display the contents of an internal table with an ALV grid control, all you need to do is to use the following three methods:



CONSTRUCTOR: The pointer to the container control instance must be passed to the constructor.



SET_TABLE_FOR_FIRST_DISPLAY: The internal table with the data to be displayed must be passed to the parameter it_outtab. This must be a standard internal table so the user can use the sort functions. Furthermore, technical information is required for editing the grid columns. The easiest approach is to use a flat structure or a transparent table definition, that is, a global type, as the line type for the internal table. In this case, you still need to pass only the name of this line type to the i_structure_name parameter. Alternatively, you can also set up a field catalog and pass it to it_fieldcatalog.



REFRESH_TABLE_DISPLAY: You need to call this method only if you have changed the contents of the internal table after the first display.

(C) SAP AG

BC400

23

14.24

Creating a Screen Element "Custom Control Area" Screen Painter

Custom Control Area

Type: Custom Control Name: CONTAINER_1 Resizing Vertical: E Minimum lines: Horizontal: E Minimum columns:

C Custom Control



5 20

SAP AG 2001



To reserve an area of the screen for an EnjoySAP control, create a custom container area using the Screen Painter (use the Layout button).



In the toolbar to the left of the editing area, you will see an icon with the name Custom control.  Choose the Custom control button. Then define the size and the position of the area in the screen. To do this, define the top left corner of the area by holding down the mouse button. Drag the cursor down diagonally to the right to where you want the lower right corner. Once you release the mouse button, the lower right corner is fixed in position.  You can change the size and position of the area at any time by dragging and dropping the drag symbols.



Enter a name for the screen element (here: CONTAINER_1).



Use the Resizing vertical and Resizing horizontal attributes to specify whether or not the area of the custom control should be resized when the main screen is resized. You can also set minimum values for these attributes using Min. row and Min. columns. The upper limit is defined by the size of the area.

(C) SAP AG

BC400

24

14.25

Defining Reference Variables

DATA gdt_spfli TYPE sbc400_t_spfli.

DATA: container_r cl_ container_r TYPE REF TO cl_gui_custom_container cl_gui_ gui_custom_ custom_container , grid_r grid_r

TYPE REF TO cl_ cl_gui_alv_grid cl_gui_ gui_alv_ alv_grid .

gdt_spfli

container_r grid_r

ok_code

DATA ok_code TYPE sy-ucomm. START-OF-SELECTION. * fill internal table ... CALL SCREEN 100.



SAP AG 2001



Two reference variables are required in the ABAP program.



The reference variable that is to point to the container control instance is called container_r in the example in the graphic, and has the global class type cl_gui_custom_container.



The reference variable that is to point to the grid control instance is called grid_r in the example in the graphic and has the global class type cl_gui_alv_grid.

(C) SAP AG

BC400

25

14.26

Creating Instances MODULE create_control OUTPUT. IF container_r IS INITIAL. CREATE _r container CREATE OBJECT OBJECT container_r container_r EXPORTING _name == 'CONTAINER_1' container EXPORTING container_ container_name 'CONTAINER_1'.

CREATE _r CREATE OBJECT OBJECT grid_r grid_r grid EXPORTING parent == container_r _r EXPORTING i_parent i_parent container_r. i_ container

container_r

grid_r

... ENDIF. ENDMODULE.



SAP AG 2001



You create control instances using the CREATE OBJECT statement.



Make sure you let the system generate the statement by using the Pattern. In this way, you avoid typing errors and mistakes. As is the case with function module calls, the complete interface is implemented in your program. CREATE OBJECT is an interface of the constructor method. Optional parameters are entered as comments.



The control processing must be complete before the respective screen is displayed. Also, it should be linked modularly to the processing of the respective screen. For this reason, we recommend that you implement a PBO module here.



Creating an instance for the controls should take place only once, before the first screen display. Querying the content of one of the two reference variables easily does this.



Creating instances for the container control is implemented in the corresponding PBO module. Therefore, it is sufficient if you enter the name of the custom container area. In other cases, you can enter the program name and the screen number also.



When you set an instance for the grid control, it is sufficient if you pass the pointer to the container instance. In this way, the container control maintains the technical link of the grid control to the screen.

(C) SAP AG

BC400

26

14.27

Calling Methods MODULE create_control OUTPUT. IF container_r IS INITIAL. container_r ... CALL CALLMETHOD METHOD grid_r-> _r->set set_ _table_ grid grid_r->set_table_for_first_display table_for_ for_first_ first_display EXPORTING i_structure_name i_structure _name == 'SPFLI' 'SPFLI' EXPORTING i_structure_ CHANGING it_outtab it_ gdt_ CHANGING it_outtab == gdt_spfli gdt_spfli .

grid_r

... ENDIF. ENDMODULE.



SAP AG 2001



To transmit the contents of the internal table and the line type to the grid control, you must call the set_table_for_first_display method.



You pass the name of the internal table to the it_outtab parameter.



Here the internal table has been typed with the transparent table SPFLI as line type. Therefore, it is sufficient to pass this name to the i_structure_name parameter. In addition, basic settings of the grid control can be passed as well.



If the contents of the internal table change during the program, you must call the refresh_table_display method before the next screen is displayed.

(C) SAP AG

BC400

27

14.28

Working with BAPIs

Working Working with with Function Function Modules Modules Working Working with with Methods Methods Working Working with with BAPIs BAPIs



SAP AG 2001

(C) SAP AG

BC400

28

14.29

Business Application Programming Interface

A BAPI is a well-defined interface to processes and data of a business application system, implemented as a business object method in the Business Object Repository (BOR).

BAPI



SAP AG 2001



A BAPI can be viewed as the door to the SAP system; this interface provides access to business data and processes in the SAP system from the outside.



Each object in the BOR can have several methods, one or more of which can be implemented as BAPIs.



BAPIs usually exist for basic functions of a business object, such as:  Creating objects  Querying the attributes of an object  Changing the attributes of an object

(C) SAP AG

BC400

29

14.30

BAPI Usage

Customer‘s and partner's own code

Distributed scenarios (ALE)

JAVA, C, ...

Internet / Intranet

Business Component

R/3 Component Creation 



Business B Component

Business Component

Business Workflow

SAP AG 2001

A BAPI can be used for various applications. For example: • Internet application components: Depiction of individual SAP R/3 functions in the Internet or intranet - for example, for users who do not have SAP R/3 experience. • R/3 component creation: Communication between the business objects of different SAP R/3 components (solutions). • Customers’ or partners’ code: External clients (for example, alternative GUIs) directly access business data and processes of the SAP R/3 System. In particular, BAPI calls (as calls of RPCenabled function modules also) can be implemented in other programming languages.

(C) SAP AG

BC400

30

14.31

Standardized BAPIs

 GetList Supplies a list of object key fields that satisfy selected criteria (search function)  GetDetail Supplies detailed information (attributes) on an object (the full key must be specified)  Create, Change, Delete, Cancel Creating, changing, and deleting objects  AddItem, RemoveItem Creating and removing subobjects (for example, item in an order)



 

SAP AG 2001

There are standard methods for BAPIs with standardized names. Some of the most important standard method names are listed here.

(C) SAP AG

BC400

31

14.32

Finding BAPI Function Modules

Hierarchy

Alphabetical

Detail

Documentation

Tools

Project

Method (BAPI) FlightBooking FlightCustomer FlightConnection AirlineCarrier ConnectionNumber DateOfFlight GetDetail Return FlightData

Method

GetDetail

Business object

FlightBooking

Short text

Flight details

New as of release

40C

Function module

BAPI_SFLIGHT_GETDETAIL

GetList



Double-click: Navigation in Function Builder

SAP AG 2001



In Release 4.6C, BAPIs are implemented using function modules.



From the SAP Easy Access menu, you call the BAPI Explorer by choosing Tools  Business Framework BAPI Browser.



Using the BAPI Explorer, you can navigate to the function module display for the selected BAPI in the Function Builder.  Select the BAPI in the hierarchy section.  In the detailed display window, choose the Detail tab.  By double-clicking on the name of the function module, you can display it in the Function Builder.

(C) SAP AG

BC400

32

14.33

Characteristics of a BAPI Function Module

Interface parameters typed with a Dictionary structure that is compiled for the BAPI

Error messages through EXPORT parameter RETURN (structure or internal table)

No CHANGING parameters No exceptions

Interface

Structure of BAPI_name

Remote capability

Source code

SAP System 



Function group

No user dialogs

SAP AG 2001

Function modules for BAPIs must fulfill the following requirements:  Naming convention BAPI__ must be used  Remote capability  No user dialogs, neither screens nor messages, allowed  Interface parameters must be typed with a Dictionary structure that was created for this BAPI  Structures must comply with the naming convention BAPI_ and are changed only on a compatible basis  No CHANGING parameters allowed  No exceptions allowed. Errors are reported to the user through the special export parameter RETURN.

(C) SAP AG

BC400

33

14.34

Calling a BAPI Function Module from an ABAP Program ABAP program

BACV

BOR

For currency and quantity fields: Possible conversion to "external format" CALL FUNCTION 'BAPI_...' EXPORTING ... IMPORTING ... return = ... For currency and quantity fields: Possible conversion to "external format"



SAP AG 2001

If you would like to use a BAPI in the SAP R/3 System, you can call the function module containing it.  Pay attention to the limitations already mentioned.  BAPI interfaces are created according to the needs for the "external" call, that is, from a non-R/3 System. Quantities are expected in an external format with 4 or 9 decimal places. The quantities must be transferred to the interface in converted format, even if the corresponding currency has no decimal places.  For this conversion you can use function modules from the BACV function group (development class SBF_BAPI). 

(C) SAP AG

BC400

34

14.35

Cross-Program Modularization: Unit Summary

You are now able to:  Acquire information on function modules  Include function module calls in your program  Include object instances and method calls in your program  Include the ALV Grid Control for displaying data in a fixed screen area  Acquire information on BAPIs  Include BAPI calls in your program



SAP AG 2001

(C) SAP AG

BC400

35

14.36Cross-Program Modularization Exercises

Unit: Cross-Program Modularization Topic: Function Modules At the conclusion of these exercises, you will be able to:  Search for a function module  Insert a function module call in a program Change your program ZBC400_##_DYNPRO or the respective template as follows: Whenever the Cancel option is chosen on a screen, a standard dialog that is encapsulated in a function module is to be processed. Program:

ZBC400_##_DYNPRO

Model solution:

SAPBC400UDS_DYNPRO_E

Template:

SAPBC400UDS_DYNPRO_D

1-1

Change your program ZBC400_##_DYNPRO or copy the template SAPBC400UDS_DYNPRO_D to the new program ZBC400_##_DYNPRO_D.

1-2

Using one of the methods outlined during the course, search for the function module that encapsulates the standard dialog that is usually triggered when the user chooses Cancel.

1-3

Find out about the function module interfaces, read the documentation, and test the function module using the test environment.

1-4

In the GUI status of the screen, activate the Cancel function.

1-5

Extend the USER_COMMAND_0100 module to evaluate the function code for the Cancel function. Then insert the function module call using the pattern function of the ABAP Editor. React to the user’s input that the function module supplies as follows:

-

If the user would like to cancel, set the next screen dynamically to 0.

-

If the user does not want to cancel, set the next screen dynamically to 100. 1-6

(C) SAP AG

Change the function code query to SAVE by using the BC400_UPDATE_BOOK function module to save the data changed on the screen. Pass the changed data to the function module in the correct type. If the change was done successfully, BC400

36

display message 148 of type S and message class BC400, and then return to the list. If the change is not successful, display message 149 of type E.

(C) SAP AG

BC400

37

Exercises Unit: Cross-Program Modularization Topic: ABAP Objects and the ALV Grid Control At the conclusion of these exercises, you will be able to:  Display a simple list using an ALV grid control

Write a program that displays the contents of the database table SPFLI using an ALV grid control.

Program:

ZBC400_##_ALV_GRID

Model solution:

SAPBC400RUS_ALV_GRID

Template:

SAPBC400RUT_ALV_GRID

2-1

Copy the program SAPBC400RUT_ALV_GRID, giving it the name ZBC400_##_ALV_GRID. In the template, there is an internal table that matches the database table SPFLI and also a screen with the number 100.

2-2

Become familiar with the program.

2-3

Fill the internal table with data records from the data table SPFLI using the Array Fetch.

2-4

Create a container control area on the screen (name proposal: CONTAINER_1).

2-5

Define two reference variables, one for the CL_GUI_CUSTOM_CONTAINER class and one for the CL_GUI_ALV_GRID class.

2-6

At PROCESS BEFORE OUTPUT of screen 100, call a module to create the objects using the CREATE OBJECT ABAP statement. Also, fill in the required parameters for the constructor methods concerned. Use a query to ensure that the object is generated only when PROCESS BEFORE OUTPUT runs for the first time.

2-7

When PROCESS BEFORE OUTPUT runs for the first time, call the SET_TABLE_FOR_FIRST_DISPLAY method, pass the name of the line type of the internal table to the I_STRUCTURE_NAME parameter, and pass the internal table to the parameter IT_OUTTAB.

(C) SAP AG

BC400

38

14.37Cross-Program Modularization Solutions

Unit: Cross-Program Modularization Topic: Function Modules

1-2

The function module is called “POPUP_TO_CONFIRM_LOSS_OF_DATA”.

1-3

There are the following interface parameters: Required import parameters: TEXTLINE1 (max 70 char.) First line of the dialog window TITEL (max 35 char.) Title line of the dialog box Optional import parameters: TEXTLINE2 (max 70 char.) Second line of the dialog box START_COLUMN (Type SY-CUCOL) First column of the dialog window START_ROW (Typ SY-CUROW): First line of the dialog box Export parameters: ANSWER (Type C): User’s input “J” = user has confirmed the processing step (ja = yes) “N” = user has canceled the processing step

1-4

The standard function code for the Cancel function is RW.

1-5 *&---------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------* MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'BACK'. SET SCREEN 0. WHEN 'RW'.

14.38 14.39

CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA' EXPORTING

textline1 = text-001 titel = text-002 IMPORTING answer = answer. CASE answer. when 'N'. LEAVE TO SCREEN 100. when 'J'. LEAVE TO SCREEN 0. ENDCASE. WHEN 'SAVE'. MOVE-CORRESPONDING sdyn_book TO wa_sbook. CALL FUNCTION 'BC400_UPDATE_BOOK' EXPORTING (C) SAP AG

BC400

39

iv_book = wa_sbook EXCEPTIONS book_not_found update_sbook_rejected book_locked currency_conversion_error OTHERS IF sy-subrc = 0. MESSAGE s148(bc400). SET SCREEN 0. ELSE. MESSAGE e149(bc400). ENDIF. ENDCASE. ENDMODULE. " USER_COMMAND_0100

(C) SAP AG

BC400

= = = = =

1 2 3 4 5.

INPUT

40

Solutions Unit: Cross-Program Modularization Topic: ABAP Objects and ALV Grid Control

2-3

START-OF-SELECTION. * fill internal table SELECT * FROM spfli INTO TABLE gdt_spfli. * WHERE ... CALL SCREEN 100.

2-4 2-5

Using the screen layout function, create a control container area (second-last icon in the toolbar). Call the container area CONTAINER_1. Fill in the declaration part: DATA: container_r TYPE REF TO CL_GUI_CUSTOM_CONTAINER, grid_r TYPE REF TO CL_GUI_ALV_GRID.

2-6 to 2-7: Flow logic: PROCESS MODULE MODULE * PROCESS MODULE MODULE

BEFORE OUTPUT. STATUS_0100. create_control. AFTER INPUT. copy_ok_code. USER_COMMAND_0100.

PBO module in the program: *&--------------------------------------------------------* *& Module CREATE_CONTROL OUTPUT *&--------------------------------------------------------* MODULE create_control OUTPUT. IF container_r IS INITIAL. CREATE OBJECT container_r EXPORTING container_name = 'CONTAINER_1'. CREATE OBJECT grid_r EXPORTING i_parent =

container_r.

CALL METHOD grid_r->set_table_for_first_display EXPORTING i_structure_name = 'SPFLI' CHANGING it_outtab = gdt_spfli. ENDIF. ENDMODULE. " CREATE_CONTROL OUTPUT (C) SAP AG

BC400

41

(C) SAP AG

BC400

42

15 Software Logistics and Software Adjustment

Contents:  Organization of development and transport  Enhancement of standard software



SAP AG 2001

(C) SAP AG

BC400

1

15.2

Software Logistics and Software Adjustment: Unit Objectives

At the conclusion of this unit, you will be able to:  Use the tools and concepts you need for organizing development  Describe how to avoid modifications to SAP objects



SAP AG 2001

(C) SAP AG

BC400

2

15.3

Organization of Development and Transport

Organization Organization of of development development and and transport transport Enhancement Enhancement of of standard standard software software



SAP AG 2001

(C) SAP AG

BC400

3

15.4

Assigning Transport Routes Customer development ZDEV

Development system

Test and translation system

SAP DEV

Production system QAS

PRD

Standard objects and modifications Create development class



...

...

Transport layer

ZDEV

...

...

SAP AG 2001

If you create a development class for your own developments, the system automatically assigns the correct transport layer. This sets the transport route for the Repository objects that are assigned to this development class.  You can see the current system configuration in the Transport Management System by choosing Tools  Administration  Transports  Transport Management System). 

(C) SAP AG

BC400

4

15.5

Joint Transport Assignment

Project Manager: FRY Team:

Workbench Organizer: Requests Change requests involving user BC400-00

FRY BC400-00 BC400-01 BC400-02 BC400-03

Changeable

Request number

Transportable

User

IT3K900051 CARSON

Task number

Project Manager

IT3K900052 CARSON IT3K900053 BC400-00

Repository objects created or corrected by employee

Report source ZBC400_00_FLIGHTLIST ABAP program IT3K900054 BC400-01

...

IT3K900055 BC400-02 IT3K900056 BC400-03 IT3K900057



...

SAP AG 2001



At the beginning of a development project, the project manager creates a change request. The project manager assigns all project team members to the change request. The Workbench Organizer (WBO) then creates a task for each project developer.



From now on, whenever an employee assigns a Repository object to this change request, the Repository object is automatically entered in that employee's task. All Repository objects that an employee works on during a development project are collected in his or her task folder. The Repository objects are, therefore, locked for all developers who do not belong to this particular project.



Unlike the logical functional divisions that separate Repository objects through the respective development class, change requests are project-related and, therefore, limited with regard to the time schedule involved. Thus, although a program always belongs to only one development class, it can belong to different change requests at different times.

(C) SAP AG

BC400

5

15.6

Developer's Tasks at End of Development Process Schedule:

...

Thursday

Friday

Project Manager: FRY Team: FRY BC400-00 BC400-01 BC400-02 Task is released BC400-03 ...



Task quality control: • Syntax check • Activation of inactive objects Task documentation

SAP AG 2001



When development is finished, the developer carries out a final quality check and releases the task.



The objects and object locks are passed from the task to the change request. However, all employees assigned to the task can still make changes to the object because the Workbench Organizer automatically creates a new task if necessary.

(C) SAP AG

BC400

6

15.7

Project Manager's Tasks at End of Development Process Schedule:

...

Thursday

Friday

Project Manager: FRY Request is released

Team: FRY

Task quality control: • Syntax check • Inactive objects • Task consistency Project documentation

BC400-00 BC400-01 BC400-02

Version management

BC400-03 ...



SAP AG 2001



When the project is complete, the project manager checks the consistency of the request and releases the change request. The locks on the objects in the request are released. The development status of every affected Repository object is stored in the version management.



Copies of the Repository objects are then exported to the central transport directory.



The system administrator initiates the importing of the objects into the target system; this does not happen automatically.



Afterwards, the developer checks the import logs.

(C) SAP AG

BC400

7

15.8

Originals and Copies

Development system

Customer object

Subsequent system

Customer object

Original

Copy Development transport

SAP object

SAP object

Original



Copy

SAP object

Copy

SAP AG 2001



When you create a Repository object, the Transport Organizer automatically notes the system in which you created it. The original of a Repository object is in a certain system.



The original version of an object can exist in only one system. All other systems contain copies of the object.



The idea of having an original system is to ensure that Repository objects can be changed only in the development system. The integration system is where you carry out your development work so all of the objects in it are originals. This means there is one central location for changing all Repository objects.



If you now transport your Repository objects into a subsequent system, they exist there as copies. Although it is possible to change copies in exceptional cases, you should always try to make the changes to the original in the development system and transport the new version to the subsequent system from there. This ensures that the state of objects remains consistent across systems.



Originals are never overwritten in transports.

(C) SAP AG

BC400

8

15.9

Corrections and Repairs

Development system

Customer object

Corrected original Correction

SAP object

Corrected original

Repair

Correction



Customer object

Copy Correction transport

SAP object

Modified copy

Subsequent system

SAP object

Copy Repair transport

SAP AG 2001



A correction is a change to an original. The system records corrections in a request containing tasks of type development/correction.



A repair is a change to a copy (that is, an object is not changed in its original system). Accordingly, this change is recorded in a task with type repair. A modification is a repair of an SAP object.



The changes made to your own objects (for example, due to an emergency in the production system) can also be made immediately to the originals in the development system. You must make the changes you made to the copies immediately to the original as well and transport the new version to the subsequent system.



This is not possible for SAP objects because the originals are not in any of your systems.

(C) SAP AG

BC400

9

15.10

Modifications During Upgrade

Development system

Customer object

Subsequent system

Customer object

Corrected original

SAP object

Corrected original

SAP object

Modified copy Modification adjustment

SAP object

Copy Adjustment transport

Upgrade

Upgrade 

Copy

SAP AG 2001

A conflict could occur if you import an upgrade, a support package, or some other transport request from SAP into your system.  Such a conflict occurs if an SAP object modified by you is newly shipped by SAP: The object newly transported by SAP becomes an active object in the Repository of your system.  If you want to save your changes, you have to make a modification adjustment for the corresponding objects. Modifying a number of SAP objects can cause a substantial delay when performing an upgrade.  To ensure that the development system and the subsequent system are consistent, you should make the modification adjustment in the development system only. The objects of the adjustment are then transported to subsequent systems. 

(C) SAP AG

BC400

10

15.11

Enhancement of Standard Software

Organization Organization of of development development and and transport transport Enhancement Enhancement of of standard standard software software



SAP AG 2001

(C) SAP AG

BC400

11

15.12

Overview: Software Adjustment Possibilities

Business applications (SAP objects) Modification

Customer objects

Customer developments

Enhancement

 assisted

 Dictionary object

 using SAP objects

 not assisted

 ABAP source code

 not using SAP objects

 Screen  Interface





SAP AG 2001

There are four different ways of changing the SAP system to meet your requirements:  Customizing: Allows you to change system parameters using your own maintenance transaction. All possible changes have been thought of and organized. Customizing is a mandatory part of setting up an SAP system.  Enhancement concept: Allows you to change SAP Repository objects without modifications.  Customer developments: Allows you to create Repository objects in accordance with the customer namespace conventions.  Modification Assistant: Allows you to change SAP Repository objects. Modifications can lead to a considerably greater workload for an upgrade. If the new release has changes to the same Repository object that was previously modified, you have to adjust the versions manually. The Modification Assistant supports adjustment of versions semi-automatically. For more details, refer to the online documentation: Basis  ABAP Workbench  Changing the SAP Standard  The Modification Assistant.

(C) SAP AG

BC400

12

15.13

Enhancement Concept Using the Function Module Exit as an Example REPORT . Enhancement call

START-OF-SELECTION. ... CALL CUSTOMER-FUNCTION '007' ... .

FUNCTION exit__007. INCLUDE zxu01. ENDFUNCTION.

Object in customer namespace

INCLUDE zxu01. zxu01. ... * extended functionality ...



SAP AG 2001

SAP objects are usually enhanced as shown above. The SAP object enables you to go to a customer object. Since this object usually does not exist, you have to implement it in the specified manner.  Different enhancement techniques are implemented differently. Depending on the enhancement technique, you have to use a different maintenance transaction to create the corresponding objects and activate the enhancement.  The corresponding maintenance transaction has a search function for finding a suitable enhancement. You can also find documentation about the corresponding enhancement here.  

(C) SAP AG

BC400

13

15.14

Enhancing User Dialogs Flight data

Edit

Field exit Airline

LH

Flight number

400

Goto System Continue First line Last line Back Customer function Table kind Back

Help

Menu exit

Additional field 1 Additional field 2

Text and documentation enhancement to data element



Screen exit

SAP AG 2001

Enhancement of user dialogs is possible at the following levels: • Menu exit: The system contains various points at which you can include menu items that call customer functions. • Screen exit: Some screens contain special areas (subscreens) in which you can display your own screens. • Field exit: You can attach additional checks or conversions to fields on screens.  In the ABAP Dictionary, you can also enhance attributes of data elements: • Field documentation: You can replace the field documentation, which is displayed when the user presses F1 with your own texts. • Field label: You can replace the short, medium, and long text field labels with your own text. 

(C) SAP AG

BC400

14

15.15

Further Enhancement Examples

 Append structure: Additional fields in standard tables  Predefined but not yet effective source code  Business Add In (BAdI): Object-oriented Enhancement





SAP AG 2001

In addition to the enhancement techniques already mentioned, other options include:  Append structures: You can create any number of append structures for every standard table. With this feature, you can append fields to a table without changing the table itself.  Predefined but not yet effective source code: In some standard programs, specific source code areas are commented out. If the comment symbols (asterisks) are removed from these lines of source code, the lines will be executed. This is technically a modification, however.  Business Add Ins (BAdIs): As with a function module exit, you can define additional program logic for appropriate standard programs. Business Add Ins are object-oriented and offer additional options.

(C) SAP AG

BC400

15

15.16

Registering Developers in the SSCR

SAP SAPSoftware SoftwareChange ChangeRegistration Registration (SSCR) (SSCR)

Register developers who use the ABAP Workbench

Register SAP objects to be changed

• • You Youmust mustregister registermodified modified SAP SAPobjects objectsusing usingthe theSSCR SSCR procedure procedure • • Each Eachobject objectobtains obtainsan anaccess access key key • • You Youcan canonly onlyapply applyfor foran an access key for an object access key for an objectinin each eachR/3 R/3Release Release

• • You Youmust mustregister registerdevelopers developers using usingthe theSSCR SSCRprocedure procedure • • Each Eachdeveloper developerobtains obtainsan an access accesskey key • • For Forevery everydeveloper, developer,you youneed need only apply once for an only apply once for anaccess access key key



SAP AG 2001



All users who want to use the ABAP Workbench to create or change a Repository object in the SAP system (including customer developments) must make a single request for a key using the SAP Software Change Registration (SSCR) procedure.



After registration, all developers receive a key. The key is linked to the developer's user ID and the license number of the SAP system. The system prompts development users for their key the first time they attempt to create or change a Repository object.



Additionally, every SAP Repository object that is modified must be registered. When registering these objects, you must specify the Repository object name, the object type, and the SAP system license number and release. The registration is valid until the next upgrade.

(C) SAP AG

BC400

16

15.17

Software Logistics and Software Adjustment: Unit Summary

You are now able to:  Use the tools and concepts you need for organizing development  Describe how to avoid modifications to SAP objects



SAP AG 2001

(C) SAP AG

BC400

17

16 Appendix

 This section contains supplementary material to be used as reference.  This material is not part of the standard course.



 Therefore, the instructor might not cover this during the course presentation.

SAP AG 2001

16.2

Program Types

Program Program Types Types Data Data Types, Types, Data Data Objects, Objects, and and Statements Statements Logical Logical Databases Databases Preview Preview



SAP AG 2001

(C) SAP AG

BC400

2

16.3

Programs of "Include" Type

Include: ( Program type: Include )

Program: REPORT . : INCLUDE .

ABAP statements

:



SAP AG 2001

(C) SAP AG

BC400

3

16.4

TOP Include

Create program

Repository Browser:

program

Create program

With TOP-Include

Program: TOP

REPORT .

Program type: Include

Program:



TYPES:... DATA: ...

INCLUDE TOP.

Program type: executable START-OF-SELECTION. : 

SAP AG 2001

(C) SAP AG

BC400

4

16.5

Standard Includes for Function Groups The Object List Edit

Goto

Utilities

Environment System Help

Object Navigator

Workbench Edit

Extras

Environment System Help

Object Navigator

The Object List Development class program Function group Class Local Objects

Object name BC402_FMDD_WAITLIST

Display



BC402_FMDD_WAITLIST

     

Function modules Fields PBO modules Screens GUI title Includes LBC402_FMDD_WAITLISTO01 LBC402_FMDD_WAITLISTTOP LBC402_FMDD_WAITLISTU01 LBC402_FMDD_WAITLISTU02 LBC402_FMDD_WAITLISTU03 LBC402_FMDD_WAITLISTU04 LBC402_FMDD_WAITLISTU05 LBC402_FMDD_WAITLISTU06 LBC402_FMDD_WAITLISTUXX

PBO modules Global declarations Function modules

Include function modules 

Goto

Add waiting customer Waiting customer from list Display waiting list Move up waiting customer Return position in list Change waiting position

SAP AG 2001



When you work with function groups and modules, you can use the ABAP Workbench to arrange the program source code in overview form and structure it with ease.



In the Navigation function, you always branch to the correct object, and Include programs are given names and created. The respective call statements are automatically entered at the correct position.



The call statements must contain only the name convention for function groups: Y| Z.



The system then creates a program of F type, SAPLY|Z. This contains only INCLUDE statements that were created automatically. The Include programs are automatically given the name LY|Z.



In addition, the system includes the Include program, LY|ZUXX. Here, there is a call for an appropriate Include program, LY|ZU, for each function module.

(C) SAP AG

BC400

5

16.6

Data Types, Data Objects, and Statements

Program Program Types Types Data Data Types, Types, Data Data Objects, Objects, and and Statements Statements Logical Logical Databases Databases Preview Preview



SAP AG 2001

(C) SAP AG

BC400

6

16.7

Structures and internal Tables Can be Nested



  

SAP AG 2001

Structure types can contain other structure types or table types. Table types can contain structure types and table types. In the keyword documentation for the keyword TYPES, you will find the syntax for defining table types.

(C) SAP AG

BC400

7

16.8

Type Groups in the ABAP Dictionary

TYPE-POOL Z400. TYPES: z400_name_type(25) TYPE C, BEGIN OF z400_flightrec_type, ... , END OF z400_flightrec_type.

REPORT ... . TYPE-POOLS z400. DATA: name TYPE z400_name_type, wa TYPE z400_flightrec_type. ... .



ABAP

SAP AG 2001

In addition to declaring a data type within an ABAP program, you can also declare data types in a type group in the ABAP Dictionary.  The type group name in the ABAP Dictionary has a maximum of five characters. Type names within the type group must begin with followed by an underscore.  The types in a type group must be declared in ABAP programs with the TYPE-POOLS command. 

(C) SAP AG

BC400

8

16.9

Type Conversion

 When are two types compatible? 

Two elementary types are compatible if they are identical in type and length (and number of decimal places in the case of packed numbers).



Two structure types are compatible if they have the same structure and their components are compatible.



Two table types are compatible if their line types are compatible and their key definitions, key categories, and table types are identical.

 Data objects with compatible types can be assigned without conversion.  Non-compatible types can be converted if a conversion rule has been defined. 

SAP AG 2001

If two data types are not compatible, but a conversion rule exists, then the system performs type conversions for value assignments, calculations, or comparisons. The following graphics introduce the basic forms of conversion rules and give examples of the most important cases. All the conversion rules can be found in the ABAP documentation on the MOVE statement. If no conversion rule is defined for a statement, the system's reaction depends upon the particular program context:  In the case of statistical types, the system issues a syntax error. Example: DATA: date TYPE d VALUE '19991231', time TYPE t. FIELD-SYMBOLS: TYPE d, TYPE t. ASSIGN: date TO , time TO . = .  In the case of dynamic types, the system issues a runtime error since the the field symbols are typed only when the data objects are assigned at runtime. Example (rest as above): ... FIELD-SYMBOLS: TYPE ANY, TYPE ANY. ...

(C) SAP AG

BC400

9

16.10

Logical Expressions * comparisons for all datatypes: .. {EQ|=} {|} .. {NE|} {|} .. {GT|>} {|} .. {GE|>=} {|} .. {LT|
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF