Maybe you already had the “joy” to find out that accessing the “Row Selector” column of an updateable tabular form isn’t that straightforward as expected. Because the corresponding g_f01 array isn’t indexed by row number as the other column-arrays of the tabular form.
Instead it contains as many values as you have checked rows. The value of the array entry contains the “real” row number for which it has been checked. So you can have the situation that g_f01 has a count of 2, but your g_f02 containing the EMPNO contains 15 rows. In the case if the g_f02 is your “driving” array, because you want to process all the records and only for the checked ones you want to do something special, it can get really challenging for a new APEX programmer (and even for a more experienced one).
That’s why I have added new functionality to my Plug & play tabular form handling package, to make accessing the row selector as easy and straightforward as possible.
The package ApexLib_TabForm now contains the additional methods isRowSelectorChecked, setRowSelector. The hasRowChanged has been enhanced to also check for the row selector column.
Let’s demonstrate the new functions with an example!
BEGIN FOR ii IN 1 .. ApexLib_TabForm.getRowCount LOOP IF ApexLib_TabForm.hasRowChanged(ii, TRUE) THEN IF ApexLib_TabForm.isRowSelectorChecked(ii) THEN callAbc ( pEmpNo => ApexLib_TabForm.NV('EMPNO', ii) , pEname => ApexLib_TabForm.V ('ENAME', ii) , pHireDate => ApexLib_TabForm.DV('HIRE_DATE', ii) ); ELSE callXyz ( pEmpNo => ApexLib_TabForm.NV('EMPNO', ii) , pEname => ApexLib_TabForm.V ('ENAME', ii) , pHireDate => ApexLib_TabForm.DV('HIRE_DATE', ii) ); END IF; END IF; END LOOP; END;
This example demonstrates several features of the ApexLib_TabForm package.
- With getRowCount you don’t have to care that you use the correct g_fxx array to process all records. Remember: If you have a row selector, g_f01 just contains as many records as you have checked values. So you would have to use g_f02 in that case.
- hasRowChanged compares the old- with the new checksum, to verify if the record has been changed. If the new additional boolean parameter pIncludeRowSelector is set to TRUE, the row selector column will also be checked.
- isRowSelectorChecked will return TRUE if the checkbox has been set for that row.
- NV, V and DV to access the column by name. You don’t have to worry anymore that when somebody is resorting the columns of the report, that it will break your code. This functions will also return the value of the column with the correct PL/SQL data type by applying the format mask which is defined for the column.
Get the source code from the original posting and try it out!