日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

as400 编程语言c,AS400_RPG入门

發布時間:2023/12/10 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 as400 编程语言c,AS400_RPG入门 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一: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 files

PRINTER        ――――>printer files

WORKSTN      ――――> display, ICF files

SEQ            ――――>tape, diskette, save, printer, database

SPECIAL        ――――>N/A

c) 描述文件的類型:

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. 建立一個庫,取名PRTLIB

CRTLIB 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 - 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

對于源碼的解釋如下:

由于還沒有很清楚,所以暫不翻譯

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.

總結

以上是生活随笔為你收集整理的as400 编程语言c,AS400_RPG入门的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。