as400 编程语言c,AS400_RPG入门
一:RPG介紹
RPG程序的特點(diǎn):
1.
程序的編寫對(duì)于每一個(gè)位置都有明確的定義,所以程序的編寫必須在指定的位置開始。通過(guò)使用ILE工具可以進(jìn)行一些方便的輸入。
2. RPG程序的設(shè)計(jì)針對(duì)每一部分都有嚴(yán)格的要求,有相應(yīng)的規(guī)格說(shuō)明,他們包括
a) 配置規(guī)格說(shuō)明(Control Specifications):主要規(guī)定了程序的命名,日期格式等信息。
b) 文件描述說(shuō)明(File Description Specifications):對(duì)程序使用到的文件的說(shuō)明
c) 定義說(shuō)明(Definition Specifications):主要對(duì)程序使用的數(shù)據(jù)進(jìn)行說(shuō)明。
d) 輸入說(shuō)明(Input Specifications):主要對(duì)文件輸入數(shù)據(jù)進(jìn)行說(shuō)明。
e) 計(jì)算說(shuō)明(Calculation Specifications):主要對(duì)數(shù)據(jù)計(jì)算和計(jì)算順序的說(shuō)明。
f) 輸出說(shuō)明(Output Specifications):主要針對(duì)數(shù)據(jù)的輸出記錄和字段的說(shuō)明。
g) 子程序說(shuō)明:包括有三種,對(duì)子程序的各種進(jìn)行進(jìn)行了定義說(shuō)明。
3. 指示器(Indicators)
通常是一個(gè)字節(jié),被設(shè)置為‘0’或者‘1’,他主要作為程序操作的結(jié)果或者進(jìn)行操作的條件。好像程序的邏輯開關(guān),決定著程序的流程。指示器必須在定義規(guī)范中進(jìn)行定義。RPG VI也有一些系統(tǒng)的指示器,他們一般是兩個(gè)字符的變量,如LR等。指示器可以在程序的任何地方使用,也可以在程序中修改他的值。
4. 操作代碼
相當(dāng)與匯編語(yǔ)言的命令一樣,有RPG程序提供一套完整的操作代碼,比如讀一條數(shù)據(jù)使用READ ,RPG程序?qū)Σ僮鞔a進(jìn)行了分類,比如字符串操作符,數(shù)組操作符等。
5. 定義描述文件
a)
文件服務(wù)是程序和IO設(shè)備的連接。系統(tǒng)里的每一個(gè)文件都有相應(yīng)的描述文件,對(duì)文件的特性和數(shù)據(jù)的組織形式進(jìn)行描述。如果在程序中要使用IO操作,必須要指定一個(gè)描述文件,對(duì)IO的設(shè)備進(jìn)行描述。對(duì)于文件的類型,系統(tǒng)支持以下幾種:
1. 數(shù)據(jù)庫(kù)文件(database files):對(duì)數(shù)據(jù)進(jìn)行持久存儲(chǔ)。
2. 設(shè)備文件(Device files):容許訪問(wèn)的擴(kuò)展設(shè)備,包括顯示文件,打印文件,磁盤文件等。
3. 一般文件(save files):保存在硬盤上的文件
4. 遠(yuǎn)程文件(DDM files):保存在遠(yuǎn)程系統(tǒng)上的文件。
b)
每一個(gè)IO設(shè)備都對(duì)應(yīng)有一個(gè)描述文件,在程序中如果要使用到IO設(shè)備,就要指定相應(yīng)的文件。這主要根據(jù)操作代碼來(lái)決定,有的操作代碼是設(shè)備依賴的,必須指定特定的設(shè)備才可以使用,而有些操作代碼是和設(shè)備獨(dú)立的,如WRITE等。
產(chǎn)用的設(shè)備類型有:
RPG Device Type ――――> iSeries File Type
DISK ――――>database, save, DDM files
PRINTER ――――>printer files
WORKSTN ――――> display, ICF files
SEQ ――――>tape, diskette, save, printer, database
SPECIAL ――――>N/A
c) 描述文件的類型:
1、 一般程序描述文件(program-described file):在輸入輸出描述的文件中會(huì)做相應(yīng)的處理。
2、 擴(kuò)展描述文件(externally described file):主要是多個(gè)應(yīng)用程序可以共享數(shù)據(jù)
a)
通過(guò)針對(duì)描述文件的不同配置,RPG程序?qū)崿F(xiàn)了程序和數(shù)據(jù)的分離,這樣可以針對(duì)不同的保存數(shù)據(jù)的設(shè)備和形式,來(lái)對(duì)描述文件進(jìn)行配置,這樣就很容易的實(shí)現(xiàn)的程序的靈活性。在設(shè)備進(jìn)行升級(jí)以后,程序依然可以使用。
二、通過(guò)ILE建立RPG程序:
a) ILE(Intergrated Language Environment)的介紹
ILE是AS400中提供的一套增強(qiáng)編程的工具包,他針對(duì)不同的編程語(yǔ)言,都有相應(yīng)的環(huán)境支持,ILE RPG,ILE C,ILE COBOL,ILE CL等。
b) ILE的優(yōu)勢(shì)
i. ILE 本身提供了許多程序模塊,供程序員調(diào)用
ii. 提供編譯的環(huán)境,可以對(duì)代碼進(jìn)行調(diào)試
iii. 提供優(yōu)化的調(diào)用性能
iv. 可以集成多種語(yǔ)言
v. 對(duì)代碼進(jìn)行優(yōu)化
vi. 而且提供老版本的代碼轉(zhuǎn)換到新版本的代碼,主要是針對(duì)RPG程序和CL程序。
c) 使用ILE建立一個(gè)應(yīng)用程序的例子
vii. 建立一個(gè)庫(kù),取名PRTLIB
CRTLIB LIB(PRTLIB) TEXT(‘SAMPLE ILE APPLICATION’)
viii. 將PRTLIB設(shè)置為當(dāng)前庫(kù)
CHGCURLIB CURLIB(PRTLIB)
ix. 建立一個(gè)源碼文件在PRTLIB中
CRTSRCPF FILE(SOURCE) RCDLEN(112) TEXT(‘SAMPLE ILE Appliaction’)
x. 編輯文件,輸入文件內(nèi)容,分配源文件類型是CLP,描述信息是OPM,
WRKMBRPDM FILE(PRTLIB/SOURCE)
xi. 按F3鍵,退出后,建立命令,系統(tǒng)將會(huì)產(chǎn)生CRTCLPGM命令。
三、SEU工具的使用
SEU(Source entry utility)源碼輸入工具。如圖:
這個(gè)界面的輸入分為兩部分:
上面的SEU:在之后,可以輸入SEU編輯的命令,包括查找等命令,都是輔助編輯使用,可以在輸入代碼的時(shí)候,隨時(shí)輸入命令。
代碼輸入在Beginning of data 和 End of data之間輸入代碼,如果要插入一行,必須在行首位置輸入I,系統(tǒng)會(huì)自動(dòng)增加一行,同時(shí)提示出代碼行號(hào)。
在此界面按F1,有具體的幫助信息。
四:源碼示例
00.10 * PRTPGMR - Print program - OPM
00.20 *
00.30 * QADSPOBJ is the outfile from DSPOBJD - Override occurs in CL
00.40 FQADSPOBJIF E DISK
00.50 FQPRINT O F 132 OF PRINTER
00.60 ****************************************************************
00.70 * Parameter list
00.80 C *ENTRY PLIST Parm list
00.90 C PARM LIB 10 Library
01.00 C EXCPTHDG Prt heading
01.10 ****************************************************************
01.20 * Read a record
01.30 * QLIDOBJD is the format name of the QADSPOBJ file
01.40 C READ QLIDOBJD 20 Read
01.50 * Continue reading until EOF
01.60 C *IN20 DOWEQ'0' Not EOF
01.70 ****************************************************************
01.80 * Use a subroutine to convert the date from MMDDYY to YYMMDD
01.90 C MOVE ODUDAT MMDDYY 6 MMDDYY fmt
02.00 C EXSR CVTDAT Convert date
02.10 C MOVE YYMMDD LSTUSD 60 Last used dt
02.20 C EXCPTDETAIL Print detail
02.30 C OF EXCPTHDG Prt heading
02.40 C READ QLIDOBJD 20 Read
02.50 C ENDDO Loop Back
02.60 * End the program
02.70 C SETON LR Set LR
02.80 ****************************************************************
02.90 C CVTDAT BEGSR
03.00 * Convert date from MMDDYY to YYMMDD format
03.10 C MOVE MMDDYY WORK2 2 Move YY
03.20 C MOVELWORK2 YYMMDD 6 Move YY
03.30 C MOVELMMDDYY WORK4 4 Move MMDD
03.40 C MOVE WORK4 YYMMDD Move MMDD
03.50 C ENDSR
03.60 ****************************************************************
03.70 OQPRINT E 206 HDG
03.80 O 25 'Objects '
03.90 O 'in Library - '
04.00 O LIB
04.10 O E 2 HDG
04.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 DETAIL
04.70 O ODOBNM 10
04.80 O ODOBTP 19
04.90 O ODOBAT 33
05.00 O LSTUSDY 41
對(duì)于源碼的解釋如下:
由于還沒(méi)有很清楚,所以暫不翻譯
00.40The externally described database file is named
QADSPOBJ.This is the
name of the file provided by the system that is used when an outfile is
created by the DSPOBJD command. The system essentially copies the
format of the model file to the outfile named on DSPOBJD. The RPG
program describes the file in QSYS because it wants to use the format
that exists in the file. An OVRDBF command in the CL program causes
the DSPOBJDP file in QTEMP to be read instead of the file that is compiled
into the program. Because both files use the same format, the compiled
RPG program knows what the layout of the format is.
00.50 The QPRINT file is described as a fixed-format file. Since no OVRPRTF
command was specified prior to the open operation of QPRINT, the
system provides access to the first QPRINT file found on the library list.
This is probably the QPRINT file supplied by IBM in the QGPL library.
This file causes spooled printed output to occur.
00.80 The PLIST and PARM operation codes provide the means to pass in the
variable library name from the CL program. This library name is printed
on the heading line.
01.00 The EXCPT statement prints the heading line as output.
01.40 The program reads a record using the QLIDOBJD format. This is the
name 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 the date-last-used field (which exists in the
outfile in a MMDDYY format) to a YYMMDD format. There are many solutions
to the problem of reformatting a date field. In this example, the subroutine
method is used because in a later chapter we change from an
RPG 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 type of coding creates a
general-purpose subroutine that can convert any MMDDYY date format.
When the subroutine returns, the YYMMDD field is moved to the field
named 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 heading
on the next page.
02.40 The program loops back to read another record.
03.10 The subroutine converts the date to the correct format by using MOVE and
MOVEL operations. There are many other ways to alter the date format,
but this method allows the same code to move to a subprogram with ease
in a later chapter.
03.70 The heading output includes the library name that was passed into the
program.
04.60 The detail line prints several fields.
總結(jié)
以上是生活随笔為你收集整理的as400 编程语言c,AS400_RPG入门的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python项目实战-----科比数据集
- 下一篇: Bezier曲线