#include #include #include #include #include #define TRUE 0 #define FALSE -1 typedef struct { int BYTESPRO; int BYTESAVL; char MSGID[7]; char RESRVD; char EXCPDATA[100]; } ERRSTRUCTURE; /* Define the error return structure */ ERRSTRUCTURE errcode;/* Error Code Structure for RCVMSG */ void ApiError(char* place, int stmno, ERRSTRUCTURE* errcode, char* pgm); void main(void){ typedef struct { Qmh_Rcvm_RCVM0200_t rcvm0200; char Message[256]; } MSG0200; MSG0200 msg0200; char msg_key[4], old_key[4], msg_type[10], msg[132]; int len, pos, waittime = 0; int i; printf("** TESTOPR **\n"); getchar(); errcode.BYTESPRO = 160; errcode.BYTESAVL = 0; memset(&msg0200, 0, sizeof(MSG0200)); memset(msg_key, ' ', sizeof(msg_key)); memcpy(msg_type, "*FIRST ", 10); i = 0; while(1){/*while*/ memcpy(old_key, msg_key, 4); QMHRCVM((char*)&msg0200, sizeof(MSG0200), "RCVM0200", "QSYSOPR QSYS ", msg_type, msg_key, waittime, "*SAME ", &errcode); if(errcode.BYTESAVL != 0){/* APIERR */ ApiError("QMHRCVM", __LINE__, &errcode, "TESTOPR"); break; }/* APIERR */ memcpy(msg_key, msg0200.rcvm0200.Message_Key, 4); if(memcmp(msg0200.rcvm0200.Message_Key, old_key, 4) == 0) break; pos = msg0200.rcvm0200.Length_Data_Returned; len = msg0200.rcvm0200.Length_Message_Returned; memcpy(msg, &msg0200.Message[pos], len); msg[len] = 0x00; i ++; printf("[%d] %s\n", i, msg); memcpy(msg_type, "*NEXT ", 10); }/*while*/ getchar(); } /*********************************************************************/ void ApiError(char* place, int stmno, ERRSTRUCTURE* errcode, char* pgm) /*********************************************************************/ { char msgid[8], msgdta[101], Message[512]; int msglen, msgdtalen, pos; char* ptr; typedef struct { Qmh_Rtvm_RTVM0100_t rtvm0100; char msg[512]; } ERRMSG; ERRMSG errmsg; memset(msgid, 0, sizeof(msgid)); memcpy(msgid, errcode->MSGID, 7); msgid[7] = 0x00; if(msgid[0] == 0x00 || msgid[0] == ' '){/*msgid ‚È‚µ */ perror("APIERROR"); printf(" at %s, STMNO=%d\n", place, stmno); getchar(); return; }/*msgid ‚È‚µ */ memset(msgdta, 0, sizeof(msgdta)); memcpy(msgdta, errcode->EXCPDATA, 100); msgdta[100] = 0x00; msglen = sizeof(ERRMSG); msgdtalen = strlen(msgdta); memset(&errmsg, 0, sizeof(ERRMSG)); QMHRTVM(&errmsg, msglen, "RTVM0100", msgid, "QCPFMSG *LIBL ", msgdta, msgdtalen, "*YES ", "*YES ", errcode); memset(Message, 0, sizeof(Message)); memcpy(Message, errmsg.msg, 512); ptr = strstr(Message, "&N"); if(ptr != NULL){ pos = (int)(ptr - Message); Message[pos] = 0x00; } printf("PGM-%s:APIERR %s-%s\n", pgm, msgid, Message); printf(" at %s, STMNO=%d\n", place, stmno); }