35
Introduction to ABAP/4 Introduction to ABAP/4

Introduction to ABAP/4

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to ABAP/4

Introduction to ABAP/4Introduction to ABAP/4

Page 2: Introduction to ABAP/4

What is ABAP/4?What is ABAP/4?

AAdvanced dvanced BBusiness usiness AApplication pplication PProgramrogram– Release Release 44

Why do we need to develop Why do we need to develop ABAP/4 applications in SAP R/3?ABAP/4 applications in SAP R/3?

Page 3: Introduction to ABAP/4

Why use ABAP?Why use ABAP?

ABAP/4 is the programming language ABAP/4 is the programming language SAP developers use to build SAP developers use to build transactions and customize SAP R/3.transactions and customize SAP R/3.

The main purpose of ABAP/4 is to The main purpose of ABAP/4 is to provide additional functionality to provide additional functionality to existing SAP applications.existing SAP applications.

We tend not to use ABAP/4 to develop We tend not to use ABAP/4 to develop custom applications from scratch.custom applications from scratch.

Page 4: Introduction to ABAP/4

Purpose of ABAP/4Purpose of ABAP/4

The two most common uses of The two most common uses of ABAP/4 are:ABAP/4 are:– Producing custom reportsProducing custom reports– Developing custom interfaces Developing custom interfaces

Page 5: Introduction to ABAP/4

Reports & InterfacesReports & Interfaces

Report - The ABAP program reads Report - The ABAP program reads specific data from the SAP database specific data from the SAP database and then displays this data on the and then displays this data on the screen or writes it to a printer.screen or writes it to a printer.

Interface - The ABAP program reads Interface - The ABAP program reads data from the SAP database and data from the SAP database and writes it to an external file to be used writes it to an external file to be used by another system (e.g. mainframe).by another system (e.g. mainframe).

Page 6: Introduction to ABAP/4

In this course we will?In this course we will?

Learn enough ABAP/4 to access the Learn enough ABAP/4 to access the SAP database using SQL.SAP database using SQL.

Write & format this data to a printer / Write & format this data to a printer / screen.screen.

Write this data to an external fileWrite this data to an external file SO YOU CAN:SO YOU CAN: Write a Report program Write a Report program Write an Interface programWrite an Interface program

Page 7: Introduction to ABAP/4

How we will proceedHow we will proceed

We will learn various parts of an We will learn various parts of an ABAP/4 program first.ABAP/4 program first.

We will then put these parts We will then put these parts together to develop a complete together to develop a complete program.program.

Page 8: Introduction to ABAP/4

Defining a programDefining a program

REPORT program nameREPORT program name

The report has various features to The report has various features to format output to the screen or format output to the screen or printer we will talk about these printer we will talk about these features later.features later.

Page 9: Introduction to ABAP/4

Commenting your codeCommenting your code

It is expected that you will have It is expected that you will have sufficient comments in all the sufficient comments in all the ABAP/4 programs you write. ABAP/4 programs you write. Why?Why?– It is EXPECTED of all PROFESSIONAL It is EXPECTED of all PROFESSIONAL

software developers.software developers.– Due to the high turnover rate of SAP Due to the high turnover rate of SAP

R/3 & ABAP/4 consultants, other R/3 & ABAP/4 consultants, other people may be stuck maintaining your people may be stuck maintaining your program. program.

Page 10: Introduction to ABAP/4

Adding comments in Adding comments in ABAP/4ABAP/4

1: To comment an entire line use 1: To comment an entire line use an asterisks (*).an asterisks (*).

* This program will…* This program will…

Page 11: Introduction to ABAP/4

Adding comments in ABAPAdding comments in ABAP

2: To comment part of a line use 2: To comment part of a line use

the double quote (the double quote (““))

– WRITE ‘HELLO’ WRITE ‘HELLO’ “This statement “This statement will….will….

Page 12: Introduction to ABAP/4

Variables and ConstantsVariables and Constants

We have given the program a We have given the program a name and added a description of name and added a description of the program in the comments.the program in the comments.

To manipulate and gather data for To manipulate and gather data for processing we need variables, processing we need variables, records, and constants.records, and constants.

Page 13: Introduction to ABAP/4

A variable is:A variable is:

- A symbolic reference to a memory - A symbolic reference to a memory location that stores information location that stores information temporarily. These variables persist temporarily. These variables persist only during the execution of the only during the execution of the program, and the data they contain program, and the data they contain is lost when the execution is is lost when the execution is complete - unless the data is complete - unless the data is transferred to a database table or transferred to a database table or system file.system file.

Page 14: Introduction to ABAP/4

VariablesVariables

MUST be declared before they are used.MUST be declared before they are used. Can be declared anywhere in the Can be declared anywhere in the

program, BUT for consistency they program, BUT for consistency they should be declared at the beginning of should be declared at the beginning of a program or subroutine.a program or subroutine.

Begin each variable with a letter and Begin each variable with a letter and then a mixture of letters and numbersthen a mixture of letters and numbers

Page 15: Introduction to ABAP/4

VariablesVariables

Use the underscore (Use the underscore (__) to separate ) to separate distinct words. DO NOT use the distinct words. DO NOT use the hyphen (hyphen ( - -) this has a special ) this has a special purpose that we will discuss later.purpose that we will discuss later.

NO reserved words (the same NO reserved words (the same name as an ABAP command)name as an ABAP command)

Page 16: Introduction to ABAP/4

VariablesVariables

Standard SCOPE rules apply. Standard SCOPE rules apply. Variables defined at the program Variables defined at the program level are considered global, level are considered global, variables in subroutines are visible variables in subroutines are visible only to the subroutine. only to the subroutine.

Page 17: Introduction to ABAP/4

Declaring variablesDeclaring variables

DATA var[(LENGTH)] [TYPE type] DATA var[(LENGTH)] [TYPE type] [DECIMALS number] [VALUE initial [DECIMALS number] [VALUE initial value]value]

var is the name of the variablevar is the name of the variable [(length)] is the size of the variable[(length)] is the size of the variable

Page 18: Introduction to ABAP/4

TYPE is the type of variable. The TYPE is the type of variable. The possible data types for variables in possible data types for variables in ABAP are:ABAP are:

Page 19: Introduction to ABAP/4

Data types for ABAP/4Data types for ABAP/4

Type/Description/ExampleType/Description/Example CC CharacterCharacter “hello world”“hello world” DD DateDate “19990101”“19990101” FF Floating point #Floating point # 3e43e4 NN Numeric textNumeric text 1000010000 PP Packed DecimalPacked Decimal 22.5022.50 T T TimeTime 104500104500 HH HexadecimalHexadecimal 23A23A

Page 20: Introduction to ABAP/4

We will only use:We will only use:

C, D, P, I, T, and maybe N.C, D, P, I, T, and maybe N. The DECIMAL is the number of decimal The DECIMAL is the number of decimal

places for the packed decimal type.places for the packed decimal type. The size of the field = digits before the The size of the field = digits before the

decimal + digits after the decimal.decimal + digits after the decimal.– IF A FIELD HAS 6 DIGITS BEFORE THE DECIMAL AND 2 IF A FIELD HAS 6 DIGITS BEFORE THE DECIMAL AND 2

DIGITS AFTER , IT MUST BE DECLARED AS A SIZE 8.DIGITS AFTER , IT MUST BE DECLARED AS A SIZE 8.

VALUE is the initial or default value for VALUE is the initial or default value for the field at execution.the field at execution.

Page 21: Introduction to ABAP/4

Example 1Example 1

Declare a variable that will hold Declare a variable that will hold the persons job title, it should be the persons job title, it should be 10 characters in length and be 10 characters in length and be initialize to MANAGER.initialize to MANAGER.

DATA JOB_TITLE (10) TYPE C VALUE DATA JOB_TITLE (10) TYPE C VALUE ‘MANAGER’.‘MANAGER’.

Page 22: Introduction to ABAP/4

Example 2Example 2

Declare a variable to store the Declare a variable to store the persons date of birth. Initialize the persons date of birth. Initialize the value to December 31, 1900.value to December 31, 1900.

DATA DATE_OF_BIRTH (8) TYPE D DATA DATE_OF_BIRTH (8) TYPE D VALUE ‘19901231’.VALUE ‘19901231’.

Page 23: Introduction to ABAP/4

Your turnYour turn

Declare a variable that will store Declare a variable that will store the employee income. It is the employee income. It is comprised of 8 digits before the comprised of 8 digits before the decimal point and 2 digits decimal point and 2 digits following it. Initialize the variable following it. Initialize the variable to 1 DOLLAR.to 1 DOLLAR.

Page 24: Introduction to ABAP/4

AnswerAnswer

DATA EMP_INCOME (10) TYPE P DATA EMP_INCOME (10) TYPE P DECIMALS 2 VALUE ‘1.00’.DECIMALS 2 VALUE ‘1.00’.

Page 25: Introduction to ABAP/4

ConstantsConstants

Data that doesn’t change its value Data that doesn’t change its value during program execution.during program execution.

Defines the same as DATA Defines the same as DATA variables.variables.

Example:Example: CONSTANTS PLANT_NUM TYPE I CONSTANTS PLANT_NUM TYPE I

VALUE ‘6523’.VALUE ‘6523’.

Page 26: Introduction to ABAP/4

Run-time ParametersRun-time Parameters

Allows us to pass data to the ABAP/4 Allows us to pass data to the ABAP/4 program at run time.program at run time.

PARAMETERS parameter name TYPE PARAMETERS parameter name TYPE type.type.

For all the options see page 16 in For all the options see page 16 in the book.the book.

Page 27: Introduction to ABAP/4

ABAP/4 StatementsABAP/4 Statements

ABAP/4 does not care where a ABAP/4 does not care where a statement begins on a line. - As a statement begins on a line. - As a result, you should indent sections result, you should indent sections of code for readability.of code for readability.

Page 28: Introduction to ABAP/4

ABAP/4 StatementsABAP/4 Statements

Multiple statements can be placed on Multiple statements can be placed on a single line. To improve readability a single line. To improve readability this is not recommended.this is not recommended.

Blank lines can be placed anywhere in Blank lines can be placed anywhere in the program and should be used to the program and should be used to improve readability.improve readability.

ALL ABAP/4 statements (except ALL ABAP/4 statements (except

comments) must end with a period (comments) must end with a period (..).).

Page 29: Introduction to ABAP/4

Coding StatementsCoding Statements

We will now discuss how to display We will now discuss how to display data including:data including:– Moving data into a variableMoving data into a variable– Moving data between variablesMoving data between variables– Writing data to the report/screenWriting data to the report/screen– Coding our first complete ABAP/4 Coding our first complete ABAP/4

programprogram

Page 30: Introduction to ABAP/4

MOVEMOVE

Move data into or between Move data into or between variables is done using the move variables is done using the move statement. There are two forms of statement. There are two forms of the move statement.the move statement.

MOVE value TO varMOVE value TO var var = valuevar = value

Page 31: Introduction to ABAP/4

Moving data into a Moving data into a variablevariable

MOVE ‘10’ TO PERSON_AGE.MOVE ‘10’ TO PERSON_AGE.

– OROR

PERSON_AGE = ‘10’.PERSON_AGE = ‘10’.

Page 32: Introduction to ABAP/4

Moving data from one Moving data from one variable to anothervariable to another

Move the contents of PERSON_AGE Move the contents of PERSON_AGE to DISPLAY_AGE:to DISPLAY_AGE:

MOVE PERSON_AGE TO MOVE PERSON_AGE TO DISPLAY_AGEDISPLAY_AGE– oror

DISPLAY_AGE = PERSON_AGE.DISPLAY_AGE = PERSON_AGE.

Page 33: Introduction to ABAP/4

ComputationsComputations

[COMPUTE] var = expression.[COMPUTE] var = expression.

ADD value TO var.ADD value TO var. SUBTRACT value FROM var.SUBTRACT value FROM var. MULTIPLY value BY var.MULTIPLY value BY var. DIVIDE value BY var.DIVIDE value BY var.

Page 34: Introduction to ABAP/4

Outputting textOutputting text

To output data to the screen we To output data to the screen we use the write command.use the write command.

– WRITE ‘text’.WRITE ‘text’.– WRITE field name.WRITE field name.

Page 35: Introduction to ABAP/4

WRITEWRITE

WRITE ‘Boyle’.WRITE ‘Boyle’. WRITE LAST_NAME.WRITE LAST_NAME.