/*
 * RC_UNMATCH.pgc - rc 모듈 서비스 RC_UNMATCH (one service = one file).
 * Moved verbatim from the former inline rc_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by rc_svr at tpsvrinit.
 */
#include "RC_UNMATCH.h"

/* 11. RC_UNMATCH - 미대사 건수 조회. (KEEP) */
void RC_UNMATCH(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM purchase p
        WHERE p.biz_date = :h_bizdate
          AND NOT EXISTS (SELECT 1 FROM ledger l WHERE l.purchase_id = p.purchase_id);
    if (sqlca.sqlcode < 0) FAIL(b);
    { long v = h_cnt; Bchg(b, T_COUNT, 0, (char *)&v, 0L); }
    OK(b);
}

/* vim: set ts=4 sw=4 et smartindent: */
