I have a subfile which is load-all.I have a function key (eg: F6).On pressing F6,i want data from subfile to be written into a PF.How to do this in RPGLE.Please give me a pseudocode if possible or steps.
Not sure about that technique
Not sure about read from a subfile
Not sure about %EOF with the subfile name
I would usually create a for loop, for x = ...but that requires that you know the number of records in the subile
Chain into the subfile on the value of x
move the fields to the physical file files
write the physical file
Phil
Phil,
READC would work if the subfile was filled with SFLNXtCHG *on
Otherwise
Define the INFDS file information data structure.
Part of the information for dispay file is the number of records in the subfile
DO RECIN# KEY#
KEY# CHAIN SFL 55 (EOF)
IF *IN55
LEAVE
ENDIF
WRITE Physical_File
ENDDO
Good Luck
READC will work if the MDT was set on, which it probably should have been the records are going to be read in to the program. CHAIN by subfile RRN works well in a FOR-loop; the program often knows how many records have been written because the program often does the writing.
If the subfile is a set of records that will all be entered by the user, CHAIN by RRN could still be used -- ignore any rows that don't exist, i.e., empty rows that the user didn't type in to. And READC should also work, since you'll usually only be interested in stuff that was typed.
The program will have created an empty subfile and it should know how big it was. I haven't seen a usage where a user can add rows without the program being informed. If the display file is shared and passed to a different program, the INFDS is definitely useful.
Tom
Thanks
That's how I remember it. READC or CHAIN no READ. EOF() function but no file or record name.
I would have style issues witj PGMBOB code but it'll work.
Phil.
Funny this question popped up when I am in the midst of my current project. I have an old manufacturing package and in the Bill of Lading Post process, I am to check the lines in the subfile for back ordered quantities and write just those lines to another file for other reporting purposes. SFLNXTCHG (MDT) is not specified in the DDS. That would be my only reason for changing the DDS (which if it ain't broke, don't fix it). And of course the INFDS is not specified. So I am doing as said, which is the easiest to do and look at later. Notice: I am using the subfile counter specified on the Sfile keyword in the F spec for the display file - srecno. This has the number of records written to the subfile.
c z-add 1 chkbolrrn 4 0
c DOU chkbolrrn > srecno
c chkbolrrn Chain MAINSFL 69
process some stuff
C add 1 chkbolrrn
c EndDO
I just wonder why this has never been changed so you can process a subfile like a physical file. i.e.
c *start Setll mainsfl
c dou %eof(mainsfl)
c read mainsfl
This may be another reason so many of us 20 year guys are loosing hair and turning grey; having to remember little quirks like this. Or we send it to compile and then slap our heads when we get messages.
Just my two cents....
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 5  Replies