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 1996 (c), SAS Institute Inc.                 |
|                Unpublished - All Rights Reserved                    |
|                                                                     |
|                     S A S / C  S A M P L E                          |
|                                                                     |
|       Name: TELBOOK                                                 |
|                                                                     |
|   Language: C                                                       |
|                                                                     |
| EntryPoint: MAIN                                                    |
|                                                                     |
| EntryType : OS Entry Linkage                                        |
|                                                                     |
| Files Note: 'prefix' is the installation defined high level         |
|             qualifier for the SAS/C product.                        |
|                                                                     |
|    Purpose: Demonstrate calls to ISPF involving tables, file        |
|             skeletons, reports, and profiles.                       |
|                                                                     |
| MVS - Compile/Link   : submit prefix.SAMPLE.AUX(TELBOOKJ)           |
|       Execution      : See SAS Programmers Report:                  |
|                                                                     |
| CMS - Not applicable.                                               |
|                                                                     |
|      Notes:                                                         |
|                                                                     |
| Translated with permission from "IBM Interactive System             |
| Productivity Facility, Dialog Management Services and Examples"     |
| Copyright (c) 1984, 1985, 1987 by International Business            |
| Machines Corporation.                                               |
|                                                                     |
+--------------------------------------------------------------------*/
#eject


/* headers */
#include "osispf.h"
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <os.h>
#define TRUE 1
#define FALSE 0
#define NULL 0

/* global strings */
char *panel1  = "CPANEL1 ";
char *panel2  = "CPANEL2 ";
char *panel3  = "CPANEL3 ";
char *telbook = "CTELBOOK";
char *report  = "TELBRPT ";
char *tabkey  = "(TLNAM) ";
char *tabvrs  = "(TFNAM TNUM TLOC) ";
char *vplist  = "(TFNAM TLNAM TNUM TLOC) ";
char *qkeys   = "QKEYS ";
char *qnames  = "QNAMES ";
char *qrows   = "QROWS ";

/* global variables */
char dsn(|60|);
char qrowsd(|9|);
char zcmd(|9|);
char zermsg(|9|);



/*-------------------------------------------------------+
| The function of the main routine is to open/create     |
| the ISPF table, setup all variables, invoke the sel-   |
| ection and service routine, and then later close any   |
| tables and exit ISPF.                                  |
+-------------------------------------------------------*/
main()
 {
  int rc;


   /* set error processing mode to terminate for rc>12  */
   CONTROL("ERRORS  ", "CANCEL  ", DUMNUM);

   /* open the table in write mode */
   rc = TBOPEN(telbook, "WRITE ");

   /* check for first time use                          */
   if (rc == 8)
      /* create a new table with the key (ie: tabkey),  */
      /* and the non-key variables (ie: tabvars)        */
      TBCREATE(telbook, tabkey, tabvrs, DUMMY, DUMMY);

   /* move the current row pointer...get ready for      */
   /* input (one row is default)                        */
   TBSKIP(telbook, DUMNUM, DUMMY);
   VPUT(vplist, "SHARED ");

   /* display initial panel until terminated at which   */
   /* time call function to handle request              */
   rc = 0;
   while (rc != 8) {

      /* give ISPF addressability to variables          */
      VDEFINE("ZERRMSG ", zermsg, "CHAR ", 8, DUMMY, DUMMY);
      VDEFINE("ZCMD ", zcmd, "CHAR ", 8, DUMMY, DUMMY);

      /* display panel.  ISPF will not return until     */
      /* selection made                                 */
      rc = DISPLAY(panel1, DUMMY, DUMMY);
      if (!rc) {

         /* copy the values listed in vplist from the   */
         /* shared variable pool                        */
         VGET(vplist, "SHARED  ");

         /* perform service functions                   */
         /* (as requested by user)                      */
         srvrtns(zcmd);

         /* copy the values of variables listed in      */
         /* vplist back into shared variable pool       */
         VPUT(vplist, "SHARED  ");
         VPUT("ZERRMSG ", "SHARED  ");

         /* remove ISPF addressability to zermsg        */
         VDELETE("ZERRMSG ");

       }
    }

   /* user requested to exit...close the table          */
   TBCLOSE(telbook, DUMMY, DUMMY, DUMNUM, DUMMY);

   /* display ending message on ISPF log file           */
   LOG("TELB024 ");

   /* display ending message on next screen             */
   SETMSG("TELB024 ");

   /* remove the ISPF addressability of any             */
   /* VDEFINEd variables                                */
   VRESET();

 return(0);
 }



/*-------------------------------------------------------+
|  This function will perform the actual user request.   |
|  Only the first character is checked (as passed by     |
|  ISPF) - the rest are for readability.                 |
+-------------------------------------------------------*/
srvrtns(cmd)
 char *cmd;
 {
  int rc;
  char tsoname(|80|);

   /*----------------------------------------------------+
   |  Check for list of table.  If so move to top and    |
   |  display entire table.                              |
   +----------------------------------------------------*/
   if (strncmp(cmd, "List", 1) == 0) {

      /* set row pointer ahead of first row in table */
      TBTOP(telbook);

      /* display table */
      TBDISPL(telbook, panel2, DUMMY, DUMMY);
    }

   /*----------------------------------------------------+
   |  Adding row to table?  Make sure to tell user if    |
   |  operation was successful.                          |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Add", 1) == 0) {

      /* add new row...if possible */
      rc = TBADD(telbook, DUMMY);

      /* check status */
      if (rc == 0) strcpy(zermsg, "TELB013 ");
      else if (rc == 8) strcpy(zermsg, "TELB010 ");

    }

   /*----------------------------------------------------+
   |  Changing a row?       Make sure to tell user if    |
   |  operation was successful.                          |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Change", 1) == 0) {

      /* try to update a row */
      rc = TBPUT(telbook, DUMMY);

      /* check status */
      if (rc == 0) strcpy(zermsg, "TELB015 ");
      else if (rc == 8) strcpy(zermsg, "TELB018 ");

    }

   /*----------------------------------------------------+
   |  Deleting a row?  If table empty, move to first     |
   |  available row and inform user of status.           |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Delete", 1) == 0) {

      /* try to delete a row */
      rc = TBDELETE(telbook);

      /* check status */
      if (rc == 8) strcpy(zermsg, "TELB011 ");
      else {
         strcpy(zermsg, "TELB012 ");
         rc = TBSKIP(telbook, 0, DUMMY);
         if (rc == 8) TBSKIP(telbook, 1, DUMMY);
       }
    }

   /*----------------------------------------------------+
   |  Searching table?  Check for entry existing...only  |
   |  keyed variable is search.                          |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Tsearch", 1) == 0) {

      /* search for a row based on keys */
      rc = TBEXIST(telbook);

      /* if found the get data */
      if (rc == 0) TBGET(telbook, DUMMY);
    }

   /*----------------------------------------------------+
   |  Save table to disk?                                |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Vsave", 1) == 0) {

      /* output the table */
      TBSAVE(telbook, DUMMY, DUMMY, DUMNUM, DUMMY);

      strcpy(zermsg, "TELB019 ");
    }

   /*----------------------------------------------------+
   |  Get and display last entry?                        |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Getlast", 1) == 0) {

      /* point to last row and retrieve that row */
      rc = TBBOTTOM(telbook, DUMMY);
      if (rc == 0) strcpy(zermsg, "TELB016 ");
      else strcpy(zermsg, "TELB017 ");

    }

   /*----------------------------------------------------+
   |  Change/mod entry.  Entry modified is one in which  |
   |  the keyed variable is matched (ie: last name)      |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Modify", 1) == 0) {

      /* modify a row */
      rc = TBMOD(telbook, DUMMY);
      if (rc == 0) strcpy(zermsg, "TELB014 ");
      else strcpy(zermsg, "TELB013 ");

    }

   /*----------------------------------------------------+
   |  Blank current table row listing.  This blanks the  |
   |  row seen on the first panel.                       |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Zblank", 1) == 0) {

      /* set current values to null */
      TBVCLEAR(telbook);

    }

   /*----------------------------------------------------+
   |  Scan for the requested argument?  Always starts    |
   |  at the top of the table.                           |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Scan", 1) == 0) {

      /* scan the table for a given row */
      TBTOP(telbook);                   /* start at top */
      TBSARG(telbook, DUMMY);           /* look for argument */
      TBSCAN(telbook, DUMMY, DUMMY);    /* scan table */

    }

   /*----------------------------------------------------+
   |  Query the table?  Get info on the table itself.    |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Query", 1) == 0) {

      /* query to find: key variable name(s), non-key variable names */
      /*  and number of rows */
      TBQUERY(telbook, qkeys, qnames, qrows, DUMMY, DUMMY, DUMMY);

      /* display query panel */
      DISPLAY(panel3, DUMMY, DUMMY);

    }

   /*----------------------------------------------------+
   |  Prepare for a report?  Create the output file.     |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Prepare", 1) == 0) {

      rc = osddinfo("ISPFILE", dsn+1, NULL, NULL, NULL, NULL);
      if (rc != 0)
         strcpy (zermsg, "TELB026 ");
      else
      {
         /* prepare report */
         FTOPEN(DUMMY);                    /* begin file tailoring */
         FTINCL(telbook, DUMMY);           /* do file tailoring */
         FTCLOSE(report, DUMMY, DUMMY);    /* store in library */
      }
    }

   /*----------------------------------------------------+
   |  Browse a report?  Invoke the browse option.        |
   |  Edit a report?  Invoke the edit option.            |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Browse", 1) == 0 ||
            strncmp(cmd, "Edit", 1) == 0) {

      rc = osddinfo("ISPFILE", dsn+1, NULL, NULL, NULL, NULL);
      if (rc != 0)
         strcpy (zermsg, "TELB026 ");
      else
      {
         /* build fully qualified dsn (including member).  */
         *dsn = '\'';
         strcat(dsn, "(");
         strncat(dsn, report, strlen(report)-1);
         strcat(dsn, ")' ");

         /* see if report really exists */
         strcpy (tsoname, "tso:");
         strcat (tsoname, dsn);
         if (access (tsoname, R_OK) != 0)
            strcpy (zermsg, "TELB025 ");
         else
         {

            /* browse or edit report  */
            if (strncmp(cmd, "Browse", 1) == 0)
               BROWSE(dsn, DUMMY, DUMMY);
            else
               EDIT(dsn, DUMMY, DUMMY);
         }
      }
    }

   /*----------------------------------------------------+
   |  Remove the report?  Delete the member.             |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Ydestroy", 1) == 0) {

      rc = osddinfo("ISPFILE", dsn+1, NULL, NULL, NULL, NULL);
      if (rc != 0)
         strcpy (zermsg, "TELB026 ");
      else
      {
         /* destroy report */
         FTERASE(report, DUMMY);
         strcpy(zermsg, "TELB023 ");
      }
    }

   /*----------------------------------------------------+
   |  Refresh the table?  This will destroy any rows     |
   |  that have not been saved.  (It copies the disk     |
   |  version of the table into the working table.)      |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Frefresh", 1) == 0) {

      /* refresh table from disk                        */
      TBEND(telbook);                      /* close without saving; */
      TBOPEN(telbook, DUMMY);              /* reopen from disk;     */
      TBSKIP(telbook, DUMNUM, DUMMY);      /* move to first row;    */
      strcpy(zermsg, "TELB021 ");

    }

   /*----------------------------------------------------+
   |  Delete the table?  Delete the table member.        |
   +----------------------------------------------------*/
   else if (strncmp(cmd, "Kremove", 1) == 0) {

      /* remove table from disk                         */
      TBCLOSE(telbook, DUMMY, DUMMY, DUMNUM, DUMMY);
      TBERASE(telbook, DUMMY);
      TBCREATE(telbook, tabkey, tabvrs, DUMMY, DUMMY);
      strcpy(zermsg, "TELB020 ");

    }

   /*----------------------------------------------------+
   |  In case ISPF passes an unknown option, inform user |
   +----------------------------------------------------*/
   else {

      /* command passed but not found???                */
      strcpy(zermsg, "TELB027 ");

    }

 return(0);
 }


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