SET DELETED ON
CLOSE ALL
CLEAR
DIMENSION NIZ(100),RECI(100)
USE \\ATHLON64\D\BELCAR\BAZE\ROBA ALIAS ROBA IN 0
SELECT ROBA
SET ORDER TO TAG SIFROB
GOTO TOP
USE \\ATHLON64\D\BELCAR\BAZE\PROIZVOD ALIAS PROIZVOD IN 0
SELECT PROIZVOD
SET ORDER TO TAG SIFRA
GOTO TOP
USE \\ATHLON64\D\BELCAR\BAZE\GRUPA ALIAS GRUPA IN 0
SELECT GRUPA
SET ORDER TO TAG GRUPA
GOTO TOP

USE \\ATHLON64\D\BELCAR\BAZE\KLJUCNE ALIAS KLJUCNE IN 0
SELECT KLJUCNE
SET ORDER TO TAG KLJUCNE
ZAP
SELECT ROBA
GOTO TOP
ko=1
DO WHILE !EOF()
A=ROBA.SIFROB
B=ALLTRIM(ROBA.NAZIV)
C=ROBA.PROIZVOD
D=ROBA.GRUPA
*?A,B
*?c,d
K=OCCURS(" ",B)
ML=LEN(B)
ODAKLE=1
	FOR I=1 TO K
		NIZ(I)=AT(" ",B,I)
		RECI(I)=SUBSTR(B,ODAKLE,NIZ(I)-ODAKLE)
		**?RECI(I)
		ODAKLE=NIZ(I)+1
	NEXT I	
	RECI(K+1)=SUBSTR(B,ODAKLE,ML-ODAKLE+1)
	*?RECI(K+1)
	FOR I=1 TO K+1
		SELECT KLJUCNE
		GOTO TOP
		SEEK A+RECI(I)
		IF !FOUND()
			APPEND BLANK
			REPLACE KLJUCNE.SIFROB 	WITH A
			REPLACE KLJUCNE.REC		WITH RECI(I)
		ENDIF
	NEXT I
SELECT PROIZVOD
GOTO TOP
SEEK C
IF FOUND()
	SELECT KLJUCNE
	APPEND BLANK
	REPLACE KLJUCNE.SIFROB 	WITH A
	REPLACE KLJUCNE.REC 	WITH PROIZVOD.NAZIV
ENDIF

SELECT GRUPA
GOTO TOP
SEEK D
IF FOUND()				
	SELECT KLJUCNE
	APPEND BLANK
	REPLACE KLJUCNE.SIFROB 	WITH A
	REPLACE KLJUCNE.REC 	WITH GRUPA.NAZIV
ENDIF
	
ko=ko+1
IF ko>10
**	EXIT
ENDIF

		
SELECT ROBA
SKIP
	
ENDDO
		
