Search code examples
proceduregenexus

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.


Solution

  • 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