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



Thanks to everyone for kindly offering examples. They are definitely helping
me understand how to use the APIs in ILE COBOL. 

Kelly

-----Original Message-----
From: cobol400-l-bounces@xxxxxxxxxxxx
[mailto:cobol400-l-bounces@xxxxxxxxxxxx]On Behalf Of Roy Restuccia
Sent: Monday, March 08, 2004 8:43 AM
To: 'COBOL Programming on the iSeries/AS400'
Subject: R: [COBOL400-L] IFS APIs for ILE COBOL


Kelly, I wrote pgms that read/write IFS files calling the corresponding
Function in the ILE C Runtime Library. The first pgm read a file the second
Write a file. I hope you find this helpful.
Best regards.

Roy.

----------------------------------------------------------------------------
       PROCESS NOMONOPRC NOSTDTRUNC APOST.
       IDENTIFICATION DIVISION.
      *----------------------------------------------------------------
      * Compilation instruction:
      * CRTCBLMOD MODULE(yourlib/UNIXAPI)
      *           SRCFILE(QCBLSRC)
      *           DBGVIEW(*SOURCE)
      * CRTPGM PGM(yourlib/UNIXAPI)
      *        MODULE(yourlib/UNIXAPI)
      *        BNDSRVPGM(QSYS/QC2IFS QSYS/QC2UTIL1)
       PROGRAM-ID. UNIXAPI.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  ERRNO-PTR POINTER VALUE NULL.
       77  RC PIC S9(9) BINARY.
       77  FILE-NAME PIC X(50).
       77  FILE-MODE PIC X(10).
       77  FILE-PTR POINTER VALUE NULL.
       77  ERRNO-EDT PIC 9(9)-.
       01  BUFFER PIC X(1024).
       LINKAGE SECTION.
       77  ERRNO PIC S9(9) BINARY.
       PROCEDURE DIVISION.
       THE-FIRST SECTION.
       FIRST-PARA.
           STRING '/myfile.txt'
                  X'00' DELIMITED BY SIZE INTO FILE-NAME.
           STRING 'r' X'00'
                  DELIMITED BY SIZE INTO FILE-MODE.
           CALL PROCEDURE '_C_IFS_fopen'
                USING FILE-NAME FILE-MODE
                RETURNING FILE-PTR.
           IF FILE-PTR = NULL
              CALL PROCEDURE '__errno'
                   RETURNING ERRNO-PTR
              SET ADDRESS OF ERRNO TO ERRNO-PTR
              MOVE ERRNO TO ERRNO-EDT
              DISPLAY 'File open failed. Errno: ' ERRNO-EDT
              GO END-PGM.

           PERFORM READ-IFS UNTIL RC NOT = ZERO.

           CALL PROCEDURE '_C_IFS_fclose'
                USING BY VALUE FILE-PTR
                RETURNING RC.
       END-PGM.  GOBACK.
      *
       READ-IFS.
           MOVE SPACES TO BUFFER
           CALL PROCEDURE '_C_IFS_fgets'
                USING BY VALUE ADDRESS OF BUFFER
                      BY VALUE LENGTH  OF BUFFER
                      BY VALUE FILE-PTR
                RETURNING RC.
           IF RC = ZERO
              UNSTRING BUFFER DELIMITED BY X'25' INTO BUFFER
              DISPLAY 'Data read from file: ' BUFFER.
----------------------------------------------------------------------------

----------------------------------------------------------------------------
       PROCESS NOMONOPRC NOSTDTRUNC APOST.
       IDENTIFICATION DIVISION.
      *----------------------------------------------------------------
      * Compilation instruction:
      * CRTCBLMOD MODULE(yourlib/UNIXAPI1)
      *           SRCFILE(QCBLSRC)
      *           DBGVIEW(*SOURCE)
      * CRTPGM PGM(yourlib/UNIXAPI1)
      *        MODULE(yourlib/UNIXAPI1)
      *        BNDSRVPGM(QSYS/QC2IFS QSYS/QC2UTIL1)
       PROGRAM-ID. UNIXAPI1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  ERRNO-PTR POINTER VALUE NULL.
       77  ERRMSG-PTR POINTER VALUE NULL.
       77  RC PIC S9(9) BINARY.
       77  FILE-NAME PIC X(50).
       77  FILE-MODE PIC X(10).
       77  FILE-PTR POINTER VALUE NULL.
       77  ERRNO-EDT PIC 9(9)-.
       01  BUFFER PIC X(1024).
       01  BUFFER-LENGTH PIC S9(9) BINARY.
       01  ITEM-COUNT    PIC S9(9) BINARY.
       LINKAGE SECTION.
       77  ERRNO PIC S9(9) BINARY.
       77  ERRMSG PIC X(1024).
       PROCEDURE DIVISION.
       THE-FIRST SECTION.
       FIRST-PARA.
           STRING '/myfile.txt'
                  X'00' DELIMITED BY SIZE INTO FILE-NAME.
           STRING 'w+' X'00'
                  DELIMITED BY SIZE INTO FILE-MODE.
           CALL PROCEDURE '_C_IFS_fopen'
                USING FILE-NAME FILE-MODE
                RETURNING FILE-PTR.
           IF FILE-PTR = NULL
              CALL PROCEDURE '__errno'
                   RETURNING ERRNO-PTR
              SET ADDRESS OF ERRNO TO ERRNO-PTR
              MOVE ERRNO TO ERRNO-EDT
              DISPLAY 'File open failed. Errno: ' ERRNO-EDT
              CALL PROCEDURE 'strerror' USING
                   BY VALUE ERRNO
                   RETURNING ERRMSG-PTR
              SET ADDRESS OF ERRMSG TO ERRMSG-PTR
              MOVE SPACES TO BUFFER MOVE ZERO TO BUFFER-LENGTH
              UNSTRING ERRMSG DELIMITED BY X'00' INTO BUFFER
                 COUNT BUFFER-LENGTH
              DISPLAY 'Sysmsg: ' BUFFER(1:BUFFER-LENGTH)
              GO END-PGM.

           PERFORM WRITE-IFS.

           CALL PROCEDURE '_C_IFS_fclose'
                USING BY VALUE FILE-PTR
                RETURNING RC.
       END-PGM.  GOBACK.
      *
       WRITE-IFS.
           MOVE SPACES TO BUFFER
           STRING 'Line Written by UNIXAPI1' X'25'
                   DELIMITED BY SIZE INTO BUFFER
           MOVE 1 TO BUFFER-LENGTH
           INSPECT BUFFER TALLYING BUFFER-LENGTH FOR CHARACTERS
               BEFORE INITIAL X'25'
           MOVE 1  TO ITEM-COUNT
           CALL PROCEDURE '_C_IFS_fwrite'
                USING BY VALUE ADDRESS OF BUFFER
                      BY VALUE BUFFER-LENGTH
                      BY VALUE ITEM-COUNT
                      BY VALUE FILE-PTR
                RETURNING RC.
           IF RC NOT = ITEM-COUNT
              CALL PROCEDURE '__errno'
                   RETURNING ERRNO-PTR
              SET ADDRESS OF ERRNO TO ERRNO-PTR
              MOVE ERRNO TO ERRNO-EDT
              DISPLAY 'File write failed. Errno: ' ERRNO-EDT
              GO END-PGM.
----------------------------------------------------------------------------


-----Messaggio originale-----
Da: cobol400-l-bounces@xxxxxxxxxxxx [mailto:cobol400-l-bounces@xxxxxxxxxxxx]
Per conto di Kelly Cookson
Inviato: lunedì 8 marzo 2004 2.03
A: 'cobol400-l@xxxxxxxxxxxx'
Oggetto: [COBOL400-L] IFS APIs for ILE COBOL

Does anyone know where I can find a good tutorial/white paper/article on
using the IFS APIs in ILE COBOL? I have checked the ILE COBOL programming
guide and the ILE COBOL reference manual, but found virtually nothing. I
have checked the Information Center, which talks quite a bit about the IFS
APIs, but which has no COBOL examples or even explanations for use in COBOL.

The ILE COBOL pogramming guide says it is possible to call IFS APIs using
CALL LINKAGE TYPE statements in the SPECIAL NAMES section of the ENVRONMENT
division. But then it doesn't exlain how to use the APIs in the PROCEDURE
division. Could anyone explain this to me?

What I would really like to see is an IFS Redbook, covering concepts of the
IFS, management of the IFS using Operations Navigator and Netserver, and
programming with the IFS APIs in each ILE languages. Maybe I will fire off a
recommendation to IBM...

Thanks in advance for any help.
Kelly

_______________________________________________
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing list
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/cobol400-l
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/cobol400-l.





_______________________________________________
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing list
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/cobol400-l
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/cobol400-l.


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