Longpela Expertise logo
Longpela Expertise Consulting
Longpela Expertise
Home | Press Room | Contact Us | Site Map
FAQ


Get z/OS System Information from C

 

This sample program shows how to get basic information about the z/OS system from C.

It returns the:

  • z/OS name (the SMFID)
  • z/OS version
  • Sysplex name
  • Name of the current job or task running the program.
/* ================================================================== */
/* LPINFO                                                             */
/*                                                                    */
/*    This C sample program shows how to get basic z/OS information,  */
/*    including:                                                      */
/*       z/OS name (the SMFID)                                        */
/*       z/OS version                                                 */
/*       Sysplex Name                                                 */
/*       Name of the current running job                              */
/*                                                                    */
/*    Unfortunately, z/OS doesn't provide functions to get this       */
/*    information, so we use z/OS control blocks. Find out more       */
/*    about z/OS control blocks in the articles at:                   */
/*    http://www.longpelaexpertise.com.au/ezine/CtBlksBeginners1      */
/*    and                                                             */
/*    http://www.longpelaexpertise.com.au/ezine/CtBlksBeginners2      */
/*                                                                    */
/*                                                                    */
/*                                       David Stephens               */
/*                                       23-Sep-2010                  */
/*                                       Longpela Expertise           */
/*                                       www.longpelaexpertise.com.au */
/*                                                                    */
/* (C) Copyright 2010 Longpela Expertise                              */
/*                                                                    */
/* This program is free software: you can redistribute it and/or      */
/* modify it under the terms of the GNU General Public License as     */
/* published by the Free Software Foundation, either version 3 of the */
/* License, or (at your option) any later version.                    */
/*                                                                    */
/* This program is distributed in the hope that it will be useful,    */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of     */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   */
/* General Public License for more details at                         */
/* http://www.gnu.org/licenses/                                       */
/* ================================================================== */

/* ================================================================== */
/* Includes and Variables                                             */
/* ================================================================== */
/* --- Includes  ---------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>

/* --- Variables ---------------------------------------------------- */
int rc;
char * str1;                           /* Output buffer               */

/* ================================================================== */
/* Map z/OS Control Blocks                                            */
/* ================================================================== */
/* --- Map PSA ------------------------------------------------------ */
struct psa {
   char psastuff[16];                  /* 16 bytes before CVT Ptr     */
   struct cvt *psacvt;
   char psastuff2[528];                /* 540 bytes before ASCB Ptr   */
   struct ascb *psaaold;
   /* Ignore the rest of the PSA */
};

/* --- Cut down CVT Structure --------------------------------------- */
 struct cvt {
    char cvtstuff[140];                /* 140 bytes before ptr        */
    struct ecvt *cvtecvt;              /* Ptr to ECVT                 */
    char cvtstuff2[196];               /* 196 bytes before SMFID      */
    char cvtsname[8];                  /* SMFID                       */
    /* Ignore the rest of the CVT */
 };

/* --- Cut down ECVT Structure -------------------------------------- */
    struct ecvt {
       char ecvtecvt[8];               /* 8 Bytes before Sysplex      */
       char ecvtsplx[8];               /* Sysplex Name                */
       char ecvtstuff[496];            /* 326 Bytes before LPAR name  */
       char ecvtpver[2];               /* z/OS Version                */
       char ecvtprel[2];               /* z/OS Release                */
       /* Ignore the rest of the ECVT */
    };
/* --- Cut down ASCB ------------------------------------------------ */
struct ascb {
   char ascbstuff[172];                /* 140 bytes before ptr        */
   char *ascbjbni;                     /* Jobname (if any)            */
   char *ascbjbns;                     /* STC Name                    */
   /* Ignore the rest of the ASCB */
};

struct psa *psa_ptr = 0;               /* PSA is at address 0         */

/* ================================================================== */
/* Main Program                                                       */
/* ================================================================== */
main() {
   /* --------------------------------------------------------------- */
   /* Set Things Up                                                   */
   /* --------------------------------------------------------------- */
   str1= (char *)malloc(256);          /* Area for printing strings   */
   memset(str1,0,255);                 /* Zero output buffer          */

   /* --------------------------------------------------------------- */
   /* Output z/OS System Name                                         */
   /* --------------------------------------------------------------- */
   memcpy(str1,psa_ptr->psacvt->cvtsname,8);
   printf("z/OS Name: %s\n",str1);
   memset(str1,0,8);                   /* Zero output buffer          */

   /* --------------------------------------------------------------- */
   /* Output z/OS Version                                             */
   /* --------------------------------------------------------------- */
   memcpy(str1,psa_ptr->psacvt->cvtecvt->ecvtpver,2);
   memcpy(str1+2,".",1);
   memcpy(str1+3,psa_ptr->psacvt->cvtecvt->ecvtprel,2);
   printf("z/OS Version: %s\n",str1);
   memset(str1,0,8);                   /* Zero output buffer          */

   /* --------------------------------------------------------------- */
   /* Output SYSPLEX name                                             */
   /* --------------------------------------------------------------- */
   memcpy(str1,psa_ptr->psacvt->cvtecvt->ecvtsplx,8);
   printf("Sysplex Name: %s\n",str1);
   memset(str1,0,8);                   /* Zero output buffer          */

   /* --------------------------------------------------------------- */
   /* Output Current Jobname                                          */
   /* --------------------------------------------------------------- */
   if (*psa_ptr->psaaold->ascbjbni) {
      /* --- Running in batch --------------------------------------- */
      memcpy(str1,psa_ptr->psaaold->ascbjbni,8);
      printf("Batch Job Name: %s\n",str1);
   } else {
      memcpy(str1,psa_ptr->psaaold->ascbjbns,8);
      printf("STC Name: %s\n",str1);
   }
   memset(str1,0,8);                   /* Zero output buffer          */

}                                      /* main                        */

Learn about control blocks from the LongEx Mainframe Quarterly article Control Blocks for Beginners



Longpela Expertise can help with your C language projects. We can port C applications to z/OS, and tune C systems running on z/OS. Contact us to get your own mainframe C expert.

© Copyright 2010 Longpela Expertise  |  ABN 55 072 652 147
Legal Disclaimer | Privacy Policy Australia
Website Design: Hecate Jay