Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Who ? Why ?
Course Objective
To introduce the structure and syntax of the ABAP language so that attendees gain an appreciation of its capabilities To introduce the ways data is held in the SAP system and demonstrate how to report this data via ABAP To provide enough hands-on examples to allow the
What is SAP?
1972 Founded by 4 IBM employees in a small German Town (Walldrof). SAP AG R/2 (Real Time / Two Tier)
SAP Modules
SD
Sales and Distribution Materials Management
FI
Financial Accounting
MM
CO
Controlling
PP
Production Planning
R/3
HR
Human Resources
AM
Fixed Assets Accounting
QA
Quality Assurance
Plant Maintenance
Client/Server PS PM OC ABAP
Project System
IS
Industry Solutions
Course Outline
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
System Architecture
System Architecture
APPLICATION SERVERS DATABASE SERVER PRESENTATION SERVERS
DATA BASE
DATA FLOW
First level Presentation level (SAP Gui). Contains the user interface whereby an end user can access an application, enter new data and receive the results of a work process.
Second level
Application level. ABAP program runs in this level, consists of both the applications provided by SAP and the ones you develop yourself. ABAP programs work with data called up from the database level and store new data there as well. Third level
Database level. Data in here is managed with the help of a relational database management system (RDBMS). In addition to master data and transaction data, programs that describes the R/3 System are stored and managed here.
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
A Powerful Tool
The system is written in it SAP can be shaped to the Clients particular needs Adds value to the implementation ?
A Dangerous Weapon
Avoid changing the source code
SAP will not support a system that has been improperly changed.
Reporting Alternatives
Performance - time to develop compared to time to run. Standard SAP
Existing Reports SAP (ABAP) Query Report Writer LIS
Extended SAP
Business Information Warehouse
Third Party - though ABAP code often needed for data extraction
Standard SAP
Data Transfer Workbench
Data reformatting and conversion ABAPs still need to be written
Extended SAP
Legacy System Migration Workbench (LSMW)
Data reformatting and conversion ABAPs are generated by the tools provided
(AB)uses of ABAP
Paper Reporting Interactive Reporting Data Export Data Import Batch Input
Transaction Development
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
Navigation
Logging on
The logon screen
To change password:
1.
The system will prompt the change password box at initial logon screen (first time logging into the system)
Click on New password at the logon screen if you wish to change again
2.
Command field
Exercise 01
Task 1:
Logon to the system. Try to change the password. Once in the system, try to familiarize with the screen. Navigate to a transaction code (e.g. SE11) and return to the SAP easy access menu.
Task 2: What is the maximum number of parallel sessions that you can open using System -> Create session?
Task 3: What is the name of the function you reach if you choose Tools -> Administration -> Monitor -> System Monitoring -> User Overview?
Exercise 01
Task 4:
Task 5: Add a new transaction to the SAP easy access menu into the
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
Ver 4.6 Tools > ABAP Workbench > Overview > Object Navigator -
Program
Creating package
A package can be created via SE80. When creating, it will prompt to enter
description (meaningful names) and assigning a transport number to it.
Creating transport
A transport can be created via transaction SE10 / SE01.
Customizing Request
Request that involves changes recorded to client-specific Customizing objects .These client specific requests are used for copying and transporting changed system settings from client-specific tables.
Releasing transport
To release a transport, click on the truck button. Note: Do NOT click on this unless instructed to do so Note: If accidentally created a TR, click on the trash button to delete the transport.
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
Program Outline
INPUT
PROCESS
OUTPUT
Program Structure I
Typical Report :
REPORT ...... * DECLARATION SECTION TYPES: ...... DATA: ...... * STATEMENT SECTION SELECT BUKRS BUTXT FROM T001 ........
To be able to create ABAP programs, you will need to be given an access key. Normally, you request this from the Basis team.
The developer access key is 20 characters in length. You only need to enter this key ONCE.
Type
Executable program
Include program
Module pool Function group etc.
object.
Save (Ctrl-S)
Display/Change mode(Ctrl-F1)
Save/activate (Ctrl-F3)
Execute (F8)
Exercise 02
Task 1:
Create an ABAP program via SE38 or SE80 which will be called Zuu_exNN_<meaningful description>
Task 2:
Write a simple program (eg. Write: / Hello World. ). Perform syntax check,
save, activation and execute the program. Get yourself familiar with the shortcut keys and the screen.
Exercise 02
Task 3:
Copy program Z00_TEST_TCODE, create a transaction code for the
program. Name your transaction Zuu_NN_tcode uu is your ABAPER number NN refers to the exercise number
Task 4:
Add the newly created transaction code to the favourites in the SAP easy access menu.
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment Packages and Transport request
PROGRAM DEBUGGING
A powerful tool to show what a program is doing Enables us to walk through code step-by-step
Starting
You have no idea where the error is:
Switch on Debugger in the Editor initial screen via Program =>
Break Points
BREAK POINTS are points at which we want to stop the program to start debugging. There are 2 types: DYNAMIC
These are session specific - you loose them when you sign off
STATIC.
Set directly into code via the Editor
User-independent - visible in program code MUST BE REMOVED FOLLOWING TESTING
Screen Display I
7 Different Views - same basic structure
Fields (default) - Displays a fields contents and technical characteristics Table - Displays the contents of an internal table Breakpoints - Gives a scrollable display of up to 30 breakpoints defined in the program Watchpoints - Displays up to 5 watchpoints Call Stack - Displays an active event chain up to the current breakpoint Overview - Displays the structure of the program being debugged Settings -
Screen Display II
There are a number of ways of stepping through the
program code using the debugger:
SINGLE STEP - executes a program statement by statement EXECUTE (subroutines treated as a single step) CONTINUE - up to the next BREAK or WATCH POINT RETURN - to the calling program. Used from within a subroutine call
Field contents
To display the contents of critical fields used in the program
Use Fields view Double Click on the field name to bring it into the display Click on Click on to display Hexadecimal value to replace the value - this can be used to force the program
Watchpoints
Set a WATCH POINT to check when a field contents changes
Debugging 1
ways.
1. Click on Stop icon.
Debugging 2
Debugging 3
3. Enter /h in the command field in the standard toolbar and press enter.
Help
COURSE OUTLINE
ABAP syntax
ABAP Syntax I
Similar commands
WRITE PERFORM
MOVE
Similar structures
IF/ELSE DO/WHILE CASE etc.
ABAP Syntax II
WRITE family_name.
Equivalent to: WRITE: My name is,
first_name,
family_name.
System Fields I
SY-DATUM - Date
SY-UZEIT - Time SY-UNAME - Your Logon ID
Format color
In a list, we can design the screen by adding colors. Below are the
Exercise 03
Task 1:
Create an ABAP program which will be called Zuu_exNN_<meaningful
description>
Task 2:
Display your Logon ID, Date and Time
Write Statement II
WRITE:/p(w) Text.
Text - Better to use numbered texts (see later)
/ - New Line (or use syntax NEW-LINE)
Example:
WRITE:/2(3) HELLO. => HEL
Exercise 03
COPY Exercise 2
Control Statements
LOGIC FLOW
IF ... ENDIF. ON CHANGE OF ... END ON. CASE ... ENDCASE.
LOOPS
DO ENDDO. WHILE ENDWHILE.
OTHERS
CHECK
CONTINUE EXIT
The IF Statement
IF <Logical Expression> .
.... ELSE. Processing done when true Optional
....
ENDIF.
IF Operations
These operations can be used within IF clauses to compare
certain values: Relational Operators (Letters or Symbols) EQ = GT > LT < NE <> >< GE >= => LE <= =<
BETWEEN <value1> AND <value2> IS INITIAL (The initial value for that data type)
String Comparisons
As well as comparing values, we can also use the IF
statement to check character strings against certain criteria using the following:
CO CA CS CP
WHEN <VALUE2>
...
WHEN OTHERS - CATCH ALL ...
ENDCASE.
Do, While
DO <N> TIMES . <N> can be a constant or
.... ENDDO. field.
WHILE
<LOGICAL EXPRESSION>.
.... ENDWHILE.
IF <undesirable condition>.
FALSE
TRUE
statements ENDWHILE.
TRUE
statements
FALSE
CONTINUE
Comments
You can comment / uncomment blocks of code: Select > Block/Buffer > Insert or Delete Comment
Write Statement I
Basic Syntax:
WRITE <FIELDNAME>.
Activation
COURSE OUTLINE
ABAP syntax
Parameters
Parameters
PARAMETERS are one way of supplying values to a program at run time PARAMETERS: pa_plant TYPE mard-werks DEFAULT READ OBLIGATORY.
SELECT werks lgort labst INTO stockstr FROM MARD WHERE werks = pa_plant. ... ENDSELECT.
To cause a selection range to appear on the Selection Screen: SELECT-OPTIONS: <SO_OPT> FOR <Field_Name>. This is a special kind of internal table containing 4 fields:
<SO_OPT>-SIGN <SO_OPT>-OPTION <SO_OPT>-LOW <SO_OPT>-HIGH I(nclusive) E(xclusive) Value (EQ, BT etc) Start of the range End of the range
SELECT-OPTIONS
SELECT-OPTIONS <SO_OPT> FOR <Field_Name>.
DATA: WA_COUNTRY TYPE Z9A01-COUNTRY. SELECT OPTIONS: SO_CNTRY FOR WA_COUNTRY DEFAULT GB TO US.
Internal table
Sign
I
Option Low
BT GB
High
US
Screen:
S_CNTRY GB US
VALUE SETS
VALUE SETS ALLOW FOR MULTIPLE SELECTIONS
Screen:
C_CNTRY (Press on )
...
Internal table SO_CNTRY
Sign Option EQ EQ Low BE FR High
I I
BT
GB
US
If a SELECT-OPTIONS is left empty on the selection screen, the ABAP will select all data.
Select-options
In select options, there are a few options that is available
GLORY You have provided a very flexible selection tool to the user
PARAMETERS vs SELECT-OPTIONS
PARAMETERS PO_PARM TYPE <Field> Support only a single value SELECT-OPTIONS
Both follow the rules: Maximum of 8 characters as a name Screen Description via Selection Texts Initial value set by DEFAULT option
Exercise 04
Task 1:
An ABAP Calculator Define 3 PARAMETERS 2 input integer numbers 1 input operand ( + , - , * , / ) Output the result to 2 decimal places Allow for invalid operators and division by zero
This can be achieved using ifelse..endif, caseendcase. Try using both methods
Exercise 05
Task 1:
Write an ABAP program to display contents of SFLIGHT table using a parameter selection. The program will prompt the user to enter (CARRID) carriage ID as the parameter selection criteria. Display all flights with the following information:
SFLIGHT-CARRID
SFLIGHT-CONNID SFLIGHT-FLDATE SFLIGHT-PLANETYPE SFLIGHT-SEATSMAX SFLIGHT-SEATSOCC
Exercise 06
Task 1:
Write an ABAP making use of the select-options selection. Distinguish the difference between no intervals and no-extensions usage.
Task 2:
Write an ABAP program to display contents of SFLIGHT table using a select-options selection. The program will prompt the user to enter a range of (CARRID) carriage ID as the selection criteria. Display all flights with the following information:
SFLIGHT-CARRID SFLIGHT-CONNID SFLIGHT-FLDATE SFLIGHT-PLANETYPE SFLIGHT-SEATSMAX SFLIGHT-SEATSOCC Notice the difference using select-options
COURSE OUTLINE
ABAP syntax
Declarations - Data
Definition of variables (fields) used in the program
Declarations- Data
C - Character
D - Date (YYYYMMDD) P - Packed (2l - 1 digits, decimals)
I - Integer
N - Numeric text (1 byte/digit)
spaces
Declarations - Constants
DATA fields may be changed by operations within the ABAP CONSTANT fields cannot be changed within the ABAP Example:
VALUE 3.1428.
Partial Fields
For types C,N,D it is possible to refer to part of a field:
<fieldname>+O(L)
O is the offset (zero is the first position) L is the length Example: TEMP_NAME = JOHN ARMYTAGE TEMP_NAME+5(4) contains ARMY Under certain conditions O and L can be variables
Numbered Texts
Message types
Message tnnn(message class) with v1 v2.
Type I Description Information Behavior Appearance
Success
Status bar
Warning
Context dependent
Error
Context dependent
A
x
Termination
Short dump
Program cancels
Runtime error triggered
Exercise 07
Task 1:
displayed.
Test the other message types namely ( W, S, E, A, and I) to see how the program handles it.
COURSE OUTLINE
ABAP syntax
TABLE SFLIGHT
COURSE OUTLINE
ABAP syntax
Accessing Data
SELECTED DATA
Basic Syntax
SELECT something - a list of table fields
INTO somewhere - a target area in the program FROM a table WHERE selection conditions
The SELECT statement does allow you to retrieve data from more than 1 table, but this is beyond the scope of this course.
Optimising SELECT
Large Tables
Indexes to improve selection on non key fields (e.g. Material Number in table MSEG) New database techniques to extract summarised data from the table on the database
Any Table
Only SELECT the fields you need
Select Endselect
SELECT <field list> INTO <target area> FROM <table> WHERE <selection criteria>. ..... ENDSELECT. Each selected record will be made available in turn within the SELECT ... ENDSELECT SY-SUBRC will not be zero if no data is selected SY-DBCNT will show the number of successful SELECTs
SELECT SINGLE
No ENDSELECT needed
Avoid the use of INTO CORRESPONDING FIELDS OF - this causes each entry in the database table to be checked in turn
MULTIPLE SELECTs
Many ABAPs need to SELECT data from several tables - there are
In this situation a poorly designed method can cause severe performance problems
NESTED SELECTs
SELECT FROM KNA1. ....
ENDSELECT.
SELECT ... FROM KNB1 INTO TABLE CUSTABB FOR ALL ENTRIES IN CUSTABA WHERE KUNNR = CUSTABA-CUSTNO.
SELECT ... FROM BSID INTO TABLE DOCTAB FOR ALL ENTRIES IN CUSTABB WHERE BUKRS = CUSTABB-COCODE AND KUNNR = CUSTABB-CUSTNO.
ENDLOOP.
ENDLOOP.
DATA: plant TYPE mard-werks, store TYPE mard-lgort, stock TYPE mard-labst.
DATA: BEGIN OF custstr, name TYPE z9a01-name, city TYPE z9a01-city, country TYPE z9a01-country, END OF custstr. NAME CITY COUNTRY
FIELD BY FIELD: CUSTSTR-NAME ... (etc) CODING SHORTCUT: MOVE-CORRESPONDING Z9A01 TO CUSTSTR . Using SELECT = Z9A01-NAME.
plant
store stock
TYPE mard-werks,
TYPE mard-lgort, TYPE mard-labst,
END OF stockstr.
SELECT werks lgort labst INTO stockstr FROM MARD WHERE .... ... ENDSELECT.
Authorization check
Authorization object S_CARRID
Fields: CARRID ACTVT
Change
CARRID = ACTVT = 02
Display
CARRID = ACTVT = 03
E.g. To display all CARRID, you can include * To create authorization object: SU21/SE80
Exercise 08
Task 1:
Display the records in a list format. If there are no records found, inform the user that No records have been selected.
Exercise 09
Task 1:
Create a program to show how a select single works. Retrieve the following
fields (CARRID, CONNID, FLDATE, PLANETYPE, SEATSMAX, SEATSOCC) using the following conditions:
CARRID = AA CONNID = 0017 FLDATE = 20070930
Display the records in a list format. If there are no records found, inform the user that No records have been selected. Try to store them in both variable and structure format.
Exercise 10
Task 1:
Display the records in a list format. If there are no records found, inform the user that No records found.
Exercise 11
Task 1:
COURSE OUTLINE
ABAP syntax
INTERNAL TABLES
These are tables internal to an ABAP and are used to store and
process data.
INTERNAL TABLES
Table type
Standard table
Sorted table
Hashed table
Index Access
Key Access
Non-unique
Unique/Nonunique
Unique
Exercise 12
Task 1:
Many date from earlier releases and still supported for compatibility
reasons We will focus on the Standard type with Work Area - this is the
Work Area
Work Area
TABLE STRUCTURE
WORK AREA:
CUSTTABCOUNTRY CUSTTAB-NAME CUSTTAB-CITY CUSTTABTURNOVER
FR JP Sartre
INTERNAL TABLE : BE FR FR Tintin Louis XIV JP Sartre
.
Paris
1234
(100 rows)
INTO wa_cust
FROM z9a01 WHERE <condition>.
Where the source of data is an SAP table - the fastest way is an array fetch
Append
1. APPEND
<tab>.
Country Sales
DE
400
AU US
700 200
Country Sales
2. APPEND
<tab>
SORTED BY SALES.
DE
400
AU
US
700
200
Collect
COLLECT <tab>.
Country Sales
DE
400
AU
100
US
DE
200
200 DE 600
filled.
Can also adjust entries
MODIFY
DELETE
INSERT APPEND
APPEND v COLLECT
Note that the field names are not qualified. Try to define table fields in correct order (primary sort field first, etc) to exploit powerful features
ENDLOOP.
SY-SUBRC NE 0 if the table is empty CHECK within the LOOP goes on to the next entry
AT COMMANDS
AT END OF <FIELD> )
SUM - Provides control break totals - note these are stored in the
header numeric fields ENDAT to end the block
The order in which these are coded is the order in which they will
take place.
AT FIRST / AT LAST
LOOP AT <internal_table> INTO <work area>.
... (processing)
AT FIRST. ... (processing to be performed during first loop pass through the table)
AT NEW / AT END OF
These are used as follows within LOOP ENDLOOP: LOOP AT it_cust INTO wa_cust.
AT NEW country.
SKIP. WRITE:/ Country:, wa_cust-country.
ENDAT.
WRITE:/ wa_cust-city, wa_cust-name, wa_cust-turnover. ENDLOOP.
SUM
SUM.
... (processing relevant to sum) ENDAT.
TABLE :
1 2 3
BE FR FR
Clear
Use with internal tables without header lines (have the same effect as
refresh). For internal table with header line, it only clears the header.
Free
Deletes entire content of the table and releases the memory used
Exercise 13
Task 1: Copy program from exercise 11. Using APPEND, insert a new record into the internal table by adding the following values:
CARRID = XX CONNID = 123 FLDATE = SY-DATUM PLANETYPE = 747-400
Task 2: Using DELETE, delete the record which was appended in task 1.
Exercise 13
Task 3:
Using INSERT, insert a new record into the internal table by adding the
following values to position 2 of the internal table content:
CARRID = XX CONNID = 123 FLDATE = SY-DATUM PLANETYPE = 747-400
Exercise 13
Task 5:
Exercise 14
Task 1: Create a new program. Retrieve CARRID, CONNID, FLDATE, PLANETYPE, SEATSMAX, SEATSOCC from SFLIGHT using conditions:
CARRID = P_CARRID
Using the records returned from SFLIGHT, retrieve CARRID, CONNID, BOOKID, CUSTTYPE, SMOKER, LUGGWEIGHT from SBOOK into a separate internal table. (Note: use for all entries addition in this select statement) This will base on:
CARRID = I_SFLIGHT-CARRID
CONNID = I_SFLIGHT-CONNID
FLDATE = I_SFLIGHT-FLDATE
Exercise 14
Task 2: The final report should show information of CARRID, CONNID, FLDATE PLANETYPE, SEATSMAX, SEATSOCC from SFLIGHT and CUSTTYPE, SMOKER, LUGGWEIGHT from SBOOK.
Hints:
Sort the tables Loop through the main table and read the next table with matching fields
Task 3: The header should contain (Carriage ID, Connection ID, Flight Date, Plane type, Seats max, Seats occ, Cust type, Smoker and Weight). Use color format on to distinguish the header and the record items. (Hint: use format color on)
COURSE OUTLINE
EVENTS
INITIALIZATION.
AT SELECTION-SCREEN START-OF-SELECTION. GET END-OF-SELECTION. TOP-OF-PAGE. END-OF-PAGE. AT LINE-SELECTION. AT USER-COMMAND. ABAP HAS PASSED THE SELECTION SCREEN
EVENTS
SUBROUTINES
PERFORM write_hello
PROGRAM MODULARITY
Advantages:
Code is easier to understand Programs are easier to test Programs are easier to maintain
FORMS I
Internal Subroutines Local DATA declarations are allowed in FORMs Basic syntax: PERFORM <FORM1>. ..... FORM <FORM1> ....... ENDFORM.
Create the skeleton FORM block by double-clicking on the name in the PERFORM block.
FORMS II - USING
Global data (eg Table fields) is known throughout the program,
including in all FORMs We may want to pass different arguments to the FORM under different circumstances. Syntax:
PERFORM ... USING - passing the ACTUAL parameters FORM ... USING - using the FORMAL parameters
Passing BY REFERENCE
Passing BY VALUE
........
FORM <FORM1> USING VALUE(A1). ... ENDFORM.
A1 is in a separate storage location to ARG1 - ARG1 will not be changed This method does not allow for any changes in the form to be passed back to the main program.
..........
FORM <FORM1> USING VALUE(A1) CHANGING VALUE(A2). ...
ENDFORM.
Exercise 15
Task 1:
Exercise 16
Task 1:
COURSE OUTLINE
FUNCTION MODULES
FUNCTION MODULES
FUNCTION GROUPS
Function module
What is FM? Function modules are applied across applications and are available throughout the SAP system. Function modules must be assigned to a function group. A function group is a placeholder which holds specific function modules that are defined in it. Function group can be created via SE37 or SE80 SE37 SE80
A Black Box
ABAP EXPORTS
FUNCTION MODULE
IMPORTS
TABLES
EXCEPTIONS (errors)
EXPORTS
ABAP IMPORTS
Use in ABAP I
Syntax (use the PATTERN button to generate this):
CALL FUNCTION EXPORTING PARM1 = <Field1> FUNCTION_NAME
.......
IMPORTING PARM10 = <Field10> .........
EXCEPTIONS
NOT_FOUND = 1 .
Use in ABAP II
To enter the FM into the ABAP program, use the Pattern push-button. Alternatively, the codes can be typed in as well.
The syntax will be copied into the program. ABAPer needs to fill in the input and/or output variables.