www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*---------------------------------------------------------------------+
|                Copyright (c) 1995, SAS Institute Inc.                |
|                  Unpublished - All Rights Reserved                   |
|                      S A S / C   S A M P L E                         |
|                                                                      |
|         NAME: SVC99C                                                 |
|     LANGUAGE: C                                                      |
|      PURPOSE: Demonstrate how to call SVC 99 from within a SAS/C     |
|               application.                                           |
|        NOTES: SVC99C is a C MAIN function that calls SVC 99          |
|               sub-functions, in: prefix.SAMPLE.C(SVC99).             |
|               where "prefix" is the installation defined high-level  |
|               qualifier for the SAS/C product.                       |
|        NOTES: You must customize the: #define DATA_SET_NAME          |
|               The default value is:  "your.dataset.name"             |
|   MVS -                                                              |
|      COMPILE, LINK, EXECUTE: SUBMIT prefix.SAMPLE.AUX(SVC99CLG)      |
|   TSO -                                                              |
|      COMPILE: LC370 CLIST                                            |
|         LINK: CLK370 CLIST                                           |
|      EXECUTE: CALL 'your.load.lib(SVC99C)' 'your.jcl.job(name)'      |
|   CMS - N/A                                                          |
|   MISC NOTES: SVC99C sub-functions:                                  |
|                                                                      |
|          1- Alloc a new dataset, write to it, close & unalloc.       |
|          2- Delete the prev dataset with the unalc_ds func.          |
|          3- Alloc a new dataset, write to it, close & unalloc.       |
|          4- Alloc the prev dataset, write agin, close unalloc.       |
|          5- Allocate the INTRDR and submit a job to it.              |
|                                                                      |
+---------------------------------------------------------------------*/
#include <lcio.h>
#include <stdio.h>
#include "svc99h.h"
#define decksize 80
#define maxdeck 9
#define DATA_SET_NAME "your.dataset.name"

/*----------------------------------------------------------------+
 | Test the svc99() function                                      |
 +----------------------------------------------------------------*/
void main(int argc, char *argv[])
{
 FILE *fptr,                  /* ddname for TST DD                */
      *inf;                   /* ddname for job to submit         */
 int rc;                      /* Return code                      */
 char buffer[81];             /* Buffer to read in job to submit  */
 char infile[50] = "DSN:";    /* Area for the infile name         */

/*----------------------------------------------------------------+
 *----------------------------------------------------------------|
 |          1- Alloc a new dataset, write to it, close & unalloc. |
 |----------------------------------------------------------------*
 +----------------------------------------------------------------*/
 printf("********Test # 1*****************\n");
 printf("1- Alloc a new dataset, write to it, close & unalloc.\n");
                              /* allocate the dataset to DD TST   */
 rc = alc_ds("TST", DATA_SET_NAME,
               "NEW", "CATLG", "DELETE",
               "TRK", 5, 2, 0,
               "FB", 80, 3200, "PS");
 if (rc!=0)
   {
    printf("Error allocating TST\n");
    exit(rc);
   }
 else
    printf("Allocation of DD TST Successful!\n");

                              /* Open the new file -- write       */
 fptr = fopen("TST","w");
 if (fptr == NULL)
   {
     printf("Open on DD TST failed\n");
     exit(12);
   }
 else
    printf("Open of DD TST Successful!\n");

                              /* Write a line to the file         */
 printf("Writing to DD TST.\n");
 fprintf(fptr, "HELLO WORLD\n");

                               /* Close the new file               */
 rc = fclose(fptr);
 if (rc!=0)
   {
    printf("Error closing DD TST\n");
    exit(rc);
   }
 else
    printf("Close of DD TST Successful!\n");

                               /* Unallocate DD TST                */
 rc = unalc_ds("TST","","");
 if (rc!=0)
   {
    printf("Error unallocating TST\n");
    exit(rc);
   }
 else
    printf("Unallocate of DD TST Successful!\n");

/*----------------------------------------------------------------+
 *----------------------------------------------------------------|
 |          2- Delete the prev dataset with the unalc_ds func.    |
 |----------------------------------------------------------------*
 +----------------------------------------------------------------*/
 printf("********Test # 2*****************\n");
 printf("2- Delete the prev dataset with the unalc_ds func.\n");
                              /* allocate the dataset to DD TST   */
 rc = alc_ds("TST", DATA_SET_NAME,
               "SHR", "DELETE", "DELETE",
               "", 0, 0, 0,
               "", 0, 0, "");
 if (rc!=0)
   {
    printf("Error allocating TST\n");
    exit(rc);
   }
 else
    printf("Allocation of DD TST Successful!\n");

                               /* Unallocate DD TST                */
 rc = unalc_ds("TST","","");
 if (rc!=0)
   {
    printf("Error unallocating TST\n");
    exit(rc);
   }
 else
    printf("Unallocate of DD TST Successful!\n");

/*----------------------------------------------------------------+
 *----------------------------------------------------------------|
 |          3- Alloc a new dataset, write to it, close & unalloc. |
 |----------------------------------------------------------------*
 +----------------------------------------------------------------*/
 printf("********Test # 3*****************\n");
 printf("3- Alloc a new dataset, write to it, close & unalloc.\n");
                              /* allocate the dataset to DD TST   */
 rc = alc_ds("TST", DATA_SET_NAME,
               "NEW", "CATLG", "DELETE",
               "TRK", 5, 2, 0,
               "FB", 80, 3200, "PS");
 if (rc!=0)
   {
    printf("Error allocating TST\n");
    exit(rc);
   }
 else
    printf("Allocation of DD TST Successful!\n");

                              /* Open the new file -- write       */
 fptr = fopen("TST","w");
 if (fptr == NULL)
   {
     printf("Open on DD TST failed\n");
     exit(12);
   }
 else
    printf("Open of DD TST Successful!\n");

                              /* Write a line to the file         */
 printf("Writting to DD TST.\n");
 fprintf(fptr, "HELLO WORLD\n");

                               /* Close the new file               */
 rc = fclose(fptr);
 if (rc!=0)
   {
    printf("Error closing DD TST\n");
    exit(rc);
   }
 else
    printf("Close of DD TST Successful!\n");

                               /* Unallocate DD TST                */
 rc = unalc_ds("TST","","");
 if (rc!=0)
   {
    printf("Error unallocating TST\n");
    exit(rc);
   }
 else
    printf("Unallocate of DD TST Successful!\n");


/*----------------------------------------------------------------+
 *----------------------------------------------------------------|
 |          4- Alloc the prev dataset, write agin, close unalloc. |
 |----------------------------------------------------------------*
 +----------------------------------------------------------------*/
 printf("********Test # 4*****************\n");
 printf("4- Alloc the prev dataset, write agin, close unalloc.\n");
                              /* allocate the dataset to DD TST   */
 rc = alc_ds("TST", DATA_SET_NAME,
               "SHR", "", "",
               "", 0, 0, 0,
               "", 0, 0, "");
 if (rc!=0)
   {
    printf("Error allocating TST\n");
    exit(rc);
   }
 else
    printf("Allocation of DD TST Successful!\n");

                              /* Open the existing file -- append */
 fptr = fopen("TST","a");
 if (fptr == NULL)
   {
     printf("Open on DD TST failed\n");
     exit(12);
   }
 else
    printf("Open of DD TST Successful!\n");

                              /* Write a line to the file         */
 printf("Writting to DD TST.\n");
 fprintf(fptr, "2nd HELLO WORLD\n");

                               /* Close the new file               */
 rc = fclose(fptr);
 if (rc!=0)
   {
    printf("Error closing DD TST\n");
    exit(rc);
   }
 else
    printf("Close of DD TST Successful!\n");

                               /* unallocate DD TST                */
 rc = unalc_ds("TST","","");
 if (rc!=0)
   {
    printf("Error unallocating DD TST\n");
    exit(rc);
   }
 else
    printf("Unallocate of DD TST Successful!\n");

/*----------------------------------------------------------------+
 *----------------------------------------------------------------|
 |          5- Allocate the INTRDR and submit a job to it.        |
 |----------------------------------------------------------------*
 +----------------------------------------------------------------*/
 printf("********Test # 5*****************\n");
 printf("5- Allocate the INTRDR and submit a job to it\n");
 if (argc > 1)
    {
    printf("Job to submit is in %s.\n", argv[1]);
    /* Submit the job */

    strcat(infile, argv[1]);  /* Put DSN: on infile name          */

    /* Alloc & open files                                         */
    inf = fopen(infile,"rb"); /* Open the INPUT jcl file          */
    if (inf == NULL)
      {
        printf("Open of the INPUT JCL  failed\n");
        exit(12);
      }

    rc = alc_intr("TST", "A");/* Dynamically alloc INTRDR         */
    if (rc!=0)
      {
       printf("Error allocating INTRDR\n");
       exit(rc);
      }
                              /* Open the INTRDR file             */
    fptr = afopen("TST","wb","","recfm=f,reclen=80");
    if (fptr == NULL)
      {
        printf("Open of the JES Reader failed\n");
        exit(12);
      }

    /* Read the input JCL and write it to the INTRDR              */
    while (fread(buffer, 80, 1, inf) != NULL)
     {
      fwrite(buffer, 80, 1, fptr);
     }

    /* Close files and deallocate the INTRDR                      */
    rc = fclose(fptr);         /* Close the INTRDR file           */
    if (rc!=0)
      {
       printf("Error closing JES reader\n");
       exit(rc);
      }

    rc = unalc_ds("TST","KEEP",""); /* Deallocate the INTRDR      */
    if (rc!=0)
      {
       printf("Error releasing INTRDR\n");
       exit(rc);
      }
    rc = fclose(inf);         /* Close the INPUT JCL file         */

    printf("SVC99C: Job %s has been submitted!\n", argv[1]);

    }
 else
    {
    printf("No job was specified to submit.\n");
    printf("  USAGE:  svc99c [\'fully.quantified.jobds(job)\']\n");
    }

 printf("SVC99C: All test complete.\n");
}

Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement