pears.IQacJournalOutstandingAmount

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

Original SQL

CREATE FUNCTION "pears"."IQacJournalOutstandingAmount"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "DocID" CHAR(8),IN "LineNo" SMALLINT ) 
RETURNS DECIMAL(12,2)
BEGIN
  DECLARE "rv" DECIMAL(12,2);
  DECLARE "amt" DECIMAL(12,2);
  SET "amt" = 0.0;
  SET "rv" = 0.0;
  // ONLY makes sense FOR suballocatable LINES
  SELECT FIRST "allocamount" INTO "amt" FROM "iqacjournal" WHERE "documentid" = "DocID" AND "linenumber" = "LineNo";
  SELECT "sum"("allocatedamount") INTO "rv" FROM "iqacallocation" WHERE "allocateddocumentid" = "DocID" AND "allocatedlinenumber" = "LineNo";
  SET "rv" = "isnull"("amt",0.0)-"isnull"("rv",0.0);
  RETURN "rv"
END