The NoteBook of EricKong

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks
Create a Physical File with or without a key field 
创建一个物理文件(有或者没有Key字段)

The AS/400 database, DB2/400 is part of the AS/400 operating system. It is a relational database and has features similar to other databases you may have used such as Microsoft Access, Oracle or Dbase. The standard method of creating files is to define the specifications of the file using DDS. Of course DDS is used for other things on the AS/400 like defining display files and print files. 
AS/400数据库,DB2/400是AS/400操作系统的一部分,它是一个关系性数据库.和其他的数据库相比,例如Microsoft Access, Oracle or Dbase有着相似的特性.用DSS文件编写说明语句是创建数据库文件的标准方法.当然,也可以使用DSS在AS400做其他东西,例如创建显示文件或者打印文件

To create a physical database file, enter your source statements in a DDS source file member. For example, name the member "CUS" for customer file. Make sure the member type is "PF". This tells the compiler that this is for a physical file. Notice that the first record has an "R" in position 17. This means that this line is specifying the record name, in this case "CUREC". The "TEXT" is optional but helps to document the file. 
创建一个物理文件数据库,你需要在DSS文件中输入你的数据描述代码.例如,以一个Customer文件为例,命名为CUS的Member,要确保这个member的类型是"PF",这是为了告诉编译器,这是一个物理文件.注意到在第一行中,位置17的地方有个"R"的标记,这一行指明了记录的名字,这里记录名字就是CUREC.而Text不是一定要,但是也对文档化比较有用.

After the line naming the record, each line describes a field. The field name is followed by the field length and its data type.
这一行命名了记录之后,下面的每一行描述了一个字段,字段名称后面是字段的长度和数据类型

The three most used data types are "A" for alpha or character, "S" for numeric and "P" for packed decimal. For numeric fields, you must also specify the number of decimal positions. So here, the company number field is a three digit number with no decimal places. The customer number and zip code are also numeric fields with no decimal places. The credit limit is a numeric, packed decimal field with 9 digits, of which two are after the decimal point. The rest of the fields are character fields. 
最常用的数据类型是下面的三种, "A"代表字符,"S"代表数值, "P"代表packed decimal,对于数值字段,你必须指明小数点的位置,这里,公司号码字段就是一个3个数字的号码,没有小数点,客户号码和邮政编码同样是数字,也是没有小数,而信用额度是一个数值,它一个有9个数字,其中两位数值位于小数点后面,其他的都是字符的定义

Once you have entered the DDS source code, you must compile it. You do this by keying option 14 next to your member name on the PDM screen. If you pay attention you will see that the AS/400 is actually executing the CRTPF (Create Physical File) command. It knows to use this command because the member type of the source code is "PF". 
一旦你输入完DDS代码,你必须编译它,在PDM界面中,在你要编译Member名字的后面输入14.假如你细心一点,你会发现AS400实际执行了CRTPF (Create Physical File)命令,这是因为这个Member的类型是"PF"

You now have a database physical file, see Figure 1. This file has built into it the fields and their attributes. Let's modify this file definition to add key fields. If a physical file has key fields, programs can randomly access the records or read them sequentially in the order of the key fields.
现在你已经有了数据库物理文件,如图1,这个文件包含了字段和他们的属性,现在我们就为文件增加key字段,假如这个物理文件包含了key字段,那么程序就可以通过Key随即的访问或者顺许的访问记录

You can see in Figure 2 that it is simple to add key fields. 
看图2,建立key字段是非常简单的

The "UNIQUE" record at the beginning of the source is used if you want the AS/400 to insist on having no records with duplicate keys. This is optional. At the end of the source code, there are two lines with "K" in position 17. These lines define the key fields. So, this file will build a key using the company number and then the customer number. Further, it will not allow a duplicate company number / customer number record to be written. 
开头的那个"UNIQUE"表明了你要AS400不能含有重复key的Record,这是可选的. 代码的末尾最后两行,在位置17的有两个"K",这两个"K"就是定义key字段了,那么,这个文件就会用公司号码和客户号码来建立key,进一步来说,文件不允许含有公司号码和客户号码都相同的recored.

The records are written to the file in arrival sequence. If you read the data by specifying keyed access, the records will read as though they have been sorted by company number and customer number. Also, your programs can randomly retrieve records. For example, a "CHAIN" instruction in RPG can now randomly read the record for a specific company number / customer number. 
Record是按顺序写入文件的,而假如你读取数据的时候指明key,读取的数据是已经按照公司号码和客户号码排好顺序,同时,你也可以随即读取Record,例如,RPG的"CHAIN"说明符就可以用公司号码和客户号码随即读取文件

Figure 1 - DDS for Physical File Without Key 
     A          R CUREC                    TEXT('CUSTOMER FILE')   
     A            CUCO           3S 0      TEXT('COMPANY #')       
     A            CUSTS          1A        TEXT('STATUS CODE')     
     A            CUNUM          5S 0      TEXT('CUSTOMER #')      
     A            CUNAME        30A        TEXT('CUSTOMER NAME')   
     A            CUADR         30A        TEXT('CUSTOMER ADDRESS') 
     A            CUCITY        18A        TEXT('CUSTOMER CITY')   
     A            CUSTAT         2A        TEXT('CUSTOMER STATE')  
     A            CUZIP          9S 0      TEXT('CUSTOMER ZIP')        
     A            CUCRLM         9P 2      TEXT('CUST CREDIT LIMIT')         
                      
Figure 2 - DDS for Physical File With Key Fields
     A                                     UNIQUE                  
     A          R CUREC                    TEXT('CUSTOMER FILE')   
     A            CUCO           3S 0      TEXT('COMPANY #')       
     A            CUSTS          1A        TEXT('STATUS CODE')     
     A            CUNUM          5S 0      TEXT('CUSTOMER #')      
     A            CUNAME        30A        TEXT('CUSTOMER NAME')   
     A            CUADR         30A        TEXT('CUSTOMER ADDRESS') 
     A            CUCITY        18A        TEXT('CUSTOMER CITY')   
     A            CUSTAT         2A        TEXT('CUSTOMER STATE')  
     A            CUZIP          9S 0      TEXT('CUSTOMER ZIP')    
     A            CUCRLM         9P 2      TEXT('CUST CREDIT LIMIT')              
      *                                                             
     A          K CUCO                                              
     A          K CUNUM 
posted on 2013-09-04 16:59 Eric_jiang 阅读(440) 评论(0)  编辑  收藏 所属分类: AS400

只有注册用户登录后才能发表评论。


网站导航: