user11708103
user11708103

Reputation:

Infinite loop in procedure genexus

I have one table called Categoria that have CategoriaId primary key and CategoriaPaiId foreign-key with auto-relationship with CategoriaId.

I need to create a procedure that returns a tree of categories.

Supossing that i have this categories with this subcategories:

Perishable > Drinks > Wine > Red

In register Drinks, i need that the variable &CategoriaSubCategoriaNome returns this varchar:

Perishable> Drinks.

In register Red, i need that return in the variable &CategoriaSubCategoriaNome the string:

Perishable> Drinks> Wines

This is the procedure that i have created:

&isTrue = true
&isAchou = true
do while &isTrue = true
    if &isAchou = true
            &isAchou = false    
            for each
                where CategoriaId = &CategoriaPaiId
                &CategoriaSubCategoriaNome = &CategoriaSubCategoriaNome+ " > " + CategoriaNome
                &isAchou = true
            endfor
        if &isAchou = false
            return
        endif
    endif
enddo

But i'm getting a infinite loop in this procedure.

Upvotes: 0

Views: 262

Answers (2)

Pablo
Pablo

Reputation: 71

I would resolve it recurrently:

Proc: CategoryList

Rules:

Parm(in:&CategoriaId, out:&CategoriaStr);

Source:

for each Categoria
where CategoriaId = &CategoriaId
if CategoriaPaiId.IsEmpty()
    &CategoriaStr = CategoriaNome
else
    &CategoriaStr = CategoryList(CategoriaPaiId) + !" > " + CategoriaNome
endif
when none
    &CategoriaStr.SetEmpty()
endfor

Upvotes: 0

gusbro
gusbro

Reputation: 22585

I'm not sure of the structure of your transactions. For this answer I show you how to get the category name hierarchy using a formula:

Transaction Category:

CategoryId*
CategoryName
CategoryFullName  formula: GetCategoryFullName(CategoryId)
CategoryParentId  <nullable=Yes>
CategoryParentName

Subtype Group CategoryParentGroup

CategoryParentId* sbt CategoryId
CategoryParentName sbt CategoryName

Procedure GetCategoryFullName

in Rules: parm(in: CategoryId, out: &CategoryFullName)

in Source:

for each
    &CategoryFullName = iif(CategoryParentId.IsNull(), 
                            CategoryName, 
                            GetCategoryFullName(CategoryParentId) + !' > ' + CategoryName)
endfor

Upvotes: 1

Related Questions