Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write to many mebers in a RPG prg 3

Status
Not open for further replies.

GAORR

Programmer
Nov 22, 2001
48
CA
I have a file with 3 members.
ie: File name is KB0405P
member 1 is KB0405All
member 2 is KB0405CAD
member 3 is KB0405OTH
record name is KB0405PR

I want to be able write to all 3 members in a program at the same time (different data). Is it possible? If so, how would one set up the file specs. A small example would be great.

Thanks
 
I don't see anything jumping out at me on why you wouldn't just bring the members in as updates and be able to write to them as needed in the program.

The one thing I think needs clarification is "At the same time" Do you simply mean in the same program or are you referring to an attempt at concurancy

___________________________________________________________________
[sub]
The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page faq333-3811
[/sub]
 
one other thing. I'm gathering these are logicals of the actual file KB0405P. correct?

in that case why not make the program a bit mroe efficeint and only bring in the PF and then use SQL in the program to write what is needed at what time in the flow of the program



___________________________________________________________________
[sub]
The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page faq333-3811
[/sub]
 
Thanks for your response.

This is what I would like to do, although you can see I will
get a compile error - 'file name already specified'.

FKB0405P O E DISK EXTMBR('KB0405ALL')
F RENAME(KB0405PR:ALLPR)
FKB0405P O E DISK EXTMBR('KB0405CAD')
F RENAME(KB0405PR:CADPR)
FKB0405P O E DISK EXTMBR('KB0405OTH')
F RENAME(KB0405PR:OTHPR)

This is a physical file - the first member will contain
all data to be passed to a user, the other 2 will contain
portions (different) of the first as well to be passed
to the user.

Please appreciate this question is coming from a COBOL guy who over the last year has been learning RPG.

note: we do not use SQL in RPG prgs in this shop.

Again thanks for any help.
 
You can't declare the same file more than once in an RPG program; either give them 3 different names in the F-specs and use the RENAME and EXTFILE keywords to rename the record format and point that F-spec to that "file name", or make the name in the EXTMBR keyword a variable which you can change (make the file is USROPN and change the value only when the file is closed; then you can open it again).


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Just code the INFDS and add EXTMBR('*ALL') keyword on the F spec as shown below.
You'll get member names & numbers in INFDS variables MbrNam & MbrNum. The MbrNum is dependant of the creation date.
hth -- Philippe

Code:
FMY3MBRFILEip   e             disk    INFDS(FILEFBK)
F                                     [COLOR=red]EXTMBR('*ALL')[/color]
DFILEFBK          ds                                
D MbrNam                129    138                  
D MbrNumM               395    396I 0               
 /free                                              
           dsply MbrNam;                            
           dsply MbrNum;                            
 /end-free
 
You can use the EXTFILE keyword, then the EXTMBR keyword.
Check this out.

Code:
FOutput1   O    F   80       Disk    ExtFile('KB0405P')
F                                    ExtMbr('KB0405ALL')
FOutput2   O    F   80       Disk    ExtFile('KB0405P')
F                                    ExtMbr('KB0405CAD')
FOutput3   O    F   80       Disk    ExtFile('KB0405P')
F                                    ExtMbr('KB0405OTH')

This approach gets you around the rule about declaring a file more than once. Some notes about this approach.

1. You must specify the record length. (The 80 above).
2. In order to pass data to the files, you must define a data structure in the "D" specs.

Code:
D KbRcd             Ds
D  Field1               1     40
D  Field2              41     80
 //-----------------------------------------------------
 /Free

  Field1 = something;
  Field2 = somethingelse;
  Write Output1 KbRcd;

 /End-Free



RedMage1967
IBM Certifed - RPG IV Progammer
 
Thanks to all for the quick reponses.

I now have it working just fine. I have tested out all the suggestions to ensure I understand them and chose the most appropriate for the app I am working on.

A star to you all!!!!

 
I used the following:

Delcared the file name once, usibg EXTMBR with a variable and opened/closed the file after setting the variable for EXTMBR. (Flapeyre)

It turns out I have just had an opportunity to use the suggestion by Redimage1967 which worked just fine as well.

Again thanks to all for the quick responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top