简体   繁体   English

在大型机中打开(C语言)

[英]fopen in Mainframe (C language)

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. 我不知道C代码或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: 这是我的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=*                                             
//

add an 添加一个

#include <errno.h>

rewrite the open() calls to trap errors 重写open()调用以捕获错误

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 而且您应该了解输入文件为什么不起作用的线索

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)). 在输入文件的fopen文件上,您无需指定DCB信息-因此recfm=vblrecl=50 (如果未指定,则该信息将从JCL(如果存在)或从目录(其中将是正确的))。

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)). 查看那里已经为输出指定的内容,或者vb错误(您正在写fb)或50错误(如果您有50字节的数据,逻辑上从fb定义获得), vb的lrecl应该为54,因为要包含RDW(记录描述符字),数据需要额外增加四个字节。

The is nothing wrong with your JCL, but no way to tell whether the files and definitions of files are correct. 您的JCL没错,但是没有办法判断文件和文件定义是否正确。

Down to you now. 现在到你。 If you still can't fix it, provide all the likely information. 如果仍然无法解决,请提供所有可能的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用fopen以C语言编写txt - using fopen to write in a txt in c language 没有fopen()的读文件(C语言) - Read file without fopen() (C language) 使用fopen(C编程语言)和“ a +”模式附加文件 - Appending Files using fopen (C programming language) and the “a+” Mode fopen()修改char数组的奇怪错误? [C语言] - Weird bug with fopen() modifying char array? [C language] (C 语言)我可以在另一个 fopen 指令中使用 fopen 指令吗? - (C language ) Can i use an fopen instruction inside another fopen instruction? 大型机上的C void指针 - C void Pointer on mainframe 字符串/正则表达式字符&#39;[&#39;,&#39;]&#39;,&#39;{&#39;,&#39;}&#39;用C语言在大型机TN3270(代码页1047,1147,500,249)上替换为空格 - String/Regular expression characters '[', ']', '{', '}' replaced by spaces on Mainframe TN3270 (with code page 1047,1147,500,249) in C language C - &gt;主机上的COBOL中介语通信 - C -> COBOL interlanguage communication on mainframe 该程序在 Visual Studio 2019 C_language 中无法正常运行 fopen_s(&amp;file, “filename”, r) - The program works incorrectly fopen_s(&file, “filename”, r) in visual studio 2019 C_language 在 Visual Studio 2019 C_language 中不起作用 fopen_s(&amp;file, “filename”, mode) - Does't work fopen_s(&file, “filename”, mode) in visual studio 2019 C_language
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM