Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
Good morning
What is the easiest way to move a data structure to a record format? I've been told that if the data structure length is the same as the record format I can just do the following, but for some reason it doesn't seem to be working:
write rcdfmt dsname;
It's telling me that a data structure cannot be used in the second parm. Any ideas? Thanks in advance!
Here's more detail on my issue. This is how it's coded. I'm trying to move the DS to a 512 char flat file.
dcl-f workfile usage(*output) rename(workfile:rworkfile) usropn;
As you can see below, I tried both defining the DS internally and externally with no luck.
dcl-ds ds_workfile extname('CSC530ED') qualified end-ds;
//dcl-ds ds_workfile len(512);
//dstyp char(1);
//dssku zoned(9:0);
//dsiamt zoned(13:0);
//dsvnd zoned(6:0);
//dsvpn char(15);
//dvamt zoned(13:0);
//dssvn zoned(6:0);
//dssty char(15);
//dssamt zoned(13:0);
//dsucd char(1);
//dsupc zoned(18:0);
//dsuamt zoned(13:0);
//dsccod char(3);
//dsprtp char(3);
//dsamt zoned(13:3);
//end-ds;
Here's where I'm trying to populate the DS with the necessary fields and write the WORKFILE record using the DS.
// load the EVN660P file from the CSC530P records
setll s1evnt csc530p;
reade s1evnt csc530p;
dow not %eof(csc530p);
reset rworkfile;
reset ds_workfile;
// load WORKFILE record based on price change type
select;
when sctyp = 'I'; // SKU level price change
dssku = scsku;
dsiamt = sciamt;
dsccod = sccod;
dsprtp = sccptp;
dsamt = scprice;
write rworkfile ds_workfile;
when sctyp = 'S'; // style level price change
dssty = scstyle;
dssamt = scsamt;
dsccod = sccod;
dsprtp = sccptp;
dsamt = scprice;
write rworkfile ds_workfile;
endsl;
reade s1evnt csc530p;
enddo;
It will not compile, the error says a data structure is not allowed for the operation.
I believe WRITE requires a DS defined using LIKEREC.
LikeRec(rworkfile:*output)
Ringer
If the output file is a flat file (no field definitions) then try specifying the length on the file definition:
dcl-f workfile(512) usage(*output) rename(workfile:rworkfile) usropn;