DLCOBJ not releasing the file - rpgle

maybe someone can help - I have a CL program where I perform ALCOBJ to a file, then call RPG program and then perform in the CL DLCOBJ. The file is not releasing. Thanks
it's a pf file, In the CL program I perform ALCOBJ on the file, clean the file, call the RPG program where I write to the file in SQL (there is no opening and closing of the file), it ends with *INLR. there is no OVR.
CL:
ALCOBJ OBJ((LIB/FILE *FILE *EXCL)) SCOPE(*JOB)
CALL PGM(PROGRAM)
DLCOBJ OBJ((FILE *FILE *EXCL))
RPGLE:
DCL-F File Template;
DCL-DS x Likerec(File);
. . .
Exec sql insert into File values(:x);
ExSr $SendFileExcel;
*INLR = *ON;
Return;

it's a pf file, In the CL program I perform ALCOBJ on the file, clean the file, call the RPG program where I write to the file in SQL (there is no opening and closing of the file), it ends with *INLR. there is no OVR.
CL:
ALCOBJ OBJ((LIB/FILE *FILE *EXCL)) SCOPE(*JOB)
CALL PGM(PROGRAM)
DLCOBJ OBJ((FILE *FILE *EXCL))
RPGLE:
DCL-F File Template;
DCL-DS x Likerec(File);
.
.
.
Exec sql insert into File values(:x);
ExSr $SendFileExcel;
*INLR = *ON;
Return;

Related

Why is my attempt to manipulate this 1GB file in Node.js deleting its contents?

I'm simply trying to overwrite the contents of a pre-generated (written with allocUnsafe(size)) 1GB file via a 4 byte buffer at an iterating offset, and before I open the file descriptor, fs.stat and the Windows file system show the correct size. As soon as I open the file descriptor, it appears both in fs.stat and in the file system the file is empty:
let stats = fs.statSync(dataPath)
let fileSizeInBytes = stats["size"]
let fileSizeInMegabytes = fileSizeInBytes / 1000000
console.log("fileSizeInMegabytes", fileSizeInMegabytes) // => fileSizeInMegabytes 1000
fd = fs.openSync(dataPath, 'w')
stats = fs.statSync(dataPath)
fileSizeInBytes = stats["size"]
fileSizeInMegabytes = fileSizeInBytes / 1000000
console.log("fileSizeInMegabytes", fileSizeInMegabytes) // => fileSizeInMegabytes 0
Why is opening the file descriptor emptying my file? Surely I'm missing something obvious, but I can't see it.
Opening the file using the w flag truncates the file, i.e. removes any contents.
You should use r+ to read and write to the file without wiping it clean.
For more info, check out the Node docs and the answers on this question.

File Handling in cpp

I am working on my Project and new to c++. I have a question related to csv file. So, I am working with multiple cpp file in a same Project (for example main.cpp, first.cpp and second.cpp). In main.cpp, I am creating two csv file which have different Name whenever I run the Code and Iopen both csv file, writing 1st row in both csv file and then Close it. Now my question is: if I wanted to open and write on these both csv file in first.cpp and second.cpp then is it possible? If yes then how can I do that?
//main.cpp
void createcsv1()
{
//creating csv file1 and writing first row
}
void createcsv2()
{
//creating csv file2 and writing first row
}
int main()
{
void createcsv1();
void createcsv2();
System ("pause");
return 0;
//first.cpp
//second.cpp
To Open a file and perform file operations(read, write, seek, truncate), all you need is the Path to the file and appropriate permissions.
I doesn't matter if you are reading from class 1 or class 2.
Try to open these two CSV files in the same way you are opening in main.cpp. you will get a file handle. Start writing in to the file using file handles.
Don't forget to close the file handle once after file operation is completed.
Example Code:
ofstream handle;
handle.open ("example.txt");
handle << "basic example.\n";
handle.close();
You can define 2 functions(createcsv1, createcsv2) in 2 cpp files.
You have to add declarations in stdafx.h.
Last, you can call functions in main() function.
int main()
{
void createcsv1();
void createcsv2();
System ("pause");
return 0;
}

Runtime error with Crystal - "Error opening file"

So I've got the following code causing issues:
if File.file?(indexPath)
puts "Have to move index"
File.rename(indexPath, "#{indexPath}.old")
end
File.new(indexPath)
File.write(indexPath, "test" )#handler.getDoc)
sleep 60.second
I would assume that this would check if the file exists, and back it up before writing a new index.html. Instead, I get the following runtime error:
Error opening file './assets/index.html' with mode 'r': No such file or directory (Errno)
0x10098ab45: *CallStack::unwind:Array(Pointer(Void)) at ??
0x10098aae1: *CallStack#initialize:Array(Pointer(Void)) at ??
0x10098aab8: *CallStack::new:CallStack at ??
0x10097c001: *raise<Errno>:NoReturn at ??
0x1009c9dd9: *File#initialize<String, String, Int32, Nil, Nil>:(Event::Event | Nil) at ??
0x1009cbba9: *File#initialize<String>:(Event::Event | Nil) at ??
0x1009cbb51: *File::new<String>:File at ??
0x10097148b: __crystal_main at ??
0x100981758: main at ??
File.new creates a new instance of the File class, not a new file. Since you give it no further arguments it tries to open the given file in read mode, you just moved it away so that fails.
To create an empty file one would use File.touch, however opening a file in write mode, which File.write internally does, creates the file when it does not exist.
So just removing the call to File.new should work fine.

How to save a table to a file from Lua

I'm having trouble printing a table to a file with lua (and I'm new to lua).
Here's some code I found here to print the table;
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
print(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
I have no idea where the 'print' command goes to, I'm running this lua code from within another program. What I would like to do is save the table to a .txt file. Here's what I've tried;
function savetxt ( t )
local file = assert(io.open("C:\temp\test.txt", "w"))
file:write(t)
file:close()
end
Then in the print-r function I've changed everywhere it says 'print' to 'savetxt'. This doesn't work. It doesn't seem to access the text file in any way. Can anyone suggest an alternative method?
I have a suspicion that this line is the problem;
local file = assert(io.open("C:\temp\test.txt", "w"))
Update;
I have tried the edit suggested by Diego Pino but still no success. I run this lua script from another program (for which I don't have the source), so I'm not sure where the default directory of the output file might be (is there a method to get this programatically?). Is is possible that since this is called from another program there's something blocking the output?
Update #2;
It seems like the problem is with this line:
local file = assert(io.open("C:\test\test2.txt", "w"))
I've tried changing it "C:\temp\test2.text", but that didn't work. I'm pretty confident it's an error at this point. If I comment out any line after this (but leave this line in) then it still fails, if I comment out this line (and any following 'file' lines) then the code runs. What could be causing this error?
I have no idea where the 'print' command goes to,
print() output goes to default output file, you can change that with io.output([file]), see Lua manuals for details on querying and changing default output.
where do files get created if I don't specify the directory
Typically it will land in current working directory.
Your print_r function prints out a table to stdout. What you want is to print out the output of print_r to a file. Change the print_r function so instead of printing to stdout, it prints out to a file descriptor. Perhaps the easiest way to do that is to pass a file descriptor to print_r and overwrite the print function:
function print_r (t, fd)
fd = fd or io.stdout
local function print(str)
str = str or ""
fd:write(str.."\n")
end
...
end
The rest of the print_r doesn't need any change.
Later in savetxt call print_r to print the table to a file.
function savetxt (t)
local file = assert(io.open("C:\temp\test.txt", "w"))
print_r(t, file)
file:close()
end
require("json")
result = {
["ip"]="192.168.0.177",
["date"]="2018-1-21",
}
local test = assert(io.open("/tmp/abc.txt", "w"))
result = json.encode(result)
test:write(result)
test:close()
local test = io.open("/tmp/abc.txt", "r")
local readjson= test:read("*a")
local table =json.decode(readjson)
test:close()
print("ip: " .. table["ip"])
2.Another way:
http://lua-users.org/wiki/SaveTableToFile
Save Table to File
function table.save( tbl,filename )
Load Table from File
function table.load( sfile )

Batch modifying xls files and save it as txt file in matlab

I have a code which reads a an excel file and modifies the xls fil and then save it as an text file
[f,n] = uigetfile('*.xls');
[num,text,row]=xlsread(f);
data=num';
temp_dir = pwd;
[f,n]=uiputfile('*.txt');
if isstr(f)
cd(n);
fid=fopen(f,'w');
[rows,cols]=size(text);
for i=1:rows
fprintf(fid,'%s\t',text{i,1:end-1});
fprintf(fid,'%s\n',text{i,end});
end
plats = '%10f\t';
[rows,cols] = size(data);
for n = 1:rows-2
plats = [plats,'%10f\t'];
end
now I have like 100 xls file and I want to this process for all of them like batch processing.
I know that I could use :
files_from= dir(fullfile(from_dir,'*.xls'));
for i = 1:length(files_from)
FileName=files_from(i).name;
[num,txt,all]= xlsread(fullfile(from_dir,FileName));
xlswrite(fullfile(to_dir, files_from(i).name),data);
end
but I can't get it write :((((((((
please any suggestion?????

Resources