#!/home/onyx/bin/onyx

database icd%ingres@durruti;

# -----------------------------------------------------------------------------

table save
	prim	int	5,
	sek	int	2;

table icd
	prim	int	5,
	sek	int	2,
	short	char	30,
	long	char	80;

# -----------------------------------------------------------------------------

program Stammdaten;

menu mask Abfrage by icd
	"",
	" Nummer : $     $",
	" Name   : $ ",
	"        : $ ",
	"";
fields
	 prim:suche_prim,
	 sek:suche_sek,
	 short:suche_short,
	 long:suche_long;

transaction suche_prim {
	if not icd.prim then break;

	set save.prim = $icd.prim;

	import icd from
		select	primcode,sekcode,short,long
		fromr	icd
		where	primcode = $icd.prim;

	if not valid icd
	then 
		set icd.prim = $save.prim;
	}

transaction suche_sek {
	if not icd.sek then break;

	set save.prim = $icd.prim;
	set save.sek = $icd.sek;

	import icd from
		select	primcode,sekcode,short,long
		fromr	icd
		where	primcode = $icd.prim
		and	sekcode  = $icd.sek;

	if not valid icd
	then 
		set icd.prim = $save.prim;
	and
		set icd.sek = $save.sek;
	}

transaction suche_short {
	if not icd.short then break;

	import icd from
		select	primcode,sekcode,short,long
		fromr	icd
		where	short like "$icd.short";
	}

transaction suche_long {
	if not icd.long then break;

	import icd from
		select	primcode,sekcode,short,long
		fromr	icd
		where	short like "$icd.long";
	}

menu transaction Speichern {
	if not icd.prim then break;
	if not icd.sek then break;

	if valid icd
	then
		update	icd
		set 	long = "$icd.long",
			short= "$icd.short"
		where	primcode = $icd.prim
		and	sekcode  = $icd.sek;
	else
		insert into icd ( primcode, sekcode, short, long )
		values ( $icd.prim,
			 $icd.sek,
			"$icd.short",
			"$icd.long");

	validate icd;
	}
