This does something different for CONSIGNM types - I don't remember the details re those.
! Find invoice number based on P/O number
FIND_INVOICE:
if not(cOpenInvoiceFH) then {
cOpenInvoiceFH=coSession'opentable(""AR_OPENINVOICE"",""COMPANY"")
}
IF STP(IMP$[5])=""CONSIGNM"" then BAB_INVOICE$=MID(IMP$[3],22,8) ELSE BAB_INVOICE$=stp(IMP$[5]) ! default to PO Number in import file
BAB_INVOICE_TYP$=""IN""
IF STP(IMP$[5])=""CONSIGNM"" then CHECK_INVOICE$=MID(IMP$[3],22,8) ELSE CHECK_INVOICE$=stp(IMP$[5])
SELECT *,rec=tmp$ FROM cOpenInvoiceFH begin ARDivisionNo$+CustomerNumber$+$$ end ARDivisionNo$+CustomerNo$+$FE$ where CHECK_INVOICE$=tmp.CustomerPONo$
BAB_INVOICE$=tmp.InvoiceNo$
BAB_INVOICE_TYP$=tmp.InvoiceType$
BREAK ! leave loop if finds first occurance
NEXT RECORD
RETURN
CLOSE_FILE:
Close(cOpenInvoicetmpFH,ERR=*next)
cOpenInvoicetmpFH=0
RETURN