Page 1 of 1

Issue in processing a file

PostPosted: Wed Aug 07, 2013 2:30 pm
by Dora ji
Hi all,

Actually i am trying to write and then update the file using seek,I am facing issue there.I am getting maxcc = 4 but nothing is written inside the dataset.In spool i am getting all the printf statements.Please look through my code and let me know the changes.

Thanks in advance!!
#include <stdio.h>                                       
int main(void)                                           
{                                                         
   FILE *fp;                                             
   printf("Process file open\n");                         
   fp = fopen("DD;FILE3","w+");                           
   printf("File opened\n");                                                     
   fputs(fp,"This is C program in Mainframe");               
   printf("Data inserted\n");                             
   fseek( fp, 7, SEEK_SET );                             
   printf("Seek performed\n");                                             
   fputs(fp,"C Programming Langauge");                   
   printf("Data transformed\n");
   fflush(fp);                   
   fclose(fp);                   
   printf("File Closed\n");     
   return(0);                   
}       

Re: Issue in processing a file

PostPosted: Wed Aug 07, 2013 3:05 pm
by steve-myers
I rarely do mainframe C programming, but I see some secondary issues that may not be directly related to your fundamental problem.

I think the file specification in your fopen function call has a problem. I think - but I'm not 100% certain - that it should be DD:FILE3, not DD;FILE3. In other words I think your semi-colon (;) should be a colon (:).

I've never done fseek on the mainframe, and only rarely (as in once, I think, and that was 10 or 20 years ago) on a toy machine, but I'm not comfortable combining fseek and an fopen specification of w+, which, if I remember toy machine C correctly, is to extend a file.

Re: Issue in processing a file

PostPosted: Wed Aug 07, 2013 3:19 pm
by NicC
You have not actually checked that the file was opened by seeing if fp == NULL. Also, you have not checked that fputs() actually wrote to the file if it is open. also, and you had this same error before, the parameters to fputs() are the other way around. Think of it like this: if you are getting (fgets() ) a book you go to the shelf first and get the book (fgets(file, string)) when you are putting (fputs() ) a book back on the shelf you get the book first and go to the shelf (fputs(string,file) ).
It almost looks as though you are getting odd bits and pieces and putting them in a program without reading about them and how they work and should be used. Read the stuff on file i/o before posting, please.

Re: Issue in processing a file

PostPosted: Wed Aug 07, 2013 4:06 pm
by steve-myers
I, too, thought about testing if the file was open, something I'm pretty religious about.

I didn't notice the fputs issues NicC noticed, probably because I make the same mistake myself all too often. The compiler should notice that, anyway, so the program would never get to execution.

Re: Issue in processing a file

PostPosted: Wed Aug 07, 2013 4:50 pm
by NicC
Further, you have basically ignored my response to an earlier query for another program when writing this program.
what is giving you a return code of 4 - the compiler or your execution step. If the compiler step, did the execution step actually run. Are you using a xxxxCLG procedure? I suggest you show us your JESMSGLG, JESJCL and JESYSMSG from your job.

Re: Issue in processing a file

PostPosted: Wed Mar 04, 2015 1:11 pm
by selinanell
JNI is not specific to z/OS, it is standarised and will be available everywhere Java is.

The thing that is specific to EBCDIC based OS's like z/OS is that you have to make the calls to Java using ASCII strings, so for instance use #pragma convert or iconv(), depending on your needs. Other than that, it's JNI as usual.

Re: Issue in processing a file

PostPosted: Wed Mar 04, 2015 2:07 pm
by enrico-sorichetti
JNI is not specific to z/OS, it is standarised and will be available everywhere Java is.

looks like You replied to the wrong topic

aparte replying to a 2 years old topic, no mention of JAVA, just good old plain C