Reading a File of unknown name, format, etc.

pts.
Tags:
DB2 Universal Database
RPGLE
I need advice on reading a data file in RPG where I will only know the file name, the file format, etc. at run time. I would like to use an API or something to read the file into a buffer; I could then use the QUSLFLD API to get field definitions and parse the fields as required. I am not interested in copying the file to get into a known format as this is too time consuming. There must be a way to read directly. Anyone have any advice?

Answer Wiki

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

Try this :
- declare your file as no-dds (program described) with only one field large enough for the largest record
- before running programm, OVRDBF compil-time file to real file
- read the record one by one
- when you know the format, move the record field to some DS

It’s an old technique. Be carefull, V5R4 seem to be the latest version witch supports program-described files.

==========================================================

I’m not sure why “Be careful” and “V5R4 seem to be the latest version witch supports program-described files” are put together. Why be careful? It’s no different in V5R4 than in previous releases. It’s the same in V6R1. It looks like it’ll be the same in V7R1 and the foreseeable future.

Tom

Discuss This Question: 2  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
  • DaddyCOZ
    I found my answer and it works very well. I am using the C Language Runtime procedures from RPG including the Ropen, Rreadf, Rreadn, Rclose procedures to read the data files. I am using List API's for getting the record layout of the file. I also ended up using the C Language Runtime to convert packed decimal and zoned decimal data which was embedded in the record. All of this was then tied to the POI procedures from jakarta.apache.org for creating Excel spreadsheets in the IFS. So, given a library, a file name, and a target IFS file name to be created, I create the Excel spreadsheet using nice formatting and nice headings as available in Excel. This circumvents the problems with CPYTOIMPF where the speadsheet looks like S**T and dates do not sort properly. And, I know nothing about C Language and almost nothing about Java. Thank God for RPG! Thanks to everyone for the assistance.
    0 pointsBadges:
    report
  • Detuli
    Can you please share a little how u have used the C language runtime or some tutorial... actually i am also working on same problem. I am trying to make a DBU kind of utility where i dont know file, library, member, format till runtime. Please share any tutorial or code sample... Thnaks in advance
    15 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