Window services coding example

This example shows the code needed to invoke window services from an assembler language program. Use this example to supplement and reinforce information that is presented elsewhere in this chapter.

EXAMPLE1 CSECT
         STM 14,12,12(13)         Save caller's registers in caller's
*                                 save area
         LR  12,15                Set up R12 as the base register
         USING EXAMPLE1,12
*        .
*        .
*        .
********************************************************************
*  Set up save area                                                *
********************************************************************
         LA  15,SAVEAREA          Load address of save area into R15
         ST  13,4(15)             Save address of caller's save area
*                                 into this program's save area
         ST  15,8(13)             Save address of this program's save
*                                 area into caller's save area
         LR  13,15                Load address of save area into R13
*        .
*        .                        Program continues....
*        .
********************************************************************
*  Call CSRIDAC to identify and access an old data object, request *
*  a scroll area, and get update access.                           *
********************************************************************
         CALL CSRIDAC,(OPBEGIN,DDNAME,OBJNAME,YES,OLD,ACCMODE,         *
               OBJSIZE,OBJID1,LSIZE,RC,RSN)
*        .
*        .                        Program continues....
*        .
********************************************************************
*  Get 50 pages of virtual storage to use as a window              *
********************************************************************
         STORAGE OBTAIN,LENGTH=GSIZE,BNDRY=PAGE,ADDR=WINDWPTR
         L  R3,WINDWPTR           Move the address of the window into
*                                 register 3
         USING  WINDOW,R3         Sets up WINDOW as based off of reg 3
********************************************************************
*  Call CSRVIEW to set up a map of 50 blocks between the virtual   *
*  storage obtained through the STORAGE macro and the data object. *
********************************************************************
         LA R4,ZERO               LOAD A ZERO INTO REGISTER 4
         ST R4,OFFSET1            Initialize offset to 0 to indicate
*                                 the beginning of the data object
         CALL CSRVIEW,(OPBEGIN,OBJID1,OFFSET1,SPAN1,(R3),ACCSEQ,       *
               REPLACE,RC,RSN)
*        .
*        .                        Program continues....
*        .                        write data in the window
*        .
********************************************************************
*  Call CSRSAVE to write data in the window to the first 50 blocks *
*  of the data object                                              *
********************************************************************
         CALL CSRSAVE,(OBJID1,OFFSET1,SPAN1,LSIZE,RC,RSN)
*        .
*        .                        Program continues....
*        .                        change data in the window
*        .
********************************************************************
*  Call CSRSCOT to write new data in the window to the first 50    *
*  blocks of the scroll area                                       *
********************************************************************
         CALL CSRSCOT,(OBJID1,OFFSET1,SPAN1,RC,RSN)
*        .
*        .                        Program continues....
*        .                        change data in the window
*        .
********************************************************************
*  Call CSRREFR to refresh the window, that is, get back the last  *
*  SAVEd data in the data object                                   *
********************************************************************
         CALL CSRREFR,(OBJID1,OFFSET1,SPAN1,RC,RSN)
*        .
*        .                        Program continues....
*        .
********************************************************************
*  Call CSRIDAC to unidentify and unaccess the data object         *
********************************************************************
         CALL CSRIDAC,(OPEND,DDNAME,OBJNAME,YES,OLD,ACCMODE,           *
               OBJSIZE,OBJID1,LSIZE,RC,RSN)
*        .
*        .                        Program continues....
*        .
         L  13,SAVEAREA+4
         LM 14,12,12(13)
         BR 14                    End of EXAMPLE1
ZERO     EQU  0                   Constant zero
GSIZE    EQU  204800              Storage for window of 50 pages (blocks)
R3       EQU  3                   Register 3
R4       EQU  4                   Register 4
         DS 0D
OPBEGIN  DC CL5'BEGIN'            Operation type BEGIN
OPEND    DC CL4'END '             Operation type END
DDNAME   DC CL7'DDNAME '          Object type DDNAME
OBJNAME  DC CL8'MYDDNAME'         DDNAME of data object
YES      DC CL3'YES'              Yes for a scroll area
OLD      DC CL3'OLD'              Data object already exists
ACCSEQ   DC CL4'SEQ '             Sequential access
ACCMODE  DC CL6'UPDATE'           Update mode
REPLACE  DC CL7'REPLACE'          Replace data in window on a map
OBJSIZE  DC F'524288'             Size of data object is 2 gig
SPAN1    DC F'50'                 Set up a span of 50 blocks
OBJID1   DS CL8                   Object identifier
LSIZE    DS F                     Logical size of data object
OFFSET1  DS F                     Offset into data object
RC       DS F                     Return code from service
RSN      DS F                     Reason code from service
SAVEAREA DS 18F                   This program's save area
WINDWPTR DS F                     Address of window's storage
WINDOW   DSECT                    Mapping of window to view the
         DS 204800C               object data
         END