
|
// Maximum length of IFS records is 32740 chars
// Records will be terminated by the windows-style CR/LF sequence
// Character fields are enclosed within double quotes (")
// and trailing blanks are removed
// Numeric and date fields are output as-is.
 
// ATENTION : EN V6R10 il faut (en plus de 5733OAR)
// SI39480 sur 5761SS1 et SI39912 sur 5761WDS
 
H DftActGrp(*No) Option(*SrcStmt)
 
// Standard IBM supplied Open Access definitions
/copy QOAR/QRPGLESRC,QRNOPENACC
// Definition of additional handler parameter and constants
/copy AF4SRCT/EXEMPLEOAR,cvs_cpy
// Standard IBM supplied IFS prototypes
/copy qsysinc/qrpglesrc,ifs
// RPG Status code values
/copy AF4SRCT/EXEMPLEOAR,status
 
// On V7 and later systems this PR can be removed and so can those for
// local subprocedures openFile(), writeFile() and closeFile().
D CVS_HDLR pr ExtPgm('CVS_HDLR')
D info likeds(QrnOpenAccess_T)
 
// Definitions for local subprocedures
D openFile pr like(fileHandle)
D path like(ifs_hdlr_info_t.path)
D const
 
D writeFile pr like(filehandle)
D handle like(fileHandle) value
 
D closeFile pr
D handle like(fileHandle) value
 
D CVS_HDLR PI
D info likeds(QrnOpenAccess_T)
 
// Field Names/Values structures
D nvInput ds likeds(QrnNamesValues_T)
D based(pNvInput)
 
// Structure to map the "additional informatin" parameter passed
|
// by the RPG program. In this case it contains the IFS file name. // Its pointer is contained within the userArea field in the info struct D ifs_info ds likeds(ifs_hdlr_info_t) D based(pIfs_info)   // Used by the IFS routines to determine which IFS file is to be used // Maps to storage dynamically allocated when opening the file. // Pointer is stored in the rpgStatus field in the info structure D fileHandle s 10i 0 based(pfileHandle)   /free // Use the pointers in the info area to set up access to the // the handle for the IFS file (stateInfo) // and the IFS file name (userArea) pfileHandle = info.stateInfo;   pIfs_info = info.userArea;   If info.rpgOperation = QrnOperation_WRITE; // Set up access to Name/Value information pNvInput = info.namesValues;   // Write error is unlikely but signal it if it occurs If ( writeFile(fileHandle) = fileError ); info.rpgStatus = errIO; EndIf;   elseIf info.rpgOperation = QrnOperation_OPEN; // Specify that we want to use Name/Value information info.useNamesValues = *On;   // Allocate the storage for the file handle and store the pointer // in the info area. That way RPG can associate the pointer with // the specific file and give it back to us on each operation. pfileHandle = %Alloc(%Size(fileHandle)); info.stateInfo = pfileHandle;   // Ensure that file handle is zero before attempting open() clear fileHandle;   fileHandle = openFile (ifs_info.path); // Open file if fileHandle = fileNotOpen; info.rpgStatus = errImpOpenClose; // Open failed EndIf; |
  elseif info.rpgOperation = QrnOperation_CLOSE; closeFile (fileHandle);   // free the state information and null out the info pointer dealloc(n) pfileHandle; info.stateInfo = *null;   else; // Any other operation is unsupported so notify RPG info.rpgStatus = 1299; // general error status endif;   Return;   /end-free     P openFile b D openFile pi like(fileHandle) D path like(ifs_hdlr_info_t.path) D const   /free return open( path : O_CREAT + O_WRONLY + O_CCSID + O_TRUNC + O_TEXTDATA + O_TEXT_CREAT : S_IRUSR + S_IWUSR + S_IRGRP + S_IROTH : 819 : 0 ); /end-free   P openFile e   P closeFile b D closeFile pi D handle like(fileHandle) value D rc s 10i 0   /free   rc = close (handle);   /end-free |
 
 
P closeFile e
 
P writeFile b
D pi like(filehandle)
D handle like(fileHandle) value
 
D buffer s 32740a Varying Inz
D value s 32470a Based(pvalue)
D i s 5i 0
D reply s 10i 0
D comma c ';'
D quote c '"'
D CRLF c x'0d25'
 
/free
// Process all fields in record
For i = 1 to nvInput.num;
pvalue = nvInput.field(i).value; // set up to access data
 
If ( nvInput.field(i).dataType = QrnDatatype_Alpha )
Or ( nvInput.field(i).dataType = QrnDatatype_AlphaVarying);
buffer += quote
+ %trimR(
%xlate(';':',':
%subst( value: 1: nvInput.field(i).valueLenBytes)))
+ quote;
 
ElseIf ( nvInput.field(i).dataType = QrnDatatype_Decimal );
buffer += %subst(value: 1: nvInput.field(i).valueLenBytes);
 
ElseIf ( nvInput.field(i).dataType = QrnDatatype_Date );
buffer += %subst(value: 1: nvInput.field(i).valueLenBytes);
 
EndIf;
 
If i <> nvInput.num; // Add comma after every field except the last
buffer += comma;
EndIf;
 
EndFor;
 
buffer += CRLF; // Add record termination
|
  // reply will contain the length of data written or -1 in case of error reply = write ( handle: %Addr(buffer:*Data): %Len(buffer) );   Return reply;   /end-free P writeFile e |