ABAP OO的八大理由(十五)

原因2:ABAP OO在类中有更严格的语法检查
面向过程的ABAP经历了较长时间的成长,这也带来了如下结果:
l         存在着大量的过时的语句
l         存在着很多交叉的概念
l         有一些奇怪的系统行为
l         有些技术显得较难理解
由于不能影响已有的代码,ABAP OO的版本引入了更加严格的语法检查以剔出面向过程的ABAP程序一些弊病,主要包括:
l         禁止使用过时的ABAP语句
l         使一些隐含性的语法变得更加明确
l         查明并禁止不正确的数据处理
注意:
向下兼容的一些ABAP语法在ABAP OO之外仍然被支持,这样你就没必要为了使用的新版本的ABAP而去修改原来的程序。从另一个角度来讲,由于有大量的现存程序存在,不得不保留用新的概念来剔出一些过时的概念对语言本身来讲也是一个沉重的负担。如果你在ABAP对象之外使用下面列表中以外的功能,语法检查最多也只能给你个警告的信息。如果想去掉这些警告信息,最好使用下面列表中的替代方式。
Context Description
Syntax notation No special characters in names; no negative length specifications, no multi-line literals
Declarations LIKE references to data objects only; no implicit length of specifications for data types I, f, d or t; no operational statements in structure definitions;FIELDS,RANGES,INFOTYPES,TABES,NODES,COMMON PART,OCCURS,NO-LOCAL not permitted
Operations CLEAR…WITH NULL,PACK,MOVE…PERCENTAGE;ADD-CORRESPONDING;DIVIDE-CORRESPONDING;SUBSTRACT-CORRESPONDING,MULTIPLY-CORRESPONDING;ADD THEN…UNTIL…,ADD FROM…TO…;CONVERT(DATE INVERTED DATE) not permitted
String Processing Not permitted on numeric processing
Field Symbols No implicit types; FIELD-SYMBOLS…STRUCTURE;ASSIGN…TYPE;ASSIGN LOCAL COPY OF,ASSIGN TABLE FIELD not permitted.
Logic expressions Operators ><,=<;= not permitted; table used with IN must be a selection table
Control structures No operational statements between CASE and WHEN;ON-ENDON not permitted
Internal Tables No header lines; no implicit work areas; no redundant key specifications; compatible work areas required where necessary; obsolete READ variants, COLLECT,SORTED BY,WRITE TO itab , PROVIDE not permitted
Procedures(methods) No implicit type assignment; compatible initial values only; passing of sy-subrc and raising of undefined exceptions not permitted
Program calls No joint of USING and SKIP FIRST SCREEN when calling transactions;passing formal parameters implicitly in CALL DIALOG not permitted
Database accesses No implicit work areas in Open SQL;READ,LOOP,REFRESH FROM on database tables not permitted; VERSION addition to DELETE and MODIFY not permitted; no PERFORMING addition in Native SQL
Data clusters No implicit identifiers; no implicit parameter names; no implicit work areas; MAJOR-ID and MINOR-ID not permitted
Lists DETAIL,SUMMARY,INPUT,MAXIMUM,MINIMUM,SUMMING,MARK,NEW-SECTION, and obsolete parameters are not permitted

上面的表格列举了在类中一些语法的限制,使用上面列表中的任何一个限制的语法都会斗志语法检查的错误。可以在ABAP文档中找到这些限制的替代方式。
下面通过举例说明使用更加清晰的ABAP OO语法的好处:
在传统的面向过程的语法中定义内表的语句如下:
DATA BEGIN OF itab OCCURS 0.

CLEAR itab.
而在ABAP OO中就只能采用下面这种方式定义内表了:
DATA itab TYPE TABLE OF …

CLEAR itab.
过去的内表的定义方式非常容易引起混淆。这种方式除了定义了内表变量,它也同时定义了一个work area。一个名字代表两个变量显然非常容易引起混淆。在ABAP OO中对此进行了严格的约束,内表的定义没有隐含的定义表头,那么CLEAR语句就是明确的清除内表的内容了。而且在传统的ABAP程序中,你不得不去判断你所操作的是内表还是表头,这样便很容易导致程序出错。而在ABAP OO中禁止了这种表头,那么就避免容易产生此种错误的弊病,它要求必须声明一个独立的表头变量来处理内表中的内容从而使程序变得更加清晰而易于维护。

posted @ 2011-01-05 15:38  Kaming's SAP  阅读(221)  评论(0编辑  收藏  举报