---
title: "pk73343_output_document stored procedure documentation"
summary: "Analysis of the Oracle output-document package used by SAIF.Business.Policy.Correspondence."
status: draft
owner: "Technical Writer"
last_reviewed: "2026-07-31"
source_schema: "WCIS_DBA"
source_name: "pk73343_output_document"
source_type: "PACKAGE"
oracle_status: "found"
---

# pk73343_output_document

## Overview

| Field | Value |
| --- | --- |
| **Schema** | `WCIS_DBA` |
| **Type** | Package |
| **Database** | Oracle |
| **Calling libraries** | `SAIF.Business.Policy.Correspondence` |
| **Calling classes** | `clsOutputDocumentInserter` |

## Purpose

`pk73343_output_document` creates policy output-document records in Oracle. The package inserts the base `OUTPUT_DOCUMENT` row, derives release status from the document type and hold flag, inserts the `POLICY_OUTPUT_DOCUMENT` link row, and standardizes error handling when the insert fails.

## Procedures / Methods

### insert_policy_output_document

| Field | Value |
| --- | --- |
| **Returns** | No scalar return; writes one `OUTPUT_DOCUMENT` row and one `POLICY_OUTPUT_DOCUMENT` row. |
| **Called by** | `clsOutputDocumentInserter.InsertOutputDocument`, `clsOutputDocumentInserter.InsertAgencyDeliveredOutputDocument` |

**Description:** Inserts a policy output document, derives hold/release status, and links the generated document to a policy period.

#### Parameters

| Parameter | Direction | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `in_policy_num` | IN | NUMBER | — | Policy number. |
| `in_policy_period_eff_date` | IN | DATE | — | Policy-period effective date. |
| `in_agency_seq_num` | IN | NUMBER | — | Agency sequence number; zero is normalized to `NULL`. |
| `in_agent_num` | IN | NUMBER | — | Agent number; zero is normalized to `NULL`. |
| `in_output_document_type_code` | IN | VARCHAR2 | — | Output-document type code used to derive agency visibility. |
| `in_image_seq_num` | IN | NUMBER | — | Imaging-system sequence number. |
| `in_hold_flag` | IN | VARCHAR2 | — | `Y`/`N` hold flag. |
| `in_agency_delivery_flag` | IN | VARCHAR2 | `'N'` or caller value | Agency-delivery flag passed by the wrapper overload. |
| `in_create_user` | IN | VARCHAR2 | — | Creating user. |
| `in_description` | IN | VARCHAR2 | — | Document description. |
| `in_source_key_text` | IN | VARCHAR2 | — | Source-key text stored with the policy link row. |
| `in_release_date` | IN | DATE | `NULL` | Optional explicit release date. |

## Business Rules

| Rule ID | Rule | Condition | Action |
| --- | --- | --- | --- |
| [BR-024](../business-rules.md#br-024-explicit-release-dates-override-the-computed-document-date) | Explicit release dates override the computed document date | `in_release_date IS NOT NULL` | Use the caller-supplied value as `DOCUMENT_CREATE_DATE`. |
| [BR-025](../business-rules.md#br-025-non-agency-viewable-output-documents-release-immediately) | Non-agency-viewable output documents release immediately | `AGENCY_VIEW_FLAG = 'N'` | Set document status to `RELE`. |
| [BR-026](../business-rules.md#br-026-held-output-documents-require-both-agency-visibility-and-hold-flag) | Held output documents require both agency visibility and hold flag | Agency-viewable document with `in_hold_flag = 'Y'` | Set document status to `HELD`. |
| [BR-027](../business-rules.md#br-027-agency-viewable-non-held-documents-start-pending) | Agency-viewable non-held documents start pending | Agency-viewable document with any non-held flag | Set document status to `PEND`. |
| [BR-028](../business-rules.md#br-028-zero-agency-and-agent-numbers-are-normalized-to-null) | Zero agency and agent numbers are normalized to NULL | `in_agency_seq_num = 0` or `in_agent_num = 0` | Persist `NULL` instead of zero. |
| [BR-029](../business-rules.md#br-029-release-dates-are-set-only-for-released-policy-output-rows) | Release dates are set only for released policy-output rows | `v_document_status_code = 'RELE'` | Write `RELEASE_DATE`; otherwise store `NULL`. |
| [BR-030](../business-rules.md#br-030-the-standard-output-document-overload-defaults-to-non-agency-delivery) | The standard output-document overload defaults to non-agency delivery | 11-argument overload | Delegate with `in_agency_delivery_flag = 'N'`, null endorsement, and null task user. |
| [BR-031](../business-rules.md#br-031-the-agency-delivered-overload-passes-the-delivery-flag-through-unchanged) | The agency-delivered overload passes the delivery flag through unchanged | 12-argument overload | Delegate with the caller-supplied delivery flag. |
| [BR-032](../business-rules.md#br-032-the-output-document-procedure-raises-a-standard-saif-error-on-exception) | The output-document procedure raises a standard SAIF error on exception | `WHEN OTHERS` | Call `pk73090_error_handler.raise_an_error(...)`. |

## Operations

| Operation | Description | Trigger |
| --- | --- | --- |
| Create output document record | Inserts `OUTPUT_DOCUMENT` using `output_document_seq.NEXTVAL` and returns the generated key. | Called from the two `clsOutputDocumentInserter` wrapper methods. |
| Resolve document status | Reads `OUTPUT_DOCUMENT_TYPE_CODE.AGENCY_VIEW_FLAG` and derives `RELE`, `HELD`, or `PEND`. | Executed after the base insert. |
| Link document to policy period | Inserts `POLICY_OUTPUT_DOCUMENT` with normalized agency/agent values and conditional release date. | Executed after status derivation. |
| Raise standard error | Re-raises any unhandled failure through `pk73090_error_handler.raise_an_error`. | Executed by the `WHEN OTHERS` handler. |

## Source Code

<details>
<summary>PL/SQL package specification excerpt</summary>

```sql
PACKAGE pk73343_output_document
AS
   PROCEDURE insert_policy_output_document (
      in_policy_num                  IN NUMBER,
      in_policy_period_eff_date      IN DATE,
      in_agency_seq_num              IN NUMBER,
      in_agent_num                   IN NUMBER,
      in_output_document_type_code   IN VARCHAR2,
      in_image_seq_num               IN NUMBER,
      in_hold_flag                   IN VARCHAR2,
      in_create_user                 IN VARCHAR2,
      in_description                 IN VARCHAR2,
      in_source_key_text             IN VARCHAR2,
      in_release_date                IN DATE default NULL);
END pk73343_output_document;
```

</details>

<details>
<summary>PL/SQL package body excerpt</summary>

```sql
v_document_create_date := get_document_date();

INSERT INTO output_document (
  output_document_seq_num,
  output_document_type_code,
  document_create_date,
  image_seq_num,
  create_date,
  create_user,
  endorse_seq_num,
  description)
VALUES (
  output_document_seq.NEXTVAL,
  in_output_document_type_code,
  CASE
    WHEN in_release_date is not null THEN in_release_date
    ELSE v_document_create_date
  END,
  in_image_seq_num,
  SYSDATE,
  in_create_user,
  in_endorse_seq_num,
  in_description)
RETURN output_document_seq_num INTO v_output_document_seq_num;

SELECT odtc.agency_view_flag
  INTO v_agency_view_flag
  FROM output_document_type_code odtc
 WHERE odtc.code = in_output_document_type_code;

v_document_status_code :=
  CASE
    WHEN v_agency_view_flag = 'N' THEN 'RELE'
    WHEN in_hold_flag = 'Y' THEN 'HELD'
    ELSE 'PEND'
  END;
```

</details>

## Related Documentation
- [Procedure catalog](index.md)
- [Business rules](../business-rules.md)
- [Operations and processes](../operations-processes.md)
- [SQL catalog](../sql/index.md)

## Sources
- Oracle DBA_SOURCE: `WCIS_DBA.pk73343_output_document`
- Calling code: `Business\SAIF.Business.Policy.Correspondence\clsOutputDocumentInserter.vb`
