          SUBROUTINE (LASTSALE,REQ)
** Version# 5.0003[28] - 10/03/2013 - 11:06pm - TSMITH - eclipse
*** V5.0003 Change - Custom Coding CUSTOM - 10/03/2013 - TSMITH - eclipse
** Copied from CBP DICT.PRD.LASTSALEQTY Version# 5.0002[4] - 10/03/2013 - 09:37pm - TSMITH - eclipse
*** V5.0002 Change - Custom Coding CUSTOM - 10/03/2013 - TSMITH - eclipse
** Copied from BP DICT.PRD.LASTSALE Version# 5 - 06/09/1997 - 05:37pm - STEELI - develop

          LASTSALE = ''
          PN = @ID


          IF SEL.BR = '' THEN SEL.BR = SECURITY<9>

          BRN = DCOUNT(SEL.BR,VM)

          FOR BRX=1 TO BRN
          BR = SEL.BR<1,BRX>
          GOSUB GETLS
          IF LS > LASTSALE THEN LASTSALE = LS
          NEXT BRX

          RETURN
*-------------------------------------------------------------------------*
GETLS:    LS = ""
          ROOT = PN:'~':BR:'~z'
          LOOP
          BSCAN PSID FROM PSUBFILE,ROOT USING '&INDEX&' BY 'D' ELSE EXIT
          ROOT = ''
          IF FIELD(PSID,'~',1)#PN THEN EXIT
          IF FIELD(PSID,'~',2)#BR THEN EXIT
          OID  = FIELD(PSID,'~',4)
          IF OID[1,1]='S' THEN
             INVN = FIELD(PSID,'~',5)
             READV GEN.IDX FROM LEDFILE,OID,8 ELSE GEN.IDX = ''
             LOCATE INVN IN GEN.IDX<1> SETTING GEN ELSE GEN = 1
             READV STAT.LIST FROM LEDFILE,OID,6 ELSE STAT.LIST = ''
             IF STAT.LIST<1,GEN> = "I" THEN
             IF REQ = "QTY" THEN
             LS = TRANS('PSUB',PSID,1,'X')
             END ELSE
             IF REQ = "ORD" THEN
             LS = FIELD(PSID,'~',4):'.':FIELD(PSID,'~',5) "R%3"
             END ELSE
             IF REQ = "BR" THEN
             LS = FIELD(PSID,'~',2)
             END ELSE
             LS = FIELD(PSID,'~',3)
             END
             END
             END
                EXIT
             END
          END
          REPEAT
          RETURN
!TSMITH~10/03/13~23:06
