Reputation: 87
I am a newbie to AS/400 and familiar with Data Description Specification (DDS) statements. I have two tables created using a Data Description Specification.
I need to write two RPGLE programs to insert and retrieve from these tables.
EMPPERS FILE
REF(HRFREF)
R EMPR
EMPID R REFFLD(IDNO)
NAME R
DOB R
STS R
K EMPID
DEPTMNT FILE
REF(HRFREF)
R DEPTR
DEPTID R REFFLD(DEPID)
DEPNM R
STS R
K DEPTID
Upvotes: 0
Views: 4864
Reputation: 2163
It's a strange question. It takes three RPG source lines to create a complete program to write a record to a file (F-spec, WRITE op-code, set LR on) and three for reading a record. The details of what needs to be done with the data are missing from the question.
Upvotes: 0
Reputation: 1859
Without actually doing the work for you, here is something to get you started. I agree with the other answers, though. You really need to get into the programmer's guide and reference manual. However, I also understand that if you're coming from this with no RPG IV knowledge whatsoever, it can be intimidating.
The example below uses direct file access in RPG and is only for the one file. Both files can be treated the same when using this technique.
Looking at the first line, this is an F-spec. It's used for direct file access to declare your file and to declare how you're going to use it. In the example I declared it as externally described, updateable, full procedural, keyed, and on the disk. Everything else is free-form.
Femppers uf a e k disk
/free
//Read from EMPPERS file with a given employee id. Change
//the status and update it.
EMPID = 12345; //assuming EMPID is numeric 5,0.
Chain (EMPID) Emppers;
If %Found();
STS = 'A'; //Assuming STS is a 1-byte alpha
Update Empr; //Update the record format, not the file.
EndIf;
//Add a new record to EMPPERS:
EMPID = 45678;
NAME = 'John Doe';
DOB = Date('1980-01-01':*ISO);
STS = 'A';
Write Empr; //Write to the record format, not the file.
*INLR = *On; //Tell the program that it's okay to end.
//Note: *INLR doesn't actually end the program,
// it just says that it's OKAY to end.
/end-free
Upvotes: 5
Reputation: 4532
JamesA and Buck have given good answers, for what might seem the simplest path, using what we would call native I/O, since it is native to the RPG language.
I would feel remiss if I did not also point you to what would generally be considered the recommended solution these days.
In general, we should be using embedded SQL for our data file I/O in RPG. This is true whether your files were created with DDS or SQL (DDL). SQL
You can look in the IBM i Information Center:
Upvotes: 1
Reputation: 41148
RPG supports direct (file) and SQL operations on the database.
Since you reference DDS I assume you are more interested in file based access.
There are a number of File Operations that can be used to access the database.
See the online documentation for more information.
Upvotes: 1