× 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.



Unfortunetly...

After I have red some answers I tried with two different prototypes of 
OPEN:

1. 

D openFile        PR            10I 0 ExtProc('open')
D  path@                          *   Value
D  oflag                        10I 0 Value
D  mode                         10I 0 Value OPTIONS(*nopass)
D  codepage                     10I 0 Value OPTIONS(*nopass)

D path@        S        *
D XMLFile      S     100A

C     *entry        plist
C                   parm                    XMLfile

and code which opens file:

path@=%ALLOC(100);
%Str(path@:%Len(%trim(XMLfile))+1)=%trim(XMLfile);
fileDesc=openFile(path@:oflag);



2. (this is from RPG sourcers guide... pg.255) OPTIONS(*string) should 
handle x'00'

D openFile        PR            10I 0 ExtProc('open')
D  path@                          *   Value OPTIONS(*string)
D  oflag                        10I 0 Value
D  mode                         10I 0 Value OPTIONS(*nopass)
D  codepage                     10I 0 Value OPTIONS(*nopass)

D path         S     100A
D XMLFile      S     100A

C     *entry        plist
C                   parm                    XMLfile

and code which opens file:

path=%Trim(XMLfile);
fileDesc=openFile(%Trim(path):oflag);


And both attempts have fileDesc=-1 after open.

What I realy don't understand WHY example 1. works if I define path in 
source:

%Str(path@:100)='/CrnaLista/Z250304122700001.XML';
fileDesc=openFile(path@:oflag); 

and WHY example 2. works if I define path in source:

path='/CrnaLista/Z250304072600001.XML';
fileDesc=openFile(%trimr(path):oflag);

PS. I'll try with __errno() or strerror()to find more. And I'm on V5R2...
The worst thing is that I succeeded to implement some kind of light SAX 
parser in RPG and all that is spoiled with this open problem...
But still, I can recompile program everytime I need new file:)) 

Thanks on replys!
Igor Bešlić, dipl. ing. rač. 
VOLKSBANK d.d.
OJ Informatika
Zelinska 2, 10000 Zagreb
tel: +385 1 6326422



Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> 
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
28.12.2004 09:41
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: Can't Open IFS file problem







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!
-- 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.