 vars dokuarten = "DMATE"
        
        vars ergebnis = api_function( "string_get_position", dokuarten, dokuart_kurz, 1, 1 )
        
        if ( ergebnis > 0 )
        {
                vars i, ar_temp = " ( ", ma_temp = " ( ", ar_hilf = 0, ma_hilf = 0, sql_where = "", sql_or = "", anzahl
                vars artikel[ CUR_60ER_FIELD_NR ], material[ CUR_60ER_FIELD_NR ]
                
                for i = 1 while i <= CUR_60ER_FIELD_NR step 1
                {
                        if ( dok_dat_feld_61[ i ] != "" )
                        {
                                ar_temp = ar_temp ## " MAT_NUMMER = '" ## dok_dat_feld_61[ i ] ## "' OR "
                                ar_hilf = 1
                        }
                        else
                        {
                                break
                        }
                }
                
                for i = 1 while i <= CUR_60ER_FIELD_NR step 1
                {
                        if ( dok_dat_feld_60[ i ] != "" )
                        {
                                ma_temp = ma_temp ## " MA_NUMMER = '" ## dok_dat_feld_60[ i ] ## "' OR "
                                ma_hilf = 1
                        }
                        else
                        {
                                break
                        }
                }
                
                
                
                
                if ( ( ar_hilf != 0 ) || ( ma_hilf != 0 ) )
                {
                        sql_where = " where "
                }
                
                if ( ar_hilf == 1 )
                {
                        ar_temp = ar_temp( 1, @length( ar_temp ) - 3 ) ## " ) "
                        sql_where = sql_where ## ar_temp
                        sql_or    = " or "
                }
                
                if ( ma_hilf == 1 )
                {
                        ma_temp = ma_temp( 1, @length( ma_temp ) - 3 ) ## " ) "
                        sql_where = sql_where ## sql_or ## ma_temp
                }
                
                if ( @length( sql_where ) > 0 )
                {
                        //call xlog( 1, "where " ## sql_where )
                        dbms alias material, artikel
                        dbms sql select MA_NUMMER, MAT_NUMMER from NEXUS_ERP_MATERIAL :sql_where
                        anzahl = @dmrowcount
                        dbms alias
                        
                        
                        if ( anzahl > 0 )
                        {
                                for i = 1 while i <= anzahl step 1
                                {
                                        if ( material[ i ] != "" )
                                        {
                                                //call xlog( 1, ":i material " ## material[ i ] ## " artikel " ## artikel[ i ] )
                                                dok_dat_feld_60[ i ] = material[ i ]
                                                dok_dat_feld_61[ i ] = artikel[ i ]
                                        }
                                        else
                                        {
                                                break
                                        }
                                }
                        }
                }
                
        }