QUSEC - "Pointer not set for location referenced error"

Hi All,

I have a file which lists the name of a few hundred files. Using RPG, i loop through all records in the file and or every record read, I call the QUSRMBRD API to fetch the number of records in a member. I am handling the error using QUSEC. When I hit a file which has no members, I capture the CPF message, set the record count to 0 and move on to the next record in the list file.

C     RECORDCNT     BEGSR                                        
C                                                                
C                   EVAL      nBufLen = %SIZE(MBRD0200)          
C                   EVAL      InObject = SYS_TNAME               
C                   EVAL      ObjectLib =  InObject  + InLibrary 
C                                                                
C     ObjectLib     DSPLY                                        
C                                                                
C                   CALL      'QUSRMBRD'                         
C                   PARM                    MBRD0200             
C                   PARM                    nBufLen              
C                   PARM                    Fmt                  
C                   PARM                    ObjectLib            
C                   PARM                    MemberName           
C                   PARM                    bOvr                 
C                   PARM                    QUSEC                
C                                                    
C                   IF        (QUSBAVL > 0)          
C     QUSEI         DSPLY                            
C                   EVAL      RecCount = 0           
C                   CLEAR                   QUSEI    
C                   CLEAR                   QUSERVED 
C                   ENDIF                            
C                                                    
C     RecCount      DSPLY                            
C                   EVAL      *INLR = *ON            
C                   ENDSR      
 

Open in new window


This was working fine as long as i have the QUSEC declared in my program as follows:

DQUSEC            DS                          
D QUSBPRV                 1      4B 0         
D QUSBAVL                 5      8B 0         
D QUSEI                   9     15            
D QUSERVED               16     16            
D ERRC0100               17    274    Varying
 

Open in new window


If i replace the above definition with the line below I get a "Pointer not set for referenced error":

D/COPY QSYSINC/QRPGLESRC,QUSEC

Open in new window


The pointer error shows up at run-time after the QUSRMBRD processes a file that has no members. Here is an extract of the job log:

DSPLY  CPF3C26                                                       
DSPLY           0                                                    
Pointer not set for location referenced.                             
Pointer or parameter error (C G D F).                                
C                                                                    
Pointer or parameter error (C G D F).                                
C                                                                    
Application error.  MCH3601 unmonitored by LTCFILESUB at statement   
  0000000249, instruction X'0000'. 

Open in new window

                                 

Please help.

Regards
Ali.
bhagataliAsked:
Who is Participating?
 
tliottaCommented:
First, if this is a production program, don't reference the QSYSINC members in the compiles. Copy any members to your production source library and modify them to fit your organization. Not only have there been errors in QSYSINC members (sometimes fixed by PTF and sometimes corrected only in later releases), but they are often incomplete.

IBM cannot know how you are going to use an API, so they distribute basic templates to show you generally how structures can be created. Many parts are left for you to complete.

The QUSEC structure is an example of one that you need to complete.

Gary's mention of the length points out that the QUSED01 subfield is left undefined in the QUSEC example. In your original code, you had this field in the area where QUSED01 would be:
D ERRC0100               17    274    Varying

Open in new window

(But it should not have the VARYING keyword because it's not a variable length field.)

Not only that, but the IBM samples aren't very well coded. They tend to use old coding methods that aren't always appropriate. For example, this field:
D QUSBPRV                 1      4B 0

Open in new window

probably should be:
D QUSBPRV                       10U 0

Open in new window

Coding 'B' data types where actual binary integers are intended will eventually get you in trouble. Also, the use of FROM and TO positions when simple data type and length will work can cause additional problems when alignment of data items is needed.

Now, you could code a data structure subfield immediately after the /COPY statement in order to add a ERRC0100 variable just like your original. But the /COPY member already has another DS immediately after the QUSEC DS. You have no way to add any correcting lines to your program. You could delete the QUSC0200 DS from the IBM /COPY member, but that would mess it up for other programmers. And if IBM ever releases a PTF for it, your change would disappear.

For those reasons and others, don't use /COPY to bring QSYSINC members into production programs. Make your own copies first and modify those copies to fit your organization's needs. It's reasonable to reference them in test programs; just be aware that they still will probably need work.

Tom
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
What's in the copybook?  Look carefully and see what's different.  Watch out for commented-out fields.

- Gary Pattterson
0
 
bhagataliAuthor Commented:
This is what is in there:

There are some differences, but i am not able to figure out why they are causing a pointer not set for reference and what I can do to overcome that.


D***************************************************************** 
DQUSEC            DS                                               
D*                                             Qus EC              
D QUSBPRV                 1      4B 0                              
D*                                             Bytes Provided      
D QUSBAVL                 5      8B 0                              
D*                                             Bytes Available     
D QUSEI                   9     15                                 
D*                                             Exception Id        
D QUSERVED               16     16                                 
D*                                             Reserved            
D*QUSED01                17     17                                 
D*                                                                 
D*                                      Varying length             
DQUSC0200         DS                                               
D*                                             Qus ERRC0200    
D QUSK01                  1      4B 0                          
D*                                             Key             
D QUSBPRV00               5      8B 0                          
D*                                             Bytes Provided  
D QUSBAVL14               9     12B 0                          
D*                                             Bytes Available 
D QUSEI00                13     19                             
D*                                             Exception Id    
D QUSERVED39             20     20                             
D*                                             Reserved        
D QUSCCSID11             21     24B 0                          
D*                                             CCSID           
D QUSOED01               25     28B 0                          
D*                                             Offset Exc Data 
D QUSLED01               29     32B 0                          
D*                                             Length Exc Data 
D*QUSRSV214              33     33                             
D*                                             Reserved2       
D*                                                             
D*QUSED02                34     34                             
D*                                                             
D*                                      Varying Length    @B1A 

Open in new window

0
 
Gary PattersonVP Technology / Senior Consultant Commented:
The error means that you are referencing a variable that has a null pointer assigned.  Usually this happens when you pass a parameter that wasn't set in the calling program.  In your program with the hardcoded QUSEC, , QUSEC is a total of 274 bytes long.  

In the copy book, QUSEC is 16 bytes long.  

That's probably what is causing the problem, directly or indirectly.  Do you (or the called API) attempt to reference something past the 16th byte of QUSEC?

You probably need to provide at least one byte for the error structure.

- Gary Patterson

0
 
MurpheyApplication ConsultantCommented:
Hi Ali,

Thee is a diference between teh file discribed and the copy member version:

File discribed:
-----------------
D ERRC0100               17    274    Varying

Copy Member:
------------------
D*QUSED01                17     17                                 
D*                                      Varying length          

Open in new window


Why is the copy-member field only one position end the other 258?
Why is there a star in the remark position on column 7?
and Varying should be used without length
Both points could be the problem.

Regards,
Murph


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.