下列 ABAP 代码,哪些行会引起编译错误?
REPORT z.
TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
DATA(lt*) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).
DATA(lt!) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).
DATA(lt$) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).
DATA(lt_) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).
DATA(ltɵ) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).
BREAK-POINT.
答案是第7行和第13行。

ABAP 里的感叹号作为 escape 字符,用以区别于 ABAP 语句中同名的ABAP keyword. ABAP 语句中前面带有 ! 字符的每个单词都被解释为一个操作数,而不是一个 ABAP keyword. 转义字符本身不是名称的一部分,在执行语句时会被忽略。

比如下面的 ABAP 代码:
FORM test USING !CHANGING
CHANGING !USING.
using = changing.
ENDFORM.
第一个 CHANGING 前面加上了感叹号,说明这个 CHANGING 不是关键字,而是 FORM 的形式参数的名称。
第13行的问题是:
In Unicode programs, the "" character cannot appear in names, as it does here in the name "".

在 ABAP unicode 程序里,希腊字符 “ɵ”不允许作为变量名。
在 TypeScript 和 JavaScript 里没有这个限制。实际上,ɵ 广泛用于 Angular 源代码里。

更多Jerry的原创文章,尽在:"汪子熙":

网友评论