Need help using STORAGE macro in QSAM

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

Post Reply
pintu1228
Member
Posts: 1
Joined: Fri Mar 25, 2016 4:35 am

Need help using STORAGE macro in QSAM

Post by pintu1228 » Fri Mar 25, 2016 4:39 am

I am trying to figure out if I am doing my STORAGE macro correctly in allocating memory to expand table.

I am trying to make my code for my INSERT, DELETE and PRINT subroutines more clear and condense but am really struggling to find a way.


The goals for this program is to:

Each line in the file is 40 bytes long and contains: one letter X in column 1, a positive integer K which is 5 digits long in columns 3-7, and spaces in columns 6-40.

1. Using the STORAGE macro request space for a table of 20 packed-decimal integers, each 3 bytes long. Initialize all of the table to the value -1.
2. Store the address of the table in a fullword variable(used TABLEADD in my code), store the size of the table in a fullword variabl(used TABSIZE in my code).
3. Declare a fullword variable named something like INUSE to store the current number of values in the table.
4. If X = 'I', insert the number K into the table at the end and update INUSE. If X = 'P', print the contents of the entire table (including the -1s at the end, if any) with 5 numbers per line. (Ignore the value of K on this line.) If X = 'D', delete one number from the beginning of the table, move the remaining numbers up to the beginning and update INUSE. (Bear in mind that the unused part of the table should all be -1s.)

I would really appreciate some help because I am completely lost.


Thanks

Code: Select all

//STEP1 EXEC PROC=ASMACLG                                                             
//C.SYSLIB DD DSN=SYS1.MACLIB,DISP=SHR                                  
//         DD DSN=KC02293.SYS2.MACLIB,DISP=SHR                          
//C.SYSIN DD *                                                          
MAIN     CSECT                                                          
         PRINT NOGEN                   
         STM   14,12,12(13)            
         LR    12,15                   
         USING MAIN,12                 
         LA    14,MAINSAVE             
         ST    13,4(0,14)              
         ST    14,8(0,13)              
         LR    13,14                   
*                                      
         OPEN  (INDCB,(INPUT))         
         LTR   15,15                   
         BZ    OPEN10K                 
         ABEND 222,DUMP                
*                                      
OPEN10K  OPEN  (OUTDCB,(OUTPUT))       
         LTR   15,15                   
         BZ    OPEN20K                 
         ABEND 333,DUMP                
*                                      
OPEN20K  DS    0H                      
         LA    1,OBTMEM                
         BAL   11,ALCTE                
*                                      
LOOP1    GET   INDCB,BUFFER            
         CLI   EOFFLAG,C'Y'            
*                                      
         BZ    ENDLOOP                 
         CLI   BUFFER,C'P'                                              
         BZ    PRINTCLL                                                 
         CLI   BUFFER,C'I'                                              
         BZ    INSRTCLL                                                 
         CLI   BUFFER,C'D'                                              
         BZ    DELTECLL                                                 
         B     LOOP1                                                    
*                                                                       
PRINTCLL DS    0H                                                       
         LA    1,PRNTPLST                                               
         BAL   11,PRNT                                                  
         B     LOOP1                                                    
*                                                                       
INSRTCLL DS    0H                                                       
         PACK  NBR(3),BUFFER+2(5)                                       
         PUT   OUTDCB,=CL80'CALLING INSERT'                             
*                                                                       
         LA    1,INSTPLST                                               
         BAL   11,INSRT                                                 
         B     LOOP1                                                    
*                                                                       
DELTECLL DS    0H                                                       
         PUT   OUTDCB,=CL80'CALLING DELETE'                             
         LA    1,INSTPLST                                               
         BAL   11,DELTE                                                 
         B     LOOP1                                                    
*                                                                       
ENDLOOP  DS    0H                                                       
*                                                                       
         L     9,TABSIZE                                                
         SR    4,4                                                      
         M     4,=F'3'                                                  
         STORAGE RELEASE,LENGTH=(5),ADDR=TABLEADD                       
*                                                                       
         CLOSE (INDCB)               
         LTR   15,15                 
         BZ    CLOSE10K              
         ABEND 555,DUMP              
*                                    
CLOSE10K CLOSE (OUTDCB)              
         LTR   15,15                 
         BZ    CLOSE20K              
         ABEND 666,DUMP              
*                                                                       
CLOSE20K DS    0H                                                       
*                                                                       
         L     13,4(0,13)                                               
         LM    14,12,12(13)                                             
         BR    14                                                       
         LTORG                                                          
***************************************************************         
MAINSAVE DS    18F'-1'                 
NBR      DS    PL3                     
TABLEADD DC    F'0'                    
TABSIZE  DC    F'0'                    
TMPSIZE  DC    F'20'                    
INUSE    DC    F'0'                    
BUFFER   DC    40C' '                  
EMPTY    DC    80C' '                  
*                                                                       
OBTMEM   DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                               
         DC    A(TABSIZE)                                               
         DC    A(INUSE)                                                 
*                                                                       
PRNTPLST DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                               
*                                                                       
INSTPLST DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                               
         DC    A(INUSE)                                                 
         DC    A(NBR)                                                   
*                                                                       
***************************************************************         
INDCB    DCB   DDNAME=INPUT,                                           X
               DEVD=DA,                                                X
               DSORG=PS,                                               X
               MACRF=GM,                                               X
               RECFM=FB,                                               X
               LRECL=40,                                               X
               EODAD=EOF1                                               
*                                                                       
EOFFLAG  DC    C'N'                                                     
*                                                                       
EOF1     MVI   EOFFLAG,C'Y'                                             
         BR    14                                                       
*                                                                       
OUTDCB   DCB   DDNAME=OUTPUT,                                          X
               DEVD=DA,                                                X
               DSORG=PS,                                               X
               MACRF=PM,                                               X
               RECFM=FBA,                                              X
               LRECL=80                                                 
*                                                                       
***********INSERT SUBROUTINE***********************************         
INSRT    DS    0H                                                       
         STM   2,8,ISAVE                                                
         ST    11,RSAVE                                                 
         LM    2,5,0(1)                                                 
         L     6,0(0,3)                                                 
         L     7,0(0,4)                                                 
         CR    6,7                                                      
         BE    RESIZE                                                   
DONE     DS    0H                                                       
         L     6,0(0,2)                                                 
         L     7,0(0,4)                                                 
         LTR   7,7                                                      
         BZ    ADD                                                      
         LR    8,7                                                      
RPT      LA    6,3(0,6)                                                 
         BCT   8,RPT                                                    
ADD      DS    0H                                                       
         ZAP   0(3,6),0(3,5)                                            
         LA    7,1(0,7)                                                 
         ST    7,0(0,4)                                                 
         LM    2,8,ISAVE                                                
         L     11,RSAVE                                                 
         BR    11                                                       
*                                                                       
RESIZE   DS    0H                                                       
         SLA   6,1(0)                                                   
         ST    6,TMPSIZE                                                
         LA    1,OBTMEM                                                 
         BAL   11,ALCTE                                                 
         PUT   OUTDCB,=80C' '
         PUT   OUTDCB,=CL80'WE HAVE ALLOCATED MORE MEMORY FOR THE TABLE'                
         PUT   OUTDCB,=80C' '                                           
         PUT   OUTDCB,=CL80'WE HAVE DELETED OLD TABLE'                  
         PUT   OUTDCB,=80C' '                                    
         B     DONE                                                     
         LTORG                                                          
***********INSERT STORAGE**************************************         
ISAVE    DS    7F                                                       
RSAVE    DS    F                                                        
***********DELETE SUBROUTINE***********************************         
DELTE    DS    0H                                                       
         STM   2,8,DSAVE                                                
         ST    11,DELTSAVE                                              
         LM    2,4,0(1)                                                 
         L     6,0(0,2)                                                 
         L     5,0(0,3)                                                 
         L     7,0(0,4)                                                 
         LTR   8,7                                                      
         BZ    FNSH                                                     
RPT1     ZAP   0(3,6),3(3,6)                                            
         LA    6,3(0,6)                                                 
         BCT   6,RPT1                                                   
         DS    0H                                                       
         BCTR  7,0                                                      
         ST    7,0(0,4)                                                 
         SRA   5,1(0)                                                   
         CR    7,5                                                      
         BL    DCR                                                      
FNSH     DS    0H                                                       
*                                                                       
         LM    2,8,DSAVE                                                
         L     11,DELTSAVE                                              
         BR    11                                                       
*                                                                       
DCR      DS    0H                                                       
         ST    5,TMPSIZE                                                
         LA    1,OBTMEM                                                 
         BAL   11,ALCTE                                                 
         PUT   OUTDCB,=80C' '                                           
         PUT   OUTDCB,=CL80'WE HAVE ALLOCATED NEW TABLE'                
         PUT   OUTDCB,=80C' '                                           
         PUT   OUTDCB,=CL80'WE HAVE DELETED OLD TABLE'                  
         PUT   OUTDCB,=80C' '                                           
         B     FNSH                                                     
***********DELETE STORAGE**************************************         
DSAVE    DS    7F                                                       
DELTSAVE DS    F                                                        
***************************************************************         
ALCTE    DS    0H                                                       
         STM   2,7,ASAVE                                                
         LM    2,5,0(1)                                                 
         L     3,0(0,3)                                                 
         L     5,0(0,5)                                                 
         LR    7,3                                                      
         SR    6,6                                                      
         M     6,=F'3'                                                  
         STORAGE OBTAIN,LENGTH=(7),ADDR=TMPADD,COND=YES                 
         LTR   15,15                                                    
         BZ    DOWN                                                     
         ABEND 123,DUMP                                                 
DOWN     L     6,TMPADD                                                 
         LR    7,3                                                      
BEGN     ZAP   0(3,6),=PL1'-1'                                          
         LA    6,3(0,6)                                                 
         BCT   7,BEGN                                                   
         LTR   5,5                                                      
         BZ    JUMP                                                     
         L     6,TMPADD                                                 
         L     7,0(0,2)                                                 
DUPL     ZAP   0(3,6),0(3,7)                                            
         LA    6,3(0,6)                                                 
         LA    7,3(0,7)                                                 
         BCT   5,DUPL                                                   
JUMP     L     7,0(4)                                                   
         LTR   7,7                                                      
         BZ    SKIP                                                     
         L     7,0(0,2)                                                 
         STORAGE RELEASE,LENGTH=(5),ADDR=(7)                            
SKIP     L     6,TMPADD                                                 
         ST    6,0(2)                                                   
         ST    3,0(4)                                                   
*                                                                       
         LM    2,7,ASAVE                                                
         BR    11                                                       
         LTORG                                                          
************ALLOCATION STORAGE*********************************         
ASAVE    DS    6F                                                       
TMPADD   DS    F                                                        
************PRINT SUBROUTINE***********************************         
PRNT     DS    0H                                                       
         STM   2,5,PSAVE                                                
         LM    2,3,0(1)                                                 
         PUT   OUTDCB,=80C' '                                           
         PUT   OUTDCB,=CL80'         NUMBERS LIST'                      
         PUT   OUTDCB,=80C' '                                           
         LA    4,OLINE                                                  
         SR    5,5                                                      
         L     2,0(0,2)                                                 
         L     3,0(0,3)                                                 
         LTR   3,3                                                      
         BZ    TOP1                                                     
AGAIN    DS    0H                                                       
         MVC   0(7,4),PAT                                               
         ED    0(7,4),0(2)                                              
         LA    2,3(0,2)                                                 
         C     5,=F'4'                                                  
         BZ    NEXT1                                                    
         LA    4,8(0,4)                                                 
         LA    5,1(0,5)                                                 
         B     BOTTOM1                                                  
NEXT1    PUT   OUTDCB,OLINE                                             
         MVI   OLINE,C' '                                               
         MVC   OLINE+1(79),OLINE                                        
         LA    4,OLINE                                                  
         SR    5,5                                                      
BOTTOM1  BCT   3,AGAIN                                                  
*                                                                       
TOP1     PUT   OUTDCB,=80C' '                                           
         LM    2,5,PSAVE                                                
         BR    11                                                       
         LTORG                                                          
***********PRINT STORAGE***************************************         
PSAVE    DS    4F                                                       
OLINE    DC    80C' '                                                   
PAT      DC    X'40202020212060'                                        
***************************************************************         
         END   MAIN                                                     
/*                                                                      
//L.SYSLIB DD DSN=KC02293.SYS2.CALLIB,DISP=SHR                          
//G.INPUT  DD DSN=KC02314.SPRING16.CSCI641.HW4ADATA,DISP=SHR            
//G.OUTPUT DD DSN=&&TEMP,DISP=(NEW,PASS,DELETE)                         
//G.XSNAPOUT DD SYSOUT=*                                                
//G.XPRNT DD SYSOUT=*                                                   
//*                                                                     
//*                                                                     
//STEP2   EXEC PGM=IEBPTPCH                                             
//SYSTU1  DD DSN=&&TEMP,DISP=(OLD,DELETE)                               
//SYSTU2  DD SYSOUT=*                                                   
//SYSPRINT DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     PRINT MAXFLDS=1                                                    
     RECORD FIELD=(80)                                                  
/*                                                                      
//                                  



Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others