Example 2. REXX procedure called from a C application

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

Sample REXX procedure called from C application

/**************************************************************/
/*********** START OF SQL C Application ***********************/

        #include <decimal.h>
        #include <stdio.h>
        #include <string.h>
        #include <wcstr.h>
        /*-----------------------------------------------------------*/
        exec sql include sqlca;
        exec sql include sqlda;
        /* ***********************************************************/
        /* Declare host variable for the CALL statement              */
        /* ***********************************************************/
        char parm1[20];
        signed long int parm2;
        decimal(10,5) parm3;
        double parm4;
        struct {  short dlen;
                   char dat[10];
                 } parm5;
        wchar_t parm6[4] = { 0xC1C1, 0xC2C2, 0xC3C3, 0x0000 };
        struct {  short  dlen;
                   wchar_t dat[10];
                 } parm7 = {0x0009, 0xE2E2,0xE3E3,0xE4E4, 0xE5E5, 0xE6E6,
                            0xE7E7, 0xE8E8, 0xE9E9, 0xC1C1, 0x0000 };

        char parm8[10];
        char parm9[8];
        char parm10[26];
        main()
        {
      
        /* *************************************************************/
        /* Call the procedure - on return from the CALL statement the  */
        /* SQLCODE should be 0. If the SQLCODE is non-zero,            */
        /* the procedure detected an error.                            */
        /* *************************************************************/
        strcpy(parm1,"TestingREXX");
        parm2 = 12345;
        parm3 = 5.5;
        parm4 = 3e3;
        parm5.dlen = 5;
        strcpy(parm5.dat,"parm6");
        strcpy(parm8,"1994-01-01");
        strcpy(parm9,"13.01.00");
        strcpy(parm10,"1994-01-01-13.01.00.000000");

         EXEC SQL CALL REXXPROC (:parm1, :parm2,
                                 :parm3,:parm4,
                                 :parm5, :parm6,
                                 :parm7,
                                 :parm8, :parm9,
                                 :parm10);

         if (strncpy(SQLSTATE,"00000",5))
           {
           /* handle error or warning returned on CALL   */
           :
           }
                :
       }

/****** END OF SQL C APPLICATION   ************************************/
/**********************************************************************/
/**********************************************************************/
/****** START OF REXX MEMBER TEST/CALLSRC CALLREXX ********************/
/**********************************************************************/
       /* REXX source member TEST/CALLSRC CALLREXX               */
       /* Note the extra parameter being passed for the indicator*/
       /* array.                                                 */
       /*                                                        */
       /* ACCEPT THE FOLLOWING INPUT VARIABLES SET TO THE        */
       /* SPECIFIED VALUES :                                     */
       /* AR1        CHAR(20)          =  'TestingREXX'          */
       /* AR2        INTEGER           = 12345                   */
       /* AR3        DECIMAL(10,5)     = 5.5                     */
       /* AR4        DOUBLE PRECISION  = 3e3                     */
       /* AR5        VARCHAR(10)       = 'parm6'                 */
       /* AR6        GRAPHIC           = G'C1C1C2C2C3C3'         */
       /* AR7        VARGRAPHIC        =                         */
       /*              G'E2E2E3E3E4E4E5E5E6E6E7E7E8E8E9E9EAEA'   */
       /* AR8        DATE              = '1994-01-01'            */
       /* AR9        TIME              = '13.01.00'              */
       /* AR10       TIMESTAMP         =                         */
       /*                       '1994-01-01-13.01.00.000000'     */
       /* AR11       INDICATOR ARRAY   = +0+0+0+0+0+0+0+0+0+0    */

       /**********************************************************/
       /* Parse the arguments into individual parameters         */
       /**********************************************************/
       parse arg ar1 ar2 ar3 ar4 ar5 ar6 ar7 ar8 ar9 ar10 ar11

       /**********************************************************/
       /* Verify that the values are as expected                 */
       /**********************************************************/
       if ar1<>"'TestingREXX'" then signal ar1tag
       if ar2<>12345 then signal ar2tag
       if ar3<>5.5 then signal ar3tag
       if ar4<>3e3 then signal ar4tag
       if ar5<>"'parm6'" then signal ar5tag
       if ar6 <>"G'AABBCC'" then signal ar6tag
       if ar7 <>"G'SSTTUUVVWWXXYYZZAA'" then ,
        signal ar7tag
       if ar8 <> "'1994-01-01'" then signal ar8tag
       if ar9 <> "'13.01.00'" then signal ar9tag
       if ar10 <> "'1994-01-01-13.01.00.000000'" then signal ar10tag
       if ar11 <> "+0+0+0+0+0+0+0+0+0+0" then signal ar11tag
       /************************************************************/
       /* Perform other processing as necessary ..                 */
       /************************************************************/
          :
       /************************************************************/
       /* Indicate the call was successful by exiting with a       */
       /* return code of 0                                         */
       /************************************************************/
       exit(0)

       ar1tag:
       say "ar1 did not match" ar1
       exit(1)
       ar2tag:
       say "ar2 did not match" ar2
       exit(1)
       :
       :

/************ END OF REXX MEMBER   **********************************/