Abapdocu sample program parsing (003)

Source: Internet
Author: User

ProgramPath: The ABAP programming language-> basic statements-> data types and data objects-> demonstration of elementary data objects

Code:

Code
Program demo_elementary_data_objects.

*Demonstrates elementary data objects

data text1 ( 20 ) type C.
data text2 type string .
data number type I.

Text1= 'The number'.
Number= 100.
Text2= 'Is an integer.'.

Write: text1, number, text2.

 

Resolution:

1. This program starts with program, which is different from what we mentioned in the previous program, but runs in the same way. This involves a situation where the program attributes are inconsistent with the program declaration statement. The runtime environment determines whether the program can be executed directly or through the transaction code based on the settings in the program attributes. You can view the program attributes by switching to the ABAP editor and clicking "go to-properties" in the menu. If the program is executable, you can run the program directly. If the program is a module pool, it must be started by the transaction code.

2. The three data statements define three variables respectively. This program demonstrates the definition of data objects of the basic data type. in ABAP, basic data types are preset Data Types in languages such as C, D, t, n, I, P, f, x, string, and xstring, use the type Additional keyword to specify the type for the variable.

3. The next three assignment statements assign values to the three variables respectively. The output result of the last write statement is as follows:

Here, the blue reversed text is marked by me. To illustrate the output length of the variable, the normal output does not exist.

4. Looking back at the code, we define text1 to be a 20-character C, that is, 20 characters, and its output length is also fixed to 20, however, when we assign a value, only 10 characters are assigned and the character type is aligned. Therefore, there are still spaces with 10 Characters left behind. The next number is I, which is an integer, the output length is fixed to 11 because the value range of integer is-2147483648 to + 2147483647, exactly 11 digits. It should be noted that the negative number in SAP is behind the number. This is a German habit and makes us very uncomfortable; finally, it is string-type text2. Its length is dynamically determined at runtime, and the actual length is the output length. If no position is specified for the Write statement, a space is added to the output of two consecutive variables. There are two spaces between the number 100 and the string is an interger, the first is the symbol bit of the number variable. The positive value is not displayed, and the negative value is displayed. The last space is the interval between the two variables.

 

========================================================== ================

Program path: the ABAP programming language-> basic statements-> data types and data objects-> elementary types statement

Code:

Code
Report demo_types_statement.

Types mytext (10) Type C.
Types myamount type P Decimals2.

Data Text Type mytext.
Data amount type myamount.

Text= '4/3 ='.
Amount= 4 / 3.
Write: Text, amount.

 

Resolution:

1. Compared with the previous program, here we mainly use the types statement to define the data type code. In a program, you can define your own data types for ease of use and consistency, and then refer to custom types when using data to define variables, avoid the assignment errors caused by omissions during code modification.

2. Here, an additional decimals keyword is defined for the type P, which specifies the number of decimal places. The p type is a special data type in SAP. It stores two digits in one byte, And the last byte contains a number and a positive/negative number. A maximum of 14 decimal places can be used.

Nothing special about others, similar to the first program.

 

========================================================== ================

Program path: the ABAP programming language-> basic statements-> data types and data objects-> demonstration of Structures

Code: omitted

Resolution:

1. This program introduces how to define the structure, structure nesting, and structure usage. A structure is a data structure that organizes multiple variables in the same class and manages them together. For the nested structure in the structure, you can use multiple-links to indicate the final data fields. Other usage is the same as that of common data objects.

 

 

========================================================== ================

Program path: the ABAP programming language-> basic statements-> data types and data objects-> demonstration of internal tables

Code: omitted

Resolution:

1. This program introduces how to define and use internal tables. Internal tables can be considered as any data objects with multiple identical structures. Logically, similar to database tables, they all store a large amount of data with the same structure; the difference is that the database tables are persistent and stored on disks, while the internal tables are temporary. The lifetime is limited to the running time of the program, and the internal tables are released when the program ends.

2. From the example, we can see sap's suggestions on using inner tables. First, define a structure as the workspace of the inner table, and then refer to the structure to create an inner table, in this way, the row structure of the internal table is the same as that of this structure. To add or delete fields when you modify code later, you only need to modify the structure definition to maximize consistency.

3. The easiest way to Add rows to the inner table is to use append, which adds data to the end of the inner table.

In this example, as long as you learn the simplest way to use the internal table, you will often use the internal table later, and then explain it in detail.

 

 

========================================================== ================

Program path: the ABAP programming language-> basic statements-> data types and data objects-> demonstration of Describe field

Code: omitted

Resolution:

1. Describe field statements are used to obtain technical information such as the length and type of Data Objects (variables. In general, such statements can be used in subprograms or function modules to obtain the data types of input and output parameters of unrestricted types and then process them accordingly. Or, it is used to determine the type of the field symbol.

This syntax is usually used in a few cases. You only need to know about it and understand its role when reading standard programs.

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.