分类: 系统运维
2012-07-20 17:29:32
RPGLE中的指针和C语言中指针类似。过多的解释在IBM i信息中心:
指针作为一种数据类型在RPGLE开发中被广泛使用。其中常用到指针的如系统API,C语言的runtime function调用。但本练习暂且不讲。此练习主要讲指针的基本用法。
EX8
0001.00 D People DS Based(Ptr1) Qualified
0002.00 D Name
0003.00 D FirstName 10A overlay(Name)
0004.00 D LastName 10A overlay(Name:*next)
0005.00 D Age 3S 0
0006.00 D*
0007.00 D Name S 10A Based(Ptr2)
0008.00 D StrName S 10A Inz('Terry Pan ')
0009.00 D StrPeople S 23A Inz('David Tan 30')
0010.00 D Result S 23A Inz
0011.00 D Ptr1 S *
0012.00 D Ptr2 S *
0013.00 D Wait S 1A
0014.00 C*
0015.00 C Eval Ptr1= %Addr(StrPeople)
0016.00 C Eval Ptr2= %Addr(StrName)
0017.00 C Eval Result = %Str(Ptr2:5)
0018.00 C Result Dsply
0019.00 C Name Dsply
0020.00 C*
0021.00 C Eval Ptr2 = Ptr2 + 6
0022.00 C Eval Result = %Str(Ptr2:4)
0023.00 C Result Dsply
0024.00 C*
0025.00 C Eval Result = People.FirstName
0026.00 C Result Dsply
0027.00 C*
0028.00 C Eval Result = People.LastName
0029.00 C Result Dsply
0030.00 C*
0031.00 C Eval Result = %char(People.Age)
0032.00 C Result Dsply
0033.00 C*
0034.00 C 'Complete' Dsply Wait
0035.00 C*
0036.00 C Eval *inlr = *on
0037.00 C ReturnEX8F
0001.00 D People DS Based(Ptr1) Qualified
0002.00 D Name
0003.00 D FirstName 10A overlay(Name)
0004.00 D LastName 10A overlay(Name:*next)
0005.00 D Age 3S 0
0006.00 D*
0007.00 D Name S 10A Based(Ptr2)
0008.00 D StrName S 10A Inz('Terry Pan ')
0009.00 D StrPeople S 23A Inz('David Tan 30')
0010.00 D Result S 23A Inz
0011.00 D Ptr1 S *
0012.00 D Ptr2 S *
0013.00 D Wait S 1A
0014.00 /free
0015.00 Ptr1= %Addr(StrPeople);
0016.00 Ptr2= %Addr(StrName);
0017.00 Result = %Str(Ptr2:5);
0018.00 Dsply Result;
0019.00 Dsply Name;
0020.00
0021.00 Ptr2 = Ptr2 + 6;
0022.00 Result = %Str(Ptr2:4);
0023.00 Dsply Result;
0024.00
0025.00 Result = People.FirstName;
0026.00 Dsply Result;
0027.00
0028.00 Result = People.LastName;
0029.00 Dsply Result;
0030.00
0031.00 Result = %char(People.Age);
0032.00 Dsply Result;
0033.00 Dsply 'Complete' '' Wait;
0034.00
0035.00 *inlr = *on;
0036.00 return;
0037.00
0038.00 /end-free