It seems that every day I get a call to do something new.
Today's newness is this: The client is in the habit of writing returns that have the same document number as the corresponding invoice. In practice, most invoices have a small return.
These are all sitting in the RM Open table, unapplied. Lots of them.
Task: Create a stored procedure that will search the RM20101 (RM Open) table and return all matching unapplied credits and invoices, and then automatically apply them.
Care to comment on my approach? Can you improve the code?
The working stored procedure is below, fully commented.