ABAP OO Development Grammar Collation

Source: Internet
Author: User
Tags case statement

"Transfer from http://blog.csdn.net/saphome/article/details/6956933"

In a class, you can specify a data type only with the type additional keyword.

types: General method of type definition

constants: General method for defining constants

You can only reference local data objects with like.

data:var1 Type <types defines the types or dictionary types;.

data:var2 like var1 < cannot use Dictionary object;.

The public property declared with data, if added with the read-only appended keyword, means that it can be read externally, but only by means of methods inside the class.

data:var3 type read-only.

Read-only Additional keywords can now be used only in the common visible sections of the class declaration (Public section) and in the interface definitions.

• Properties and visibility

To define a private attribute in the private section, define a common property in the public section

CLASS lcl_vehicle DEFINITION.

Public section DATA: Common Properties

Make TYPE string. PRIVATE section

Private section DATA: "Proprietary property

Zmake TYPE String

Endclass.

• Static properties are defined with the Class-data keyword.

In ABAP objects, methods can have importing, exporting, changing, and returning parameters and exception parameters. All parameters can be transferred with a value or address. (After SAP R/3 BASIS 6.10, you cannot use the EXCEPTIONS parameter for the exception, instead of the raising additional keyword, which is mentioned later.)

You can use returning to define the return value of a method, where you can define only one parameter and only pass values, and no longer define the exporting and changing parameters, you define the method of functionality with the returning parameter (detailed later).

– Using the optional and default append keywords in a declaration can define all input parameters (importing and changing parameters) as optional parameters, so that when an object is called, the value of the relevant parameter is not required to be transferred. If the OPTIONAL keyword is used, the parameter gets the initial value based on the type, and in addition, a start value can be specified with default.

Static methods use the Class-method statement to define

To instantiate an object by using the statement create object

• Reference variables

Data:r_vehicle1 TYPE REF to Lcl_vehicle. statement declares a reference variable as a pointer to an object.

• Create objects: syntax

The Create OBJECT statement creates an object in main memory that is either an initial value or is specified by a value entry.

Reference variables can be assigned to each other. For example, in the example above, you can define a r_vehicle2 that points to the same object as R_vehicle1.

• Syntax for invoking instance methods

---Invoking instance methods with Call method <reference>-><instance_method>

---after SAP R/3 Basis 6.10, the short notation is supported and the call METHOD is omitted.

---Special case, when an instance method is called from another instance method, the instance name can be omitted, and the method of the current object is automatically executed.

When you---only one parameter, you can omit the exporting appended keyword in parentheses, and if there are two or more parameters in the interface, all the arguments and the formal parameters must be listed.

---you must use the importing Append keyword when the method returns a parameter to the caller, all arguments and parameters are listed.

---When a method is called, multiple arguments are separated by a space.

• Calling the syntax of a static method

---Call a static method with the

Call METHOD <classname>=><class_method>

---static method is positioned with the class name because it does not require an instance.

---If you call a static method in a class, you can omit the class name.

• Functional Methods

---Methods with returning parameters are called functional methods, which cannot be used with exporting or changing parameters, but can be used with multiple importing parameters and exceptions if necessary.

---Functional methods can be used directly in various expressions:

• Logical Expressions (IF, ELSEIF, while, CHECK, WAIT)

Case Statement (case, when)

Loop Statements

• Mathematical Expressions (COMPUTE)

• Bit-expression (COMPUTE)

Move Statements

ABAP OO Development Grammar Collation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.