To put data into a fields object, use the following fields API calls:
MQeFieldsPut() is the most basic API and its use is described here. The other functions are described in the
Advanced MQeFields APIs section of this document.
Every piece of data put into an MQeFields object has a WebSphere MQ Everyplace field type associated with it. The type gives hints to the WebSphere MQ Everyplace system on how to handle the message when it passes between different host system (for example between a big-endian and a little-endian system). In other words, the WebSphere MQ Everyplace system converts a primitive data type into a host-friendly format so that the correct integer value is retrieved from the MQeFields object regardless of the format of the host system.
Table 1 shows the data types that are available in
WebSphere MQ Everyplace
Table 1. MQeFields object data types
#include <hmq.h> MQEHSESS hSess; MQEINT32 compcode; MQEINT32 reason; MQEHFIELDS hFlds, hMsg; static const MQECHAR Echo[] = "Hello world!"; MQEBYTE testBool =0x1; MQEBYTE testByte =0xab, testBytes[]={ 0x12, 0x34, 0x56 }; MQEINT16 testShort=0xabcd, testShorts[]={ 0x1234, 0x3456, 0x5678 }; MQEINT32 testInt=0xabcdef12, testInts[]={ 0x12121212, 0x34343434, 0x56565656 }; struct MQEINT64 testLong={0x12345678, 0x9abcdef0}, testLongs[]={ {0x12, 0x34}, {0x56,0xab} }; MQEINT32 testData[256]; MQEINT16 i; hSess = MQeInitialize("MyAppsName", &compcode, &reason); hFlds = MQeFieldsAlloc( hSess, MQE_OBJECT_TYPE_MQE_FIELDS, &compcode, &reason); hMsg = MQeFieldsAlloc( hSess, MQE_OBJECT_TYPE_MQE_MSGOBJ, &compcode, &reason); /* Put in an ASCII string */ MQeFieldsPut( hSess, hFlds, "hello", MQE_TYPE_ASCII, (void*)Echo, strlen(Echo), &compcode, &reason); /* Put in an primitive data type */ MQeFieldsPut( hSess, hFlds, "aBool", MQE_TYPE_BOOLEAN, (void*)&testBool,1, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aByte", MQE_TYPE_BYTE, (void*)&testByte, 1, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aShort", MQE_TYPE_SHORT, (void*)&testShort, 1, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aInt", MQE_TYPE_INT, (void*)&testInt, 1, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aLong", MQE_TYPE_LONG, (void*) &testLong, 1, &compcode, &reason); /* Put in an array of primitive data type */ MQeFieldsPut( hSess, hFlds, "aBytes", MQE_TYPE_BYTE , (void*)testBytes, 3, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aShorts", MQE_TYPE_SHORT, (void*)testShorts, 3, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aInts", MQE_TYPE_INT, (void*)testInts, 3, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "aLongs", MQE_TYPE_LONG, (void*)testLongs, 2, &compcode, &reason); MQeFieldsPut( hSess, hFlds, "testData", MQE_TYPE_INT, (void*)testData, 256, &compcode, &reason); /* Put the fields object into a message object. */ MQeFieldsPut( hSess, hMsg, "aFldsObj", MQE_TYPE_FIELD, (void*)&hFlds, 1, &compcode, &reason); MQeFieldsFree(hSess, hMsg, &compcode, &reason); MQeTerminate (hSess, &compcode, &reason);