z/OS MVS Programming: Callable Services for High-Level Languages
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


C/370 example

z/OS MVS Programming: Callable Services for High-Level Languages
SA23-1377-02

The following example, coded in C/370™, creates and uses a temporary data object.
#include <stdio.h>
#include <stdlib.h>
/* Defined macros that will be used in the program.             */
#define SIZE  8*1024
#define OBJ_SIZE  8
#define PAGE_SIZE  (4*1024)
#define DWS_FILE  "DWS.FILE1 "
#define TRUE  1
#define FALSE 0
char windows[SIZE];
char *view;
void init_mem(char init_value, char *low_mem, int size);
int chk_code(long int ret, long int reason, int linenumber);
main()
{
  /* Initialized variables that will be used in the Callable    */
  /* Services.                                                  */
  char op_type1[5] = "BEGIN";
  char op_type2[5] = "END ";
  char object_type[9] = "TEMPSPACE";
  char object_name[45] = DWS_FILE;
  char scroll_area[3] = "YES";
  char object_state[3] = "NEW";
  char access_mode[6] = "UPDATE";
  long int object_size = OBJ_SIZE;
  char disposition[7] = "REPLACE";
  char usage[6] = "SEQ ";
  char object_id[8];
  long int high_offset, return_code, reason_code;
  long int offset, window_size, window_addr;
  long int span, new_hi_offset;
  long int addr;
  int i, ret, origin, errflag = FALSE;
  double id;
  /* Set up access to a Hiperspace object using TEMPSPACE.      */
  /* Check for return code and reason code after the call.      */
  csridac(op_type1, object_type, object_name, scroll_area, object_state,
          access_mode,&object_size,&object_id,&high_offset,&return_code,;
          &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Define a window in a 4K region and initialize              */
  /* variables for CSRVIEW. Define the window for  the          */
  /* TEMPSPACE and verify the return code and reason code.      */
  init_mem('0',windows,SIZE);
  addr = (int) windows % 4096;
  if (addr != 0) view = windows + 4096 - addr;
  offset = 0; window_size = 1;
  csrview(op_type1,&object_id,&offset,&window_size,view,;
          usage, disposition, &return_code, &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Change values in the window into 1.                        */
  init_mem('1',view,4096);
  /* Capture the view in the 1st window.                        */
  offset = 0; window_size = 1;
  csrscot(&object_id, &offset, &window_size,&return_code,;
          &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Make sure that CSRSAVE will not save changes for temporary */
  /* object. The return code should be equal to 8 and control   */
  /* will be returned to the program.                           */
  offset = 0; window_size = 1;
  csrsave(&object_id, &offset, &window_size, &high_offset,;
          &return_code, &reason_code);
  if (return_code != 8) {
      errflag = TRUE;
      printf("return_code was not set to proper value.\n");
  }
  /* Terminate the view to the window.                          */
  offset = 0; window_size = 1;
  csrview(op_type2,&object_id,&offset,&window_size,view,;
          usage, disposition, &return_code, &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Change values in the window array into 0's.                */
  init_mem('0',view,4096);
  /* View the window again.                                     */
  offset = 0; window_size = 1;
  csrview(op_type1,&object_id,&offset,&window_size,view,;
          usage, disposition, &return_code, &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* The values in the window should remain to 1's.             */
  for (i=0; i<4096; i++) {
      if (errflag == TRUE) printf("%d %c  ", i, view[i]);
      if (view[i] != '1') errflag = TRUE;
  }
  /* Refresh the window to 0's.                                 */
  offset = 0; window_size = 1;
  csrrefr(&object_id, &offset, &window_size,;
          &return_code, &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* The values inside the window should equal to 0's.          */
  for (i=0; i<4096; i++) {
      if (errflag == TRUE) printf("%d %c  ", i, view[i]);
      if (view[i] != 0) errflag = TRUE;
  }
  /* Terminate the view to the window.                          */
  offset = 0; window_size = 1;
  csrview(op_type2,&object_id,&offset,&window_size,view,;
          usage, disposition, &return_code, &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Terminate the access to the Hiperspace object.             */
  csridac(op_type2, object_type, object_name, scroll_area, object_state,
          access_mode,&object_size,&object_id,&high_offset,&return_code,;
          &reason_code);
  chk_code(return_code,reason_code,__LINE__);
  /* Report the status of the test.                             */
  if (errflag) {
      printf("Test failed at line %d\n", __LINE__);
      exit(1);
  }
  else {
      printf("Test successful : %s\n", __FILE__);
      exit(0);
  }
}
/* Functions that will be used in the program.                  */
/* chk_code will check return code and reason code returned from*/
/* the Callable Services. It will report an error if the code(s)*/
/* is not equal to 0.                                           */
int chk_code(long int ret, long int reason, int linenumber)
{
    if (ret != 0)
        printf("return_code = %ld instead of 0 at line %d\n",
                ret, linenumber);
    if (reason != 0)
        printf("reason_code = %ld instead of 0 at line %d\n",
                reason, linenumber);
}
/* init_mem will initialize a block of memory starting at a     */
/* given location to a specified value.                         */
void init_mem(char init_val, char *low_mem, int size)
{
    int i;
    for (i=0; i<size; i++) *(low_mem+i) = init_val;
}
//*
//*--------------------------------------------------------------------
//* JCL USED TO COMPILE, LINK, AND, EXECUTE THE C/370 PROGRAM
//*--------------------------------------------------------------------
//*
//DPTTST1A JOB 'DPT04P,DPT,?,S=I','DPTTST1',MSGCLASS=H,
//        CLASS=J,NOTIFY=DPTTST1,MSGLEVEL=(1,1)
//CC      EXEC EDCC,INFILE='DPTTST1.DWS.SOURCE(DWS1)',
//        CPARM='NOOPT,SOURCE,NOSEQ,NOMAR',
//        OUTFILE='DPTTST1.DWS.OBJECT(DWS1)'
//*--------------------------------------------------------------------
//* LINK STEP
//*--------------------------------------------------------------------
//LKED    EXEC PGM=IEWL,PARM='MAP,RMODE=ANY,AMODE=31'
//SYSLIB  DD DSN=CEE.SCEELKED,DISP=SHR
//        DD DSN=SYS1.CSSLIB,DISP=SHR
//OBJECT  DD DSN=DPTTST1.DWS.OBJECT,DISP=SHR
//SYSLIN  DD *
   ENTRY CEESTART
   INCLUDE OBJECT(DWS1)
   NAME DWS1(R)
//SYSLMOD   DD DSN=DPTTST1.DWS.LOAD,DISP=SHR
//SYSPRINT  DD SYSOUT=*
//SYSUT1    DD DSN=&&SYSUT1,UNIT=SYSDA,DISP=(NEW,DELETE,DELETE),
//    SPACE=(32000,(30,30))
//*--------------------------------------------------------------------
//* GO STEP.  THIS STEP DEFINES A NAME FOR A PERMANENT OBJECT THAT
//* THE DDNAME OBJECT TYPE WILL REFERENCE.
//*--------------------------------------------------------------------
//GO      EXEC PGM=DWS1,REGION=4M
//STEPLIB   DD DSN=CEE.SCEERUN,DISP=SHR
//          DD DSN=DPTTST1.DWS.LOAD,DISP=SHR
//SYSPRINT  DD SYSOUT=*,DCB=(RECFM=VB,LRECL=125,BLKSIZE=6000)
//PLIDUMP   DD SYSOUT=*
//SYSUDUMP  DD SYSOUT=*
//DD1       DD DSN=DPTTST1.DWS.FILE1,DISP=SHR

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014