Search code examples
plsqloraclereports

PL/SQL in oracle reports, incrementation doesn't work


In my response 2 rows is different from '.' and will therefor print out, and should increment the "myCounter".
But in both the print outs 1 as in myCounter doesn't gets incremented...

function R_G_cnFormatTrigger return boolean is
myCounter number :=0;
begin
  -- Automatically Generated from Reports Builder.
  if (mod(myCounter,2) = 0)
  then
    srw.set_foreground_fill_color('gray8');
    srw.set_fill_pattern('solid');
  else
    srw.set_foreground_fill_color('');
    srw.set_fill_pattern('transparant');
  end if;
 if(:CP_WAYBILL_NO <> '.')
    then
        myCounter:=(myCounter+1);
        srw.message(123,'myCounter:'||myCounter);
        return true;
    else
        return false;
 end if;
end;

Solution

  • When you print myCounter it always equals 1, right? This is because you return true; at the end of if(:CP_WAYBILL_NO <> '.').

    When you use return in function, it breaks the execution. myCounter is a local variable, so its value isn't remembered.

    You can try creating a package with myCounter as global variable or read/write myCounter from/to temporary table.