Thank you for the help. See attached for the solution. The last select could be deleted and just use l1docid field as a flag field.
PROCEDURE coretest
SET DELETED OFF
SELECT ;
Sllines.descrip, ;
Sllines.originli, ;
Sllines.doctype, ;
Sllines.docid, ;
Sllines.item, ...