PRIVATE mnozstvi, c_karty
SELECT davka
SCAN
   SCATTER FIELDS c_karty, mnozstvi MEMVAR 
   SELECT buffer
   LOCATE FOR c_karty = m.c_karty
   IF FOUND()
        ubrat = MIN(mnozstvi, m.mnozstvi)
        REPLACE mnozstvi WITH mnozstvi - m.ubrat
   ELSE
        SELECT davka 
   ENDIF 
ENDSCAN 
SELECT buffer
DELETE FOR mnozstvi = 0
