一:RPG介绍RPG程序的特点:1.程序的编写对于每一个位置都有明确的定义,所以程序的编写必须在指定的位置开始。
通过使用ILE工具可以进行一些方便的输入。
2. RPG程序的设计针对每一部分都有严格的要求,有相应的规格说明,他们包括a) 配置规格说明(Control Specifications):主要规定了程序的命名,日期格式等信息。
b) 文件描述说明(File Description Specifications):对程序使用到的文件的说明c) 定义说明(Definition Specifications):主要对程序使用的数据进行说明。
d) 输入说明(Input Specifications):主要对文件输入数据进行说明。
e) 计算说明(Calculation Specifications):主要对数据计算和计算顺序的说明。
f) 输出说明(Output Specifications):主要针对数据的输出记录和字段的说明。
g) 子程序说明:包括有三种,对子程序的各种进行进行了定义说明。
3.指示器(Indicators)通常是一个字节,被设置为‘0’或者‘1’,他主要作为程序操作的结果或者进行操作的条件。
好像程序的逻辑开关,决定着程序的流程。
指示器必须在定义规范中进行定义。
RPG VI也有一些系统的指示器,他们一般是两个字符的变量,如LR等。
指示器可以在程序的任何地方使用,也可以在程序中修改他的值。
4.操作代码相当与汇编语言的命令一样,有RPG程序提供一套完整的操作代码,比如读一条数据使用READ ,RPG程序对操作代码进行了分类,比如字符串操作符,数组操作符等。
5.定义描述文件a) 文件服务是程序和IO设备的连接。
系统里的每一个文件都有相应的描述文件,对文件的特性和数据的组织形式进行描述。
如果在程序中要使用IO操作,必须要指定一个描述文件,对IO的设备进行描述。
对于文件的类型,系统支持以下几种:1. 数据库文件(database files):对数据进行持久存储。
2. 设备文件(Device files):容许访问的扩展设备,包括显示文件,打印文件,磁盘文件等。
3. 一般文件(save files):保存在硬盘上的文件4. 远程文件(DDM files):保存在远程系统上的文件。
b) 每一个IO设备都对应有一个描述文件,在程序中如果要使用到IO设备,就要指定相应的文件。
这主要根据操作代码来决定,有的操作代码是设备依赖的,必须指定特定的设备才可以使用,而有些操作代码是和设备独立的,如WRITE等。
产用的设备类型有:RPG Device Type ――――> iSeries File Type DISK ――――>database, save, DDM filesPRINTER ――――>printer filesWORKSTN ――――> display, ICF filesSEQ ――――>tape, diskette, save, printer, databaseSPECIAL ――――>N/Ac) 描述文件的类型:1、一般程序描述文件(program-described file):在输入输出描述的文件中会做相应的处理。
2、扩展描述文件(externally described file):主要是多个应用程序可以共享数据a) 通过针对描述文件的不同配置,RPG程序实现了程序和数据的分离,这样可以针对不同的保存数据的设备和形式,来对描述文件进行配置,这样就很容易的实现的程序的灵活性。
在设备进行升级以后,程序依然可以使用。
二、通过ILE建立RPG程序:a) ILE(Intergrated Language Environment)的介绍ILE是AS400中提供的一套增强编程的工具包,他针对不同的编程语言,都有相应的环境支持,ILE RPG,ILE C,ILE COBOL,ILE CL 等。
b) ILE的优势i. ILE 本身提供了许多程序模块,供程序员调用ii. 提供编译的环境,可以对代码进行调试iii. 提供优化的调用性能iv. 可以集成多种语言v. 对代码进行优化vi. 而且提供老版本的代码转换到新版本的代码,主要是针对RPG程序和CL程序。
c) 使用ILE建立一个应用程序的例子vii. 建立一个库,取名PRTLIBCRTLIB LIB(PRTLIB) TEXT(‘SAMPLE ILE APPLICATION’)viii. 将PRTLIB设置为当前库CHGCURLIB CURLIB(PRTLIB)ix. 建立一个源码文件在PRTLIB中CRTSRCPF FILE(SOURCE) RCDLEN(112) TEXT(‘SAMPLE ILE Appliaction’)x. 编辑文件,输入文件内容,分配源文件类型是CLP,描述信息是OPM,WRKMBRPDM FILE(PRTLIB/SOURCE)xi. 按F3键,退出后,建立命令,系统将会产生CRTCLPGM命令。
三、SEU工具的使用SEU(Source entry utility)源码输入工具。
如图:这个界面的输入分为两部分:上面的SEU:在之后,可以输入SEU编辑的命令,包括查找等命令,都是辅助编辑使用,可以在输入代码的时候,随时输入命令。
代码输入在Beginning of data 和End of data之间输入代码,如果要插入一行,必须在行首位置输入I,系统会自动增加一行,同时提示出代码行号。
在此界面按F1,有具体的帮助信息。
四:源码示例00.10 * PRTPGMR - Print program - OPM00.20 *00.30 * QADSPOBJ is the outfile from DSPOBJD - Override occurs in CL00.40 FQADSPOBJIF E DISK00.50 FQPRINT O F 132 OF PRINTER00.60*********************************************************** *****00.70 * Parameter list00.80 C *ENTRY PLIST Parm list00.90 C PARM LIB 10 Library01.00 C EXCPTHDG Prt heading01.10*********************************************************** *****01.20 * Read a record01.30 * QLIDOBJD is the format name of the QADSPOBJ file01.40 C READ QLIDOBJD 20 Read01.50 * Continue reading until EOF01.60 C *IN20 DOWEQ'0' Not EOF01.70*********************************************************** *****01.80 * Use a subroutine to convert the date from MMDDYY to YYMMDD01.90 C MOVE ODUDAT MMDDYY 6 MMDDYY fmt02.00 C EXSR CVTDAT Convert date02.10 C MOVE YYMMDD LSTUSD 60 Last used dt02.20 C EXCPTDETAIL Print detail02.30 C OF EXCPTHDG Prt heading02.40 C READ QLIDOBJD 20 Read02.50 C ENDDO Loop Back02.60 * End the program02.70 C SETON LR Set LR02.80*********************************************************** *****02.90 C CVTDAT BEGSR03.00 * Convert date from MMDDYY to YYMMDD format 03.10 C MOVE MMDDYY WORK2 2 Move YY03.20 C MOVELWORK2 YYMMDD 6 Move YY03.30 C MOVELMMDDYY WORK4 4 Move MMDD03.40 C MOVE WORK4 YYMMDD Move MMDD03.50 C ENDSR03.60*********************************************************** *****03.70 OQPRINT E 206 HDG03.80 O 25 'Objects '03.90 O 'in Library - '04.00 O LIB04.10 O E 2 HDG04.20 O 6 'Object'04.30 O 18 'Obj type'04.40 O 30 'Attribute'04.50 O 42 'Last used'04.60 O E 1 DETAIL04.70 O ODOBNM 1004.80 O ODOBTP 1904.90 O ODOBAT 3305.00 O LSTUSDY 41对于源码的解释如下:由于还没有很清楚,所以暂不翻译00.40The externally described database file is named QADSPOBJ.This is thename of the file provided by the system that is used when an outfile iscreated by the DSPOBJD command. The system essentially copies theformat of the model file to the outfile named on DSPOBJD. The RPGprogram describes the file in QSYS because it wants to use the formatthat exists in the file. An OVRDBF command in the CL program causesthe DSPOBJDP file in QTEMP to be read instead of the file that is compiledinto the program. Because both files use the same format, the compiledRPG program knows what the layout of the format is.00.50 The QPRINT file is described as afixed-format file. Since no OVRPRTFcommand was specified prior to the open operationof QPRINT, thesystem provides access to the first QPRINT filefound on the library list.This is probably the QPRINT file supplied by IBMin the QGPL library.This file causes spooled printed output to occur. 00.80 The PLIST and PARM operation codes providethe means to pass in thevariable library name from the CL program. Thislibrary name is printedon the heading line.01.00 The EXCPT statement prints the heading lineas output.01.40 The program reads a record using the QLIDOBJD format. This is thename of the format used in the QADSPOBJD outfile.01.60 If end of file is detected, the program sets the LR indicator on and returns.01.80 A subroutine is used to convert thedate-last-used field (which exists in theoutfile in a MMDDYY format) to a YYMMDD format. There are many solutionsto the problem of reformatting a date field. Inthis example, the subroutinemethod is used because in a later chapter we change from anRPG subroutine to a subprogram.01.90 The program moves the ODUDAT field (date last used) to a common field(MMDDYY) and then calls the subroutine. This typeof coding creates ageneral-purpose subroutine that can convert anyMMDDYY date format.When the subroutine returns, the YYMMDD field is moved to the fieldnamed LSTUSD, which is a decimal field, so that editing can occur.02.20 A detail line is printed.02.30 If printer overflow occurs, an EXCPT operation is used to print the headingon the next page.02.40 The program loops back to read another record.03.10 The subroutine converts the date to thecorrect format by using MOVE andMOVEL operations. There are many other ways toalter the date format,but this method allows the same code to move to a subprogram with easein a later chapter.03.70 The heading output includes the library name that was passed into theprogram.04.60 The detail line prints several fields.。