Login Register Actian.com  

Actian Community Forum


Go Back   Actian Community Forums > Development Tools > Application Development using OpenROAD
 

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 2012-06-15   #1 (permalink)
Ingres Community
 
komathi's Avatar
 
Join Date: Sep 2007
Location: OpenROAD (SL)
Posts: 42
Question how to assign Value to Dynamic Column with Row number

Hi

I have created some dynamic columns on a table (first two columns are fixed colums - i.e employee_no, empname & others are going to be dynamic columns). On the dynamic columns,(with different row number) I am trying to assign 'hoursworked' for each employees.

This line is just assigning the value for the whole column :
"EntryField(columnfield(field(emp_tbl).TableBody.C hildFields[Li_Posn]).ProtoField).TextValue = varchar(Lu_tax.arrEmps[li_n].SalaryAmt);"

Can anyone have any idea how to specify the row number on the above line?

Thanks in advance.

This is My Full Code Block:

For li_n=1 to Lu_tax.arrhisped.Lastrow() do
emp_tbl[li_n].employee_no = employee_no; //---------------------------> column 1
emp_tbl[li_n].empname = Lu_tax.arrEmps[li_n].fullname;//----------> column 2

Li_Posn = 3; //----------> column position 3 (start creating dynamic column from column 3 on emp_tbl)

IF li_n = 1 THEN //-- emp_tbl: creating columns only once

for li_ctn=1 to Li_ColumCount do

//--creating an entryfield & adding into emp_tbl
efields = EntryField.Create();
colname = 'hr_wk'+varchar(li_ctn);
efields.fullname = colname;
efields.Name = colname;
efields.DataType = templ_fields.DataType;
efields.IsMultiLine = templ_fields.IsMultiLine;
efields.OuterHeight = templ_fields.OuterHeight;
efields.Width = templ_fields.Width;
efields.FormatString = templ_fields.FormatString;
efields.textvalue = varchar(1000*li_ctn);
efields.isbold = templ_fields.isbold;
efields.TypeFace = templ_fields.TypeFace;
efields.TypeSize = templ_fields.TypeSize;
efields.ExactWidth = templ_fields.ExactWidth;
efields.BgColor = templ_fields.BgColor;

field(emp_tbl).InsertColumn(fieldtoinsert = efields, position = Li_Posn, title = colname);

EntryField(columnfield(field(emp_tbl).TableBody.Ch ildFields[Li_Posn]).ProtoField).TextValue = varchar(Lu_tax.arrEmps[li_n].hoursworked);

Li_Posn = Li_Posn +1;

endfor;
ELSE
//--this is to enter 2nd, 3rd, 4th....nth rows

for li_ctn=1 to Li_ColumCount do

EntryField(columnfield(field(emp_tbl).TableBody.Ch ildFields[Li_Posn]).ProtoField).TextValue = varchar(Lu_tax.arrEmps[li_n].hoursworked);
Li_Posn = Li_Posn +1;
endfor;
ENDIF;

Endfor;

Last edited by komathi; 2012-06-15 at 02:28 AM.
komathi is offline   Reply With Quote
Old 2012-06-15   #2 (permalink)
Actian Corp
 
Join Date: Mar 2007
Location: On the OpenROAD
Posts: 1,713
Default

You want to assign values to different attributes of different rows of the underlying array.
Therefore you have to access the underlying data rather than field/cell attributes.
E.g. "TextValue" is not even a CellAttribute attribute, so you can't set it for individual cells.

What you have to do is:
Assign the values to the according row/attribute in the "emp_tbl" array, e.g. if the class of emp_tbl already contains attributes like hr_wk1, hr_wk2 etc.
Or you can use dynamic expressions (DynExpr class objects) to assign the values.
Bodo is offline   Reply With Quote
Old 2012-06-15   #3 (permalink)
Ingres Community
 
komathi's Avatar
 
Join Date: Sep 2007
Location: OpenROAD (SL)
Posts: 42
Question

emp_tbl is a Tablefield;

I used dynamic expression but it returning it as null;

code block :
-------------
colname = columnfield(field(emp_tbl).TableBody.ChildFields[Li_Posn]).Name; //--dynamically created column

dynamic_exp = CurFrame.Scope.CreateDynExpr ( string = 'emp_tbl['+varchar(li_n)+'].'+colname);
IF dynamic_exp IS NOT NULL THEN
dynamic_exp.SetValue(value = 10.00);
ENDIF;

I would like to attach my working frame for you to have a look - please find the attachment.

When you run the attached frame - the colored cells are assigned with the same values (i.e row 1 value is change on the row 2 then row 1&2 values go as row3 value ..). Can you please help me.

Thank you again..
Attached Files
File Type: zip fm_dynamic_table.zip (21.7 KB, 1 views)

Last edited by komathi; 2012-06-15 at 05:03 AM.
komathi is offline   Reply With Quote
Old 2012-06-15   #4 (permalink)
Actian Corp
 
Join Date: Mar 2007
Location: On the OpenROAD
Posts: 1,713
Default

Ok, I had a look at your frame.
The tablefield has no datatype assigned, that is the underlying class of the array will be built dynamically.
If you add columns to the tablefield you will also have to recreate the underlying array, otherwise the new columns could not be mapped to attributes of the rows of the array.

What you need to do is:
1. Set the "Declared" attribute of emp_tbl to FALSE (so no initial array will be created)
2. Use one FOR loop to create your new columns (without assigning any data)
3. Use "FIELD(emp_tbl).DeclareData();" to create the underlying array.
4. Use a FOR loop to create rows and assign data to emp_tbl using dynamic expressions or the SetAttribute() method.
Bodo is offline   Reply With Quote
Old 2012-06-15   #5 (permalink)
Actian Corp
 
Join Date: Mar 2007
Location: On the OpenROAD
Posts: 1,713
Default

Here is an example of how to do it, based on the frame you provided
It uses SetAttribute() method rather than DynExpr.
Code:
PROCEDURE Pi_LoadAll()=
Declare
    li_n = Integer Not Null;
    lv_Dt = varchar(20) Not Null;
    Lv_pre_period_end_date = varchar(20) Not Null;
    li_ctn = Integer Not Null;
    templ_fields = EntryField;
    Li_ColumCount = Integer Not Null;
    colname= varchar(100) Not null;
    efield = ENTRYFIELD DEFAULT NULL;
    emp_tbl_arr = ARRAY OF Object DEFAULT NULL;
EndDeclare
{
 periods_tbl.clear();
 Lfd_tbl = field(emp_tbl);
 templ_fields = field(tax_paid_copy);
 
 For li_n=1 to 10 do
       lv_Dt =''; 
       lv_Dt = VARCHAR(li_n)+'/01/1991';
       lv_Dt = Left(lv_Dt, Length(lv_Dt)-3);
       Lv_pre_period_end_date='';
       Lv_pre_period_end_date = lv_Dt;

    periods_tbl[li_n].pay_period ='Period:'+ HC_Newline + :Lv_pre_period_end_date;
    periods_tbl[li_n].full_tx_total_of_pay_period = 5000*li_n;
    Field(periods_tbl).NumVisibleRows = li_n;   
    Li_ColumCount = li_n;
 Endfor;

 FIELD(periods_tbl).UpdField();

 if FIELD(emp_tbl).Declared = TRUE then
    FIELD(emp_tbl).UndeclareData();
 endif;
 // Adding columns
 for li_n=1 to Li_ColumCount do
    efield = templ_fields.Duplicate();
    colname = 'hrs_wk'+varchar(li_n);
    efield.Name = colname;
    efield.FgColor = CC_YELLOW;
    IF li_n =1 THEN
        efield.BgColor = CC_RED;
    ELSEIF li_n=2 THEN
        efield.BgColor = CC_GREEN;
    ELSEIF li_ctn !=2 THEN
        efield.BgColor = CC_BLUE;
    ENDIF;
    field(emp_tbl).InsertColumn(fieldtoinsert = efield, position = li_n+2, title = colname); 
 endfor;

 // Creating the array
 FIELD(emp_tbl).DeclareData(result=byref(emp_tbl_arr));
 FIELD(emp_tbl).Declared = TRUE;
 emp_tbl_arr.clear();

 // Loading data
 For li_n=1 to 10 do 
  emp_tbl_arr.InsertRow(rownumber=li_n);    
  emp_tbl_arr[li_n].SetAttribute(employee_no = 10000+li_n, empname = 'Employee'+varchar(li_n));

  for li_ctn=1 to Li_ColumCount do
	colname = 'hrs_wk'+varchar(li_ctn);
	 // I added li_n to demonstrate different values  in different lines
	emp_tbl_arr[li_n].SetAttribute(:colname = 350*li_ctn + li_n);
  endfor;
 Endfor;
 Field(emp_tbl).NumVisibleRows = 10;
}
Bodo is offline   Reply With Quote
Old 2012-06-17   #6 (permalink)
Ingres Community
 
komathi's Avatar
 
Join Date: Sep 2007
Location: OpenROAD (SL)
Posts: 42
Default

Hi Bodo

Thank you so much for your assistance.

I still have problem:

Line :
FIELD(emp_tbl).DeclareData(result=byref(emp_tbl_ar r));

The trace says :
------------------------------------------------------------------------------------
E_PW009F The 'declaredata' method failed on the field 'emp_tbl'. A
subsequent message should give more information.

E_PW009A The 'declaredata' method was invoked on the field 'emp_tbl', but
the field 'emp_tbl' is already declared.
------------------------------------------------------------------------------------
komathi is offline   Reply With Quote
Old 2012-06-18   #7 (permalink)
Actian Corp
 
Join Date: Mar 2007
Location: On the OpenROAD
Posts: 1,713
Default

Have you followed the first step of my instructions?
1. Set the "Declared" attribute of emp_tbl to FALSE (so no initial array will be created)
This has to be done in the Property Inspector rather than in the code.
Bodo is offline   Reply With Quote
Old 2012-06-18   #8 (permalink)
Ingres Community
 
komathi's Avatar
 
Join Date: Sep 2007
Location: OpenROAD (SL)
Posts: 42
Default

once I set the "Declared" attribute of emp_tbl to FALSE in the design mode - worked well.

THANK YOU so much bodo.
komathi is offline   Reply With Quote
Old 2012-06-19   #9 (permalink)
Ingres Community
 
komathi's Avatar
 
Join Date: Sep 2007
Location: OpenROAD (SL)
Posts: 42
Default

Hi,

Why I am unable to delete the rows or columns of the undeclared tablefield (emp_tbl) fully?

The below code block removing all the generated columns but the last column not removed (i.e '%total_hrs%' ) from the tablefield.

/* REMOVE DYNAMiCALLY GENERATED COLUMNS FROM TABLEFiLED (iF ANY) EXCEPT FiRST 2 COLUMN */

While FIELD(emp_tbl).TableBody.ChildFields.LastRow is not NULL Do
lv_attrname = FIELD(emp_tbl).TableBody.ChildFields[i].Name;

IF FIELD(emp_tbl).TableBody.ChildFields.LastRow = 2 THEN
endloop;
ENDIF;

IF FIELD(emp_tbl).TableBody.ChildFields.LastRow = 3 THEN
IF lv_attrname LIKE '%empname%' THEN
endloop;
ENDIF;
ENDIF;

IF lv_attrname LIKE '%hrs_wk%' THEN
FIELD(emp_tbl).DeleteColumn(position = FIELD(emp_tbl).TableBody.ChildFields.FirstRow + i);
FIELD(emp_tbl).UpdField();
i=i-1;
ELSEIF lv_attrname LIKE '%total_hrs%' THEN //--Final Column to show the Full Total of each emp worked hours (on the right side)
Li_ColumnNumber = ColumnField(field(emp_tbl).TableBody.ChildFields[i]).ColumnNumber;
FIELD(emp_tbl).DeleteColumn(position = :Li_ColumnNumber);
FIELD(emp_tbl).UpdField();
i=i-1;
ENDIF;
ENdWhile;

Last edited by komathi; 2012-06-19 at 08:57 PM.
komathi is offline   Reply With Quote
Old 2012-06-20   #10 (permalink)
Actian Corp
 
Join Date: Mar 2007
Location: On the OpenROAD
Posts: 1,713
Default

You use:
Quote:
While FIELD(emp_tbl).TableBody.ChildFields.LastRow is not NULL
LastRow is defined as integer not null, therefore it will never be NULL.
Later you do
Quote:
FIELD(emp_tbl).DeleteColumn(position = FIELD(emp_tbl).TableBody.ChildFields.FirstRow + i);
FirstRow is 1 and I assume that you start with i=LastRow, that is you try to delete column lastrow+1, which doesn't exist.
Why aren't you deleting just column i?
And why a WHILE loop and decrementing the variable i rather than using a FOR loop? Something like this:
Code:
FOR i=FIELD(emp_tbl).TableBody.ChildFields.LastRow DOWNTO 3 DO
    FIELD(emp_tbl).DeleteColumn(position = i);
ENDFOR;
Bodo is offline   Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


© 2011 Actian Corporation. All Rights Reserved