View Full Version : [CLOSED]IFS write
ktoole
03-10-2010, 02:19 PM
You have functions for open/close/read/etc..., but no apparent function is show on how to write to an IFS file. I want to write the ExtJS code to an IFS file and then use the new function for ExtJS that you created to have an HTML file pull in the IFS file I wrote out to create a page that may change. Is there a way to write to an IFS file?
sean.lanktree
03-10-2010, 03:31 PM
Sure is...prototype the "write" api.
d WriteToFile pr extproc('write')
d fileHandle 10i 0
d data * value
d dataLength 10u 0 value
d fieldA s 100a
/free
fieldA = 'add this text to the file';
WriteToFile(myHandle:%addr(fieldA):%len(%trim(fiel dA)));
ktoole
03-10-2010, 03:37 PM
I thought that might be what I would have to do, but I thought I would ask just incase I missed an API that you already had. Thanks for your help.
ktoole
03-11-2010, 03:42 PM
I'm probably missing something obvious, but the file is deleted (if it exists), opened (the date and time on the IFS change for the file), but I cannot get anything into the file. In debug the field to write the data is full of data, but nothing gets into the file. I write several times and then close the file, but the file is empty. Any suggestions? PS: The definition for the write function matches your's exactly.
p buildDGridsRPG b
d pi
d fileHandle s 10i 0
d dataToWrite s 5000 varying
d Comp s like(##CMP)
d Loc s like(##LOC)
d Area s 1
d Fields ds qualified dim(100)
d Name 24
d Field 10
d Seq 4 0
d i s 4 0
d x s 4 0
d filePathName c '/valence-2.1/html/LPS/datagrids-
d /dataCollectionGrids2.js'
D CRLF c const(x'0d25')
D TAB c const(x'09')
// at the bottom is code for writing to IFS
/free
// delete the old copy of this file
if vvIfs_deleteFile( filePathName ) = 0;
endif;
// create/open a new copy of the dataCollectionGrids2 file for read/write and give it
// the following authority:
// - all owner authority
// - group read authority
// - other execute authority
//
fileHandle = vvIfs_openFile( filePathName
:OREADWRITE+OCRTNOEXIST
:S_IRWXO
:819);
if fileHandle <> -1;
dataToWrite = '// this JavaScript is not called directly but'+
' retrieved by an RPG program for use with testgrid.html'+CRLF+CRLF;
GetDfts( Comp:Loc:Area );
setll Comp MLPXREF1;
reade Comp MLPXREF1;
dow not %eof;
%len(dataToWrite) = 0;
// load all the fields for a group into the fields array
i=0;
setll (Comp:L1GROUP) MLPXREF2;
reade (Comp:L1GROUP) MLPXREF2;
dow not %eof;
i+=1;
Fields(i).Name = L2Desc;
Fields(i).Field = L2Field;
Fields(i).Seq = L2Seq;
reade (Comp:L1GROUP) MLPXREF2;
enddo;
// only write to the IFS if there are fields for the data collection group
if i > 0;
// write data to IFS file for update to JS file
dataToWrite += '//'+L1GROUP+' items'+CRLF;
dataToWrite += '// update function'+CRLF;
dataToWrite += 'var upd'+L1GROUP+'Rec = function(record) {'+CRLF;
dataToWrite += TAB+'Ext.Ajax.request({'+CRLF;
dataToWrite += TAB+TAB+'url: "vvcall.pgm",'+CRLF;
dataToWrite += TAB+TAB+'params: {'+CRLF;
dataToWrite += TAB+TAB+TAB+'pgm: "MLPDGRIDS"'+CRLF;
dataToWrite += TAB+TAB+TAB+'action: "updateRec",'+CRLF;
dataToWrite += TAB+TAB+TAB+'gridName: "+L1GROUP+",'+CRLF;
dataToWrite += TAB+TAB+TAB+'CO: record.get("CO"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'LOC: record.get("LOC"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'FARMNO: record.get("FARMNO"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'BARNID: record.get("BARNID"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'FYEAR: record.get("FYEAR"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'NUM: record.get("NUM"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'PENID: record.get("PENID"),'+CRLF;
dataToWrite += TAB+TAB+TAB+'DDATE: record.get("DDATE"),'+CRLF;
for x = 1 to i-1;
dataToWrite += TAB+TAB+TAB+Fields(x).Field+': record.get("+
Fields(x).Field+"),'+CRLF;
endfor;
dataToWrite += TAB+TAB+TAB+Fields(i).Field+': record.get("+
Fields(i).Field+")'+CRLF;
dataToWrite += TAB+TAB+TAB+'},'+CRLF;
dataToWrite += TAB+TAB+'success:function(response, options) {'
+CRLF;
dataToWrite += TAB+TAB+TAB+'var check=response.responseText;'
+CRLF;
dataToWrite += TAB+TAB+TAB+'if (check) {'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+
'var data = Ext.util.JSON.decode(response.responseText);'+CRLF ;
dataToWrite += TAB+TAB+TAB+TAB+'if (data.SUCCESS == "1") {'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+TAB+'record.commit();'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+TAB+'record.commit();'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+TAB+'vvShowError("ERROR OCCURED",'+
'"Received a negative response from the server when'+
' attempting to update a record.");'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+'};'+CRLF;
dataToWrite += TAB+TAB+TAB+'} else {'+CRLF;
dataToWrite += TAB+TAB+TAB+TAB+'vvShowError("ERROR OCCURED",'+
'"Received a null response from the server when attempting to'+
' update a record.");'+CRLF;
dataToWrite += TAB+TAB+TAB+'}'+CRLF;
dataToWrite += TAB+TAB+'},'+CRLF;
dataToWrite += TAB+TAB+'failure:function() {,'+CRLF;
dataToWrite += TAB+TAB+TAB+'vvShowError("ERROR OCCURED",'+
'"Received a failure response from the server when'+
' attempting to update a record.");'+CRLF;
dataToWrite += TAB+TAB+'}'+CRLF;
dataToWrite += TAB+'});'+CRLF;
dataToWrite += '};'+CRLF;
WriteToFile( fileHandle
:%addr(dataToWrite)
:%len(%trim(dataToWrite)) );
endif;
reade Comp MLPXREF1;
enddo;
// close the file when done writing data
vvIfs_closeFile(fileHandle);
vvOut_toJsonPair('SUCCESS:1,MSG:File created!');
else;
vvOut_toJsonPair('SUCCESS:0,MSG:File not created!');
endif;
/end-free
p e
sean.lanktree
03-11-2010, 03:55 PM
Nothing is really popping out at me. I am assuming that the write API is passing back a -1 (failure). Just realized my original post with the prototype for write is not correct, it should return a 10i 0. Not sure if that is the problem or not. If not, try adding this code to your program so you can extract the error information after your call to WriteToFile:
d errorNumber s 10i 0 based(errorNumberPtr)
d getCErrorNumber...
d pr * extproc('__errno')
d translateCErrorNumber...
d pr * extproc('strerror')
d errorNumber 10i 0 value
/free
if WriteToFile(fileHandle:%addr(data):%len(%trim(data )) = -1;
errorNumberPtr = getCErrorNumber();
if errorNumber<>0;
errorText = %str(translateCErrorNumber(errorNumber));
endif;
endif;
ktoole
03-12-2010, 07:21 AM
The return of the int in write is zero. There is no error, but just in case I put the other code in and ran it with that in debug. The text is "There is no error". I can't figure out why the data is not being written to the IFS file. Scott Klement in one of his sites was saying that the int returned by the write, if not error, was the number of bytes written. My number is zero. I can't seem to figure out what is wrong.
sean.lanktree
03-12-2010, 09:37 AM
I think you may need to make this a %trimr
WriteToFile( fileHandle
:%addr(dataToWrite)
:%len(%trimr(dataToWrite)) );
sean.lanktree
03-12-2010, 09:46 AM
Just noticed that you are passing a varying field to the api. In that case, when you pass the address of dataToWrite you may need to offset it by 2 bytes.
WriteToFile( fileHandle
:%addr(dataToWrite)+2
:%len(%trimr(dataToWrite)) );
Otherwise, try moving dataToWrite into a fixed length field and then passing the fixed length field to WriteToFile.
ktoole
03-12-2010, 10:31 AM
I tried several things. First I added the trimr and the size adjustment. This didn't work. I then tried changing the variable to a fixed length. This didn't work either. I'm not sure what else to try.
ktoole
03-12-2010, 01:20 PM
I found the problem. I missed specifing VALUE for the first parm of fileHandle. Once this was changed it started writing to the file. Now I just have to get it to write in ASCII and not EBCIDIC.
// Write data to IFS file subprocedure
d writeToFile pr 10i 0 extproc('write')
d fileHandle 10i 0 value
d data * value
d dataLength 10u 0 value
ktoole
03-12-2010, 01:54 PM
I got it writing in ASCII now too. I used an old routine that someone else helped with a while ago. It is setup to open the IFS file as follows:
D open PR 10I 0 extproc('open')
D path * value options(*string)
D oflag 10I 0 value
D mode 10U 0 value options(*nopass)
D codepage 10U 0 value options(*nopass)
D txtcreateid 10U 0 value options(*nopass)
The open looks like this:
fileHandle = open( filePathName:
O_CREAT + O_TRUNC + O_WRONLY + O_CCSID +
O_TEXTDATA + O_TEXT_CREAT:
RW*OWNER + RW*GROUP + R:819:0);
The constants are as follows:
D O_WRONLY c 2
D O_CREAT c 8
D O_CCSID c 32
D O_TRUNC c 64
D O_CODEPAGE c 8388608
D O_TEXTDATA c 16777216
D O_TEXT_CREAT c 33554432
D RW c 6
D R c 4
D OWNER c 64
D GROUP c 8
This all works, maybe I missed something with the Valence parms, let me know if you figure out which one and I will try it.
vBulletin® v3.7.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.