MQeFieldsFields

Description
Returns the total number of fields in an MQeFields object.

From this number, the application can use MQeFieldsGetByIndex to iterate through the indices and retrieve all the fields in the MQeFields object.

Syntax
#include <hmq.h>
MQEINT32 MQeFieldsFields( MQEHSESS hSess, 
									MQEHFIELDS hFlds, 
             					MQEINT32 * pCompCode, 
									MQEINT32 * pReason)

Parameters

MQEHSESS hSess - input
The session handle, returned by MQeInitialize.

MQEHFIELDS hFlds - input
The handle to an MQeFields object.

MQEINT32 * pCompCode - output
MQECC_OK, MQECC_WARNING or MQECC_ERROR.

MQEINT32 * pReason - output
If the returned *pCompCode equals MQECC_ERROR, *pReason may have any of the following values:

MQE_EXCEPT_INVALID_HANDLE

Return Value

MQEINT32
On success, returns the number of fields.

Example
#include <hmq.h>
static  MQECHAR const * FieldsType = "com.ibm.mqe.MQeFields";
static  MQECHAR * textBuf  = 
						"The Owl and the Pussy Cat went to sea.";
static  MQEBYTE   byteBuf[] 
						= { 0xAB, 0xCD, 0x12, 0x44 };
 
MQEHSESS   hSess;
MQEHFIELDS hFlds;
MQEINT32   compcode;
MQEINT32   reason;
MQEINT32   int32Val;
MQEINT32   nFlds;
MQEINT32   rc,i;
MQEFIELD   fd;
 
hSess   = MQeInitialize("MyAppsName", &compcode, &reason);
hFlds   = MQeFieldsAlloc( hSess, FieldsType, &compcode, &reason);
 
int32Val = 0x12345678;
rc = MQeFieldsPut( hSess, hFlds, "x", 
							MQE_TYPE_INT,  
							&int32Val;, 1, 
							&compcode, 
							&reason); 
rc = MQeFieldsPut( hSess, hFlds, "nm", 
							MQE_TYPE_ASCII, 
							textBuf, 
							strlen(textBuf), 
							&compcode, 
							&reason); 
rc = MQeFieldsPut( hSess, hFlds, "b", 
							MQE_TYPE_BYTE,  
							byteBuf, 4, 
							&compcode, 
							&reason); 
 
nFlds = MQeFieldsFields( hSess, hFlds, 
									&compcode, 
									&reason);
/* nFlds is 4 
	(3 added above + 1 field object identifier field) */
/* Ignore the first field 
		(field object identifier) - start at 1 */ 
 
for (i=1; i<nFlds; i++) {
 
   memset( &fd, 0, sizeof(fd));
   
   /* Get each field by index */
   rc = MQeFieldsGetByIndex( hSess, hFlds, i, 
										&fd, 1, 
										&compcode, 
										&reason);
   fd.fd_name = (MQECHAR *) malloc(fd.fd_namelen+1);
   fd.fd_data = (MQEBYTE *) 
						malloc(fd.fd_datalen * 
						MQE_SIZEOF(fd.fd_datatype));
 
   rc = MQeFieldsGetByIndex( hSess, hFlds, i, 
										&fd, 1, 
										&compcode, 
										&reason);
   fd.fd_name[fd.fd_namelen] = '\0';
   
   free(fd.fd_name);
   free(fd.fd_data);

See Also
MQeFieldsGetByIndex


© IBM Corporation 2002. All Rights Reserved