Help with Deleting Records - Parent Child One to Many

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 :frowning:

A couple of suggestions when posting questions here:

  1. 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.

  2. Clarion works with a number of database backends. It’s a good idea to specify (Topspeed?, MS SQL?, postgres? … etc…)

Good luck!

Jane

Hi Kajee,

First my condolences for your loss. Good luck with your Clarion learning cycle.

Regarding your code. You can simplify the LOGOUT to:

LOGOUT(20, SALES_ORDER_LINE)

because you are only working with that file.

Few questions

  1. What columns are in your SOL:ORDER_LINE_KEY index?
  2. What database are you using?

First, my condolences on the loss of your father.

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?

good luck with your rapid learning

Geoff R

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

@vitesse @Jane @CarlBarnes @Koen Thank you all for taking the time to reply, I appreciate it.

  1. I believe it is ABC code
  2. In Clarion 11 IDE
  3. 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’

  1. 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)

Hi Kajee,

  1. 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.

  2. You have
    IF ERROR()
    in your code. It might be better to change that into
    IF ERRORCODE()

  3. 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.

Thank you Koen, appreciate the response.

Can you advise on good materials that will be suitable for Legacy code and covers Database access of TPS based database, by any chance ?

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().

2 Likes

@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

1 Like

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.

1 Like

Ahh ok, got them, Thanks