Apologies in advance as i know this is trivial, but coming from a web and mobile development background and used to sql, this is really throwing me off.
I need to Delete records from Sale Order Line File that match the Sales Order Header , Order No.
The loop works, but if its the last records in the file, it fails , with a record not found, i believes its reading past the end of the file, how would i amend below
LOGOUT(20, CUSTOMER_CARDS, POS_CUSTOMERS, POS_HEADER, SALES_ORDER_HEADER, SALES_ORDER_LINE)
CLEAR(SOL:Record)
SOL:ORDER_NO = SOH:ORDER_NO
SET(SOL:ORDER_LINE_KEY, SOL:ORDER_LINE_KEY)
LOOP
NEXT(SALES_ORDER_LINE)
IF ERROR()
BREAK
END
IF SOL:ORDER_NO ~= SOH:ORDER_NO
BREAK
END
MESSAGE(SALES_ORDER_LINE.ORDER_NO)
END
COMMIT
I donât envy you your crash course in Clarion, Kajee
A couple of suggestions when posting questions here:
Clarion has two development paradigms: âLegacy/Classic/Clarionâ or âABCâ. When asking about coding or code âembedsâ (and especially about data access) itâs really important to specify whether the app in question is ABC or Legacy.
Clarion works with a number of database backends. Itâs a good idea to specify (Topspeed?, MS SQL?, postgres? ⌠etcâŚ)
As well as the other questions and comments people have asked, what do you mean by âif its the last records in the file, it fails , with a record not foundâ? You are not showing your delete logic - is it the delete that is failing or the read? Or perhaps the commit that is failing? The more detail you give the better. And show all your code. And say exactly where and how it is failing.
I normally would use errorcode() rather than error() but either should work OK. So when it reaches the end of file the code should break out of the loop. You should not get an error message.
Finally 20 is a large value for the logout timeout. Maybe two seconds is enough?
It may help to know the Error Code occurring on Next() by showing a Message(). It may be something unexpected. Also Logout() can fail. Without detailed error info like this we are just guessing.
LOGOUT(20, CUSTOMER_CARDS, POS_CUSTOMERS, POS_HEADER, SALES_ORDER_HEADER, SALES_ORDER_LINE)
IF ERRORcode() THEN !<-- ADD THIS --
Message('LOGOUT error '& ErrorCode() &' '& Error() & |
'|'& FileErrorCode() &' '& FileError() ,'LOGOUT Error')
END
CLEAR(SOL:Record)
SOL:ORDER_NO = SOH:ORDER_NO
SET(SOL:ORDER_LINE_KEY, SOL:ORDER_LINE_KEY)
LOOP
NEXT(SALES_ORDER_LINE)
IF ERRORcode() THEN
Message('NEXT(SALES_ORDER_LINE) error '& ErrorCode() &' '& Error() & |
'|'& FileErrorCode() &' '& FileError() ,'Next Error') !<-- ADD THIS --
BREAK
END
IF SOL:ORDER_NO ~= SOH:ORDER_NO
Message('NEXT(SALES_ORDER_LINE) Break ' & | !<-- ADD THIS --
'|SOL:ORDER_NO='& SOL:ORDER_NO &' |SOH:ORDER_NO='& SOH:ORDER_NO ,'Next Break')
BREAK
END
MESSAGE(SALES_ORDER_LINE.ORDER_NO)
END
what do you mean by âif its the last records in the file, it fails , with a record not foundâ? For example if i had 5 sales orders, i was looping over the lines of sales order 5 which are last in the file according to the order no key, then it end of by filing âRecord Not Availableâ Apologies, it was Not Available and not ânot foundâ
Will you logout the file once before the loop, or so you logout within the loop ? (His original code was deleted the sales order line in a loop while doing other processing) The change is to only delete the sales order lines after all processing is done. I have attached the entire module, you can see where i Commented out the original delete(SALES_ORDER_LINE) and below it where i trying my loop, with a MESSAGE(SALES_ORDER_LINE.ORDER_NO) cashsale010.clw (607.8 KB)
The LOGOUT in your code above might be a problem. In the cashsale010.clw on line 1073 is also a line with a LOGOUT statement and the corresponding COMMIT is on line 1436. But if your code including the LOGOUT/COMMIT pair is included on line 1430 that might be a problem. You cannot do two LOGOUTâs without committing the first.
You have IF ERROR()
in your code. It might be better to change that into IF ERRORCODE()
The code in your cashsale010.clw is not ABC but legacy. So I presume all your code will be legacy. Not that is makes much difference, but you will need solutions in legacy.
I would check, but that sounds normal. Just note that the error on NEXT() will NOT clear the file buffer, so the previous contents will still be there.
So double check to see if all your records are in fact deleted.
I donât know if there are books available special for legacy. I suggest use the Clarion documentation that comes with Clarion. And ask your questions here.
Regarding your question you started this topic with. I cannot see any errors other then what I said on the logout/commit pair and using ERRORCODE() instead of ERROR().
@CarlBarnes@Koen@seanh@vitesse@Jane
Thank you all, i have come right with this.
The issue was , to exit the loop , you break on the the end of file error. and after the loop i had an error catcher, which was catching that error.
I found one of my dads old books, he, its for clarion 5.5, Programmers Guide, it seems like a good starting point for me .
With a loop like that, if you are dealing with the last order in the file, you EXPECT to run into Record not found. For the records that are not at the end of the file, you expect to run into the next order number at some point. In both of those cases you just want to (I would expect) stop your looping process (i.e. BRAK) and return, rather than tell the user that something bad happened.
I assume you actually have something like:
if error() then
message(error()
break
end
You can do something like
if errorcode() = 33 or sol:order_no != soh_order_no! record not available (end of file) or finished order
break
else if errorcode()
message('This is a real error â & error())
break
end
True, but you have also a Clarion 11 version available. Not as a hard copy as your 5.5 version but as a PDF file. You can find it in the directory âDocâ which is a sub directory in your Clarion install directory.