* vyplni kod EAN12 pro karty, ktere nemaji druh_kalk, co z pocitam, ze v MTZ jsou vsechny karty,
* se kterymi se bude s carovym kodem pracovat



#DEFINE EAN_PREFIX "7410"

max_kod = EAN_PREFIX + REPLICATE("0", 12-LEN(EAN_PREFIX))
SELECT MAX(kod) as max_kod WHERE LEFT(kod, LEN(EAN_PREFIX)) = EAN_PREFIX ;
       FROM karty INTO CURSOR max_kod

IF RECCOUNT() > 0
    IF LEFT(max_kod, LEN(EAN_PREFIX)) = EAN_PREFIX
        SCATTER MEMVAR 
    ENDIF 
ENDIF 

n_max_kod = INT(VAL(m.max_kod))

SELECT karty
SET FILTER TO 
SCAN FOR EMPTY(druh_kalk) .and. EMPTY(karty.kod)
    n_max_kod = n_max_kod + 1
    REPLACE kod WITH ALLTRIM(STR(m.n_max_kod,15))
ENDSCAN 
? m.n_max_kod