Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1083301
  • 博文数量: 106
  • 博客积分: 9093
  • 博客等级: 中将
  • 技术积分: 2770
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 17:22
文章分类

全部博文(106)

文章存档

2014年(1)

2012年(29)

2011年(32)

2010年(20)

2008年(24)

分类:

2011-04-15 15:03:29

我们可以在rpgle中使用关键字EXTNAME和EXTFLD来定义DS.

关键字EXTNAME & EXTFLD的定义格式如下:
EXTNAME(file-name{:format-name}{:*ALL| *INPUT|*OUTPUT|*KEY})
EXTFLD(field_name)

EXTNAME参数1:file-name就是定义DS时引用的外部文件
EXTNAME参数2:format-name就是引用的外部文件的format,如果又多个format的时候。
EXTNAME参数3:*ALL|*INPUT|*OUTPUT|*KEY的意思是提取format中符号参数的字段来定义DS.
*ALL:提取全部字段
*INPUT:只提取输入字段
*OUTPUT:只提取输出字段
*KEY:只提取key字段

EXTFLD是重命名EXTNAME引用的字段的。

EXTNAME只能用来定义DS,不能定义DS的子字段。
d dcustom       e ds                  extname(custom:*key)  QUALIFIED 
上面是可以的,但下面就不被允许了。
d dcustom         ds                 
d  subfld                             extname(custom:*key)  QUALIFIED

下面是具体的例子:
DB FILE: CUSTOM
                R CUSTOMR                   TEXT('CUSTOMER FILE')
                  CUST           5          TEXT('CUSTOMER NUMBER')
                                            COLHDG('CUSTOMER NUMBER')
                  NAME          20          TEXT('CUSTOMER NAME')
                                            COLHDG('CUSTOMER NAME')
                  ADDR          20          TEXT('CUSTOMER ADDRESS')
                                            COLHDG('CUSTOMER ADDRESS')
                  CITY          20          TEXT('CUSTOMER CITY')
                                            COLHDG('CUSTOMER CITY')
                  STATE          2          TEXT('STATE ABBREVIATION')
                                            COLHDG('STATE ABBREVIATION')
                  ZIP            5  0       TEXT('ZIP CODE')
                                            COLHDG('ZIP CODE')
                  ARBAL         10  2       TEXT('ACCOUNTS RECEIVABLE BALANCE')
                                            COLHDG('ACCOUNTS RECEIVABLE '-
                                             'BALANCE')
                K CUST
                K STATE

DSP FILE:TESTDSP
     A                                      DSPSIZ(24 80 *DS3)
     A                                      CA03
     A          R DSP1R
     A            FLDA           5A  I  1 25
     A            FLDB           2A  I  2 25
     A            FLDC           2Y 0B  3 25
     A            FLDD           2Y 0O  4 25
     A          R DSP2R
     A            FLDE           5A  O  5 25
     A            FLDF           2A  O  6 25
     A            FLDG           2Y 0B  7 25
     A            FLDH           2Y 0I  8 25

RPGLE FILE:TEST
     d dcustom       e ds                  extname(custom:*key)  QUALIFIED
     d  custID       e                     extfld(CUST)
     d dsDSPi        e ds                  extname(TESTDSP:DSP1R:*input)
     d                                     QUALIFIED
     d dsDSPo        e ds                  extname(TESTDSP:DSP2R:*output)
     d                                     QUALIFIED
     d wait            s              1a
     c*
      /free
             // manipulate *key field
                         dcustom.custID = '*key';
                         dsply     dcustom.custID  wait;
             // manipulate *input field
                         dsDSPi.flda = '*input';
                         dsply     dsDSPi.flda     wait;
             // manipulate *output field
                         dsDSPo.flde = '*output';
                         dsply     dsDSPo.flde     wait;
      /end-free
     c*
     c                   SETON                                        LR
     c                   RETURN


TEST编译后的spooled file
                      S o u r c e   L i s t i n g                                                
 1 d dcustom       e ds                  extname(custom:*key)  QUALIFIED                         
 2 d  custID       e                     extfld(CUST)                                            
    *--------------------------------------------------------------------------------------------*
    * Data structure . . . . . . :  DCUSTOM                                                      *
    * External format  . . . . . :  CUSTOMR : PTRLIB/CUSTOM                                      *
    * Format text  . . . . . . . :  CUSTOMER FILE                                                *
    *--------------------------------------------------------------------------------------------*
 3=D CUSTID                         5A   EXTFLD (CUST)                        CUSTOMER NUMBER    
 4=D STATE                          2A                                        STATE ABBREVIATION 
 5 d dsDSPi        e ds                  extname(TESTDSP:DSP1R:*input)                           
 6 d                                     QUALIFIED                                               
    *--------------------------------------------------------------------------------------------*
    * Data structure . . . . . . :  DSDSPI                                                       *
    * External format  . . . . . :  DSP1R : PTRLIB/TESTDSP                                       *
    *--------------------------------------------------------------------------------------------*
 7=D FLDA                           5A                                                           
 8=D FLDB                           2A                                                           
 9=D FLDC                           2S 0                                                         
10 d dsDSPo        e ds                  extname(TESTDSP:DSP2R:*output)                          
11 d                                     QUALIFIED                                               
    *--------------------------------------------------------------------------------------------*
    * Data structure . . . . . . :  DSDSPO                                                       *
    * External format  . . . . . :  DSP2R : PTRLIB/TESTDSP                                       *
    *--------------------------------------------------------------------------------------------*
12=D FLDE                           5A                                                           
13=D FLDF                           2A                                                           
14=D FLDG                           2S 0                                                         
15 d wait            s              1a                                                           
16 c*                                                                                            
17  /free                                                                                        
18         // manipulate *key field                                                              
19                     dcustom.custID = '*key';                                                  
20                     dsply     dcustom.custID  wait;                                           
21         // manipulate *input field                                                            
22                     dsDSPi.flda = '*input';                                                   
23                     dsply     dsDSPi.flda     wait;                                           
24         // manipulate *output field                                                           
25                     dsDSPo.flde = '*output';                                                  
26                     dsply     dsDSPo.flde     wait;                                           
27  /end-free                                                                                    
28 c*                                                                                            
29 c                   SETON                                        LR----                       
30 c                   RETURN                                                                    
   * * * * *   E N D   O F   S O U R C E   * * * * *                                             
从编译后的spooled file来看dcustom只提取了DB CUSTOM中的KEY字段,dsDSPi只提取了TESTDSP的format(DSP1R)的具有input能力的字段,而dsDSPo只提取了TESTDSP的format(DSP2R)的具有output能力的字段。

在例子中我把DB CUSTOM中cust重命名为CUSTID。
阅读(2902) | 评论(1) | 转发(2) |
给主人留下些什么吧!~~

chinaunix网友2011-07-21 14:09:15

从来没用过extname(*input/*output/*key),学习了,呵呵