Re: FOPEN(
Posted: Wed Dec 07, 2022 9:45 am
DATA-INTO is able to read the file from the IFS for you... For example:
When DOC=FILE is given, the first parameter to %DATA is the IFS filename.
If the open API is returning -1, it means that something is wrong. You can retrieve the error number to determine what the error is...
The parameters you are currently sending to open() don't make any sense. You are specifying the options used by O_TEXT_CREAT, but are not providing that parameter. You are specifying options used by O_CREAT, but have told us that the file should already be there, so why are you specifying that you wish to create it? If you don't specify O_CREAT, then there is no reason to specify the parameters for it.
Assuming you want it to translate whatever the IFS file happens to be to UTF-8 (1208), the flags I'm giving above should be correct.
If you don't want it to perform any translation at all (which would make sense since both your program and file are listed as 1208 in the example where you were creating the file) then you only need this:
But you may not need to use open() at all if you are willing to let data-into read the file for you.
Code: Select all
data-into putapiwms_err
%DATA(%TRIM(IFSFILE)
:'DOC=FILE case=convert allowmissing=yes +
allowextra=yes trim=none countprefix=num_')
%PARSER('YAJLINTO');
If the open API is returning -1, it means that something is wrong. You can retrieve the error number to determine what the error is...
Code: Select all
dcl-s ptr_unix_error pointer;
dcl-s unix_error int(10) based(ptr_unix_error);
dcl-pr get_unix_error extproc('__errno') pointer;
end-pr;
.
.
FD = OPEN( %TRIM(IFSFILE)
: O_RDONLY + O_TEXTDATA + O_CCSID: 0: 1208);
If (Fd < 0);
p_errno = get_unix_error();
wwErrorMsg = 'Open failed with CPE' + %char(unix_error);
// TODO: send error message somewhere...
FClose(Fd);
Else;
Assuming you want it to translate whatever the IFS file happens to be to UTF-8 (1208), the flags I'm giving above should be correct.
If you don't want it to perform any translation at all (which would make sense since both your program and file are listed as 1208 in the example where you were creating the file) then you only need this:
Code: Select all
FD = OPEN( %TRIM(IFSFILE): O_RDONLY);