RBKP is not useful? that is the invoices main table...
Anyhow getting the data using the value_new without an index on it will be very slow since CDPOS is usually a very big table. so try using CDHDR for the first selection -> use the object class and key to limit first the selection and then select from CDPOS, I think this way will work faster since in the second selection you can use the keys of CDPOS for all entries found in CDHDR.