× 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 Michael,

I've read that you've already solved your problem. Since it sounds like you're very new to this type of stuff, I'm going to go over your code with a fine-toothed comb and tell you what I see:


I found in the archives that someone else needed to trim the FileName for
the openFile() routine that they were using, I'm wondering though, do I
need to have a trim about my FileNam on the FileNamP = %ADDR(FileNam) line?

Say this with me 3 times:

Never ever ever use %ADDR() or a pointer when you've coded OPTIONS(*STRING) on the prototype. Never ever ever use %ADDR() or a pointer when you've coded OPTIONS(*STRING) on the prototype. Never ever ever use %ADDR() or a pointer when you've coded OPTIONS(*STRING) on the prototype.

And yes, you do have to trim the spaces from the filename (if there are any spaces, that is.)

   // This is new to me, but I believe that I'm telling
   // this field to point to the address of FileNam
   FileNamP = %ADDR(FileNam);

Yes, that's what you're doing.  But you shouldn't be doing that!!

   // setup the OFlag to indicate that we want
   // this file to be write only and to truncate
   // left over data when the file already exists.
   // Again, I don't know how this works, but
   // O_WRONLY = write only, O_TRUNC = truncate.
   Oflag = O_WRONLY + O_TRUNC + O_TEXTDATA;

O_TRUNC means "clear the file before opening it". It's the IFS equivelent of the CLRPFM command.

A bigger problem is the way you're dealing with text data. You've specified O_TEXTDATA which means "my data is text". But, I usually think of it as meaning "I'd like you to translate my data from one character set to another", because that's what it enables.

The problem, however, is that you've told it that your program's data is in code page 819 (which is a variant of ASCII). That's a rather strange approach, since most RPG programs have EBCDIC data, not ASCII data!

All I can conclude is that you were very confused, and trying things at random.

   // Open the file name requested.
   If open(FileNamP:Oflag:Omode:cp) = -1;
      perror(FileNamP);
      *In99 = *On;
      LeaveSR;
   EndIf;

It seems very strange to me that you'd use perror() from ILE C here. Do you like your error messages to go to stderr? That's not the way iSeries programmers typically do things!

Again, I want to remind you that you should NOT be using a pointer or %addr() when you have options(*string) specified. Your code SHOULD look like this:

    If open(%trimr(FileNam):Oflag:Omode:cp) = -1;
       errMsg = %str(strerror(errno));
       // display errMsg to user, or write to log, or whatever...
       *In99 = *On;
       LeaveSR;
    EndIf;

I see three important concepts that you should read about, and understand, before continuing:

a) How options(*string) works.  How to use it properly.

b) How to enable translation of text data in IFS files. (and, related... why you should be using a CCSID instead of a code page. If you're running V5R2 or later, you should also learn about O_TEXT_CREAT.)

c) How error message handling works with unix-type APIs.


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.