370 likes | 604 Views
Introduction to ABAP/4. What is ABAP/4?. A dvanced B usiness A pplication P rogram Release 4 Why do we need to develop ABAP/4 applications in SAP R/3?. Why use ABAP?. ABAP/4 is the programming language SAP developers use to build transactions and customize SAP R/3.
E N D
What is ABAP/4? • Advanced Business Application Program • Release 4 • Why do we need to develop ABAP/4 applications in SAP R/3?
Why use ABAP? • ABAP/4 is the programming language SAP developers use to build transactions and customize SAP R/3. • The main purpose of ABAP/4 is to provide additional functionality to existing SAP applications. • We tend not to use ABAP/4 to develop custom applications from scratch.
Purpose of ABAP/4 • The two most common uses of ABAP/4 are: • Producing custom reports • Developing custom interfaces
Reports & Interfaces • Report - The ABAP program reads specific data from the SAP database and then displays this data on the screen or writes it to a printer. • Interface - The ABAP program reads data from the SAP database and writes it to an external file to be used by another system (e.g. mainframe).
In this course we will? • Learn enough ABAP/4 to access the SAP database using SQL. • Write & format this data to a printer / screen. • Write this data to an external file • SO YOU CAN: • Write a Report program • Write an Interface program
How we will proceed • We will learn various parts of an ABAP/4 program first. • We will then put these parts together to develop a complete program.
Defining a program • REPORT program name • The report has various features to format output to the screen or printer we will talk about these features later.
Commenting your code • It is expected that you will have sufficient comments in all the ABAP/4 programs you write. Why? • It is EXPECTED of all PROFESSIONAL software developers. • Due to the high turnover rate of SAP R/3 & ABAP/4 consultants, other people may be stuck maintaining your program.
Adding comments in ABAP/4 • 1: To comment an entire line use an asterisks (*). * This program will…
Adding comments in ABAP • 2: To comment part of a line use the double quote (“) • WRITE ‘HELLO’ “This statement will….
Variables and Constants • We have given the program a name and added a description of the program in the comments. • To manipulate and gather data for processing we need variables, records, and constants.
A variable is: • - A symbolic reference to a memory location that stores information temporarily. These variables persist only during the execution of the program, and the data they contain is lost when the execution is complete - unless the data is transferred to a database table or system file.
Variables • MUST be declared before they are used. • Can be declared anywhere in the program, BUT for consistency they should be declared at the beginning of a program or subroutine. • Begin each variable with a letter and then a mixture of letters and numbers
Variables • Use the underscore (_) to separate distinct words. DO NOT use the hyphen ( -) this has a special purpose that we will discuss later. • NO reserved words (the same name as an ABAP command)
Variables • Standard SCOPE rules apply. Variables defined at the program level are considered global, variables in subroutines are visible only to the subroutine.
Declaring variables • DATA var[(LENGTH)] [TYPE type] [DECIMALS number] [VALUE initial value] • var is the name of the variable • [(length)] is the size of the variable
TYPE is the type of variable. The possible data types for variables in ABAP are:
Data types for ABAP/4 • Type/Description/Example • C Character “hello world” • D Date “19990101” • F Floating point # 3e4 • N Numeric text 10000 • P Packed Decimal 22.50 • T Time 104500 • H Hexadecimal 23A
We will only use: • C, D, P, I, T, and maybe N. • The DECIMAL 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 FIELD HAS 6 DIGITS BEFORE THE DECIMAL AND 2 DIGITS AFTER , IT MUST BE DECLARED AS A SIZE 8. • VALUE is the initial or default value for the field at execution.
Example 1 • Declare a variable that will hold the persons job title, it should be 10 characters in length and be initialize to MANAGER. DATA JOB_TITLE (10) TYPE C VALUE ‘MANAGER’.
Example 2 • Declare a variable to store the persons date of birth. Initialize the value to December 31, 1900. DATA DATE_OF_BIRTH (8) TYPE D VALUE ‘19901231’.
Your turn • Declare a variable that will store the employee income. It is comprised of 8 digits before the decimal point and 2 digits following it. Initialize the variable to 1 DOLLAR.
Answer • DATA EMP_INCOME (10) TYPE P DECIMALS 2 VALUE ‘1.00’.
Constants • Data that doesn’t change its value during program execution. • Defines the same as DATA variables. • Example: • CONSTANTS PLANT_NUM TYPE I VALUE ‘6523’.
Run-time Parameters • Allows us to pass data to the ABAP/4 program at run time. • PARAMETERS parameter name TYPE type. • For all the options see page 16 in the book.
ABAP/4 Statements • ABAP/4 does not care where a statement begins on a line. - As a result, you should indent sections of code for readability.
ABAP/4 Statements • Multiple statements can be placed on a single line. To improve readability this is not recommended. • Blank lines can be placed anywhere in the program and should be used to improve readability. • ALL ABAP/4 statements (except comments) must end with a period (.).
Coding Statements • We will now discuss how to display data including: • Moving data into a variable • Moving data between variables • Writing data to the report/screen • Coding our first complete ABAP/4 program
MOVE • Move data into or between variables is done using the move statement. There are two forms of the move statement. • MOVE value TO var • var = value
Moving data into a variable • MOVE ‘10’ TO PERSON_AGE. • OR • PERSON_AGE = ‘10’.
Moving data from one variable to another • Move the contents of PERSON_AGE to DISPLAY_AGE: • MOVE PERSON_AGE TO DISPLAY_AGE • or • DISPLAY_AGE = PERSON_AGE.
Computations • [COMPUTE] var = expression. • ADD value TO var. • SUBTRACT value FROM var. • MULTIPLY value BY var. • DIVIDE value BY var.
Outputting text • To output data to the screen we use the write command. • WRITE ‘text’. • WRITE field name.
WRITE • WRITE ‘Boyle’. • WRITE LAST_NAME.