Hi all,
I hope that someone can help me 'coz th problem described below is drivig me nuts:
I have a function Import_Order in a Code Unit to import ascii files.
The ascii files contain sales order header lines (labeled TI ) as well sales order lines (labeled LI )
A typical file would look like this:
TI;70;14012008;16012008;"PRI";"CF-0000001";"TILL";"Urgent svp"
LI;70;0;"CF-0000001";1;"F003-105";10;188,2
LI;70;0;"CF-0000001";2;"F003-106";8;150,56
LI;70;0;"CF-0000001";3;"F003-110";15;79,35
TI;70;19102010;19102010;"PRI";"CFA-000001";"TILL";""
LI;70;0;"CFA-000001";1;"F001-41";10;1000
LI;70;0;"CFA-000001";2;"F001-41";10;900
TI;70;20102010;20102010;"PRI";"CFA-000002";"TILL";""
LI;70;0;"CFA-000002";1;"F001-40";4;42,34
The basic code of the import function is below:
FUNCION Import_Order
L_Tag_Ok := TRUE;
IF ( EXISTS ( P_Full_File_Name ) ) THEN
BEGIN
IF ( L_File.OPEN( P_Full_File_Name) ) THEN
BEGIN
L_File.WRITEMODE( FALSE );
L_File.TEXTMODE( TRUE );
WHILE ( L_File.READ( L_StrLine ) <> 0 ) AND ( L_Tag_Ok ) DO
BEGIN
L_StrField := Get_Field( L_StrLine, ';' );
CASE ( UPPERCASE( L_StrField ) ) OF
'TI' : L_Tag_Ok := Import_Order_Header( LR_Order_Header,
L_StrLine,
L_Customer_No,
L_File_Name ) ;
'LI' : L_Tag_Ok := Import_Order_Line( LR_Order_Line,
L_StrLine,
LR_Order_Header ) ;
END;
END;
L_File.CLOSE ();
END;
END;
EXIT( L_Tag_Ok );
The problem:
When the function gets called from within an OnPush trigger of a button on a form all lines are read.
When the function gets called from the OnRun trigger of the same code unit, only the first line of a text file gets imported.
Actually the File.Read method only reads a line the first time the cycle gets executed.
In both situations I'm trying to import the same file.
Anybody has a suggestion ?
0
Answers
I would use the debugger to see what's happening in the case of the OnRun-trigger.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
thanks for your suggestions.
I tried limiting the fuctionality of the code as below.
Sadly the same behaviour still occurs.
FUNCION Import_Order ( P_Full_File_Name : Text[250]) L_Tag_Ok : Boolean
L_Tag_Ok := TRUE;
IF ( EXISTS ( P_Full_File_Name ) ) THEN
BEGIN
IF ( L_File.OPEN( P_Full_File_Name) ) THEN
BEGIN
L_File.WRITEMODE( FALSE );
L_File.TEXTMODE( TRUE );
WHILE ( L_File.READ( L_StrLine ) <> 0 ) AND ( L_Tag_Ok ) DO
BEGIN
MESSAGE( L_StrLine );
END;
L_File.CLOSE ();
END;
END;
EXIT( L_Tag_Ok );
One thing that has changed between is the size of L_StrLine and P_Full_File_Name. Changed (and rechanged ) between size 1024 and 250.
Another thing I can mention is that it has worked before, but i made some changes I can't recall, but sadly we don't work with a versionning system...
I hoped somebody actually had expierenced the same issue.
cheers.
Is not good condition to test end of file. If you read empty string, the result could be 0, but not EOF hitted... Try to compare position and file length, it is much better.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Allthough we're not supposed to receive files with empty lines, I'll change that anyway just to practice Best practices.
Furthur to my problem I found out the following:
A difference between the two calls to the import_order function is the loation of the file to import.
In the case where the file is imported from the user's temp directory on the C: drive, the file gets read correctly
If the file is in a directory on my drive (2nd partition on my disk) only the first line gets read.
I confirmed this by hardcoding the filename in both function calls.
Anybody ?
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
So best test on length of the string and if it is 0 then also test EOF. The code is something as this:
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
But your suggestion pointed me into a direction. The file gets downloaded with different functions, depeding on from which form the import_order funtion gets called...
I'll have to do some research there..
In the case where the file was downloaded in FTP-mode Binary all lines where correctly read by FILE.READ,
In the case where the file was downloaded in FTP-mode ASCII FILE, only the first line was read by FILE.READ.
Silly me to think that if you would use Mode ASCII for File.Read, you'ld have to use ftp-mode ASCII as well.... :roll:
Thanks for your time guys...
\:D/ \:D/
Luckily a binary transfer works for you.