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


/*-------------------------------------------------------------------+  00010000
|                Copyright (c) 1996, SAS Institute Inc.              |
|                  Unpublished - All Rights Reserved                 |
|                      S A S / C   S A M P L E                       |
|                                                                    |
|         NAME: IMSC                                                 |
|     LANGUAGE: C                                                    |
|      PURPOSE: Demonstrate calls to IMS and to read all of the      |
|               checking account information for all customers having|
|               a particular ZIP code and print the information to   |
|               STDOUT. This example is a simple DL/I batch program. |
|               The data base upon which it operates is a simplified |
|               banking data base which has two segments: CUSTOMER,  |
|               which describes the bank's customers, and CHCKACCT,  |
|               which contains the customer's checking account       |
|               information. One of the fields in the CUSTOMER       |
|               segment contains the customer's ZIP code.            |
|                                                                    |
|             * See Technical Support Programmer's Report, entitled, |
|               DEVELOPING IMS-DLI APPLICATIONS IN C WITH THE SAS/C  |
|               COMPILER, for more information on this example as    |
|               well as general IMS - SAS/C information.             |
| SYSTEM NOTES: Written for OS.                                      |
|               Compatibility is limited to IMS.                     |
|                                                                    |
|   MVS -                                                            |
| COMPILE,LINK,EXECUTE: submit prefix.SAMPLE.AUX(IMSC)               |
|        USAGE: Invoke from a valid IMS environment                  |
|   REFERENCES: SAS/C Compiler and Library User's Guide              |
|               IBM-IMS/VS Version 1 Primer                          |
|               IBM-IMS/VS Version 1 Application Programming         |
|               IBM-IMS/VS Version 1 Installation Guide              |
|                                                                    |
+-------------------------------------------------------------------*/
#include <stdio.h>
#include <packed.h>

/* DECLARE A STRUCTURE TYPE TO MAP THE CHCKACCT SEGMENT */

typedef struct {
  char number[12];       /* Account Number          */
  char balance[5];       /* Account Balance         */
  char date[8];          /* Last Transaction Date   */
  char stmt_bal[5];      /* Last Statement Balance  */
  char filler[8];
  } Account_Segment;

#include "imschdr.h"                            /* DB PCB structure */

/* DECLARE FUNCTION TO PRINT THE CHECKING ACCT. INFO.   */
static void print_account(const Account_Segment *);

/* DEFINE A MACRO TO SIMPLIFY CHECKING THE STATUS CODE  */
#define STATUS(pcb,code) (memcmp(pcb->status_code,code,2) == 0)

/*****************************************************************/
/* THIS PGM IS PASSED TWO PCB'S,OF WHICH ONLY THE SECOND IS USED */
/*****************************************************************/

void main(int argc,struct PCB *argv[])
  {
  struct PCB *db_pcb;         /* Declare a PCB pointer      */
  Account_Segment ioarea;     /* Declare an I/O Area        */
  char GU[4] = "GU  ";        /* Create fn. code parameters */
  char GN[4] = "GN  ";        /* as auto character arrays   */

/*****************************************************************/
/* CREATE TWO SSAs. THE FIRST SSA IS QUALIFIED SO THAT DL/I WILL */
/* RETURN ONLY THOSE CUSTOMER SEGMENTS FOR WHICH THE CUSTOMER'S  */
/* ZIPCODE IS EQUAL TO 26001-00.  THE SECOND SSA IS UNQUALIFIED  */
/* SO THAT ALL OF THE CHCKACCT SEGMENTS FOR THOSE CUSTOMERS WILL */
/* BE RETURNED.                                                  */
/*****************************************************************/

  char ssa1[] = "CUSTOMER(CUSTZIP  =26001-0670)";
  char ssa2[] = "CHCKACCT ";

  if (argc < 3) {             /* Ensure PCB pointers were passed */
     fputs("DB PCB not passed.",stderr);
     exit(8);
     }

  db_pcb = argv[2];           /* Only the 2nd PCB will be used   */

  /***************************************************************/
  /* ISSUE A GET UNIQUE REQUEST TO DL/I TO POSITION TO THE FIRST */
  /* MATCHING CUSTOMER SEGMENT.                                  */
  /***************************************************************/

  asmtdli(GU, db_pcb, &ioarea, ssa1, ssa2);
  printf("   Status Code: %.2s:n", db_pcb->status_code);

  while (STATUS(db_pcb,"  ")) {

     /***********************************************************/
     /* PRINT THE CHECKING ACCOUNT INFORMATION. ISSUE A GET     */
     /* NEXT REQUEST TO DL/I TO GET THE NEXT CHCKACCT SEGMENT.  */
     /***********************************************************/

     print_account(&ioarea);
     asmtdli(GN, db_pcb, &ioarea, ssa1, ssa2);
     }

   exit(0);
   }

/****************************************************************/
/* PRINT THE INFORMATION FROM THE CHCKACCT SEGMENT TO STDOUT    */
/****************************************************************/

static void print_account(const Account_Segment *ioarea)
   {
   double d;

   puts("Account Segment Info:\n");
   printf("   Number: %.12s\n", ioarea->number);

   /* Convert the current balance to double for printing        */
   d = _pdval((char (*)[])ioarea->balance, 5, 2);
   printf("   Balance: %6.2f\n", d);
   printf("   Date: %.8s\n", ioarea->date);

   /* Convert the last statement balance to double for printing */
   d = _pdval((char (*)[])ioarea->stmt_bal, 5,2);
   printf("    Statement Balance: %6.2f\n\n", d);
   }


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