定义CL变量的DCL语句F4内容如下
----------------------------------------------------------------------------------------------------
Declare CL Variable (DCL)
Type choices, press Enter.
Label . . . . . . . . . . . . .
CL variable name . . . . . . . . > &VAR1 Variable name
Type . . . . . . . . . . . . . . > *CHAR *DEC, *CHAR, *LGL, *INT...
Storage . . . . . . . . . . . . *AUTO *AUTO, *BASED, *DEFINED
Length of variable:
Length . . . . . . . . . . . . > 10 Number
Decimal positions . . . . . . Number
Initial value . . . . . . . . .
...
Basing pointer variable . . . . Variable name
More...
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys
---------------------------------------------------------------------------------------------------------
在CL reference中有这样一个例子:
PGM
DCL &AUTO *CHAR 20 //定义一个普通的char类型变量, 自动分配内存地址
DCL &PTR *PTR ADDRESS(&AUTO) //定义一个指针变量,并初始化为指向&AUTO的第一个内存byte
DCL &BASED *CHAR 10 STG(*BASED) BASPRT(&PRT) //定义一个普通char类型变量, 根据BASPRT参数指定的指针分配内存, 这样做有个好处
...
IF COND(%SST(&AUTO 1 10) *EQ &BASED) +
THEN (CHGVAR %OFS(&PTR) (%OFS(&PRT) +10))
...
ENDPGM
定义*BASED类型变量的好处是, 由于起始内存地址是根据定义时给定的指针指定的, 随着指针指向位置的变化, *BASED变量在内存中的位置是会变化的; 从而*BASED变量可以 随意 重复某段内存, 进一步将随意内存中的值读取出来.
关于这个例子的说明
In the above example, the basing pointer &PTR is declared to be equal to the address of &AUTO. The
variable &BASED then has the value of the first 10 bytes addressed by the pointer variable &PTR. Later
in the procedure, the value of variable &BASED is checked for equality against the first 10 bytes of
variable &AUTO. If the values are the same, meaning pointer &PTR addresses the first byte of &AUTO,
the pointer offset is changed to address byte 11 of variable &AUTO. Now variable &BASED has a value
equal to bytes 11-20 of variable &AUTO.
关于STG参数的F4说明如下:
Storage (STG) - Help
Specifies the storage type of the variable. The value for
this parameter cannot be specified by a CL variable.
*AUTO
The storage for this variable is allocated in
automatic storage.
*BASED
The storage for this variable is based on the pointer
variable specified on the Basing pointer variable
(BASPTR) parameter. A based CL variable cannot be
used unless the basing pointer variable has been set
to a valid address.
*DEFINED
The storage for this variable is provided by the CL
variable specified on the Defined on variable (DEFVAR)
parameter.
在稍高版本的OS400中(至少V5R3的CL中还没指针类型变量, 德国服务器就没), 定义CL变量时可以指定该变量的内存分配方式, 一共有三种:
1.自动分配内存(automatic storage),
2.用指针变量指定内存位置(based storage),这里的'based'表示 '根据, 依赖, 依据'等, 绝对不是'基本的'意思. 这内存配置方式的好处是变量可以在内存中根据指定指针的变化而变化.
3.defined storage, 没用过噻, 不甚理解.
关于BASPTR参数的F4说明如下:
Basing pointer variable (BASPTR) - Help
Specifies the basing pointer for a CL variable declared
with storage of *BASED. STG(*BASED)声明的CL变量叫做"Based Variable"
Note: This parameter must be specified if *BASED is
specified for the Storage (STG) parameter.
CL-variable-name
Specify the name of a CL variable declared as
TYPE(*PTR) which will serve as the basing pointer for
the based CL variable being declared. This pointer
must be initialized to a value before the based
variable can be used.
The name must start with an ampersand (&).
阅读(1966) | 评论(0) | 转发(0) |