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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Fields by Name

Status
Not open for further replies.

jsplice

Programmer
Jun 3, 2003
88
US
Hello everyone. I'm using a For loop and am trying to reference 8 fields in a neat manner. The fields are:

LCDT01
LCDT02
...
LCDT08

Here is part of the loop:

C For i = 1 to 8
C Move i @LCDField
C MoveL 'LCDT0 ' @LCDField



@LCDField is a 6 character field that is holding the file field name. I want to be able to reference each field inside the loop by using @LCDField so that I don't have to manually check each field. However, I'm not sure if this is possible. Can anyone help with this?


 
No, you can't do it that way. RPG does not allow it.

Unless you are writing somrthing that will process any file, I don't understand why you need to do that.

If these fields are all the same length and type, you can declare an array and rename them in the I-specs, and refer to them as the elements of that array.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
The fields are actually coming from a data structure that is being passed in as a parm to this procedure. The data structure is externally described on the file, so I can access these fields by their name. Essentially the data structure is holding an entire record that is being passed in. Yes, I know it seems a bit ridiculous to do it this way, but I'm simply following the specs. Thanks for the answer though.
 
I think that SQL PREPARE stm could do the trick. Depends on what you want to do next.
 
I was told by someone that it may be possible to "dynamically determine" the buffer positions and lengths of all the fields in a file and the use those positions to reference the fields. I'm running into the same problem again. I have a procedure that is passed a field name which is the field to be compared between two files or data structures. Is there absolutely no way to do this in RPG-only code?
 
Yes, actually it's possible to determine lengths and fields names aso in a file using SQL DESCRIBE and SQLDA (SQL Descriptor Area); however this is not for faint-hearted programmers.

Check out sql Describe and SQLDA in the manual "DB2 Universal Database for iSeries SQL Reference" at
and the examples in the manual "DB2 Universal Database for iSeries SQL Programming with Host Languages" at
These manuals are a true treasury for programmers :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top