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




           alloc     256           pfname
           eval      docID=  %trim(FlrPth) + %trim(DocNam)
           eval      flrlen= %checkr(' ':docid)+1
           eval      %str(pfname:flrlen)= docid

Probably ugly, but it worked.

Not just ugly, but VERY DANGEROUS. The way you have this coded, docID could be as long as 297 bytes. However, you've hardcoded the allocation length as 256. Why on earth would you do that?! If the two parameters put together should exceed 256 bytes, you'll overwrite memory that doesn't belong to you, with potentially nasty consequences.

If you absolutely MUST allocate the length this way (though I don't see why you'd have to) you should do this:

            eval      docID=  %trim(FlrPth) + %trim(DocNam)
            eval      flrlen= %checkr(' ':docid)+1
            alloc     flrlen        pfname
            eval      %str(pfname:flrlen)= docid

This way, the length of memory that you allocate isn't hard-coded to 256, but instead, matches the size of the data that you're storing into it. Hard-coding the 256 is a very bad idea.

However, there's absolutely no need for this extra complexity, just do it the way I explained in my previous e-mail, it's simpler, far more elegant, and far less dangerous.


So everything is working except for the CCSID.

When I look at the file created in the IFS, it has the CCSID value of
819 and it looks fine when opened via WRKLNK. However when I open it via
Windows Explorer it looks like and EBCDIIC file (gobbledy-gook all over
the place).

The previous example you posted didn't use CCSIDs or the i5/OS capability to do translation for you. If you want automatic translation, you have to specify it on the open() statement.

Prior to V5R2, you need to first create the file with the correct CCSID or codepage. Then close & re-open it in text mode. Text mode means "translate the data from the file's CCSID/codepage to my job's CCSID". The translation doesn't work when a file doesn't exist, because the file doesn't have a CCSID/codepage yet if it doesn't exist. That's why you have to create it first.

On V4R5 or earlier, IFS doesn't support CCSIDs so you need to use a codepage. Here's a V4R5 example of opening a file with translation

 ** Create a new, empty file tagged with codepage 819:
C                   callp     unlink(%trimr(Docid))

C                   eval      fildes = open( %trimr(Docid)
C                                          : O_CREAT+O_WRONLY+O_CODEPAGE
C                                          : RW*OWNER + RW*GROUP + RW
C                                          : 819 )
c                   callp     close(fildes)

 ** Open the file in text mode so that it's auto-translated
c                   eval      fildes = open( %trimr(Docid)
C                                          : O_WRONLY + O_TEXTDATA )




In V5R1, the IFS supports CCSIDs, so instead of using O_CODEPAGE, you use O_CCSID. It's otherwise the same:

C                   eval      fildes = open( %trimr(Docid)
C                                          : O_CREAT+O_WRONLY+O_CCSID
C                                          : RW*OWNER + RW*GROUP + RW
C                                          : 819 )
c                   callp     close(fildes)

 ** Open the file in text mode so that it's auto-translated
c                   eval      fildes = open( %trimr(Docid)
C                                          : O_WRONLY + O_TEXTDATA )



Starting in V5R2, they added a new capability called O_TEXT_CREAT that lets you create the file and start translating in one go. They also added a ne parameter for the "local" CCSID (as opposed to the file's CCSID), which supports a special value of 0 to mean "the current job's CCSID". so, in V5R2 (and later), you can do this:

c                   eval      fildes = open( %trimr(DocId)
c                                          : O_CREAT+O_TRUNC+O_WRONLY
c                                            +O_TEXTDATA+O_CCSID
c                                            +O_TEXT_CREAT
c                                          : RW*OWNER + RW*GROUP + RW
c                                          : 819
c                                          : 0 )



GOOGLING doesn't seem to provide any references other than one which
said that he opened, then closed then re-opened the file.

Any hints?

I've provided some hints above. For older (V4R5) info on how to do this, you'll find some info here:

http://www.scottklement.com/rpg/ifs_ebook/textmode.html

For info on the newer releases, plus a bit more detailed explanations, read the article entitled "RPG and the IFS: A Text File Primer" from the December 2004 issue of iSeries NEWS magazine (ProVIP edition). If you're a ProVIP subscriber, you can read it on-line at the following link:
http://www.iseriesnetwork.com/article.cfm?id=19473



As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.