I/O Operations in Program described files

165 pts.
Tags:
Program Described Files
RPG I/O operations
RPG/400
Hi, I have written a program, which reads records from a program described file and write records to another program describe file. However it seems working but that doesn't seem an efficient program to me. Could anyone please suggest me what can be done to improve this program. FEmployee IF F 39 DISK FEmpoutf O F 39 DISK Drecemp DS DEMPID 1 10 DFNAME 11 20 DMNAME 21 21 DLNAME 22 31 DSALARY 32 35P 2 DDEPT 36 39 IEmployee NS I 1 10 empid I 11 20 fname I 21 21 mname I 22 31 lname I P 32 35 2Salary I 36 39 DEPT /FREE READ EMPLOYEE; DOW NOT %EOF; WRITE EMPOUTF RECEMP; READ EMPLOYEE; ENDDO; EVAL *INLR = *ON; RETURN; /END-FREE Oempoutf D O EMPID 10 O FNAME 20 O MNAME 21 O LNAME 31 O SALARY 35P O DEPT 39 Some doubts: 1. I had to define an extra data structure recemp as for program described files it's necessary to use the data structure name in WRITE operation. Now my doubt is, could i have defined data structure only once and use that data structure in I-specs and O-specs as my both Input and Output file structure is exactly same. 2. I have seen in some programs that after reading the record we dont move it to output record, while in COBOL we explicitly have to populate the output record before writing it to a file. How is this achieved in RPG? 3. Kindly suggest me more ways the program can be improved. Regards Shruti
ASKED: April 3, 2009  10:26 AM
UPDATED: April 3, 2009  2:51 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

Why didn’t you just use CPYF?

Regards,

Martin Gilbert.

As to 1, yes you can use the ds for input and output. Unlike COBOL, where you deal directly with the input and output buffers, in RPG you don’t directly access the buffers. When you do a read with a ds or use i specs, the program reads in the record into the buffer and then copies the data into the fields you specify. Same with a write.
The ds is a ever so slightly more efficient than i and o specs because only one field (the ds) is being copied into or out of the buffer, as opposed to all of the fields one after another.
Greg

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Shrutigupta
    Ok, I dont know the use of CPYF in RPG program. I will search for it. Thanks.
    165 pointsBadges:
    report
  • Shrutigupta
    In this particular example how can i populate RECEMP data structure (i.e how to move record from input file to the data structure) as there is no record format name of input file. I am so confused in this program described file...extarnally described file is a way easier than this....but i need to learn these concepts as well....kindly help...
    165 pointsBadges:
    report
  • Gilly400
    Hi, I think you're making it a bit too complicated. The following should do the trick. Notice that I put an A for add in the file spec for empoutf and an ADD on the output spec. I changed the write to use EXCEPT and the D (detail time) to and E (exception time) on the output spec. I removed the D specs completely and replaced the input field definitions with one field for the whole length of the record - the field is also used in the output specs. FEmployee IF F 39 DISK FEmpoutf O A F 39 DISK IEmployee NS I 1 39 data /FREE READ EMPLOYEE; DOW NOT %EOF; EXCEPT EMPOUTF; READ EMPLOYEE; ENDDO; EVAL *INLR = *ON; RETURN; /END-FREE Oempoutf EADD O data 39 Hope this makes some sense to you. I can understand that the use of internally defined files can be quite confusing if you're used to externally defined files. All this stuff comes from older (non-AS400) versions of RPG where externally defined files couldn't be used. If you come from a System/36 background like me, then internally defined files are almost second nature. By the way CPYF is an AS/400 (CL) command. What I meant by using CPYF was that you didn't really need to write a program at all for this. If you use CPYF you can copy data from one file to another - it's a very powerful command which lets you select what data you want to copy, allows creation of a duplicate file if necessary, can clear existing data by using a replace option, etc. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Shrutigupta
    Hey thanks Martin, this looks quite simple and tidy now :) I have used CPYF command quite many times, earlier I thought CPYF is some keyword in RPG also, using which file description can be copied.... In the given code, both the input file and output file are specified as flat file. Suppose the input data has a packed field in it, then also the program will work as expected? Won't in abend?
    165 pointsBadges:
    report
  • Shrutigupta
    I tried both ways, by defining the explicit fields in input specs and by defining the flat record structure, and it doesn't abend....howcome? Issuing a read on this file means moving packed data to this flat structure....is this permissible?
    165 pointsBadges:
    report
  • Gilly400
    Hi, It doesn't matter about the packed data as long as the file has no fields defined (flat file). If you tried to copy a flat file to an externally defined file you may get problems if for example you have blanks or character data in the position of a numeric or packed field. If you copy from an externally defined file to a flat file you won't have any problems. The OS checks data that gets copied into externally described files and will issue error messages if the data being copied is invalid for the file field definitions. Flat files only (normally) have one character field (often with the same name as the file, which means you'd have to use a RENAME in your RPG if you want to use the file as externally described). Packed data is allowed in character fields, be aware that if you query or dsppfm a file with packed data in a character field the packed data may not be shown unless you display in hex mode (which you can't do in query). Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Shrutigupta
    Thanks Martin for your help....it was described so well that i understood it easily....thx again..
    165 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following