Reading BSAM help



High Level Assembler(HLASM) for MVS & VM & VSE

Reading BSAM help

Postby pintu1228 » Thu Feb 18, 2016 2:02 am

Hi, I am writing an assembler program to read in data file using BSAM and writing it out to a file. I am able to read out the data but the last 7 records are repeated, there should be only 45 records but prints out 52. I know there is something I have to do with DECBBLKSIZE but don't know how.

If anyone can help me fix this issue, that would be really great.


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 777,DUMP                
*                                                                  
OPEN10K  OPEN  (OUTDCB,(OUTPUT))              
         LTR   15,15                        
         BZ    OPEN20K              
         ABEND 888,DUMP              
*                                                                      
OPEN20K  DS    0H                                                      
*                                                                      
LOOP     READ  INDECB,SF,,,,MF=E                                        
         CHECK INDECB                                                  
         CLI   EOFFLAG,C'Y'                                            
*                                                                      
         BE    ENDLOOP                    
         L     3,=F'0'                                                
         L     5,=F'13'      
                                         
NEXTLOOP LA    4,CARD                                                  
         AR    4,3                                                      
         MVC   OUTDATA(22),0(4)    
         AP    COUNT(2),=PL1'1'          
         MVC   CNT(4),=X'40202120'      
         ED    CNT(4),COUNT        
         PUT   OUTDCB,PRINTLN          
         A     3,=F'22'                                                
         BCT   5,NEXTLOOP                                              
         B     LOOP                                                    
ENDLOOP  DC    0H                                                      
         CLOSE (INDCB,,OUTDCB)        
*                                                                      
         L     13,4(0,13)                                              
         LM    14,12,12(13)                                          
         BR    14                                                      
         LTORG                                                          
*                                                                      
MAINSAVE DS    18F'-1'                          
COUNT    DC    PL2'0'                                  
PRINTLN  DC    C'RECORD'                                  
CNT      DC    4C' '                            
         DC    1C' '              
OUTDATA  DC    22C' '             OUTPUT RECORD                        
HEADER   DC    33C'              
*                                                                      
CARD     DS    CL286                                                  
*                                                                      
         READ  INDECB,SF,INDCB,CARD,286,MF=L                            
*                                                                      
INDCB    DCB   DDNAME=FT05F001,                                        
               DEVD=DA,                                                
               DSORG=PS,                                              
               MACRF=R,                                                
               RECFM=FB,                                              
               EODAD=EOF1                                              
*                                                                      
EOFFLAG  DC    C'
N'                                                    
*                                                                      
EOF1     MVI   EOFFLAG,C'
Y'                                            
         BR    14                                                    
*                                                                      
OUTDCB  DCB    DDNAME=OUTPUT,                                        
               DEVD=DA,                                              
               DSORG=PS,                                              
               MACRF=PM,                                              
               LRECL=33,                                              
               BLKSIZE=495,                                            
               RECFM=FB                                                
*                                                                      
        END    MAIN                                                    
/*                                                                      
//L.SYSLIB DD DSN=KC02293.SYS2.CALLIB,DISP=SHR                          
//G.OUTPUT DD DSN=&&TEMP,DISP=(NEW,PASS,DELETE),LRECL=33,              
//            BLKSIZE=495                                              
//G.XSNAPOUT DD SYSOUT=*                                            
//G.XPRNT DD SYSOUT=*                                                  
//*                                                                    
//*                                                                    
//STEP2    EXEC PGM=IEBPTPCH                                                        
//SYSUT1   DD DSN=&&TEMP,DISP=(OLD,DELETE)                            
//SYSUT2   DD SYSOUT=*                                                  
//SYSPRINT DD SYSOUT=*                                                  
//SYSIN    DD *                                                        
  PRINT    MAXFLDS=1                                                    
  RECORD   FIELD=(33)                    


pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Reading BSAM help

Postby enrico-sorichetti » Thu Feb 18, 2016 2:29 am

if You look closely You will find that the last seven records are the last seven record of the previous block.

register 5 used to deblock is always initialised to 13 ( the blocking factor )
without taking into account that the last block might be incomplete!
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Reading BSAM help

Postby pintu1228 » Thu Feb 18, 2016 2:40 am

So how would I fix that in my code, I have searched all over but can't find any examples, really new to BSAM
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Reading BSAM help

Postby enrico-sorichetti » Thu Feb 18, 2016 2:54 am

there is no advantage in using BSAM,
QSAM get/put work well enough.

anyway, the DECB contains after a read the residual count ( the number of bytes that were not read/ residual space in the input buffer )
subtract it from the buffer size, divide by the record length and You will have the number of records to process
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Reading BSAM help

Postby pintu1228 » Thu Feb 18, 2016 4:32 am

sorry, still am lost regarding what lines of code I need to put and where.

Any sample code regarding solution would be really helpful.


Thanks so much
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Reading BSAM help

Postby Robert Sample » Thu Feb 18, 2016 5:29 am

        L     5,=F'13'      
This works if -- AND ONLY IF -- each and every block of data has 13 records in it. Since you have 45 records (3 blocks of 13 records per block plus a final block of 6 records), and you do not check for / handle this condition, you are getting repeats of the last 7 records from the previous block as you are not doing anything to clear CARD before reading another block of data. If you clear CARD you'll get 7 blank records at the end instead of repeated records; what you really need to do is put logic into your loop -- BEFORE using the data -- to validate that you actually have usable data at that offset into CARD.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Reading BSAM help

Postby steve-myers » Thu Feb 18, 2016 6:07 am

Mr. Sorichetti is incorrect when he says the DECB contains a “residual byte count.” This value is in another data area that the DECB points to after the CHECK macro completes.

Mr. Sorrichetti is also incorrect when he states there is no advantage to using BSAM versus QSAM. Properly programmed – which yours is not – BSAM uses less CPU time and less elapsed time compared to QSAM. Except for a very large data set, you will not notice any practical difference.

You should execute this code after every CHECK macro.
         LA    0,286
         L     1,INDECB+16
         SH    0,14(,1)
The LA instruction loads the BLKSIZE you expected to read into register 0.

The L instruction loads the address of the control block that contains the residual byte count. In OS/360 this control block was known as an IOB. Part of the IOB is a hardware data area called a CSW (Channel Status Word). The CSW no longer exists in z/Architecture, but it is simulated here so code written for OS/360 will execute correctly.

The SH instruction subtracts the residual byte count in the simulated CSW from the BLKSIZE value you loaded into register 0 to compute the data bytes in the I/O buffer. Using this corrected BLKSIZE, you can compute the number of logical records in the I/O buffer, thus correcting the problem Mr. Sample observed.

These users thanked the author steve-myers for the post (total 2):
Aki88 (Thu Feb 18, 2016 10:19 am) • pintu1228 (Thu Feb 18, 2016 6:33 am)
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Reading BSAM help

Postby pintu1228 » Thu Feb 18, 2016 12:46 pm

Thanks and now how do I go about reading and writing using BSAM?
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Reading BSAM help

Postby NicC » Thu Feb 18, 2016 4:00 pm

This is not a tutorial/do my work for me forum. You said you were reading and writing already it was just that the last write wrote an incorrect block, so why do you now ask how to read/write? Go to one of the many tutorials on the web to learn. Ask questions here when something you read and tried did not work and you could not understand why.

And why is this in the PL/1 section and not the Assembler section? Moved.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Reading BSAM help

Postby steve-myers » Thu Feb 18, 2016 8:12 pm

If you can figure out how to read using BSAM, you can figure out how to write using BSAM. Based on previous experience with you, I will provide no more help, and I hope all other helpers in this forum will go along with this.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Next

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post