/*
 * VL_CODEVAL.pgc - vl 모듈 서비스 VL_CODEVAL (one service = one file).
 * 기능: 공통코드 유효성 검증 vs mm_code (RC 1=미존재).
 * 기존 인라인 vl_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * vl_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "VL_CODEVAL.h"

void VL_CODEVAL(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char grp[32], code[32];
    long rc = 0;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    char h_grp[32], h_code[32];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_STR3, grp, sizeof(grp));  if (grp[0] == 0) strcpy(grp, "CARD_TYPE");
    gets_(b, T_KEY1, code, sizeof(code));
    strncpy(h_grp,  grp,  sizeof(h_grp)-1);  h_grp[sizeof(h_grp)-1]   = 0;
    strncpy(h_code, code, sizeof(h_code)-1); h_code[sizeof(h_code)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_code
        WHERE code_group = :h_grp AND code = :h_code AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) FAIL(b);
    if (h_cnt == 0) rc = 1;
    setl(b, T_RC, rc);
    OK(b);
}
