1 / 54

Lesson 1: Introduction to ABAP OBJECTS

Lesson 1: Introduction to ABAP OBJECTS. Todd A. Boyle, Ph.D. St. Francis Xavier University. 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. What is ABAP OBJECTS?.

kalea
Download Presentation

Lesson 1: Introduction to ABAP OBJECTS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

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

  5. Using the ABAP Editor

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

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

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

  9. Adding comments in ABAP To comment part of a line use the double quote (“) <program code> “This statement will….

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

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

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

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

  14. 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:

  15. Data types for ABAP OBJECTS • Type/Description/Example • C Character hello world • D Date 19990101 • N Numeric text 10000 • P Packed Decimal 22.50 • T Time 104500 • I Integer 12123

  16. 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’.

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

  18. 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’.

  19. Declaring Variables: Decimal Type • 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.

  20. Declaring Variables: Decimal Type • 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.

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

  22. 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’.

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

  24. 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:

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

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

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

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

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

  30. Moving values into a variable • MOVE ‘10’ TO PERSON_AGE. • OR • PERSON_AGE = ‘10’.

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

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

  33. 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?)

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

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

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

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

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

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

More Related