Scarica Complete ABAP Guide for SAP system e più Appunti in PDF di Tecniche E Linguaggi Di Programmazione solo su Docsity!
H^
E^
L P
.^
B^
C
A^
B^
A
BC - ABAP Programmin g
R e l e a s e 4. 6 C
TM
BC - ABAP Programming SAP AG
Copyright
© Copyright 2001 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.
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 Server Informix Software Incorporated.
are registered trademarks of
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.
BC - ABAP Programming SAP AG
- BC - ABAP Programming ................................................................................. Contents
- Introduction to AB AP
- The R/3 Basis System: Overview...............................................................................................
- Position of the Basis System Within the R/3 System...............................................................
- Application Servers
- Work Processes
- Overview of the Components of Application Programs
- Structure of an Application Program
- Screens
- Structure of ABAP Programs
- Processing Blocks in ABAP Programs.....................................................................................
- ABAP Statements
- Logical Databases and Contexts
- Memory Structures of an ABAP Program
- Creating and Changing ABAP Programs..................................................................................
- Opening a Program from the Repository Browser
- Opening Programs in the ABAP Editor
- Opening Programs Using Forward Navigation
- Maintaining Program Attributes................................................................................................
- Editing Programs
- The ABAP Programming Language
- ABAP Syntax................................................................................................................................
- Types and Objects
- Basic Statements
- Data Types and Data Objects
- Data Types..........................................................................................................................
- Defining Data Types
- Predefined ABAP Types...........................................................................................
- Local Data Types in Programs
- Data Types in the ABAP Dictionary........................................................................
- The TYPE Addition
- The LIKE Addition
- Data Objects
- Literals
- Text Symbols
- Variables
- Constants.....................................................................................................................
- Interface Work Areas
- Predefined Data Objects..............................................................................................
- Compatibility......................................................................................................................
- Determining the Attributes of Data Objects
- Examples of Data Types and Objects
- Processing Data
- Assigning Values
- Assigning Values with MOVE SAP AG BC - ABAP Programming
- Assigning Values with WRITE TO
- Resetting Values to Their Initial Value.........................................................................
- Numerical Operations
- Arithmetic Calculations
- Mathematical Functions
- Business Calculations..................................................................................................
- Date and Time Calculations.........................................................................................
- Processing Character Strings
- Shifting Field Contents.................................................................................................
- Replacing Field Contents.............................................................................................
- Converting to Upper or Lower Case or Replacing Characters
- Converting into a Sortable Format...............................................................................
- Overlaying Character Fields
- Finding Character Strings
- Finding the Length of a Character String.....................................................................
- Condensing Field Contents
- Concatenating Character Strings
- Splitting Character Strings
- Assigning Parts of Character Strings...........................................................................
- Single Bit Processing in Hexadecimal Fields....................................................................
- Setting and Reading Bits
- Bit Operations
- Set Operations Using Bit Sequences
- Type Conversions
- Conversion Rules for Elementary Data Types
- Conversion Rules for References................................................................................
- Conversion Rules for Structures..................................................................................
- Conversion Rules for Internal Tables
- Alignment of Data Objects
- Processing Sections of Strings
- Field Symbols and Data References
- Field Symbols
- Defining Field Symbols
- Assigning Data Objects to Field Symbols....................................................................
- Basic Form of the ASSIGN Statement
- Assigning Components of Structures to a Field Symbol
- Defining the Data Type of a Field Symbol..............................................................
- Data Areas for Field Symbols.................................................................................
- Data References
- Reference Variables
- Creating Data Objects Dynamically
- Getting References to Data Objects
- Dereferencing Data References
- Data References: Example..........................................................................................
- Logical Expressions BC - ABAP Programming SAP AG
- Comparisons Between Different Data Types....................................................................
- Comparing Strings
- Comparing Bit Sequences
- Checking W hether a Field Belongs to a Range................................................................
- Checking for the Initial Value
- Checking Selection Criteria...............................................................................................
- Checking W hether a Field Symbol is Assigned
- Combining Several Logical Expressions
- Controlling the Program Flow.................................................................................................
- Branching Conditionally
- Loops
- Processing Large Volumes of Data
- Internal tables.........................................................................................................................
- Creating Internal Tables....................................................................................................
- Internal table types
- Internal table objects....................................................................................................
- Special Features of Standard Tables
- Processing Internal Tables
- Operations on Entire Internal Tables
- Assigning Internal Tables
- Initializing Internal Tables
- Comparing Internal Tables
- Sorting Internal Tables
- Internal Tables as Interface Parameters
- Determining the Attributes of Internal Tables
- Operations on Individual Lines
- Operations for all Table Types
- Inserting Lines into Tables
- Appending Summarized Lines
- Reading Lines of Tables....................................................................................
- Changing Lines
- Deleting Lines....................................................................................................
- Processing Table Entries in Loops....................................................................
- Operations for Index Tables
- Appending Table Lines......................................................................................
- Inserting Lines Using the Index
- Reading Lines Using the Index
- Binary Search in Standard Tables
- Finding Character Strings in Internal Tables.....................................................
- Changing Table Lines Using the Index
- Deleting Lines Using the Index
- Specifying the Index in Loops
- Access Using Field Symbols
- Using Header Lines as Work Areas
- Extracts SAP AG BC - ABAP Programming
- Defining an Extract............................................................................................................
- Filling an Extract with Data
- Processing Extracts
- Reading an Extract
- Sorting an Extract
- Processing Control Levels
- Calculating Numbers and Totals
- Formatting Data...............................................................................................................
- Example of Formatted Data
- Formatting Data During Reading
- Refining Data Using Internal Tables
- Formatting Data Using Extracts
- Saving Data Externally..............................................................................................................
- Saving Data Objects as Clusters
- Data Clusters in ABAP Memory........................................................................................
- Saving Data Objects in Memory
- Reading Data Objects from Memory
- Deleting Data Clusters from Memory
- Data Clusters in the Database
- Cluster Databases
- Structure of a Cluster Database
- Example of a Cluster Database..............................................................................
- Saving Data Objects in Cluster Databases
- Creating a Directory of a Data Cluster.........................................................................
- Reading Data Objects From Cluster Databases
- Deleting Data Clusters from Cluster Databases..........................................................
- Open SQL Statements and Cluster Databases...........................................................
- Working with Files
- Working with Files on the Application Server
- File Handling in ABAP
- Opening a File
- Basic Form of the OPEN DATASET Statement................................................
- Opening a File for Read Access
- Opening a File for Write Access........................................................................
- Opening a File for Appending Data
- Using Binary Mode
- Using Text Mode
- Opening a File at a Given Position....................................................................
- Executing Operating System Com mands
- Receiving Operating System Messages
- Closing a File
- Deleting a File.........................................................................................................
- Writing Data to Files
- Reading Data from Files
- Automatic Checks in File Operations BC - ABAP Programming SAP AG
- Authorization Checks for Programs and Files
- General Checks for File Access
- Working with Files on the Presentation Server.................................................................
- Writing Data to Presentation Server (Dialog)
- Writing Data to Presentation Server (no Dialog)
- Reading Data from Presentation Server (Dialog)
- Reading Data from Presentation Server (no Dialog)
- Checking Files on the Presentation Server
- Using Platform-Independent Filenames
- Maintaining Syntax Groups..........................................................................................
- Assigning Operating Systems to Syntax Groups
- Creating and Defining Logical Paths
- Creating and Defining Logical Filenames....................................................................
- Using Logical Files in ABAP Programs
- Modularization Techniques
- Source Code Modules............................................................................................................
- Procedures
- Subroutines
- Defining Subroutines
- Global Data from the Main Program.......................................................................
- Local Data in the Subroutine
- The Parameter Interface.........................................................................................
- Terminating Subroutines
- Calling Subroutines......................................................................................................
- Naming Subroutines
- Passing Parameters to Subroutines
- Examples of Subroutines........................................................................................
- Shared Data Areas
- Function Modules..............................................................................................................
- Function Groups
- Calling Function Modules
- Creating Function Modules..........................................................................................
- Organization of External Procedure Calls.........................................................................
- Special Techniques
- Catchable Runtime Errors......................................................................................................
- Program Checks
- Catching Runtime Errors...................................................................................................
- Checking Authorizations
- Checking User Authorizations...........................................................................................
- Defining an Authorization Check
- Checking the Runtime of Program Segments........................................................................
- GET RUN TIME FIELD
- Runtime Measurement of Database Accesses.................................................................
- Generating and Running Programs Dynamically................................................................... SAP AG BC - ABAP Programming
- Creating a New Program Dynamically
- Changing Existing Programs Dynamically........................................................................
- Running Programs Created Dynamically..........................................................................
- Creating and Starting Temporary Subroutines
- ABAP User Dialogs
- Screens.......................................................................................................................................
- Screen Elements
- Screen Attributes
- Screen Elements...............................................................................................................
- Screen Fields
- Screen Flow Logic
- Processing Screens
- User Actions on Screens
- Processing Input/Output Fields
- Pushbuttons on the Screen
- Checkboxes and Radio Buttons with Function Codes
- Using GUI Statuses
- Reading Function Codes
- Finding Out the Cursor Position
- Calling ABAP Dialog Modules...........................................................................................
- Simple Module Calls
- Controlling the Data Transfer
- Calling Modules Unconditionally..................................................................................
- Conditional Module Calls
- Input Checks
- Automatic Input Checks...............................................................................................
- Checking Fields in the Screen Flow Logic...................................................................
- Input Checks in Dialog Modules
- Field Help, Input Help, and Dropdown Boxes...................................................................
- Field Help.....................................................................................................................
- Input Help.....................................................................................................................
- Input Help from the ABAP Dictionary
- Input Help on the Screen........................................................................................
- Input Help in Dialog Modules
- Dropdown Boxes
- Modifying Screens D ynamically
- Setting Attributes D ynamically
- The Field Selection Function
- Setting the Cursor Position
- Switching on Hold Data Dynamically...........................................................................
- Complex Screen Elements.....................................................................................................
- Status Icons
- Context Menus
- Subscreens
- Tabstrip Controls............................................................................................................. BC - ABAP Programming SAP AG
- Custom Controls
- Table Controls...................................................................................................................
- Using the LOOP Statement
- Looping Through an Internal Table
- Example Transaction: Table Controls
- Looping Directly Through a Screen Table
- How the System Transfers Data Values......................................................................
- Using Step Loops
- Selection Screens
- Selection Screens and Logical Databases
- Defining Selection Screens
- Defining Input Fields for Single Values
- Basic Form of Parameters
- Dynamic Dictionary Reference
- Default Values for Parameters
- SPA/GPA Parameters as Default Values
- Allowing Parameters to Accept Upper and Lower Case
- Reducing the Visible Length
- Defining Required Fields
- Search Helps for Parameters
- Checking Input Values
- Defining Checkboxes...................................................................................................
- Defining Radio Buttons
- Hiding Input Fields
- Modifying Input Fields
- Defining Complex Selections
- Selection Tables
- Basic Form of Selection Criteria
- Selection Criteria and Logical Databases....................................................................
- Default Values for Selection Criteria............................................................................
- Restricting Entry to One Row
- Restricting Entry to Single Fields.................................................................................
- Additional Options for Selection Criteria
- Formatting Selection Screens...........................................................................................
- Blank Lines, Underlines, and Comments
- Several Elements in a Single Line
- Blocks of Elements
- Calling Selection Screens
- Calling Standard Selection Screens
- Calling User-Defined Selection Screens...........................................................................
- User Actions on Selection Screens........................................................................................
- Pushbuttons on the Selection Screen...............................................................................
- Checkboxes and Radio Buttons with Function Codes......................................................
- Pushbuttons in the Application Toolbar
- Changing the Standard GUI Status SAP AG BC - ABAP Programming
- Selection Screen Processing
- Basic Form
- PBO of the Selection Screen
- Processing Single Fields...................................................................................................
- Processing Blocks.............................................................................................................
- Processing Radio Buttons.................................................................................................
- Processing Multiple Selections
- Defining Field Help............................................................................................................
- Defining Input Help
- Subscreens and Tabstrip Controls on Selection Screens
- Selection Screens as Subscreens
- Tabstrip Controls on Selection Screens
- Subscreens on Selection Screens
- Using Selection Criteria..........................................................................................................
- Selection Tables in the W HERE Clause
- Selection Tables in Logical Expressions
- Selection Tables in GET Events
- Lists
- Creating Lists
- Creating Simple Lists with the WRITE Statement
- The WRITE Statement.................................................................................................
- Positioning WRITE Output on the List
- Formatting Options
- Displaying Symbols and Icons on the List
- Blank Lines and Drawing Lines
- Displaying Field Contents as Checkboxes
- Using WRITE via a Statement Structure
- Creating Complex Lists
- The Standard List
- Structure of the Standard List.................................................................................
- GUI Status for the Standard List
- The Self-Defined List
- Individual Page Header
- Determining the List Width
- Creating Blank Lines
- Determining the Page Length.................................................................................
- Defining a Page Footer...........................................................................................
- Lists with Several Pages..............................................................................................
- Programming Page Breaks
- Standard Page Headers of Individual Pages
- Page length of individual pages
- Page Width of List Levels
- Scrolling in Lists
- Scrolling Window by Window
- Scrolling by Pages BC - ABAP Programming SAP AG
- Scrolling to the Margins of the List
- Scrolling by Columns..............................................................................................
- Defining W here the User Can Scroll on a Page
- Laying Out List Pages..................................................................................................
- Positioning the Output
- Absolute Positioning
- Relative Positioning
- Formatting Output...................................................................................................
- The FORMAT Statement...................................................................................
- Colors in Lists...............................................................................................
- Enabling Fields for Input
- Outputting Fields as Hotspots
- Special Output Formats
- Lines in Lists......................................................................................................
- Interactive Lists
- Detail Lists.........................................................................................................................
- Dialog Status for Lists
- Context Menus for Lists
- List Events in an ABAP Program
- Lists in Dialog Boxes.........................................................................................................
- Passing Data from Lists to Programs
- Passing Data Automatically
- Passing Data by Program Statements
- Manipulating Detail Lists
- Scrolling in Detail Lists.................................................................................................
- Setting the Cursor from within the Program
- Modifying List Lines
- Lists and Screens...................................................................................................................
- Starting Lists from Screen Processing..............................................................................
- Calling Screens from List Processing
- Printing Lists...........................................................................................................................
- Printing a List after Creating it...........................................................................................
- Printing a List while Creating it..........................................................................................
- Print Parameters
- Execute and Print
- Printing from within the Program
- Printing Lists from a Called Program
- Print Control
- Determining Left and Upper Margins...........................................................................
- Determining the Print Format
- Documentation Not Available in Release 4.6C.................................................................
- Messages
- Message Management...........................................................................................................
- Messages
- Message Processing
- Messages Without Screens SAP AG BC - ABAP Programming
- Messages on Screens
- Messages on Selection Screens
- Messages in Lists
- Messages in Function Modules and Methods
- Running ABAP P rogram s
- Defining Processing Blocks
- Event blocks
- Dialog modules
- Running Programs Directly - Reports
- Linking to a Logical Database
- Report Transactions
- Event Blocks in Executable Programs
- Description of Events
- INITIALIZATION
- AT SELECTION-SCREEN...........................................................................................
- START- OF-SELEC TION
- GET..............................................................................................................................
- GET … LATE
- END-OF-SELECTION
- Leaving Event Blocks........................................................................................................
- Leaving Event Blocks Using STOP
- Leaving Event Blocks Using EXIT
- Leaving Event Blocks Using CHECK
- Leaving a GET Event Block Using REJECT
- Dialog-Driven Programs: Transactions
- Dialog Programs: Overview
- Maintaining Transactions
- Dialog Transactions
- Report Transactions..........................................................................................................
- Variant Transactions
- Parameter Transaction
- Screen Sequences
- Static Next Screen
- Dynamic Next Screen
- Leaving a Screen from a Program
- Starting a Screen Sequence
- Calling Modal Dialog Boxes
- Screen Sequences: Example Transaction......................................................................
- Calling Programs.....................................................................................................................
- Calling Executable Programs...............................................................................................
- Filling the Selection Screen of a Called Program
- Affecting Lists in Called Programs
- Program Statements to Leave a Called Program
- Calling Transactions.............................................................................................................
- Calling Screen Sequences as Modules BC - ABAP Programming SAP AG
- Passing Data Between Programs
- Filling an Initial Screen using SPA/GPA Parameters
- ABAP Database Access..........................................................................................................
- Accessing the Database in the R/3 System
- Open SQL
- Reading Data
- Defining Selections
- Specifying a Target Area
- Specifying Database Tables
- Selecting Lines................................................................................................................
- Grouping Lines................................................................................................................
- Selecting Groups of Lines...............................................................................................
- Specifying a Sort Order...................................................................................................
- Subqueries
- Using a Cursor to Read Data..........................................................................................
- Locking Conflicts
- Changing Data
- Inserting Lines into Tables
- Changing Lines
- Deleting Lines
- Inserting or Changing Lines
- Committing Database Changes
- Performance Notes
- Keep the Result Set Small
- Minimize the Amount of Data Transferred
- Minimize the Number of Data Transfers
- Minimize the Search Overhead.......................................................................................
- Reduce the Database Load
- Native SQL
- Native SQL for Oracle
- Native SQL for Informix........................................................................................................
- Native SQL for DB2 Common Server
- Logical D atabases
- Structure of Logical Databases
- Selection Views
- Example of a Logical Database
- Using Logical Databases
- Linking a Logical DB to an Executable Program
- Calling a Logical Database Using a Function Module
- Editing Logical Databases....................................................................................................
- Creating a Logical Database...........................................................................................
- Processing the Structure.................................................................................................
- Editing a Search Help
- Editing Selections
- Editing the Database Program........................................................................................
- Dynamic Selections in the Database Program
- Field Selections in the Database Program SAP AG BC - ABAP Programming
- Search Helps in the Database Program
- Independent Calls and the Database Program
- Editing Other Components..............................................................................................
- Improving Performance...................................................................................................
- Using C ontexts
- What are Contexts?
- The Context Builder in the ABAP Workbench......................................................................
- Creating and Editing a Context
- Using Tables as Modules
- Using Function Modules as Modules.........................................................................
- Using Contexts as Modules
- Testing a Context
- Buffering Contexts
- Fields...............................................................................................................................
- Modules..........................................................................................................
- Interfaces
- Using Contexts in ABAP Programs......................................................................................
- Finding and Displaying a Context
- Creating an Instance of a Context
- Supplying Context Instances with Key Values................................................................
- Querying Data from Context Instances...........................................................................
- Message Handling in Contexts
- Message Handling in Table Modules
- Message Handling in Function Module Modules.......................................................
- Working With Contexts - Hints
- Programming Database Updates...........................................................................................
- Transactions and Logical Units of Work
- Database Logical Unit of Work (LUW)............................................................................
- SAP LUW
- SAP Transactions
- The R/3 Lock Concept
- Example Transaction: SAP Locking
- Update Techniques
- Asynchronous Update.....................................................................................................
- Updating Asynchronously in Steps
- Synchronous Update
- Local Update
- Creating Update Function Modules
- Calling Update Functions
- Calling Update Functions Directly...................................................................................
- Adding Update Task Calls to a Subroutine
- Special LUW Considerations
- Transactions That Call Update Function Modules..........................................................
- Dialog Modules that Call Update Function Modules.......................................................
- Error Handling for Bundled Updates
- ABAP O bjects
- What is Object Orientation? BC - ABAP Programming SAP AG
- What are ABAP Objects?........................................................................................................
- From Function Groups to Objects.........................................................................................
- Classes
- Overview Graphic.................................................................................................................
- Classes - Introductory Example
- Object Handling
- Overview Graphic.................................................................................................................
- Objects - Introductory Example............................................................................................
- Declaring and Calling Methods..............................................................................................
- Methods in ABAP Objects - Example
- Inheritance
- Inheritance: Overview Graphic.............................................................................................
- Inheritance: Introductory Example
- Interfaces..................................................................................................................................
- Overview Graphics
- Interfaces - Introductory Example
- Triggering and Handling E vents
- Overview Graphic..............................................................................................................
- Events: Introductory Example
- Events in ABAP Objects - Example
- Class P ools
- Appendix
- Programs, Screens, and Processing Blocks
- Introductory Statements for Program s
- Overview of ABAP Calls
- Call Contexts
- Internal Calls
- External Procedure Calls
- External Program Calls
- Callable Units
- ABAP Programs
- Procedures......................................................................................................................
- Screens and Screen Sequences
- ABAP Statement Overview.....................................................................................................
- ABAP System Fields
- ABAP G lossary
- Syntax C onventions
SAP AG BC - ABAP Program ming
BC - ABAP P rogramm ing
BC - ABAP Programming
This documentation describes how to write application programs within the three-tier client/server architecture of the R/3 System.
Presentation
SASAPP GU GUII
SS A SAAPPP GGUUII
SSAPAP GGUUII SSAAPP G GUUII
Application
A ABBAAPP (^) AABBAAPP
Database
RRDDBBMMSS
R/3 applications are written in the ABAP programming language, and run within the application layer of the R/3 System.
ABAP programs communicate with the database management system of the central relational database (RDBMS), and with the graphical user interface (SAPgui) at presentation level.
Contents
The documentation is divided into five sections:
Introduction to ABAP [Page 19]
This contains the basics of application programming in the R/3 System. This information is essential for an understanding of ABAP programming. Following an overview of the R/3 Basis system, it introduces the essential features of application programs and the ABAP programming language. Finally, it gives a short introduction to how you can create an application program in the ABAP Workbench.
The ABAP Programming Language [Page 82]
This section describes the statements in the ABAP programming language. Beginning with simple statements for data declarations, data processing, and program flow control, it progresses to topics such as modularization and special techniques, explaining which ABAP statements can be used for which purposes.
ABAP User Dialogs [Page 523]
SAP AG BC - ABAP Program ming
Introduction to AB AP
Introduction to ABAP
… but before you start, please read
the following sections:
The R/3 Basis System: Overview [Page 20]
Overview of the Components of Application Programs [Page
37] Creating and Changing ABAP Programs [Page 68]
BC - ABAP Programming SAP AG
The R/3 Basis System: Overview
The R/3 Basis System: Overview
The R/3 Basis system is the platform for all other applications (financial accounting, logistics, human resources management) in the R/3 System.
This documentation explains just what the Basis system is, and how it ties in with the R/3 System as a whole. It starts by introducing the Basis system in general. The second part concentrates on one central component - the application server. Finally, it will explain about work processes, which are components of the application server.
Position of the Basis System Within the R/3 System [Page 21]
Application Server [Page 27]
Work Processes [Page 32]