Welcome! Log In Create A New Profile

Advanced

[WD19] HReset before HAdd

Posted by Mujahid 
[WD19] HReset before HAdd
June 11, 2019 04:17PM
Hi All,

Before this, I found that if im using HReset before HAdd, then some table line not be save in record file.

For example :

FOR ALL ROW OF TABLE_Line
HReadSeekFirst(InvLine,usInvLineID,TABLE_Line.COL_usInvLineID)
IF HFound(InvLine) = False THEN
HReset(InvLine)
Invline.usInvLineID = TABLE_Line.COL_usInvLineID
Invline.sItemRef = TABLE_Line.COL_sItemRef
IF NOT HAdd(InvLine) THEN
gp_TransactionCancel()
bFlag=False
END

END
END


Then i remove the HReset(InvLine), but 1% or 2% of the record still not save in the file.

Im using HFSQL Classic and HTransaction.

Whats wrong with my coding?

How to make it rock solid to save the record?

When actually the right time to use HReset?

Thanks a lot

Regards,
Mujahid
Re: [WD19] HReset before HAdd
June 11, 2019 04:39PM
Hi,

HReset() resets all of data items of a file buffer to the values you had defined as default values in the analysis. There's no need to use HReset(..) if you're setting the data items of the file anyway. Are there really only two data items in the file? The FOR ALL ROWS may disturb the progress of the file pointer ... is this a memory table or a datafile table? If this is table control driven by exactly the same file that you're using for HAdd, it may well be that newly inserted records are moving the table?

Kind regards,
Guenter Predl
office@windev.at
José Antonio
Re: [WD19] HReset before HAdd
June 13, 2019 09:58PM
Hi.
Maybe sometimes hreadseek didn't find the searched record.
Try with this:

FOR ALL ROW OF TABLE_Line 
	HReadSeekFirst(InvLine,usInvLineID,TABLE_Line.COL_usInvLineID) 
	IF not HFound(InvLine) THEN CONTINUE
	Trace("found "+"InvLine.usInvLineID)
		HReset(InvLine) 
		Invline.usInvLineID = TABLE_Line.COL_usInvLineID 
		Invline.sItemRef = TABLE_Line.COL_sItemRef 
		IF not HAdd(InvLine) THEN 
			gp_TransactionCancel() 
			bFlag=False 
			Trace("error "+HError())
		ELSE
			Trace("added ok")
			
		END	

	
END

Regards,
José Antonio.
Peter Holemans
Re: [WD19] HReset before HAdd
June 14, 2019 03:41PM
Hi,

I'm missing proper error/exception handling in your code making it hard to trace what's going on...
You might have a look to my oErrorMessage and oErrorMessageList classes here for e.g. accumulating multiple error messages in e.g. batch processing or loops: https://repository.windev.com/resource.awp?file_id=91;wxframework-open-source-oop-multiplatform-framework-allows-rapid-development-wdwb-and-later
(It has evolved a bit since but you can get the concepts out it)

WHEN EXCEPTION IN 
   //
   IF NOT (hAdd) THEN
      //Do error/warning handling here and get details with hErrorInfo()
      Info(hErrorInfo(hErrFullDetails))
   END
DO
   //Do exception logging and/or handling here e.g. by writing to a log file...
   ExceptionEnable()
END

Cheers,

Peter Holemans
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: