Bei einem gemeinsamen (virtuellen) Frühstück ein paar Tipps und Tricks rund um Sage b7 erfahren? - Termin verpasst? - Jetzt nachlesen!
Bei unserem nächsten Anwenderfrühstück geht es um die Verwendung sog. Hashtabellen.
Eine Hashtabelle hilft beim schnellen Auffinden von Datenobjekten in großen Tabellen.
Der Zeitaufwand dafür bleibt konstant und ist unabhängig von der Tabellengröße.
Datei: saw_anwf_240523.cdt
define sawtest {
string stlidentnr,
int stufe,
}
Datei: saw_anwf_240523.bsl
include saw_anwf_240523.cdt
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_01()
{
string keyL
string valueL
call boa_ht_create("saw")
keyL = "Andreas"
valueL = "Hamburg"
call boa_ht_put("saw", keyL, valueL)
keyL = "Bernd"
valueL = "München"
call boa_ht_put("saw", keyL, valueL)
keyL = "Charlie"
valueL = "Dortmund"
call boa_ht_put("saw", keyL, valueL)
keyL = "Dieter"
valueL = "Osnabrück"
call boa_ht_put("saw", keyL, valueL)
keyL = "Egon"
valueL = "Essen"
call boa_ht_put("saw", keyL, valueL)
msg emsg boa_ht_get ("saw", "Bernd")
msg emsg boa_ht_get ("saw", "Friedrich", "unbekannt")
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_02()
{
string keyL
string valueL
call boa_ht_create("saw")
keyL = "Andreas"
valueL = "Hamburg"
call boa_ht_put("saw", keyL, valueL)
keyL = "Bernd"
valueL = "München"
call boa_ht_put("saw", keyL, valueL)
keyL = "Charlie"
valueL = "Dortmund"
call boa_ht_put("saw", keyL, valueL)
keyL = "Dieter"
valueL = "Osnabrück"
call boa_ht_put("saw", keyL, valueL)
keyL = "Egon"
valueL = "Essen"
call boa_ht_put("saw", keyL, valueL)
// key- und value - Ziele in Anführungszeichen
call boa_ht_iterator("saw", "keyL", "valueL")
while (boa_ht_next("saw") == OK)
{
msg emsg "keyL <:keyL> valueL <:valueL>"
}
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_03()
{
string keyL
string valueL
call boa_ht_create("saw")
// Key: stlnr
// Value: stufe^identnr
keyL = "1"
valueL = "10^11000011"
call boa_ht_put("saw", keyL, valueL)
keyL = "2"
valueL = "9^11000022"
call boa_ht_put("saw", keyL, valueL)
keyL = "3"
valueL = "8^11000033"
call boa_ht_put("saw", keyL, valueL)
keyL = "4"
valueL = "7^11000044"
call boa_ht_put("saw", keyL, valueL)
keyL = "5"
valueL = "7^11000055"
call boa_ht_put("saw", keyL, valueL)
// unsortiert
call boa_ht_iterator("saw", "keyL", "valueL")
while (boa_ht_next("saw") == OK)
{
msg emsg "keyL <:keyL> valueL <:valueL>"
}
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_04()
{
string keyL
string valueL
call boa_ht_create("saw")
// Key: stlnr
// Value: stufe^identnr
keyL = "1"
valueL = "10^11000011"
call boa_ht_put("saw", keyL, valueL)
keyL = "2"
valueL = "9^11000022"
call boa_ht_put("saw", keyL, valueL)
keyL = "3"
valueL = "8^11000033"
call boa_ht_put("saw", keyL, valueL)
keyL = "4"
valueL = "7^11000044"
call boa_ht_put("saw", keyL, valueL)
keyL = "5"
valueL = "7^11000055"
call boa_ht_put("saw", keyL, valueL)
// Sortierung nach Stufe aufsteigend
call boa_ht_sort_iterator("saw", "keyL", "valueL", "Vi^1")
while (boa_ht_next("saw") == OK)
{
msg emsg "keyL <:keyL> valueL <:valueL>"
}
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_05()
{
string keyL
string valueL
call boa_ht_create("saw")
// Key: stlnr
// Value: stufe^identnr
keyL = "1"
valueL = "10^11000011"
call boa_ht_put("saw", keyL, valueL)
keyL = "2"
valueL = "9^11000022"
call boa_ht_put("saw", keyL, valueL)
keyL = "3"
valueL = "8^11000033"
call boa_ht_put("saw", keyL, valueL)
keyL = "4"
valueL = "7^11000044"
call boa_ht_put("saw", keyL, valueL)
keyL = "5"
valueL = "7^11000055"
call boa_ht_put("saw", keyL, valueL)
// Sortierung nach Stufe aufsteigend, Teilenummer aufsteigend
call boa_ht_sort_iterator("saw", "keyL", "valueL", "Vi^1, V^2")
while (boa_ht_next("saw") == OK)
{
msg emsg "keyL <:keyL> valueL <:valueL>"
}
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_06()
{
string keyL
string valueL
call boa_ht_create("saw")
// Key: stlnr
// Value: stufe^identnr
keyL = "1"
valueL = "10^11000011"
call boa_ht_put("saw", keyL, valueL)
keyL = "2"
valueL = "9^11000022"
call boa_ht_put("saw", keyL, valueL)
keyL = "3"
valueL = "8^11000033"
call boa_ht_put("saw", keyL, valueL)
keyL = "4"
valueL = "7^11000044"
call boa_ht_put("saw", keyL, valueL)
keyL = "5"
valueL = "7^11000055"
call boa_ht_put("saw", keyL, valueL)
// Sortierung nach Stufe absteigend, Teilenummer aufsteigend
call boa_ht_sort_iterator("saw", "keyL", "valueL", "Vi^1 desc, V^2")
while (boa_ht_next("saw") == OK)
{
msg emsg "keyL <:keyL> valueL <:valueL>"
}
call boa_ht_discard("saw")
return OK
}
#-------------------------------------------------------------------------------
int proc saw_anwf_240523_07()
{
vars htNameL = "sawtests"
vars sawtestL
vars keyL
call boa_ht_create(htNameL)
// Key: stlnr
// Value: cdt sawtest
sawtestL = new sawtest()
sawtestL=>stlidentnr = '11000011'
sawtestL=>stufe = 10
call boa_ht_put(htNameL, 1, sawtestL)
sawtestL = new sawtest()
sawtestL=>stlidentnr = '11000022'
sawtestL=>stufe = 9
call boa_ht_put(htNameL, 2, sawtestL)
sawtestL = new sawtest()
sawtestL=>stlidentnr = '11000033'
sawtestL=>stufe = 8
call boa_ht_put(htNameL, 3, sawtestL)
sawtestL = new sawtest()
sawtestL=>stlidentnr = '11000055'
sawtestL=>stufe = 7
call boa_ht_put(htNameL, 4, sawtestL)
sawtestL = new sawtest()
sawtestL=>stlidentnr = '11000044'
sawtestL=>stufe = 7
call boa_ht_put(htNameL, 5, sawtestL)
sawtestL = new sawtest()
// Sortierung nach Stufe absteigend, STL-Identnr
call boa_ht_sort_iterator(htNameL, "keyL", "sawtestL", "V=>stufe desc, V=>stlidentnr")
while (boa_ht_next(htNameL) == OK)
{
msg emsg "keyL <:keyL> sawtestL=>stufe <:(sawtestL=>stufe )> sawtestL=>stlidentnr <:(sawtestL=>stlidentnr)>"
}
call boa_ht_discard(htNameL)
}