Page 1 of 1

Simplify Code

Posted: November 23rd, 2021, 7:43 am
by lmangcahan
Hi CSPro Team,
Hope all is well. Can you help me simplify my code below? I declared F2001...F2004 individually since when I try displaying their values using concat("F2",edit("999",x)) it display the value F2001 and not the value stored to this variable.

Thank you in advance.
Numeric F2001,F2002,F2003,F2004;
filewrite(summary_file," TOTAL ERRORS PER ERRORCODE: ");
filewrite(summary_file," F2001: %d", F2001);
filewrite(summary_file," F2002: %d", F2002);
filewrite(summary_file," F2003: %d", F2003);
filewrite(summary_file," F2004: %d", F2004)

Re: Simplify Code

Posted: November 23rd, 2021, 11:00 am
by aaronw
The assignments to F2001, F2002, F2003, and F2004 are what are of interest here. Have you just tried displaying them with an error message?
errmsg("%d, %d, %d, %d", F2001, F2002, F2003, F2004);
If these values are incorrect you need to take a step back and look why that is.

Re: Simplify Code

Posted: November 23rd, 2021, 11:13 pm
by lmangcahan
Hi Aaronw,

The code below actually works but I was thinking if I can simplify it in CSPRO. I have over hundred errorcodes to declare and maybe there's a shorter steps to take. Thank you.

Re: Simplify Code

Posted: November 24th, 2021, 9:23 am
by Gregory Martin
You can potentially use the getvalue function. Something like this:
do numeric ctr = 2001 while ctr <= 2004
    string item_name = maketext("F%d", ctr);
    summary_file.write("%s: %d", item_name, getvalue(item_name));
enddo;