The csvWriteHdr procedure writes a record to a file on the IFS in CSV (comma separated values) format. This record contains a list of field names separated by the comma delimiter.
The csvWriteHdr procedure can be used generated a "header row" that is output to the IFS file.
bytes-written = csvWriteHdr( hIFSFile 10I 0 szFmtFileName 21A Const OPTIONS(*NOPASS) szUserSpace 21A Const OPTIONS(*NOPASS) ) |
|
See also: csvWrite |
*...v....1....v....2....v
'qgpl/custmast'
*...v....1....v....2....v
'QTEMP/XT_CSVFLD'
The return value is the number of bytes written to the record in the comma separated value.
Call this procedure if you did not specify the bHeaders(*ON) option on the csvOpen procedure to create and write a row of headers to your IFS file.
Normally you would specify bHeaders(*ON) during an open to the file with the csvOpen procedure and therefore not need to call this procedure.
In following example, the csvOpen procedure opens the CUSTMAST.CSV file on the IFS for output and avoids writing a row of headers (the bHeaders parameter is *OFF). It then calls csvWriteHdr to generate and write a row of heads to the IFS file. The headers row is only written if the DB2/400 database file contains 1 or more records.
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':'*':*ON:*OFF)
C read CustRec
C if Not %EOF
C callp csvWriteHdr(hFile:'QGPL/CUSTMAST')
C dow Not %EOF
C eval nBytes=csvWrite(hFile: CUSTDS)
C eval nBytesWritten = nBytesWritten + nBytes
C Read CustRec
C enddo
C endif
C callp csvClose(hFile)