Question

I'm working on opening a file from the mainframe. currently, I can't access the input file I wanted. I don't know if there is something wrong with the C code or my JCL. Anyone help me out?

Here is my code:

int main()                                               
{                                                        

 FILE *ifp, *ofp;                                        

 printf("CTRACE1\n");                                    
 ifp = fopen("dd:INPUTF", "rb, recfm=vb, lrecl=50");     
 printf("CTRACE2\n");                                    
 ofp = fopen("dd:OUTPUTF","w");                          
 printf("CTRACE3\n");                                    

 fread( buffer, sizeof( char ), LINESZ, ifp );           
 printf( "Number of characters read = %i\n", num );

 printf( "buffer = %s\n", buffer );                         

 dstr = (DATASTR*) buffer;                                  

 printf("VAR_A = %.*s\n", sizeof(dstr->VAR_A), dstr->VAR_A);
 printf("VAR_B = %.*s\n", sizeof(dstr->VAR_B), dstr->VAR_B);
 printf("VAR_C = %.*s\n", sizeof(dstr->VAR_C), dstr->VAR_C);
 printf("CTRACE4\n");                                       

 x[sizeof(x)+1]='\0';                                       
 y[sizeof(y)+1]='\0';                                       
 z[sizeof(z)+1]='\0';                                       
 printf("CTRACE5\n");                                       


 memcpy(x, dstr->VAR_A,sizeof(dstr->VAR_A));                
 memcpy(y, dstr->VAR_B,sizeof(dstr->VAR_B));                
 memcpy(z, dstr->VAR_C,sizeof(dstr->VAR_C));                
 printf("CTRACE6\n");                                       

 printf("%s,%s,%s",x,y,z);                                  
 printf("CTRACE7\n");                                       

 fwrite(buffer, sizeof(char), LINESZ, ofp);                 

 fprintf(ofp,"%s,%s,%s\n",x,y,z);                           


 fclose(ifp);                                               
 fclose(ofp);                                               
 return(0);                                                 
}                      

Here's my JCL:

...                                 
//*         TYPRUN=SCAN                                             
//JOBLIB    DD DSN=X543863.LOADLIB1,DISP=SHR                        
//STEP1     EXEC PGM=CCCGRATE                                       
//INPUTF    DD DSN=X543863.SAMPLE.INPUT01,DISP=SHR                  
//OUTPUTF   DD DSN=X543863.SAMPLE.OUTPUT01,                         
//            DISP=(NEW,CATLG,DELETE),                              
//            SPACE=(CYL,(1,1,45)),                                 
//            DCB=(RECFM=FB,LRECL=50)                               
//SYSOUT    DD SYSOUT=*                                             
//  
Was it helpful?

Solution 2

Without knowing exactly what output you get, at best it is difficult to say.

Are you trying to copy variable-length records to fixed-length records?

Two things. On the fopen for an input file you do not need to specify DCB information - so recfm=vb and lrecl=50 are not needed (the information if not specified, will be taken from the JCL (if present) or from the catalog (which will be correct)).

Since they are not needed, you have probably got them wrong :-)

Take them off, and try your program.

Looking at what you have there and have specified for the output, either the vb is wrong (you are writing an fb) or the 50 is wrong (if you have 50 bytes of data, which you logically have from your fb definition, the the lrecl for a vb should be 54, because four bytes extra to the data are needed to include the RDW (Record Descriptor Word)).

The is nothing wrong with your JCL, but no way to tell whether the files and definitions of files are correct.

Down to you now. If you still can't fix it, provide all the likely information.

OTHER TIPS

add an

#include <errno.h>

rewrite the open() calls to trap errors

if (!ifp = fopen("dd:INPUTF", "rb, recfm=vb, lrecl=50"))
  { 
  perror("ifp");
  exit(1);
  }     
 printf("CTRACE2\n");                                    
 if (!ofp = fopen("dd:OUTPUTF","w"))
  {
  perror("ofp");
  exit(1);
  }

And you should get a clue on why the input file does not work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top