×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Hi Igor,
I'm useing prototyped C function 'open' (in qC2LE dir) to open a xml file.
The open() API does not require BNDDIR(QC2LE). It's a regular system API
that's always available without any special binding options. (However,
the __errno() function that you use to get error information DOES require
QC2LE.)
You state that the following is working:
path='/CrnaLista/Z250304072600001.XML';
fileDesc=openFile(%trimr(path):oflag);
And that the following code is failing to work:
path=%trim(XMLFile);
fileDesc=openFile(path:oflag);
Is 'path' defined with the VARYING keyword? If not, then your %trim()
statement won't work. The way your code is written, the blanks get added
back to the end of the 'path' variable immediately after you %trim() them
off, and before the API is called. The API will think that those blanks
are supposed to be part of the filename!
You see, a fixed length (non-varying) RPG field must always have a certain
number of characters in it. If you define it as, for example, 100A, then
it will ALWAYS (without exception) have 100 characters. If you assign
fewer than 100 characters to it, it'll fill the rest of the field with
blanks.
So, in the above example, assuming that 'path' is 100A if you execute the
following code, what will you have?
path = '/CrnaLista/Z250304072600001.XML';
You will have 31 characters of pathname followed by 69 blanks. When you
execute the following code what happens?
path = %trim(path);
What will happen is that the %trim() BIF will search for the first
non-blank character in 'path', then search for the last non-blank
character in 'path'. It will copy all of the characters in between to the
start of the path variable. Then, because that result is less than 100
characters long, it'll fill the rest with blanks.
So, you'd have made the computer do a lot of work to remove the blanks,
just to add them back again as soon as the result gets assigned to the
'path' variable.
In the end, you'll have the same result that you started with.
There are two solutions to the problem. First, you could define 'path' as
a VARYING field. A VARYING field will not automatically add blanks to the
end of the field, but will keep them off.
The other solution would be to perform the %trim() directly on the
openFile() call, just as you did in your first example. When you do that,
the data gets passed to the API without the blanks, since they never get
added back -- adding them back is only done when it's assigned to a fixed
length field, and since the first parameter to the open() API is not
fixed-length, the blanks won't be included.
to summarize... change the following code:
path=%trim(XMLFile);
fileDesc=openFile(path:oflag);
To read as follows:
fileDesc = openFile(%trimr(path):oflag);
openFile returns -1.
Is there anything more to do before open file??
Other than trimming the pathname properly, no, there's nothing else you
need to do before opening the file.
However, after the openFile() call fails, you SHOULD be checking
__errno() (and maybe also strerror()!) to determine what went wrong. The
return code of -1 means "it failed". The error number will tell you WHY
it failed, which is often very valuable information.
Good Luck!
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.