Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1294193
  • 博文数量: 287
  • 博客积分: 11000
  • 博客等级: 上将
  • 技术积分: 3833
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-16 08:43
文章分类
文章存档

2013年(15)

2012年(17)

2011年(17)

2010年(135)

2009年(85)

2008年(18)

分类: 系统运维

2009-05-03 09:32:46

RPGIV编程问题百解(22)一个程序中,对同一个文件并行操作
 
问题:
 
一个问题一直困绕着我,在一个程序中,对同一个文件可以操作码?
 
回答1:
 
FTestPF    if   e           k disk                                     
FTestPFAlt if   e           k disk     Usropn                          
F                                      Rename(TSTRCD : TSTRCDALT )     
D OvrDbf        C                   CONST('Ovrdbf File(TESTPFALT) Tofile-
D                                    (*LIBL/TESTPF) OPNSCOPE(*JOB)')  
Downside is that TestPFAlt would have to be overriden (both to compile and
run), but it allows you to read the same file throug two open data paths:
  Read testpf;
  Read testPFAlt; // actually a second ODP to TestPF
 
回答2:
 
If you are at 6.1 (probably not, eh?), then you can use EXTDESC and EXTFILE.
FTestPF    if   e             disk          
FTestPF2   if   e             disk  extdesc('TESTPF')
F                                   extfile(*extdesc)
F                                   rename(TSTRCD:TSTRCD2)
EXTDESC is new with 6.1 and it tells the compiler where to get the external
field definitions.
 
回答3:
 
Try using ExtFile, Rename and Prefix keywords for the second instance of your
file and use external DS for one or both of them.
FTestPF    if   e             disk          
FTestPF2   if   e             disk 
F                                   extfile('TESTPF')
F                                   rename(TSTRCD:TSTRCD2)
F                                   Prefix(PF2)
D DsPF2         E DS                  ExtName(TestPF)  
D                                     Prefix(PF2)
 
回答4:
 
FTestPF    if   e             disk  PREFIX('PF.')        
FTestPF2   if   e             disk  PREFIX('PF2.')
F                                   extfile('TESTPF')
F                                   rename(TSTRCD:TSTRCD2)
D PF        DS         LikeRec(TSTRCD)
D PF2       DS         LikeRec(TSTRCD)  // Could also use LikeREC(TSTRCD2)
This assumes you have a logical TESTPF2 over the physical TESTPF which is
nothing more than a format file in this case.

 
阅读(854) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~