Hello I would need help
FD = FOPEN(%TRIM(IFSFILE)
: O_WRONLY + O_CREAT + O_TRUNC + O_TEXTDATA +
O_INHERITMODE + O_CCSID
: 0
: 1208
: 1208);
If (Fd < 0);
FClose(Fd);
Else;
Bytesread = FRead(Fd:%addr(Dataread):%size(DataRead));
Data = %Subst(DataRead:1:Bytesread);
Fclose(fd);
CdeRetour = *Blanks;
Endif;
I run this command, the contents of the file contain an accent car (French) ,
This explains the 1208 in CCSID
Here is the content of the IFS file before FOPEN(
{"statut":"Error","evenementId":"8dc9d47f-b7a1-4b7a-b615-5c685ac25130","validationResultats":[{"message":"L'evenement de stock ne permet pas de créer un lot car il ne contient pas d'Article","logLevel":"Error"}]}
Then after FOPEN(
Content disappears
Can you help me
Thank you
FOPEN(
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: FOPEN(
This code makes no sense. You are writing the code as if you are calling the open() and read() APIs -- but your code says fopen and fread which are different APIs with different parameters.
Also, you posted this in the HTTPAPI forum, and it doesn't appear to be related at all to HTTPAPI.
Also, you posted this in the HTTPAPI forum, and it doesn't appear to be related at all to HTTPAPI.
Re: FOPEN(
In addition Scott, unless I am misreading it, he is also opening the file for write with O_TRUNC which I believe is what is causing the file to be empty after the close.
Looks like a case of cloning an existing piece of IFS code.
Looks like a case of cloning an existing piece of IFS code.
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: FOPEN(
Well, if he were calling the open() API, yes. O_TRUNC makes no sense in the context of fopen()
Re: FOPEN(
Good point - I must try to stop answering questions before I'm awake!Scott Klement wrote: ↑Sun Dec 04, 2022 1:56 am Well, if he were calling the open() API, yes. O_TRUNC makes no sense in the context of fopen()
But what could cause the file content to disappear then?
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: FOPEN(
Well, he's probably calling open(), but just to confuse us, has renamed it to fopen().... so the O_TRUNC is the likely culprit.
It'd be nice if he'd come on here and tell us that so we don't have to guess.
It'd be nice if he'd come on here and tell us that so we don't have to guess.
-
- Posts: 11
- Joined: Fri Dec 02, 2022 2:34 pm
Re: FOPEN(
Hello, first of all my apologies for the confusion
Indeed, it is the Open and Read function
It's a program I copied
Thank you for your reply
I'm going to do a test
Indeed, it is the Open and Read function
It's a program I copied
Thank you for your reply
I'm going to do a test
-
- Posts: 11
- Joined: Fri Dec 02, 2022 2:34 pm
Re: FOPEN(
Hello, I can not recover the contents of this Json file
{"statut":"Error","evenementId":"4b0cfac1-377c-44e8-86f5-e6013725c465","validationResultats":[{"message":"L'evenement de stock ne permet pas de créer un lot car il ne contient pas d'Article","logLevel":"Error"}]}
The code :
dcl-ds putapiwms_err qualified;
statut varchar(10);
evenementId varchar(50);
dcl-ds validationResultats dim(1);
message varchar(200);
logLevel varchar(10);
end-ds validationResultats;
end-ds putapiwms_err;
Http_setCCSIDs( 1208: 0 );
Rc = http_req( 'POST': URL: Filename: *omit: *omit: PRM_DATA: 'application/json');
If Rc = 1;
Prm_Retour = '200' ;
unlink(Filename);
else;
Prm_Retour = %Char(Rc);
Extract json file info
Reponse = GetIfsFile(%Trim(%subst(Filename:1:FileNameLen)):
Data_reponse);
Insert the contents of the .json into a table
data-into putapiwms_err %DATA(Data_reponse
:'doc=string case=convert allowmissing=yes +
allowextra=yes trim=none countprefix=num_')
%PARSER('YAJLINTO');
Prm_MessageErreur = putapiwms_err.validationResultats(1).message;
Prm_LogLevel = putapiwms_err.validationResultats(1).logLevel;
endif;
on-error;
http_error(Erreur_http);
wwErrorMsg = http_error(Erreur_http);
http_dmsg('SetError() #' +
%trim(%editc(Erreur_http:'L')) +
': '+ wwErrorMsg);
Prm_Retour = %subst(wwErrorMsg:10:3);
endmon;
Return;
dcl-proc GetIfsFile;
dcl-pi *N ind;
IfsFile char(32767) const options(*varsize);
Data char(32768);
end-pi;
FD = OPEN(%TRIM(IFSFILE)
: O_WRONLY + O_CREAT + O_TEXTDATA +
O_INHERITMODE + O_CCSID
: 0
: 1208
: 1208);
If (Fd < 0);
FClose(Fd);
Else;
// Lecture fichier Json
Bytesread = Read(Fd:%addr(Dataread):%size(DataRead));
Data = %Subst(DataRead:1:Bytesread);
Fclose(fd);
CdeRetour = *Blanks;
UNLINK(%TRIM(IFSFILE));
Endif;
Error handling
On-Error;
CdeReturn = 'ERROR';
Dump(a);
Endmon;
If CdeRetour = *Blanks;
Return *ON;
Else;
Return *Off;
Endif;
End-proc GetIfsFile;
FD = -1 so I jump on the management of On-Error, I do not understand why
Could this be a story from CCSID 1208 , because as you have noticed the message is in French with an accent
{"statut":"Error","evenementId":"4b0cfac1-377c-44e8-86f5-e6013725c465","validationResultats":[{"message":"L'evenement de stock ne permet pas de créer un lot car il ne contient pas d'Article","logLevel":"Error"}]}
The code :
dcl-ds putapiwms_err qualified;
statut varchar(10);
evenementId varchar(50);
dcl-ds validationResultats dim(1);
message varchar(200);
logLevel varchar(10);
end-ds validationResultats;
end-ds putapiwms_err;
Http_setCCSIDs( 1208: 0 );
Rc = http_req( 'POST': URL: Filename: *omit: *omit: PRM_DATA: 'application/json');
If Rc = 1;
Prm_Retour = '200' ;
unlink(Filename);
else;
Prm_Retour = %Char(Rc);
Extract json file info
Reponse = GetIfsFile(%Trim(%subst(Filename:1:FileNameLen)):
Data_reponse);
Insert the contents of the .json into a table
data-into putapiwms_err %DATA(Data_reponse
:'doc=string case=convert allowmissing=yes +
allowextra=yes trim=none countprefix=num_')
%PARSER('YAJLINTO');
Prm_MessageErreur = putapiwms_err.validationResultats(1).message;
Prm_LogLevel = putapiwms_err.validationResultats(1).logLevel;
endif;
on-error;
http_error(Erreur_http);
wwErrorMsg = http_error(Erreur_http);
http_dmsg('SetError() #' +
%trim(%editc(Erreur_http:'L')) +
': '+ wwErrorMsg);
Prm_Retour = %subst(wwErrorMsg:10:3);
endmon;
Return;
dcl-proc GetIfsFile;
dcl-pi *N ind;
IfsFile char(32767) const options(*varsize);
Data char(32768);
end-pi;
FD = OPEN(%TRIM(IFSFILE)
: O_WRONLY + O_CREAT + O_TEXTDATA +
O_INHERITMODE + O_CCSID
: 0
: 1208
: 1208);
If (Fd < 0);
FClose(Fd);
Else;
// Lecture fichier Json
Bytesread = Read(Fd:%addr(Dataread):%size(DataRead));
Data = %Subst(DataRead:1:Bytesread);
Fclose(fd);
CdeRetour = *Blanks;
UNLINK(%TRIM(IFSFILE));
Endif;
Error handling
On-Error;
CdeReturn = 'ERROR';
Dump(a);
Endmon;
If CdeRetour = *Blanks;
Return *ON;
Else;
Return *Off;
Endif;
End-proc GetIfsFile;
FD = -1 so I jump on the management of On-Error, I do not understand why
Could this be a story from CCSID 1208 , because as you have noticed the message is in French with an accent
Re: FOPEN(
I mentioned this before but you seem to have missed it.
You are specifying O_WRONLY on the open(). That says explicitly only to allow _write_ operations! So it is not surprising that a read() fails.
In fact, if you are opening for read your options really make no sense. Look them up and you'll see. In particular, O_CREAT makes no sense.
Why are you not just jetting DATA-INTO read the file for you?
You are specifying O_WRONLY on the open(). That says explicitly only to allow _write_ operations! So it is not surprising that a read() fails.
In fact, if you are opening for read your options really make no sense. Look them up and you'll see. In particular, O_CREAT makes no sense.
Why are you not just jetting DATA-INTO read the file for you?
-
- Posts: 11
- Joined: Fri Dec 02, 2022 2:34 pm
Re: FOPEN(
Thanks jonboy for the advice
So I removed O_CREAT and O_WRONLY
I still have -1 when I come back from the IFSFILE OPEN
You were asking me this question ...
“Why are you not just jetting DATA-INTO read the file for you? “
I must use the OPEN function before making a DATA_INTO ?? right ??
If not, could you help me by seeing the code how to do it?
Thank you
So I removed O_CREAT and O_WRONLY
I still have -1 when I come back from the IFSFILE OPEN
You were asking me this question ...
“Why are you not just jetting DATA-INTO read the file for you? “
I must use the OPEN function before making a DATA_INTO ?? right ??
If not, could you help me by seeing the code how to do it?
Thank you