If you do a DSPSRVPGM on the QC2IFS service program you can see that the
procedures you are using are still exported from the service program
except I don't see ferror by itself - just _C_IFS_ferror

I could not find any documentation for invoking them using the exported
name (_C_IFS_xxxx). I only found a C header file in what is labeled as a
PTF file in QSYSINC which maps the _C_IFS_xxxx type functions to the
ones we use in C like fgets( ) (which is mapped to _C_IFS_fgets) stored
in QSYSINC/QPZ1C204(IFS) - I would ask IBM for the latest C runtime PTFs
in case this has anything to do with it. 

But also it looks like you can maybe use the direct C function names in
RPG (rather than the longer procedure name you are using) according to
this IBM link:
nfo/apis/Unixapiex.htm which has examples of using some of these in RPG
as well as C and COBOL. Not sure if it covers all the ones that you are
using however. I also noticed this online tutorial

However, in this IBM Redbook it seems to indicate that the _C_IFS prefix
is required when using these C functions in RPG.
http://www.redbooks.ibm.com/redbooks/pdfs/sg245402.pdf (Chapter 5.7).
Dunno - guess I would try the most recent published advice first. I
didn't try any of this myself to verify it - it would mean I'd have to
write a program in RPG from scratch (*shudder*).

Your current error could actually be due to a difference in the way
variables are spaced when the program object is turned into machine code
in the new version of the operating system. In the past if you 'got
away' with declarations in RPG that were not quite the same as what the
C expected but were 'close' it is possible that in the new OS the
runtime of either the C or RPG is changing the layout of the variables
in runtime memory when the program initializes in the job, so that now
you are stepping on the memory of another variable when you make one of
your calls (causing some pointer to an entry parameter for example to be
overwritten) - whereas before you were potentially just getting lucky by
being allocated some 'buffer space' in between these variables which was
not explicitly declared in the way the program was written. 

Hope this is of some help (I am by no means an expert in RPG (or C for
that matter)!!!)

Genyphyr Novak


message: 3
date: Wed, 6 Jul 2005 10:08:25 -0400
from: "Chris Wolcott" <cwolcott@xxxxxxxxxxxxxxxxxxxxxx>
subject: [C400-L] MCH3601 error

I have the following RPG copybook that prototypes C library functions:


 * RPG Procedures definitions for accessing IFS files via C functions.

 * Based on article on iSeriesNetwork.com by Jef Sutherland

 * If you create an IFS file, specify 'w codepage=1252' on the open,
 * close it and reopen with 'a codepage=37'.  This will cause the
 * function to translate the data from EBCDIC to ASCII and back for
 * Open Modes and their meanings:

 * 'r'  Open existing file for reading - Fails if not found

 * 'w'  Creates empty file for writting - Clears existing file

 * 'a'  Open existing file for appending - Creates file if not found

 * 'r+' Open existing file for reading/writing - Fails if not found

 * 'w+' Creates empty file for reading/writting - Clears existing file

 * 'a+' Open existing file for reading/appending - Creates file if not
* @version V0R0M0

 * @see
 * @see

D/IF              NOT DEFINED(UTL_IFS)



DifsOpn           PR              *   EXTPROC( '_C_IFS_fopen' )
Open IFS file    
D                                 *   VALUE OPTIONS( *String )
<full filename   
D                                 *   VALUE OPTIONS( *String )

DifsClo           PR            10I 0 EXTPROC( '_C_IFS_fclose' )
Close IFS file   
D                                 *   VALUE
<file pointer    

DifsDlt           PR            10I 0 EXTPROC( '_C_IFS_remove' )
Delete IFS file  
D                                 *   VALUE OPTIONS( *String )
<full filename   

DifsRd            PR              *   EXTPROC( '_C_IFS_fgets' )
Read IFS file    
D                                 *   VALUE
<record pointer  
D                               10I 0 VALUE
<size to read    
D                                 *   VALUE
<file pointer    

DifsWrt           PR            10I 0 EXTPROC( '_C_IFS_fputs' )
Write IFS file   
D                                 *   VALUE OPTIONS( *String )
<data to write   
D                                 *   VALUE
<file pointer      >

DifsFileErr       PR            10I 0 EXTPROC( 'ferror')
Chk File Errors     
D                                 *   VALUE
<file pointer      >

DifsSts           PR            10I 0 EXTPROC( 'lstat' )
Get File Status     
D                                 *   VALUE  OPTIONS( *String )
<STS struc pointer >
D                                 *   VALUE
<file pointer      >

DifsEOF           PR            10I 0 EXTPROC( '_C_IFS_feof' )
End of File Test    
D                                 *   VALUE
<file pointer      >

D p_ifsSts        S               *   Inz( %Addr( ifsSts_t ))

D ifsSts_t        DS                  Align
IFS Status Structure
D  st_mode                      10U 0

D  st_ino                       10U 0

D  st_nlink                      5U 0

D                                2A

D  st_uid                       10U 0

D  st_gid                       10U 0

D  st_size                      10I 0 
D  st_atime                     10I 0 
D  st_mtime                     10I 0 
D  st_ctime                     10I 0 
D  st_dev                       10U 0 
D  st_blksize                   10U 0 
D  st_allocsize                 10U 0 
D  st_objtype                   11A   
D                                1A   
D  st_codepage                   5U 0 
D  st_reserv1                   62A   
D  st_ino_gen_id                10U 0 

All was well until V5R3 (V4R5 to V5R2), now we get this during the call
to ferror() after doing an fgets():

>From program . . . . . . . . . :   QC2IFS     
  From library . . . . . . . . :     QSYS     
  From module  . . . . . . . . :     QC2IP124 
  From procedure . . . . . . . :     fp124    
  From statement . . . . . . . :     38       
To program . . . . . . . . . . :   QC2IFS     
  To library . . . . . . . . . :     QSYS     
  To module  . . . . . . . . . :     QC2IP124 
  To procedure . . . . . . . . :     fp124    
  To statement . . . . . . . . :     38       

    Pointer not set for location referenced.

    Function check. MCH3601 unmonitored by QC2IFS at statement
      instruction X'0000'.

    Application error.  *N unmonitored by *N at statement *N,

    Function check. CEE9901 unmonitored by QUIMNDRV at statement *N,

      instruction X'0CDE'.

    Exception handler not available because of reason code 5.

    Function check. CPF2524 unmonitored by QUIMNDRV at statement *N,

      instruction X'0CDE'.

Any ideas?  Are these functions no longer supported?  I called IBM
support and he could not find ANY references to these functions at all.
Is there a better way to access the IFS from RPG?  


This is the C programming iSeries / AS400 (C400-L) digest list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

End of C400-L Digest, Vol 3, Issue 50

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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

This mailing list archive is Copyright 1997-2021 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.