[IBM i]

Preparing and running C and COBOL samples on IBM i

To run the samples, either use the C executable versions, which are supplied in the library QMQM, or compile them in a similar way to any other IBM® MQ application. If you want to run COBOL samples, you might need to do some additional preparation.

Before you begin

For RPG samples, see Preparing and running the RPG sample programs for IBM i.

Before you run the C and COBOL samples on IBM i, a queue manager and queues must already exist.

About this task

The source for the IBM MQ for IBM i sample programs is provided in library QMQMSAMP as members of QCSRC, QCLSRC, QCBLLESRC, and QRPGLESRC.

You can use your own queues when you run the samples, or you can run the sample program AMQSAMP4 to create some sample queues. The source for this program is included in file QCLSRC in library QMQMSAMP. You can compile it by using the CRTCLPGM command.

[MQ 9.4.0 Jun 2024][MQ 9.4.0 Jun 2024]The following sample programs have authentication capabilities:
  • amqsbcg0.c
  • amqsfhac.c
  • amqsget0.c
  • amqsghac.c
  • amqsmhac.c
  • amqsphac.c
  • amqspuba.c
  • amqsput0.c
  • amqssslc.c
  • amqssuba.c
The executable versions of these samples have authentication enabled. However, compiling the source versions with authentication enabled requires the compile flag SAMPLE_AUTH_ENABLED to be defined and the amqsauth.c source file to be compiled with the desired sample. For example:
  • Creating the amqssslc program without authentication enabled:
    CRTCMOD MODULE(MYLIB/AMQSSSLC) SRCFILE(QMQMSAMP/QCSRC)
    CRTPGM PGM(MYLIB/AMQSSSLC) MODULE(MYLIB/AMQSSSLC) BNDSRVPGM(QMQM/LIBMQIC)
  • Creating the amqssslc with authentication enabled:
    CRTCMOD MODULE(MYLIB/AMQSSSLC) DEFINE('SAMPLE_AUTH_ENABLED') SRCFILE(QMQMSAMP/QCSRC)
    CRTCMOD MODULE(MYLIB/AMQSAUTH) SRCFILE(QMQMSAMP/QCSRC)
    CRTPGM PGM(MYLIB/AMQSSSLC_AUTH) MODULE(MYLIB/AMQSSSLC MYLIB/AMQSAUTH) BNDSRVPGM(QMQM/LIBMQIC)

Procedure

  1. Create a queue manager and set up the default definitions.
    You must do this before you can run any of the sample programs. For more information about creating a queue manager, see Administering IBM MQ. For information about configuring a queue manager to securely accept incoming connection requests from applications that are running in client mode, see Configuring a queue manager to accept client connections on Multiplatforms.
  2. To call one of the sample programs by using data from member PUT in file AMQSDATA of library QMQMSAMP, use a command like:
    CALL PGM(QMQM/AMQSPUT4) PARM('QMQMSAMP/AMQSDATA(PUT)')
    
    Note: For a compiled module to use the IFS file system, specify the option SYSIFCOPT(*IFSIO) on CRTCMOD, then the file name, passed as a parameter, must be specified in the following format:
    home/me/myfile
    
  3. If you want to use the COBOL versions of the Inquire, Set, and Echo examples, change the process definitions before you run these samples.
    For the Inquire, Set, and Echo examples, the sample definitions trigger the C versions of these samples. If you want the COBOL versions, you must change the process definitions:
    • SYSTEM.SAMPLE.INQPROCESS
    • SYSTEM.SAMPLE.SETPROCESS
    • SYSTEM.SAMPLE.ECHOPROCESS

    On IBM i, you can use the CHGMQMPRC command (for details, see Change MQ Process (CHGMQMPRC) ), or edit and run the AMQSAMP4 program with the alternative definition.

  4. Run the sample programs.
    For more information on the parameters that each of the samples expects, see the descriptions of the individual samples.
    Note: For the COBOL sample programs, when you pass queue names as parameters, you must provide 48 characters, padding with blank characters if necessary. Anything other than 48 characters causes the program to fail with reason code 2085.