Friday, December 08, 2006

ABAP基础

一些需要注意的地方:
过程可以拥有自己的局部数据,事件块和对话模块中定义的数据为全局数据定义
函数名称和左括号间不能有空格,括号和参数间必须有空格
字段符号:ASSIGN (f) TO .”不是将f分配给,而是将f的内容作为新的数据对象名称分配给
指针指向的对象得是字段符号:ASSIGN dref1->* TO .
子程序:USING/CHANGING传址,USING VALUE传值,CHANGING VALUE传值后改变实参,其作用在于一旦自程序非正常中断,实参仍保持原值
两种类的构造方法:实例构造方法和对象构造方法
除属性、方法之外的第三种类成员——事件:声明、触发、事件处理、注册事件处理


一些简单的例子:
1. se38 activate compile, Pretty Printer, do n times, sy-index, write
data n type i value 5.
do n times.
write / sy-index left-justified.
enddo.
write: sy-uzeit,
sy-datum.


2. 简单内表操作
TYPES: BEGIN OF address,
street(20) TYPE c,
city(20) TYPE c,
END OF address.

DATA: BEGIN OF company,
cname(20) TYPE c,
addresses TYPE address,
END OF company.

DATA itab_company LIKE TABLE OF company WITH KEY cname.

company-cname = 'SAP Shanghai'.
company-addresses-street = 'Nanjing Road'.
company-addresses-city = 'Shanghai'.

APPEND company TO itab_company.

company-cname = 'SAP Beijing'.
company-addresses-street = 'Shuang Qing Road'.
company-addresses-city = 'Beijing'.

APPEND company TO itab_company.

READ TABLE itab_company WITH TABLE KEY cname = 'SAP Shanghai' INTO company."work area
WRITE / company.

READ TABLE itab_company WITH KEY addresses-city = 'Beijing' INTO company.
WRITE / company.


3. 静态分配字段符号
data: begin of address,
street(20) type c value 'Huatuo Road',
no(4) type c value '28',
zip(6) type c value '201203',
district(20) type c value 'Pudong',
city(20) type c value 'Shanghai',
end of address.

field-symbols: type c,
type c.

assign: address(30) to ,
address+30(40) to .

Write: / ,
/ .



4. 动态分配字段符号

field-symbols: .
data: str(20) type c value 'Output String',
name(20) type c value 'str'.

*Static assignment
assign name to .
write / .

*Dynamic assignment
assign (name) to .
write / .


5. 数据引用
Create data dref1 type t_struct
在运行期内动态创建一个数据对象,同时引用变量dref指向这一对象。该对象没有名称,只能通过数据引用变量进行寻址,在操作该数据对象之前,需要通过字段符号解除引用。

TYPES: BEGIN OF t_struct,

col1 TYPE i,

col2 TYPE i,

END OF t_struct.



DATA: dref1 TYPE REF TO DATA,

dref2 TYPE REF TO DATA.



FIELD-SYMBOLS: TYPE t_struct,

TYPE i.



CREATE DATA dref1 TYPE t_struct.

ASSIGN dref1->* TO .

-col1 = 1.

-col2 = 2.

dref2 = dref1.

ASSIGN dref2->* TO CASTING.

WRITE / .

GET REFERENCE OF -col2 INTO dref2.

ASSIGN dref2->* TO .

WRITE / .WRITE / .


与之基本对应的C

#include



struct t_struct{

int col1;

int col2;

};



void main(){

struct t_struct * dref1;

int * dref2;



struct t_struct aaa;

dref1 = & aaa;

dref1 -> col1 = 1;

dref1 -> col2 = 2;



dref2 = & aaa.col1;

printf ( "%d\n", * dref2 );

dref2 = & aaa.col2;

printf ( "%d\n", * dref2 );

}




6. 子程序
DATA: int1 TYPE i VALUE 1,
int2 TYPE i VALUE 1.

WRITE: / 'Before Calling Subroutine :',
int1, int2.

PERFORM self_add USING int1 int2.

WRITE: / 'After Calling Subroutine : ',
int1, int2.

FORM self_add USING p1 TYPE i
value(p2) TYPE i.
p1 = p1 + 1.
p2 = p2 + 1.
WRITE: / 'Inside Subroutine : ',
p1, p2.
ENDFORM.


7. 功能组功能模块

se38 create function group, creat function module
LTOP是功能组内部的全局数据定义区
LUXX包含具体的功能模块代码
LFXX用于容纳功能组内部的子程序
Import input_1,input_2
Export output
Source code 输入:output = input_1 + input_2. 运行测试
在希望调用功能模块的程序编辑状态中单击Pattern功能
data: int1 type i value 3,
int2 type i value 4,
sum type i.

CALL FUNCTION 'Z_TTT_ADD'
EXPORTING
input1 = int1
input2 = int2
IMPORTING
OUTPUT = sum.
if sy-subrc = 0.
write sum.
endif.


8. 类定义

class vehicle definition.
public section.
class-data class_name(10) type c value 'Vehicle'.
methods: accelerate,
show_speed.
protected section.
data speed type i.
endclass.

class vehicle implementation.
method accelerate.
speed = speed + 1.
endmethod.
method show_speed.
write: / 'Speed:', speed.
endmethod.
endclass.



9. 定义全局类
se80 (se24)
Instantiation实例类型,
Final不能被继承
Persistent 稳定性检查
Only modeled该类只有图形化模型,没有具体实现部分
设置attributes,method 保存
activate, test


10. 函数方法
class circle definition
public section.
methods get_area importing value(i_radius) type i
returning value(r_size) type f.
private section.
constants pi type f value '3.14159265'.
endclass.

class circle implementation.
method get_area.
r_size = i_radius ** 2 * pi.
endmethod.
endclass.

parameters radius type i.
data: o_circle type ref to circle,
area type f.

create object o_circle.
call method o_circle->get_area
exporting i_radius = radius
receiving r_size = area.
write: / area.
area = o_circle->get_area( radius ).
write: / area.


疑惑:
对象的命名限制
ABAP编辑器与word编辑器不兼容

ABAP编辑器的缩进



Linux

Andrew Tanenbaum created MINIX

Every time there was a choice between code simplicity and efficiency/features Tanenbaum chose simplicity (to make it easy to teach with MINIX), which meant that this system lacked many of features people wanted. Linux goes in the opposite direction.

Because this is the reverse of the way a normal copyright works (it gives rights instead of limiting them), it has been termed a copyleft.Two key words for Linux are "Have Fun!"

one of several replacements for the vi editor is named elvis

In fact, it made so many popular changes that one version of the system is called the Berkeley Software Distribution (BSD)of the UNIX system (or just Berkeley UNIX). The other major version is UNIX System V (SVR4), which descended from versions developed and maintained by AT&T and UNIX System Laboratories.

Although it mimics UNIX in many ways, the Linux operating system departs from UNIX in several significant ways: The Linux kernel is implemented independently of both BSD and System V, the continuing development of Linux is taking place through the combined efforts of many capable individuals throughout the world, and Linux puts the power of UNIX within easy reach of business and personal computer users. Using the Internet, today's skilled programmers submit additions and improvements to the operating system to Linus Torvalds, GNU, or one of the other authors of Linux.

IBM (www.ibm.com/linux) is a major Linux supporter. Linux conforms increasingly more closely to POSIX standards, and some distributions and parts of others meet this standard.

Linux often supports a peripheral or interface card before any company does. Unfortunately some types of peripherals—particularly proprietary graphics cards—lag in their support because the manufacturers do not release specifications or source code for drivers in a timely manner, if at all.

the Compaq's (née Digital Equipment Corporation) Alpha-based machines

Emulators
Linux supports programs, called emulators, that run code intended for other operating systems. By using emulators you can run some DOS, Windows, and Macintosh programs under Linux. Wine (www.winehq.com) is an open-source implementation of the Windows API on top of X and UNIX/Linux; QEMU (fabrice.bellard.free.fr/qemu) is a CPU-only emulator that executes x86 Linux binaries on non-x86 Linux systems.

More than 95 percent of the Linux operating system is written in the C programming language, and C is portable because it is written in a higher-level, machine-independent language. (The C compiler is written in C.)

POSIX (Portable Operating System Interface for computer Environments) standard

Programs written in assembly language work on only one machine or, at best, one family of machines

high-level language

the American National Standards Institute (ANSI)

the GNU Project's C compiler (named gcc)

The GNU Project's C compiler and its C++ compiler (g++) are integral parts of the Linux operating system.

If you are running the X Window System (page 15), you can run different programs in different windows on the same screen and watch all of them.

link of Linux = shortcut of Windows

The Shell: Command Interpreter And Programming Language

In a textual environment, the shell—the command interpreter—acts as an interface between you and the operating system. When you enter a command on the screen, the shell interprets the command and calls the program you want. A number of shells are available for Linux including these two common ones:

The Bourne Again Shell (bash), an enhanced version of the Bourne Shell, one of the original UNIX shells

The TC Shell (tcsh), an enhanced version of the C Shell, developed as part of BSD UNIX

Shell commands can be arranged in a file for later execution. Linux calls these files shell scripts; DOS and Windows call them batch files

No comments: