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


  • Subject: Re: RPG400 write a pc file to Folder
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Thu, 1 Mar 2001 11:53:37 -0600 (CST)

On Thu, 1 Mar 2001, Superdog superdog wrote:
>
> I am using RPG/400 not the ILE, can you kindly provide some sample codes 
> for me as reference ?
> Thank you.

I strongly discourage you from doing this.   doing this type of coding 
in RPG III is much like running a high-powered web server in Windows 3.1.
Or towing your friends car with your motorcycle.  

It may not be impossible, but its a bad idea.  Use RPG IV, its VASTLY more
powerful.

Having said that...   Here's how to get documentation on these APIs...
Start by going to:
http://publib.boulder.ibm.com/pubs/html/as400/v4r5/ic2924/info/rzaj5_frm.htm
Then click "APIs by Category".   and click "Hierarchical File System".

Here's your example:

      **  THIS IS AN EXAMPLE OF WRITING A "STREAM FILE"
      **  (PC-STYLE FILE) IN RPG III.
      **
      **  NOTE THAT I DO NOT RECOMMEND USING THIS METHOD.
      **  I DON'T LIKE THE HFS APIS OR TRYING TO DO STRING
      **  MANIPULATION IN RPG III.   I STRONGLY ADVISE YOU
      **  TO USE RPG IV WITH THE IFS API.
      **
      **  THE HFS API CAN ONLY WORK WITH /QDLS AND /QOPT
      **  TO USE /QDLS, YOU MUST BE ENROLLED IN THE
      **  DIRECTORY. THE DIRECTORY TO WRITE TO MUST
      **  EXIST, AND YOU MUST HAVE AUTHORITY TO WRITE TO IT.
      **
      **  SO:
      **        1) DO A WRKDIRE AND MAKE SURE YOU'RE LISTED
      **               IN THE DIRECTORY.  IF NOT, ADD YOURSELF
      **        2) DO A WRKFLR AND MAKE SURE A FOLDER CALLED
      **               'TEST' EXISTS.  IF NOT, CREATE ONE.
      **        3) FROM THE WRKFLR DISPLAY, DO A "14" TO WORK
      **                WITH AUTHORITY ON THE "TEST" FOLDER.
      **                MAKE SURE YOU CAN WRITE TO IT.
      **
     E                    TXT     1   5 60
     I              '/QDLS/TEST/TEST-     C         PATH
     I              '.TXT'
     I              'OPEN FAILED:'        C         ERROPN
     I              'WRITE FAILED:'       C         ERRWRT
     I              'CLOSE FAILED:'       C         ERRCLO
     I*
     I            DS
     I                                    B   1   40PTHLEN
     I                                    B   5   80ATRLEN
     I                                    B   9  120BUFLEN
     I                                    B  13  160WRTLEN
     IERROR       DS
     I                                    B   1   40BYTPRV
     I                                    B   5   80BYTAVL
     I                                        9  15 MSGID
     I                                       16  16 RESRV1
     I                                       17 256 MSGDTA
     IOPNINF      DS
     I                                        1   1 FILEXS
     I                                        2   2 CREATE
     I                                        3   3 SYNC
     I                                        4   4 RESRV2
     I                                        5   5 LOCK
     I                                        6   6 ACCESS
     I                                        7   7 OPNTYP
     I                                        8  10 RESRV3
     C*
     C                     EXSR OPEN
     C*
     C                     DO   5         X       10
     C                     MOVELTXT,X     STRING 80
     C                     EXSR WRLINE
     C                     ENDDO
     C*
     C                     EXSR CLOSE
     C*
     C                     MOVE *ON       *INLR
     C*
     C*----------------------------------------------------
     C*  THIS OPENS A STREAM FILE FOR WRITING TO
     C*----------------------------------------------------
     CSR         OPEN      BEGSR
     C*********************************************
     C*  SET THE OPEN FLAGS:
     C*********************************************
     C* IF THE FILE EXISTS, REPLACE IT:
     C                     MOVE '2'       FILEXS
     C* IF THE FILE DOESN'T EXIST, CREATE IT:
     C                     MOVE '1'       CREATE
     C* USE ASYNC WRITES:
     C                     MOVE '0'       SYNC
     C* DENY OTHER JOBS BOTH READ/WRITE ACCESS
     C*    WHILE WE HAVE THE FILE OPEN:
     C                     MOVE '4'       LOCK
     C* WE WILL ONLY BE WRITING TO THE FILE:
     C                     MOVE '1'       ACCESS
     C* DO A NORMAL OPEN
     C                     MOVE '0'       OPNTYP
     C*********************************************
     C* SET PATHNAME, AND SET LENGTH VARIABLES
     C*********************************************
     C                     MOVELPATH      PTHNAM    P
     C           ' '       CHEKRPTHNAM    PTHLEN
     C                     Z-ADD0         ATRLEN
     C                     Z-ADD256       BYTPRV
     C                     Z-ADD0         BYTAVL
     C*********************************************
     C*  OPEN THE FILE
     C*********************************************
     C                     CALL 'QHFOPNSF'             99
     C                     PARM           HANDLE 16
     C                     PARM           PTHNAM 64
     C                     PARM           PTHLEN
     C                     PARM           OPNINF
     C                     PARM           ATTRIB  1
     C                     PARM           ATRLEN
     C                     PARM           ACTION  1
     C                     PARM           ERROR
     C*********************************************
     C* CHECK FOR ERRORS
     C*********************************************
     C           *IN99     IFEQ *ON
     C           ERROPN    CAT  '*IN99':1 MSG    52
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     C           BYTAVL    IFGT 0
     C           ERROPN    CAT  MSGID:1   MSG
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     CSR                   ENDSR
     C*
     C*----------------------------------------------------
     C*  THIS TAKES A STRING, STRIPS OFF TRAILING BLANKS
     C*  ADDS A CR/LF PAIR, CONVERTS IT TO ASCII AND
     C*  WRITES IT TO A STREAM FILE:
     C*----------------------------------------------------
     CSR         WRLINE    BEGSR
     C*********************************************
     C*  ADD CR/LF AND GET STRING LENGTH
     C*********************************************
     C                     CAT  X'0D25':0 STRING
     C           ' '       CHEKRSTRING    STRLEN  50
     C*********************************************
     C* TRANSLATE TO ASCII
     C*********************************************
     C                     CALL 'QDCXLATE'
     C                     PARM           STRLEN
     C                     PARM           STRING
     C                     PARM 'QASCII'  TABLE  10
     C*********************************************
     C*  WRITE TO STREAM FILE
     C*********************************************
     C                     CALL 'QHFWRTSF'               99
     C                     PARM           HANDLE
     C                     PARM           STRING
     C                     PARM STRLEN    BUFLEN
     C                     PARM           WRTLEN
     C                     PARM           ERROR
     C*********************************************
     C* CHECK FOR ERRORS
     C*********************************************
     C           *IN99     IFEQ *ON
     C           ERRWRT    CAT  '*IN99':1 MSG    52
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     C           BYTAVL    IFGT 0
     C           ERRWRT    CAT  MSGID:1   MSG
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     CSR                   ENDSR
     C*----------------------------------------------------
     C*  THIS CLOSES AN OPEN STREAM FILE
     C*----------------------------------------------------
     CSR         CLOSE     BEGSR
     C*********************************************
     C* CLOSE THE FILE
     C*********************************************
     C                     CALL 'QHFCLOSF'             99
     C                     PARM           HANDLE
     C                     PARM           ERROR
     C*********************************************
     C* CHECK FOR ERRORS
     C*********************************************
     C           *IN99     IFEQ *ON
     C           ERRCLO    CAT  '*IN99':1 MSG    52
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     C           BYTAVL    IFGT 0
     C           ERRCLO    CAT  MSGID:1   MSG
     C                     DSPLY          MSG
     C                     MOVE *ON       *INLR
     C                     RETRN
     C                     ENDIF
     C*
     CSR                   ENDSR
**
Why the heck am I writing this text file in RPG III?
RPG III is awkward -- nearly impossible to do any serious
coding in.   I should really stop messing with this
horrible, archaic language and switch to RPG IV.
Bye.

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

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.