Forum Post: Working With Mqseries (4gl)

Status
Not open for further replies.
F

Fuelfire

Guest
Hello, everybody! I'm trying to open WebSphere MQ queuе through API function. I want to connect to the queue manager, open a specific queue, put in her message, get the message and then close and disconnect. I installed the WebSphere MQ client 7.5 and downloaded the manual "MQSeries Application Programming Interface". I wrote a program: &SCOPED-DEFINE MQCC_OK 0 &SCOPED-DEFINE MQRC_NONE 0 &SCOPED-DEFINE MQOO_INPUT_EXCLUSIVE 4 &SCOPED-DEFINE MQOO_OUTPUT 16 &SCOPED-DEFINE MaxMsgLength 104 857 600 &SCOPED-DEFINE DLL-LIB mqic32.dll &SCOPED-DEFINE MQCO_NONE 0 &SCOPED-DEFINE MQCNO_VERSION_2 2 DEFINE VARIABLE QMgrName AS CHAR FORMAT "X(48)" NO-UNDO. /* Name of queue manager */ DEFINE VARIABLE Hconn AS INT64 NO-UNDO. /* Connection handle */ DEFINE VARIABLE CompCode AS INT64 NO-UNDO. /* Completion code */ DEFINE VARIABLE Reason AS INT64 NO-UNDO. /* Reason code qualifying CompCode */ DEFINE VARIABLE CharString AS CHARACTER. DEFINE VARIABLE StrLength AS INT. DEFINE VARIABLE ObjDesc AS MEMPTR NO-UNDO. DEFINE VARIABLE ConnectOpts AS MEMPTR NO-UNDO. DEFINE VARIABLE ClientConnPtr AS MEMPTR NO-UNDO. DEFINE VARIABLE Hobj AS INT NO-UNDO. DEFINE VARIABLE MsgDesc AS MEMPTR NO-UNDO. DEFINE VARIABLE GetMsgOpts AS MEMPTR NO-UNDO. DEFINE VARIABLE PutMsgOpts AS MEMPTR NO-UNDO. DEFINE VARIABLE Buffer_ AS CHAR NO-UNDO. /*Area to contain the message data*/ DEFINE VARIABLE DataLength AS INT NO-UNDO. /*connecting*/ PROCEDURE MQCONN EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER QName AS CHAR NO-UNDO. /*Name of queue manager*/ DEFINE OUTPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*connecting with connection options*/ PROCEDURE MQCONNX EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER QName AS CHAR NO-UNDO. /*Name of queue manager*/ DEFINE INPUT-OUTPUT PARAMETER ConnectOpts AS MEMPTR NO-UNDO. /*Options that control the action of MQCONNX.*/ DEFINE OUTPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*opening*/ PROCEDURE MQOPEN EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE INPUT-OUTPUT PARAMETER ObjDesc AS MEMPTR NO-UNDO. /*Object descriptor*/ DEFINE INPUT PARAMETER OPTIONS_ AS LONG NO-UNDO. /*Options that control the action of MQOPEN*/ DEFINE OUTPUT PARAMETER Hobj AS LONG NO-UNDO. /*Object handle*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*get the message*/ PROCEDURE MQGET EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE INPUT PARAMETER Hobj AS LONG NO-UNDO. /*Object handle*/ DEFINE INPUT-OUTPUT PARAMETER MsgDesc AS MEMPTR NO-UNDO. /*message descriptor*/ DEFINE INPUT-OUTPUT PARAMETER GetMsgOpts AS MEMPTR NO-UNDO. /*Options that control the action of MQGET*/ DEFINE INPUT PARAMETER BufferLength AS LONG NO-UNDO. /*Length in bytes of the Buffer area*/ DEFINE OUTPUT PARAMETER Buffer_ AS CHAR NO-UNDO. /*Area to contain the message data*/ DEFINE OUTPUT PARAMETER DataLength AS LONG NO-UNDO. /*Length of the message*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*put the message*/ PROCEDURE MQPUT EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE INPUT PARAMETER Hobj AS LONG NO-UNDO. /*Object handle*/ DEFINE INPUT-OUTPUT PARAMETER MsgDesc AS MEMPTR NO-UNDO. /*message descriptor*/ DEFINE INPUT-OUTPUT PARAMETER PutMsgOpts AS MEMPTR NO-UNDO. /*Options that control the action of MQPUT*/ DEFINE INPUT PARAMETER BufferLength AS LONG NO-UNDO. /*Length in bytes of the Buffer area*/ DEFINE INPUT PARAMETER Buffer_ AS CHAR NO-UNDO. /*Area to contain the message data*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*closing*/ PROCEDURE MQCLOSE EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT PARAMETER Hconn AS LONG NO-UNDO. /*Connection handle*/ DEFINE INPUT-OUTPUT PARAMETER Hobj AS LONG NO-UNDO. /*Object handle*/ DEFINE INPUT PARAMETER OPTIONS_ AS LONG NO-UNDO. /*Options that control the action of MQCLOSE*/ DEFINE OUTPUT PARAMETER CompCode AS LONG NO-UNDO. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG NO-UNDO. /*Reason code qualifying CompCode*/ END PROCEDURE. /*disconnecting*/ PROCEDURE MQDISC EXTERNAL "{&DLL-LIB}" CDECL PERSISTENT: DEFINE INPUT-OUTPUT PARAMETER Hconn AS LONG. /*Connection handle*/ DEFINE OUTPUT PARAMETER CompCode AS LONG. /*Completion code*/ DEFINE OUTPUT PARAMETER Reason AS LONG. /*Reason code qualifying CompCode*/ END PROCEDURE. ASSIGN QMgrName = "UNIQM". SET-SIZE(ConnectOpts) = 104857. SET-SIZE(ClientConnPtr) = 104857. ASSIGN CharString = "ChannelName=~"EXTMQUSER.SVRCONN.CH~"" StrLength = LENGTH(CharString). PUT-STRING(ClientConnPtr,1) = CharString. ASSIGN CharString = "StrucId = 'CNOb'" StrLength = LENGTH(CharString). PUT-STRING(ConnectOpts,1) = CharString. ASSIGN CharString = "Version = 1 ". PUT-STRING(ConnectOpts,StrLength + 1) = CharString. ASSIGN StrLength = StrLength + 1 + LENGTH(CharString) CharString = "Options = 0 ". PUT-STRING(ConnectOpts,StrLength + 1) = CharString. ASSIGN StrLength = StrLength + 1 + LENGTH(CharString) CharString = "ClientConnOffset = 0". PUT-STRING(ConnectOpts,StrLength + 1) = CharString. /* RUN MQCONNX (QMgrName, INPUT-OUTPUT ConnectOpts, OUTPUT Hconn, OUTPUT CompCode, OUTPUT Reason).*/ /*Connect to certain queue manager*/ RUN MQCONN (QMgrName, OUTPUT Hconn, OUTPUT CompCode, OUTPUT Reason). IF ((CompCode = {&MQCC_OK} ) AND (Reason = {&MQRC_NONE})) THEN DO: MESSAGE "+++ MQCONN() ended OK!" VIEW-AS ALERT-BOX. END. ELSE DO: /* report reason and exit */ MESSAGE "--- MQCONN() ended with Completion Code " (IF CompCode = -1 THEN "MQCC_UNKNOWN" ELSE (IF CompCode = 0 THEN "MQCC_OK" ELSE (IF CompCode = 1 THEN "MQCC_WARNING" ELSE "MQCC_FAILED"))) "~nReason code " STRING(Reason) VIEW-AS ALERT-BOX. LEAVE. END. /*Open a query*/ RUN MQOPEN (HConn, INPUT-OUTPUT ObjDesc, /*{&MQOO_INPUT_EXCLUSIVE},*/ {&MQOO_OUTPUT}, OUTPUT Hobj, OUTPUT CompCode, OUTPUT Reason). IF ((CompCode = {&MQCC_OK} ) AND (Reason = {&MQRC_NONE})) THEN DO: MESSAGE "+++ MQOPEN() ended OK!" VIEW-AS ALERT-BOX. END. ELSE DO: /* report reason and exit */ MESSAGE "--- MQOPEN() ended with Completion Code " STRING(CompCode) "~nReason code " STRING(Reason) VIEW-AS ALERT-BOX. LEAVE. END. And also create and initialize system environment variable MQServer. I call this program from Windows 7 and faced with problem when calling MQOPEN. I must initialize memptr parameter ObjDesc. I have no thought how to do it. This parameter is a structure: C declaration typedef struct tagMQOD { MQCHAR4 StrucId; /* Structure identifier */ MQLONG Version; /* Structure version number */ MQLONG ObjectType; /* Object type */ MQCHAR48 ObjectName; /* Object name */ MQCHAR48 ObjectQMgrName; /* Object queue manager name */ MQCHAR48 DynamicQName; /* Dynamic queue name */ MQCHAR12 AlternateUserId; /* Alternate user identifier */ MQLONG RecsPresent; /* Number of object records present */ MQLONG KnownDestCount; /* Number of local queues opened successfully */ MQLONG UnknownDestCount; /* Number of remote queues opened successfully */ MQLONG InvalidDestCount; /* Number of queues that failed to open */ MQLONG ObjectRecOffset; /* Offset of first object record from start of MQOD */ MQLONG ResponseRecOffset; /* Offset of first response record from start of MQOD */ MQPTR ObjectRecPtr; /* Address of first object record */ MQPTR ResponseRecPtr; /* Address of first response record */ MQBYTE40 AlternateSecurityId; /* Alternate security identifier */ MQCHAR48 ResolvedQName; /* Resolved queue name */ MQCHAR48 ResolvedQMgrName; /* Resolved queue manager name */ } MQOD; Maybe someone initialized similar parameters and give an example of how to do it? How should I pass the name of the field structure and its value? Something like that? SET-SIZE(ObjDesc) = 104857. ASSIGN CharString = "StrucId = 'ODbb'" StrLength = LENGTH(CharString). PUT-STRING(ObjDesc,1) = CharString. ASSIGN CharString = "Version = 1 ". PUT-STRING(ObjDesc,StrLength + 1) = CharString. ASSIGN StrLength = StrLength + 1 + LENGTH(CharString) CharString = "ObjectType = 1 ". PUT-STRING(ObjDesc,StrLength + 1) = CharString. ASSIGN StrLength = StrLength + 1 + LENGTH(CharString) CharString = "ObjectName = ~"TEST.Q~"". PUT-STRING(ObjDesc,StrLength + 1) = CharString. I would be grateful for any help. Thanks!

Continue reading...
 
Status
Not open for further replies.
Top