/*
 * MM_CODE_INQ.pgc - mm 모듈 서비스 MM_CODE_INQ (one service = one file).
 * 기능: 공통코드 조회.
 * 기존 인라인 mm_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * mm_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "MM_CODE_INQ.h"

void MM_CODE_INQ(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char grp[32], code[32];
    EXEC SQL BEGIN DECLARE SECTION;
    char h_grp[32], h_code[32], h_name[64], h_status[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_STR1, grp, sizeof(grp));  if (grp[0] == 0) strcpy(grp, "GEN");
    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 code_name, status INTO :h_name, :h_status
        FROM mm_code WHERE code_group = :h_grp AND code = :h_code;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    Bchg(b, T_STR2, 0, h_name, 0L);
    Bchg(b, T_STATUS, 0, h_status, 0L);
    OK(b);
}
