× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi list,

I am trying to update an ifs file by using the c function lseek() for positioning and then write() to update the ifs file. I had no success so far.

The program created a text file and get populated with "Hello World". After the file is populated then its closed. I re-open the file and read the contend of the file. I then attempt to change the read data by doing the lseek first and updating the file via write().

Any ideas on how to achieve that?

A list of the code is attached

Regards,

Emmanuel Zannis

Analyst/Programmer
HRG
Spectrum Point
279 Farnborough Road
Farnborough
Hampshire GU14 7NJ
United Kingdom
Telephone: +44 (0) 1252 881000 Ext 3262
Fax: +44 (0) 1252 518961
Email: Emmanuel.Zannis@xxxxxxxxxxxxxxxx

Web: <blocked::http://www.hrgworldwide.com> www.hrgworldwide.com


HRG logo <http://www.hoggrobinson.co.uk/upload/files1/HRG_Email_Small.jpg> HRG (Hogg Robinson Group). The worldwide network that provides a range of corporate services which add real value to our clients' travel expenditure.


*************** Beginning of data ******************************************************************
0018.00 * Open - Open an IFS file
0019.00 D open PR 10I 0 ExtProc('open')
0020.00 D filename * Value
0021.00 D openflags 10I 0 Value
0022.00 D mode 10U 0 Value options(*nopass)
0023.00 D codepage 10U 0 Value options(*nopass)
0025.00 * Read - Read an IFS file
0026.00 D read PR 10I 0 ExtProc('read')
0027.00 D filehandle 10I 0 Value
0028.00 D datarcved * Value
0029.00 D nbytes 10U 0 Value
0031.00 * lseek - Position IFS file
0032.00 D lseek PR 10I 0 ExtProc('lseek')
0033.00 D fildes * value
0034.00 D offset 10I 0 value
0035.00 D whence 10I 0 value
0037.00 * Write - Write recprd to IFS file
0038.00 D write PR 10I 0 ExtProc('write')
0039.00 D filehandle 10I 0 Value
0040.00 D datatowtr * Value
0041.00 D nbytes 10U 0 Value
0043.00 * Close - Close Ifs file
0044.00 D close PR 10I 0 ExtProc('close')
0045.00 D filehandle 10I 0 Value
0047.00 * Set file Details
0048.00 D Pr_SetFile PR 1 0
0050.00 * Open PC File in IFS directory
0051.00 D Pr_OpnFile PR 1 0
0053.00 * Write Hello World
0054.00 D Pr_FileValues PR
0056.00 * Write Goodbye World
0057.00 D Pr_FileValues2 PR
0059.00 * Read PC File in IFS directory
0060.00 D Pr_ReadFile PR 512A
0062.00 * Write to IFS File
0063.00 D Pr_WrtIfs PR
0065.00 * RC - IFS Api return code
0066.00 D O_APPEND S 10I 0 Inz(256)
0067.00 D O_CODEPAGE S 10I 0 Inz(8388608)
0068.00 D O_CREAT S 10I 0 Inz(8)
0069.00 D O_EXCL S 10I 0 Inz(16)
0070.00 D O_RDONLY S 10I 0 Inz(1)
0071.00 D O_RDWR S 10I 0 Inz(4)
0072.00 D O_TEXTDATA S 10I 0 Inz(16777216)
0074.00 D O_TRUNC S 10I 0 Inz(64)
0075.00 D O_WRONLY S 10I 0 Inz(2)
0077.00 D S_IRUSR S 10I 0 Inz(256)
0078.00 D S_IWUSR S 10I 0 Inz(128)
0079.00 D S_IXUSR S 10I 0 Inz(64)
0080.00 D S_IRWXU S 10I 0 Inz(448)
0082.00 D S_IRGRP S 10I 0 Inz(32)
0083.00 D S_IWGRP S 10I 0 Inz(16)
0084.00 D S_IXGRP S 10I 0 Inz(8)
0085.00 D S_IRWXG S 10I 0 Inz(56)
0087.00 D S_IROTH S 10I 0 Inz(4)
0088.00 D S_IWOTH S 10I 0 Inz(2)
0089.00 D S_IXOTH S 10I 0 Inz(1)
0090.00 D S_IRWXO S 10I 0 Inz(7)
0092.00 * Replace the contens of filename
0093.00 D Comma C Const(',')
0094.00 D Quote C Const('"')
0095.00 D SQuote C Const(x'7d')
0096.00 D Null C Const(x'00')
0097.00 D FldDlm C Const(x'05')
0100.00
0101.00 D SEEK_SET C Const(0)
0102.00 D SEEK_CUR C Const(1)
0103.00 D SEEK_END C Const(2)
0104.00
0105.00 D Filename S 100A Inz
0107.00 D Err_Flag S 10I 0
0108.00 D Oflag S 10I 0
0109.00 D rc S 10I 0
0110.00 D BufferI S 512A Inz(*Blank)
0111.00 D BufferI@ S * Inz(%Addr(BufferI))
0112.00 D NBytes S 10I 0
0113.00 D NBytesSet S 10U 0 Inz(512)
0114.00 D RecIn S 512A
0115.00 D CLRFPos S 10I 0 Inz(0)
0116.00 D CLRF S 2A Inz(x'0d25')
0118.00 D CodePage S 10U 0 Inz(819)
0119.00 D Omode S 10U 0
0120.00 D BufLen S 10U 0
0122.00 D OutRec S 512
0123.00 D Str S 3P 0
0124.00 D EOLA S 2 Inz(x'0d25')
0126.00 D Num S 20 Varying
0128.00 * Entry parameters
0129.00 D PrmFileName S 100A Inz('/EFS/HELLOWORLD.TXT')
0130.00 D Err_Occur S 1A Inz('N')
0132.00 * Work Fields
0133.00 D Wrk_1stErr S Like(*In01)
0134.00 D Wrk_FrstTime S 1A Inz('Y')
0135.00 D Wrk_First_Time S Like(*In01) Inz(*On)
0136.00 D Wrk_File S 10A Inz
0137.00 D Wrk_Eof S 1A Inz('N')
0138.00 D Wrk_End_Loop S 1A Inz('N')
0139.00 D X S 10P 0 Inz
0140.00 D L S 5P 0 Inz
0141.00
0142.00 D Wrk_WrtRec DS 2048
0143.00 D Wrk_OutRec 1 1024

0151.00 /free
0153.00 // Set Pc file details
0154.00 L = Pr_SetFile ();
0155.00 If L = -1;
0157.00 ExSr *PSSR;
0159.00 EndIf;
0161.00 // Open PC file in IFS directory
0162.00 L = Pr_OpnFile ();
0163.00 If L = -1;
0165.00 ExSr *PSSR;
0167.00 EndIf;
0169.00 // Write Hello World
0170.00 CallP Pr_FileValues ();
0172.00 // Close IFS file
0173.00 RC = Close(Err_Flag);
0174.00 If RC = -1;
0176.00 Exsr *Pssr;
0178.00 EndIf;
0180.00 // Open PC file in IFS directory
0181.00 L = Pr_OpnFile ();
0182.00 If L = -1;
0184.00 ExSr *PSSR;
0186.00 EndIf;
0188.00 // Read PC file in IFS directory
0189.00 Monitor;
0190.00 outrec = Pr_ReadFile ();
0191.00 On-Error;
0192.00 ExSr *Pssr;
0193.00 EndMon;
0195.00 // Write GoodBye World
0196.00 CallP Pr_FileValues2 ();
0198.00 // Close IFS file
0199.00 RC = Close(Err_Flag);
0200.00 If RC = -1;
0202.00 Exsr *Pssr;
0204.00 EndIf;
0206.00 // End Of Program
0207.00 *InLr = *On;
0209.00 /end-free
0215.00 C *Pssr BegSr
0226.00
0227.00 C EndSr '*CANCL'
0233.00 C *Inzsr BegSr
0239.00 /free
0241.00 // Default path name
0242.00 Filename = %Trim(PrmFileName);
0244.00 /end-free
0246.00 C EndSr
0253.00 P Pr_SetFile B
0254.00
0255.00 D Pr_SetFile PI 1 0
0257.00 /free
0259.00 Oflag = O_CREAT + O_CODEPAGE + O_RDWR;
0261.00 Omode = S_IRWXU + S_IROTH;
0263.00 Filename = %Trim(FileName) + Null;
0265.00 Err_Flag = Open(%Addr(Filename) : OFLAG : Omode : CodePage);
0267.00 If Err_Flag < 0;
0269.00 Return -1;
0271.00 Else;
0273.00 Return 0;
0275.00 EndIf;
0277.00 /end-free
0278.00
0279.00 P Pr_SetFile E
0286.00 P Pr_OpnFile B
0287.00
0288.00 D Pr_OpnFile PI 1 0
0290.00 /free
0292.00 Oflag = O_RDWR + O_TEXTDATA;
0294.00 Err_Flag = Open(%Addr(Filename) : Oflag);
0296.00 If Err_Flag < 0;
0298.00 Return -1;
0300.00 Else;
0302.00 Return 0;
0304.00 EndIf;
0306.00 /end-free
0307.00
0308.00 P Pr_OpnFile E
0315.00 P Pr_ReadFile B
0316.00
0317.00 D Pr_ReadFile PI 512A
0319.00 /free
0321.00 nbytes = Read(Err_Flag:BufferI@:NBytesSet);
0323.00 If NBytes > 0 And
0325.00 Err_Flag >= 0;
0327.00 ClRfPos =%Scan(CLRF:BufferI);
0329.00 If ClRfPos > 0;
0330.00 RecIn = %SubSt(BufferI:1:ClRfPos + 1);
0331.00 EndIf;
0333.00 EndIf;
0336.00 Return RecIn;
0338.00 /end-free
0339.00
0340.00 P Pr_ReadFile E
0347.00 P Pr_FileValues B
0348.00
0349.00 /free
0351.00 OutRec = %Trim(OutRec) + 'Hello World!!!' +
0352.00 EOLA;
0354.00 // Write to IFS file
0355.00 CallP Pr_WrtIfs ();
0357.00 /end-free
0358.00
0359.00 P Pr_FileValues E
0366.00 P Pr_FileValues2 B
0367.00
0368.00 /free
0370.00 Clear OutRec;
0372.00 Err_Flag = lseek(%Addr(Filename): 1: SEEK_SET);
0374.00 If Err_Flag > 0;
0376.00 OutRec = %Trim(OutRec) + 'GoodBye World!!!' +
0377.00 EOLA;
0379.00 // Write to IFS file
0380.00 CallP Pr_WrtIfs ();
0382.00 EndIf;
0384.00 /end-free
0385.00
0386.00 P Pr_FileValues2 E
0393.00 P Pr_WrtIfs B
0394.00
0395.00 /free
0397.00 BufLen = %Len(%Trim(OutRec));
0399.00 RC = Write(Err_Flag:%Addr(OutRec): BufLen);
0401.00 Clear OutRec;
0403.00 /end-free
0405.00 P Pr_WrtIfs E

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.