Use these hierarchical file system examples to help you program your optical file system.
This topic demonstrates how the HFS API can be used with the ILE RPG programming language.
For more information about APIs, see Application device programming (APIs).
E AR 1 5 36 C *ENTRY PLIST * 2 PARAMETERS - A DATA BUFFER ID AND AN INDEX TO THE ARRAY C PARM DATAIN 256 C PARM IDX 10 * MOVE THE ARRAY ELEMENT TO A FIELD CALLED "PATH" C MOVE AR,IDX PATH * EXECUTE SUBROUTINES TO OPEN, WRITE AND CLOSE A FILE C EXSR OPNSF C RTCD IFEQ 0 C EXSR WRTSF C EXSR CLOSF C END C SETON LR * TABLE/ARRAY . . . . . . . : AR ** /QOPT/MYVOL1/DIRA/FILE /QOPT/MYVOL1/DIRA/SUBDIRB/FILE /QOPT/MYVOL1/DIRA/SUBDIRB/C/FILE /QOPT/MYVOL1/DIRA/SUBDIRB/C/D/FILE /QOPT/MYVOL1/DIRA/SUBDIRB/C/D/E/FILE
* PATH LENGTH PARAMETER IPATHLN DS I B 1 40PATHL * OPEN INFORMATION PARAMETER IOPNINF DS I 1 1 EXISTS I 2 2 NOTTHR I 3 3 SYNASY I 4 4 RSV1 I 5 5 SHAREM I 6 6 ACCESS I 7 7 OTYPE I 8 10 RSV3 * ATTRIBUTE LENGTH PARAMETER IATTRLN DS I B 1 40ATTRL * RETURN CODE PARAMETER IRETCD DS I B 1 40RCLEN I B 5 80RTCD I 9 15 CONDTN I 16 16 RSV I 17 272 MSG * BYTES TO READ/WRITE PARAMETER IBYTRDW DS B 1 40BYT2RW * BYTES ACTUALLY READ/WRITTEN PARAMETER IBYTACT DS B 1 40BYTARW
* PARAMETER LIST FOR QHFOPNSF CALL C POPNSF PLIST C PARM FHDLE 16 C PARM PATH 36 C PARM PATHL C PARM OPNINF C PARM ATRTBL 1 C PARM ATTRLN C PARM ACTION 1 C PARM RETCD C* OPEN FILE SUBROUTINE C OPNSF BEGSR C* FILL IN THE PATH AND ATTRIBUTE LENGTHS C Z-ADD36 PATHL SET PATH LEN=36 C Z-ADD*ZEROS ATTRL ZERO ATTRIBUTE LENGTH C* FILL IN THE OPNINF PARAMETER C MOVE '0' EXISTS 1 FAIL IF EXISTS C MOVE '1' NOTTHR 1 CREATE IF NOT THERE C MOVE '0' SYNASY 1 ASYNCHRONOUS C MOVE *BLANKS RSV1 1 C MOVE '1' SHAREM 1 DENY NONE C MOVE '2' ACCESS 1 READ/WRITE C MOVE '0' OTYPE 1 NORMAL C MOVE *BLANKS RSV3 3 C* CALL THE API TO OPEN THE STREAM FILE C CALL 'QHFOPNSF'POPNSF 50 C OPNEND ENDSR
* PARAMETER LIST FOR QHFRDSF OR QHFWRTSF CALL C PRWSF PLIST C PARM FHDLE 16 C PARM DATAIN C PARM BYT2RW C PARM BYTARW C PARM RETCD C* CALL API TO WRITE TO THE FILE C WRTSF BEGSR C Z-ADD256 BYT2RW SET WRITE LENGTH=256 C CALL 'QHFWRTSF'PRWSF 50 C WRTEND ENDSR
* PARAMETER LIST FOR QHFCLOSF CALL C PCLOSF PLIST C PARM FHDLE 16 C PARM RETCD C* CALL API TO CLOSE THE FILE C CLOSF BEGSR C CALL 'QHFCLOSF'PCLOSF 50 C CLSEND ENDSR C* END OF SAMPLE RPG CALL TO THE HFS API