Close a CSV File

csvClose

The csvClose procedure close a file on the IFS that was previously open by the csvOpen procedure.

The csvClose procedure can be used to close a file previously open by the csvOpen procedure or a regular IFS file opened with the Unix-style "open" API.

 return-code =  csvClose(
  hIFSFileHandle      10I 0   Const
)

See also: csvWrite

Parameters

hFile
[input int4 (10i0) ]  The file handle returned from a previous call to the csvOpen procedure. See example below for an illustration of how to declare a variable to be used as a file handle.
 

Return Value

If the file is successfully csvClose returns a value of 0. If an unsuccessful close was performed, csvClose returns -1 and writes a message to the job log.

Remarks

csvClose uses the simple Unix-style close() API to close the file. You may also use close() if you prefer. The csvClose() procedure is a wrapper for close() API, however, should an error occur during a close attempt, csvClose logs the error in text form to the joblog.

Example

The following example uses csvOpen to create and open the output file named CUSTMAST.CSV on the IFS. It then processes the file, and finally closes the IFS file using csvClose.

     FCUSTMAST  IF   E             DISK

 

     D hFile           S             10I 0

     D nBytes          S             10I 0

     D hBytesWritten   S             10U 0

     DCUSTDS         E DS                  EXTNAME(CUSTMAST)

 

.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++++++++++

     C                   eval      hFile = csvOpen('/home/cozzi/custmast.csv':

     C                                             'QGPL/CUSTMAST')

     C                   Read      CustRec

     C                   dow       Not %EOF

     C                   eval      nBytes=csvWrite(hFile: CUSTDS)

     C                   eval      nBytesWritten = nBytesWritten + nBytes

     C                   Read      CustRec

     C                   enddo

     C                   callp     csvClose(hFile)