How can I get 0,142 instead of ,142 in my output file?
QDECFMT is set to 2 and my H spec has decedit('0,') but still can not get the zero on the left.
Thank you for your help
Aïcha

- 39
- 6
-
Not enough details. I guess from "H-Spec" that you're using some sort of RPG.I also guess your "output file" is a spooled file for printing. How to you write to it? O-Specs? Printer file? – PoC May 23 '20 at 16:20
-
Yes I am using RPGLE. No the file is a sql table and I write to it using 'write format' in the c-spec – aicha04 May 24 '20 at 22:25
-
The presentation of data (you want to have a 0 beforehand) and the actual data are most often separate. As long as there's no malfunction with your program, leave it like it is. If you defined the fields of your output table properly, any program getting data from your SQL table will most often do the right thing. But if you're just trying to insert text from numbers into your output file, I guess that the data handling concept itself is flawed. Again, too much guessing from my side, not enough details from yours. – PoC May 26 '20 at 21:04
-
my output table is getting data from a numeric operation done in my program. The field getting this data is set to decimal(15 , 3) and I've just wanted de display 0,142 instead of ,142. The problem was solved using an output file type *PF instead of *table (created with DDS with edtcode(j) on the numeric field) – aicha04 May 27 '20 at 14:20
-
@aicha04 the problem wasn't "solved" there's absolutely no difference between the actual data in the table vs the PF. It's just that UI of older tools recognize the EDTCODE specified in the PF. – Charles Jul 08 '20 at 14:48
3 Answers
the decedit
setting in RPG has zero effect on the numeric value in the DB.
It also has zero effect on how an SQL query tool displays the data.
Neither the green screen STRSQL nor the GUI Run SQL Scripts tools have an option that I could find to show lead zeros on numeric fields.
Trust the DB, the numeric value is correct.
If you really want to see it, you'd need to convert the numeric value to character with the varchar_format()
function.
select varchar_format(dec(.95,5,2), '000.00')
from sysibm.sysdummy1
EDIT
from the OP's comment
The problem was solved using an output file type *PF instead of *table (created with DDS with edtcode(j) on the numeric field)
the problem wasn't "solved" there's absolutely no difference between the actual data in the table vs the PF. It's just that UI of older tools recognize the EDTCODE specified in the PF. The reason for using an EDTCODE in a PF is so that you can use the PF as a reference file in a DSPF or PRTF and have the edit code automatically picked up.

- 21,637
- 1
- 20
- 44
Assuming you're using DDS to describe a printer file, look at IBM documentation about EDTCDE and EDTWRD in Printer Files.

- 521
- 3
- 13
Often the easy solution to number formatting in RPG is to use the defined edit codes or a custom edit word, but I do not think they will work alone in your case. No system-defined edit codes match your desired format and it looks like custom edit words always remove leading zeros: documentation and example.
In a comment you say that you are using the WRITE
operation to write to a spooled output file. You will have to do string manipulation to achieve what you want. I can think of a couple of ways to do it. You could use the function %editc(value:'X') to give you a string of the format '0847' and use %subst to cut it up and insert the ',' yourself. You could divide by 1000 and truncate it to an integer (%int or %dec), subtract that from the original, then convert those two numbers to strings with a ',' in between. Either way, you'll have to write this yourself since the basic language facilities do not format the way you want.
The same thing would happen whether your spooled file was externally described in DDS, or program described with O-specs. Either way, I would make the field a string, not a number and manually format it.

- 1,274
- 10
- 24