Preparing RPG programs in IBM i
When building RPG applications to run under IBM® i, in addition to coding the MQI calls in your source code, you must add the appropriate language statements to include the IBM MQ for IBM i copy files for the RPG language.
IBM MQ copy files
IBM MQ for IBM i provides copy files to assist you with writing your applications in the RPG programming language. They are suitable for use with the WebSphere® Development toolset (5722 WDS) ILE RPG 4 Compiler.
The copy files that IBM MQ for IBM i provides to assist with the writing of channel exits are described in Channel-exit programs for messaging channels.
The names of the IBM MQ for IBM i copy files for RPG have the prefix CMQ. They have a suffix of G or H. There are separate copy files containing the named constants, and one file for each of the structures. The copy files are listed in Language considerations.
The structure declarations do not contain DS statements. This allows the application to declare a data structure (or a multiple-occurrence data structure) by coding the DS statement and using the /COPY statement to copy in the remainder of the declaration.
D*..1....:....2....:....3....:....4....:....5....:....6....:....7
D* Declare an MQMD data structure
D MQMD DS
D/COPY CMQMDG
Preparing your programs to run
To create an executable IBM MQ for IBM i application, you have to compile the source code you have written. To do this for ILE RPG/400, you can use the typical IBM i commands, CRTRPGMOD and CRTPGM.
After creating your *MODULE, you need to specify BNDSRVPGM(QMQM/LIBMQM) in the
CRTPGM command. This includes the various IBM MQ
procedures in your program.
Make sure that the library containing the copy files (QMQM) is in the library list when you perform the compilation.
For further information concerning programming considerations, including client modes, see Language considerations.
Interfaces to the IBM i external syncpoint manager
IBM MQ for IBM i uses native IBM i commitment control as an external syncpoint coordinator.
To start the IBM i commitment control facilities, use the STRCMTCTL system command. To end commitment control, use the ENDCMTCTL system command.
STRCMTCTL LCKLVL(*ALL) CMTSCOPE(*JOB)
If you call MQPUT, MQPUT1, or MQGET, specifying PMSYP or GMSYP, after starting commitment control, IBM MQ for IBM i adds itself as an API commitment resource to the commitment definition. This is typically the first such call in a job. While there are any API commitment resources registered under a particular commitment definition, you cannot end commitment control for that definition.
IBM MQ for IBM i removes its registration as an API commitment resource when you disconnect from the queue manager, provided there are no pending MQI operations in the current unit of work.
If you disconnect from the queue manager while there are pending MQPUT, MQPUT1, or MQGET operations in the current unit of work, IBM MQ for IBM i remains registered as an API commitment resource so that it is notified of the next commit or rollback. When the next syncpoint is reached, IBM MQ commits or rolls back the changes as required. It is possible for an application to disconnect and reconnect to a queue manager during an active unit of work and perform further MQGET and MQPUT operations inside the same unit of work (this is a pending disconnect).
If you attempt to issue an ENDCMTCTL system command for that commitment definition, message
CPF8355 is issued, indicating that pending changes were active. This message also
appears in the job log when the job ends. To avoid this, ensure that you commit or roll back all
pending IBM MQ operations, and that you disconnect from
the queue manager. Thus, using COMMIT or ROLLBACK commands before ENDCMTCTL should enable
end-commitment control to complete successfully.
When IBM i commitment control is used as an external syncpoint coordinator, MQCMIT, MQBACK, and MQBEGIN calls might not be issued. Calls to these functions fail with the reason code RC2012.
- CL commands: COMMIT and ROLLBACK
- ILE C Programming Functions: _Rcommit and _Rrollback
- RPG/400: COMMIT and ROLBK
- COBOL/400: COMMIT and ROLLBACK
Syncpoints in CICS for IBM i applications
IBM MQ for IBM i participates in units of work with CICS®. You can use the MQI within a CICS application to put and get messages inside the current unit of work.
You can use the EXEC CICS SYNCPOINT command to establish a syncpoint that includes the IBM MQ for IBM i operations. To back out all changes up to the previous syncpoint, you can use the EXEC CICS SYNCPOINT ROLLBACK command.
If you use MQPUT, MQPUT1, or MQGET with the PMSYP, or GMSYP , option set in a CICS application, you cannot log off CICS until IBM MQ for IBM i has removed its registration as an API commitment resource. Therefore, you should commit or back out any pending put or get operations before you disconnect from the queue manager. This will allow you to log off CICS.