File and Fields in RPG400

85 pts.
Tags:
AS400 RPGLE
RPG/400
RPG/400 field validation
I have a file that contains the file and its' respective field.

In my RPG, I want to read the file as retreive from the database. And use the fields from the file for testing.

For example: F Specs FILEAAA

My database contains:

Filename : FILEAAAA

Field Name : FIELD1

Value = 30

In RPG, I want to

Read FILEAAA

If FIELD1 = 20

  select record

endif

 

However, I don't want to hardcode FILEAAA and FIELD1 in RPG. I want this as retreived from database. Is this possible?

Answer Wiki

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

well, if your database file of files contains the field’s attributes like starting locations, lengths, decimal positions, and the data types of the field, you could define a long flat file as usropn, and by using the extfile keyword open the specified file, read it in as a long character field, and use %subst, %dec, etc. as needed to make the comparisons based on the the field’s attributes

Discuss This Question: 6  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
  • JoBi
    Hi, Thanks for your reply. But can you please give me an example on how this is to be coded? Thanks in advance.
    85 pointsBadges:
    report
  • TomLiotta
    The coding will be different for different data types. A packed-decimal field will need different handling than a character field. A timestamp field will be very different from a zoned-decimal field. An integer (signed? unsigned) will be different from a 'B'inary field. This is not going to be trivial. Eventually you'll run into fields that can't be reasonably expressed (nor even accessed) by RPG I/O. Now, it's not likely that some of the SQL data types will ever be handled by this program, but the files might. Overall, this seems far better suited for dynamic SQL than for RPG I/O. It might even be a good use for SQL CLI. Tom
    125,585 pointsBadges:
    report
  • Sloopy
    If you don't want to hardcode FIELD1, then you can't write "IF FIELD1 = 20" in your code. So how do you expect to write an "IF" statement? I can help by providing a program which will use the file/field information to return the individual values in the correct formats - packed, timestamp, character and so on. All you would have to do is provide the data type and the substringed data. But as has been said, it is not trivial, and will require a lot of work. SQL is certainly the best way to go - but I've written that sort of thing, and it is not straighforward. If you need help to understand substringing data out of a flat record, then you certainly don't have enough knowledge to be able to do the work required.
    2,195 pointsBadges:
    report
  • Dickdono
    Is your FIELD 1 is always the same data type and size? For example, if you have 4 different files and the first field is always a 3 digit number, you could create an SQL statement on the fly and fetch the first field. It could look something like this (disclaimer: this is code made up on the fly and not tested and you'd definitely want to check SQLCOD after your "exec sql"s). D MyField 3S 0 inz(0) /free file = 'FILEA'; field = 'FLDA'; SqlStmt = 'SELECT ' + field + ' FROM '+ file; exec sql declare cursor c1 from :SqlStmt; exec sql open c1; exec sql fetch c1 into :MyField; if MyField = 20; blah blah endif Now having said this, if you worked with me, I might just want to hurt you. ;-) No cross-referencing tool is going to know that your program references that file. You could be creating a maintenance nightmare... Remember, just because you can do something, doesn't mean it is always a good idea. Hope this helps. Good luck!
    35 pointsBadges:
    report
  • TomLiotta
    just because you can do something, doesn’t mean it is always a good idea. Very true. The original is not very uncommon on some other platforms, but it doesn't quite fit in with a relational database paradigm. I wouldn't want to tackle the task in SQL Server, for example. I'd only consider it on the AS/400 line because of the tight relationship between 'native' I/O and higher-level DB2 (SQL) I/O. Tom
    125,585 pointsBadges:
    report
  • JoBi
    Thanks so much Guys!!! I will keep in mind all suggestions pointed......:)
    85 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