lecture1 intro to abap
TRANSCRIPT
-
8/6/2019 Lecture1 Intro to ABAP
1/54
Lesson 1: Introduction toABAP OBJECTS
Todd A. Boyle, Ph.D.St. Francis Xavier University
-
8/6/2019 Lecture1 Intro to ABAP
2/54
Section Report
Develop a simple report that will accept two
numbers from the user and display the sumof the two numbers on a report.
-
8/6/2019 Lecture1 Intro to ABAP
3/54
-
8/6/2019 Lecture1 Intro to ABAP
4/54
-
8/6/2019 Lecture1 Intro to ABAP
5/54
Wha t is ABAP OBJECTS?
Advanced Business Application
P rogramming. Previously known as ABAP /4 . Since renamed to ABAP OBJECTS .
W hy do we need to develop ABAPapplications in SAP R/3?
-
8/6/2019 Lecture1 Intro to ABAP
6/54
Why use ABAP?
ABAP OBJECTS is the programming
language SAP developers use to buildtransactions and reports and customize SAPR/3.The main purpose of ABAP OBJECTS is to
provide additional functionality to existingSAP applications.W e do not use ABAP OBJECTS to developcustom applications from scratch.
-
8/6/2019 Lecture1 Intro to ABAP
7/54
Using t h e ABAP Editor
-
8/6/2019 Lecture1 Intro to ABAP
8/54
-
8/6/2019 Lecture1 Intro to ABAP
9/54
-
8/6/2019 Lecture1 Intro to ABAP
10/54
-
8/6/2019 Lecture1 Intro to ABAP
11/54
-
8/6/2019 Lecture1 Intro to ABAP
12/54
-
8/6/2019 Lecture1 Intro to ABAP
13/54
Defining a progr am
REPORT program name.
The REPORT command has various featuresto format output to the screen or printer. W ewill discuss these features later.program name must start with a Z. You can also use a Y, but Z is used far more
often.
-
8/6/2019 Lecture1 Intro to ABAP
14/54
Co mm enting your code
It is expected that you will have sufficient
comments in all the ABAP OBJECTSprograms you write. Why ? It is EXPECTED of all PROFESS IONAL software
developers.
Due to the high turnover rate of SAP R/3 & ABAPOBJECTS consultants, other people may bestuck maintaining your program.
-
8/6/2019 Lecture1 Intro to ABAP
15/54
Adding co mm ents inABAP OBJECTS
To comment an entire line use an asterisks (*).
* This program will
-
8/6/2019 Lecture1 Intro to ABAP
16/54
Adding co mm ents in ABAP
To comment part of a line use the double quote
( )
T h is st a te m ent will.
-
8/6/2019 Lecture1 Intro to ABAP
17/54
Va riab les a nd Const a nts
W e have given the program a name and
added a description of the program in thecomments.
To manipulate and gather data for processing we need variables, records, andconstants.
-
8/6/2019 Lecture1 Intro to ABAP
18/54
Va riab les in ABAP
MU ST be declared before they are used.
Can be declared anywhere in the program,BU T for consistency they should be declaredat the beginning of a program or subroutine.Begin each variable with a letter and then amixture of letters and numbers
-
8/6/2019 Lecture1 Intro to ABAP
19/54
Va riab les
U se the underscore ( _) to separate distinct
words.DO NOT use the hyphen ( -). This has aspecial purpose that we will discuss later.NO reserved words (the same name as an
ABAP command).
-
8/6/2019 Lecture1 Intro to ABAP
20/54
Va riab les
V ariables defined at the program level are
considered global.V ariables in defined in a subroutine arevisible only to the subroutine.
-
8/6/2019 Lecture1 Intro to ABAP
21/54
Decl a ring v a riab les
DATA var[(LENGTH)] [TYPE type]
[DEC IM ALS number] [ V ALU E initial value]var is the name of the variable[(length)] is the size of the variableTYPE is the type of variable. The possibledata types for variables in ABAP are:
-
8/6/2019 Lecture1 Intro to ABAP
22/54
-
8/6/2019 Lecture1 Intro to ABAP
23/54
Decl a ring Va riab les: Ex am ple 1
Declare a variable that will hold a persons
job title.It should be 10 characters in length and beinitialize to M ANAGER.
DATA JOB_T ITLE (10) TYPE C V ALU EM ANAGER.
-
8/6/2019 Lecture1 Intro to ABAP
24/54
Decl a ring Va riab les: Ex am ple 2
Declare a variable to hold the employee ID
number.W hen we declare a variable of type I (i.e.,Integer) we do not specify the variable size.
DATA E M P_ ID TYPE I.
-
8/6/2019 Lecture1 Intro to ABAP
25/54
Decl a ring Va riab les: Ex am ple 3
Declare a variable to store the persons date
of birth.Initialize the variable to December 31, 1900.
DATA DATE_OF_B IRTH TYPE D V ALU E19001231.
-
8/6/2019 Lecture1 Intro to ABAP
26/54
DATA var[(LENGTH)] [TYPE type]
[DEC IM ALS number] [ V ALU E initial value] The DEC IM AL is the number of decimal places
for the packed decimal type.
The size of the field = digits before the
decimal + digits after the decimal. IF A F IELD HAS 6 D IG ITS BEFORE THE DEC IM AL AND 2
DIG ITS AFTER , THEN IT MU ST BE DECLARED AS AS IZE 8.
Decl a ring Va riab les: Deci ma l Type
-
8/6/2019 Lecture1 Intro to ABAP
27/54
Decl a ring Va riab les: Deci ma l Type
Declare a variable that will store the
employee income.It is comprised of 8 digits before the decimalpoint and 2 digits following it.Initialize the variable to 1 DOLLAR.
-
8/6/2019 Lecture1 Intro to ABAP
28/54
Answer
DATA E M P_ INCO M E (10) TYPE P
DEC IM ALS 2 V ALU E 1.00.
-
8/6/2019 Lecture1 Intro to ABAP
29/54
Const a nts
Data that does not change its value during
program execution.Defined the same as DATA variables.Example: CONSTANTS PLANT_N UM TYPE I V ALU E
6523.
-
8/6/2019 Lecture1 Intro to ABAP
30/54
Run -tim e P a r am eters
Allows the user to pass data to the program at
run time. At run time, the default SAP R/3 screen will bedisplay with the parameters you have coded.PARA M ETERS parameter name TYPE type.
-
8/6/2019 Lecture1 Intro to ABAP
31/54
Run -tim e P a r am eters
If we wanted the user to enter an
employee ID. PARA M ETERS E M P_ ID TYPE I.The parameter name is limited to 8
characters.For the lesson example, the input screenwould look like this:
-
8/6/2019 Lecture1 Intro to ABAP
32/54
-
8/6/2019 Lecture1 Intro to ABAP
33/54
Ex am ple Progr am
Let us review what we covered so far, by
examining the simple ABAP calculator program.
ZW SCALC
-
8/6/2019 Lecture1 Intro to ABAP
34/54
ABAP OBJECTS St a te m ents
ABAP OBJECTS does not care where a
statement begins on a line.However, to ensure programprofessionalism, you should indent sectionsof code for readability.
You can easily do this using PRETTYPR INTER.
-
8/6/2019 Lecture1 Intro to ABAP
35/54
ABAP OBJECTS St a te m ents
M ultiple statements can be placed on a
single line. To improve readability, this is notrecommended.Blank lines can be placed anywhere in theprogram and should be used to improve
readability. ALL ABAP OBJECTS statements (except
comments) must end with a period ( .).
-
8/6/2019 Lecture1 Intro to ABAP
36/54
Coding St a te m ents
W e will now discuss how to display data
including: M oving data into a variable M oving data between variables Performing basic computations
W riting data to the report/screen Coding your first complete ABAP OBJECTS
program.
-
8/6/2019 Lecture1 Intro to ABAP
37/54
MOVE
M ove data into or between variables is done
using the M O V E statement. There are twoforms of the M OV E statement.
M OV E value TO var var = value
-
8/6/2019 Lecture1 Intro to ABAP
38/54
Moving v a lues into a va riab le
M OV E 10 TO PERSON_AGE.
OR
PERSON_AGE = 10.
-
8/6/2019 Lecture1 Intro to ABAP
39/54
Moving d a ta fro m oneva riab le to a not h er
M ove the contents of PERSON_AGE to
DISPLAY_AGE:
M OV E PERSON_AGE TO D ISPLAY_AGE or
DISPLAY_AGE = PERSON_AGE.
-
8/6/2019 Lecture1 Intro to ABAP
40/54
Co m put a tions
CO M P U TE variable = expression.
CO M P U TE is optional.
ADD value TO variable.S U BTRACT value FRO M variable.MU LT IPLY variable BY value.DIV IDE variable BY value.
-
8/6/2019 Lecture1 Intro to ABAP
41/54
Co m put a tions
CO M P U TE INCO M E_TAX =
GROSS_ INCO M E * TAX_RATE.
ADD 1 TO REC_CO U NTER
MU LT IPLE GROSS_ INCO M E BYTAX_RATE. ( W hat is the problem with this?)
-
8/6/2019 Lecture1 Intro to ABAP
42/54
Outputting text
To output data to the screen, we use the
write command.
W R ITE text. W R ITE field name.
-
8/6/2019 Lecture1 Intro to ABAP
43/54
WRITE
W R ITE Boyle.
W R ITE LAST_NA M E.Some of the basic write options include:: = groups of text, variables.
/ = break to a new lineW R ITE: /, F IRST_NA M E, LAST_NA M E.
-
8/6/2019 Lecture1 Intro to ABAP
44/54
Write: Outputting groups of text
If we wanted to write the following:W eekly Sales Total: 13456.32
W e could code:W R ITE CON_SALE_HEADER.W R ITE W _SALES_TOT.
ORW R ITE : CON_SALE_HEADER, W _SALES_TOT.
-
8/6/2019 Lecture1 Intro to ABAP
45/54
Write: Bre ak ing to a new line
W R ITE HELLO.
W R ITE W ORLD.
would give us:
HELLO W ORLD
-
8/6/2019 Lecture1 Intro to ABAP
46/54
Write: Bre ak ing to a new line
W hat if we want the text on two separate lines?W
e use a / following theW
RITEW R ITE / HELLO.
W R ITE / W ORLD.
W e can combine both grouping and breaking:
W R ITE : /, CON_SALE_HEADER, W _SALES_TOT.
-
8/6/2019 Lecture1 Intro to ABAP
47/54
Review
Let us finish the calculator program.
ZW SCALC
M odify the program to accept four numbers from the
user and calculate and display the average. Instead of retyping the program you can create a copy of it.
-
8/6/2019 Lecture1 Intro to ABAP
48/54
-
8/6/2019 Lecture1 Intro to ABAP
49/54
-
8/6/2019 Lecture1 Intro to ABAP
50/54
-
8/6/2019 Lecture1 Intro to ABAP
51/54
-
8/6/2019 Lecture1 Intro to ABAP
52/54
-
8/6/2019 Lecture1 Intro to ABAP
53/54
Answer to t h eAver a ge Report Progr am
ZWSCALCA VG
-
8/6/2019 Lecture1 Intro to ABAP
54/54
Exercises
INCLASS11
INCLASS12