ABAP开发需要养成的习惯—变量定义

变量定义

Global variables are BAD 

定义内表先在程序开头定义types,如

types: begin of ty_structure,
        id type i,
        date type datum,
        time type uzeit,
        message type string,
       end of ty_structure.

 

"structure"常常简写为"stru"或"struc".

 

局部变量

l表示local,it表示internal table,wa表示工作区;

DATA l_index type i value 0.

一般不用lv_index

DATA l_wa_xxx type line of ty_structure."

这条语句会报错,因为ty_structure不是内表,直接用 data l_wa_xxx type ty_structure.

 

DATA l_it_xxx type ty_structure occurs 0.

"不带表头,loop和read需要别的工作区来操作数据

 

DATA l_it_xxx type ty_structure occurs 0 with header line.

"有header line,也就是有了l_it_xxx这个工作区和l_it_xxx[]这个内表

 

DATA l_it_xxx type table of ty_structure.

DATA l_it_xxx type table of ty_structure with header line.

DATA l_it_xxx type standard table of ty_structure.

DATA l_it_xxx type sorted table of ty_structure.

DATA l_it_xxx type hashed table of ty_structure.

 *同上,新式声明,一般还有standard table,sorted table以及hashed table之分

尽量放在FORM里面用局部变量

 

全局变量

非要定义的话,用g_xxx,g_it_xxx,全局变量使用要更加注意CLEAR的问题,使用前/后clear掉。

posted @ 2018-07-13 09:29  auroracj  阅读(455)  评论(0编辑  收藏  举报