Example: Calling IBM i programs from IBM PASE for i
This example shows how you call programs in an PASE for i program using the _PGMCALL runtime function.
Interspersed in the following example code are comments that explain the code. Make sure to read these comments as you enter or review the example.
Note: By using the code examples, you agree
to the terms of the Code license and disclaimer information.
/* This example uses the IBM i PASE _PGMCALL function to call the IBM i
API QSZRTVPR. The QSZRTVPR API is used to retrieve information about
i5/OS software product loads. Refer to the QSZRTVPR API documentation
for specific information regarding the input and output parameters needed
to call the API */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "as400_types.h"
#include "as400_protos.h"
int main(int argc, char * argv[])
{
/* IBM i API's (including QSZRTVPR) typically expect character
parameters to be in EBCDIC. However, character constants in
PASE for i programs are typically in ASCII. So, declare some
CCSID 37 (EBCDIC) character parameter constants that will be
needed to call QSZRTVPR */
/* format[] is input parameter 3 to QSZRTVPR and is
initialized to the text 'PRDR0100' in EBCDIC */
const char format[] =
{0xd7, 0xd9, 0xc4, 0xd9, 0xf0, 0xf1, 0xf0, 0xf0};
/* prodinfo[] is input parameter 4 to QSZRTVPR and is
initialized to the text '*OPSYS *CUR 0033*CODE ' in EBCDIC
This value indicates we want to check the code load for Option 33
of the currently installed i5/OS release */
const char prodinfo[] =
{0x5c, 0xd6, 0xd7, 0xe2, 0xe8, 0xe2, 0x40, 0x5c, 0xc3,
0xe4, 0xd9, 0x40, 0x40, 0xf0, 0xf0, 0xf3, 0xf3, 0x5c,
0xc3, 0xd6, 0xc4, 0xc5, 0x40, 0x40, 0x40, 0x40, 0x40};
/* installed will be compared with the "Load State" field of the
information returned by QSZRTVPR and is initialized to the text
'90' in EBCDIC */
const char installed[] = {0xf9, 0xf0};
/* rcvr is the output parameter 1 from QSZRTVPR */
char rcvr[108];
/* rcvrlen is input parameter 2 to QSZRTVPR */
int rcvrlen = sizeof(rcvr);
/* errcode is input parameter 5 to QSZRTVPR */
struct {
int bytes_provided;
int bytes_available;
char msgid[7];
} errcode;
/* qszrtvpr_pointer will contain the IBM i 16-byte tagged
system pointer to QSZRTVPR */
ILEpointer qszrtvpr_pointer;
/* qszrtvpr_argv6 is the array of argument pointers to QSZRTVPR */
void *qszrtvpr_argv[6];
/* return code from _RSLOBJ2 and _PGMCALL functions */
int rc;
/* Set the IBM i pointer to the QSYS/QSZRTVPR *PGM object */
rc = _RSLOBJ2(&qszrtvpr_pointer,
RSLOBJ_TS_PGM,
"QSZRTVPR",
"QSYS");
/* initialize the QSZRTVPR returned info structure */
memset(rcvr, 0, sizeof(rcvr));
/* initialize the QSZRTVPR error code structure */
memset(&errcode, 0, sizeof(errcode));
errcode.bytes_provided = sizeof(errcode);
/* initialize the array of argument pointers for the QSZRTVPR API */
qszrtvpr_argv[0] = &rcvr;
qszrtvpr_argv[1] = &rcvrlen;
qszrtvpr_argv[2] = &format;
qszrtvpr_argv[3] = &prodinfo;
qszrtvpr_argv[4] = &errcode;
qszrtvpr_argv[5] = NULL;
/* Call the IBM i QSZRTVPR API from PASE for i */
rc = _PGMCALL(&qszrtvpr_pointer,
(void*)&qszrtvpr_argv,
0);
/* Check the contents of bytes 63-64 of the returned information.
If they are not '90' (in EBCDIC), the code load is NOT correctly
installed */
if (memcmp(&rcvr[63], &installed, 2) != 0)
printf("IBM i Option 33 is NOT installed\n");
else
printf("IBM i Option 33 IS installed\n");
return(0);
}