Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University.

Similar presentations


Presentation on theme: "Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University."— Presentation transcript:

1 Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University

2 Section Report Develop a simple report that will accept two numbers from the user and display the sum of the two numbers on a report.

3

4

5 What is ABAP OBJECTS? Advanced Business Application Programming. – Previously known as ABAP/4. – Since renamed to ABAP OBJECTS. Why do we need to develop ABAP applications in SAP R/3?

6 Why use ABAP? ABAP OBJECTS is the programming language SAP developers use to build transactions and reports and customize SAP R/3. The main purpose of ABAP OBJECTS is to provide additional functionality to existing SAP applications. We do not use ABAP OBJECTS to develop custom applications from scratch.

7 Using the ABAP Editor

8

9

10

11

12

13 Defining a program REPORT program name. The REPORT command has various features to format output to the screen or printer. We will discuss these features later. program name must start with a Z. – You can also use a Y, but Z is used far more often.

14 Commenting your code It is expected that you will have sufficient comments in all the ABAP OBJECTS programs you write. Why? – It is EXPECTED of all PROFESSIONAL software developers. – Due to the high turnover rate of SAP R/3 & ABAP OBJECTS consultants, other people may be stuck maintaining your program.

15 Adding comments in ABAP OBJECTS To comment an entire line use an asterisks (*). * This program will…

16 Adding comments in ABAP To comment part of a line use the double quote ( “ ) “This statement will….

17 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.

18 Variables in ABAP 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

19 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).

20 Variables Variables defined at the program level are considered global. Variables in defined in a subroutine are visible only to the subroutine.

21 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:

22 Data types for ABAP OBJECTS Type/Description/Example CCharacterhello world DDate19990101 NNumeric text10000 PPacked Decimal 22.50 T Time104500 I Integer12123

23 Declaring Variables: Example 1 Declare a variable that will hold a person’s job title. It should be 10 characters in length and be initialize to MANAGER. DATA JOB_TITLE (10) TYPE C VALUE ‘MANAGER’.

24 Declaring Variables: Example 2 Declare a variable to hold the employee ID number. When we declare a variable of type I (i.e., Integer) we do not specify the variable size. DATA EMP_ID TYPE I.

25 Declaring Variables: Example 3 Declare a variable to store the person’s date of birth. Initialize the variable to December 31, 1900. DATA DATE_OF_BIRTH TYPE D VALUE ‘19001231’.

26 DATA var[(LENGTH)] [TYPE type] [DECIMALS number] [VALUE initial value] – 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, THEN IT MUST BE DECLARED AS A SIZE 8. Declaring Variables: Decimal Type

27 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.

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

29 Constants Data that does not change its value during program execution. Defined the same as DATA variables. Example: – CONSTANTS PLANT_NUM TYPE I VALUE ‘6523’.

30 Run-time Parameters Allows the user to pass data to the program at run time. At run time, the default SAP R/3 screen will be display with the parameters you have coded. PARAMETERS parameter name TYPE type.

31 Run-time Parameters If we wanted the user to enter an employee ID. – PARAMETERS EMP_ID TYPE I. The parameter name is limited to 8 characters. For the lesson example, the input screen would look like this:

32

33 Example Program Let us review what we covered so far, by examining the simple ABAP calculator program. ZWSCALC

34 ABAP OBJECTS Statements ABAP OBJECTS does not care where a statement begins on a line. However, to ensure program professionalism, you should indent sections of code for readability. You can easily do this using PRETTY PRINTER.

35 ABAP OBJECTS 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 OBJECTS statements (except comments) must end with a period (. ).

36 Coding Statements We will now discuss how to display data including: – Moving data into a variable – Moving data between variables – Performing basic computations – Writing data to the report/screen – Coding your first complete ABAP OBJECTS program.

37 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

38 Moving values into a variable MOVE ‘10’ TO PERSON_AGE. – OR PERSON_AGE = ‘10’.

39 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.

40 Computations COMPUTE variable = expression. – COMPUTE is optional. ADD value TO variable. SUBTRACT value FROM variable. MULTIPLY variable BY value. DIVIDE variable BY value.

41 Computations COMPUTE INCOME_TAX = GROSS_INCOME * TAX_RATE. ADD 1 TO REC_COUNTER MULTIPLE GROSS_INCOME BY TAX_RATE. (What is the problem with this?)

42 Outputting text To output data to the screen, we use the write command. – WRITE ‘text’. – WRITE field name.

43 WRITE WRITE ‘Boyle’. WRITE LAST_NAME. Some of the basic write options include: : = groups of text, variables. / = break to a new line WRITE: /, FIRST_NAME, LAST_NAME.

44 Write: Outputting groups of text If we wanted to write the following: Weekly Sales Total: 13456.32 We could code: WRITE CON_SALE_HEADER. WRITE W_SALES_TOT. OR WRITE : CON_SALE_HEADER, W_SALES_TOT.

45 Write: Breaking to a new line WRITE “HELLO”. WRITE “WORLD”. would give us: HELLO WORLD

46 Write: Breaking to a new line What if we want the text on two separate lines? We use a “/” following the WRITE WRITE / ‘HELLO’. WRITE / ‘WORLD’. We can combine both grouping and breaking: WRITE : /, CON_SALE_HEADER, W_SALES_TOT.

47 Review Let us finish the calculator program. ZWSCALC Modify 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.

48

49

50

51

52

53 Answer to the Average Report Program ZWSCALCAVG

54 Exercises INCLASS11 INCLASS12


Download ppt "Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University."

Similar presentations


Ads by Google