MAINTAIN generic stack coding examples, Cactus code snippets :

For those that haven't heard of Cactus, it was the name used for the IBI Maintain product (client server, and web) in the early Web Focus days. It was later renamed - WebFocus Maintain.

 Add a computed field to a dataBase (bound) stack:
 Creating a non-dataBase (unbound) stack:
 Remove an item from a stack by shifting:
 Remove an item from a stack by copying:
 Add an item to the top of a stack:
 Add a new item into a sorted stack:
 Removing Duplicate items from a stack:
 Position a grid to a new item:
 Add, Change, Delete segment data using COPY:
 Clear a segments fields in the Current Area:

 

Add a computed field to a dataBase (bound) stack:

Compute stkExample.New_Fld/fmt =;

Repeat stkExample.Foccount Cnt=1;
Compute stkExample(Cnt).New_Fld = 'Some Value' ;
Endrepeat Cnt=Cnt+1;

Creating a non-dataBase (unbound) stack:

Compute NewFld_1/I4 =; -* create the Current Area field
NewFld_2/A8 =; -* ????
stkExample.NewFld_1/I4 =;
stkExample.NewFld_2/A8 =;
stkExample(1).NewFld_1 = 1 ;
stkExample(1).NewFld_2 = 'First' ;
stkExample(2).NewFld_1 = 2 ;
stkExample(2).NewFld_2 = 'Second' ;
stkExample(3).NewFld_1 = 3 ;
stkExample(3).NewFld_2 = 'Third' ;

Remove an item from a stack by shifting:

-** Removes a deleted item from the stack by shifting down all the higher items and removing the last one

If stkExample.Foccount EQ 0 Then Goto endcase ;

Compute RemoveItem = stkExample.Focindex ; -* user selected item
SavePlace = If stkExample.Foccount EQ 1 Then 1
Else stkExample.Focindex - 1 ;

If stkExample.Foccount EQ 1 Then 
Compute stkExample.Foccount = 0 ;
Else Begin
Repeat (stkExample.Foccount - RemoveItem) Cnt = RemoveItem ;
For 1 Copy From stkExample(Cnt+1) into stkExample(Cnt) ;
Endrepeat Cnt=Cnt+1;
Compute stkExample.Foccount = stkExample.Foccount - 1 ;
Endbegin ;

Compute stkExample.Focindex = SavePlace ;

Remove an item from a stack by copying:

-** Remove a deleted item from the stack by copying between two stacks with a where clause to remove the item

If stkExample.Foccount EQ 0 Then Goto endcase ;

Compute RemoveItem = stkExample.Key_Field ; -* user selected item

Stack Clear stkWorkSheet
Stack Copy From stkExample Into stkWorkSheet
Where (Key_Field NE RemoveItem);
Stack Clear stkExample
Stack Copy From stkWorkSheet Into stkExample

Add an item to the top of a stack:

-** Increment the stack item count/ Compute stkExample.Foccount = stkExample.Foccount + 1 ;
SavePlace = sstkExample.Focindex ;

-** Shift all the existing items down one, to make room for the new item
Repeat (stkExample.Foccount - 1) Cnt = stkExample.Foccount;
For 1 Copy From stkExample(Cnt-1) into stkExample(Cnt) ;
Endrepeat Cnt=Cnt-1;

-** Move in the new items data from another stack or the Current Area
Copy From CURRENT Into stkExample(1)

-** Or, Setup default field values for the new item 
Compute stkExample.Focindex = 1 ;
stkExample().Fld_One = ' ' ;
stkExample().Fld_Two = ' ' ;
stkExample().Fld_Three = 0 ;

Add a new item into a sorted stack:

-** Add the new item to the bottom of the stack, sort, position to the proper place

Compute stkExample.Foccount = stkExample.Foccount + 1 ;
stkExample.FocIndex = stkExample.Foccount ;
stkExample().Key_Fld1 = Key_Fld1 ;
stkExample().Key_Fld2 = Key_Fld2 ;
stkExample().Fld3 = Fld3 ;
stkExample().Fld4 = Fld4 ;

Stack Sort stkExample By Key_Fld1 Key_Fld2

Repeat stkExample.Foccount Cnt=1;
Compute stkExample.Focindex = Cnt ;
If stkExample(Cnt).Key_Fld1 EQ Key_Fld1 And
stkExample(Cnt).Key_Fld2 EQ Key_Fld2 Then Goto Exitrepeat ;
Endrepeat Cnt=Cnt+1;

Removing Duplicate items from a stack:

-** Move only Unique records to a second stack, after sorting duplicates together


STACK SORT stkExample1 BY UniqueField 
Repeat stkExample1.foccount Cnt=1;
If Cnt = 1 Then Begin 
  COPY FROM stkExample1(Cnt) INTO stkExample2(Cnt2) 
  Compute Cnt2=Cnt2+1; 
  EndBegin 
Else Begin 
  If stkExample1(Cnt).UniqueField NE stkExample1(Cnt-1).UniqueField Then Begin 
    COPY FROM stkExample1(Cnt) INTO stkExample2(Cnt2) 
    Compute Cnt2=Cnt2+1; 
    EndBegin 
  EndBegin 
EndRepeat Cnt=Cnt+1;

Position a grid to a new item:

-** Add the new Position name to the stack

Compute NxCnt = stkExample.Foccount+1 ;
Copy From CURRENT Into stkExample(NxCnt)
Stack Sort stkExample By KeyName

-** Reposition the Example Stack and Grid to the new item

Repeat stkExample.Foccount Cnt=1;
Compute stkExample.Focindex = Cnt ;
If stkExample(Cnt).KeyName EQ NewKeyName Then Goto Exitrepeat ;
Endrepeat Cnt=Cnt+1;

Compute FrmExample.GrdExample.CurStkRowNum = stkExample.Focindex ;
WINFORM SET FrmExample.GrdExample.FOCUS TO HERE

Add, Change, Delete segment data using COPY:

-** (from Cactus Help Example)The following takes data from one stack and places it into three stacks, one to add data, one to delete data, and one to update data.

FOR ALL COPY FROM Inputstk INTO Addstk WHERE Flag EQ 'A'
FOR ALL COPY FROM Inputstk INTO Delstk WHERE Flag EQ 'D'
FOR ALL COPY FROM Inputstk INTO Chngstk WHERE Flag EQ 'C'
FOR ALL INCLUDE Dbfield FROM Addstk
FOR ALL DELETE Dbfield FROM Delstk
FOR ALL UPDATE Dbfield1 Dbfield2 FROM Chngstk

Clear a segments fields in the Current Area:

-** (from InfoElite News) Infer a Stack and create an empty row to use in clearing fields

Infer Key_Fld1 Into stkNullExample 
Compute stkNullExample.Foccount = stkNullExample.Foccount + 1 ;
...
Copy From stkNullExample() Into CURRENT