Hello,
I have an issue where I try to print multiple pdfs and the first PDF gets replaced. I am putting this in a for each now but when I use a buffer to the table i don't get a compile error (but the code doesn't work). But when I do this by using the table I get the below error . I did a find first for the table earlier
"Illegal nested block statement reference to table ... "
Can anyone see what I am doing wrong?? Thanks for any help
IF pdfcheck THEN
DO:
DEFINE BUFFER bdd_pdfln FOR dd_pdfln.
FOR EACH bdd_pdfln WHERE
bdd_pdfln EQ dd_pdfhd.company AND
bdd_pdfln EQ "S" AND
bdd_pdfln EQ dd_pdfhd.rec AND
bdd_pdfln EQ dd_pdfhd.order
NO-LOCK
BREAK BY dd_pdfln.company:
{lbls\print_pdf.i &lbl=ttpdf.rept_name &ctnlbl=ttpdf.label}
IF NOT LAST-OF(dd_pdfln.company) THEN
RUN newpage IN handlePrnt.
END.
END.
maybe it "doesn't work" because the BREAK BY and LAST-OF phrase are referencing the default buffer of the table (dd_pdfln), instead of the defined buffer (bed_pdfln).
Illegal nested block statement is usually when you have a for each x within a for each x. Using defined buffers is a good way to make this work - there's only one caveat: use a define buffer for BOTH for each blocks. That way, if you refer to the original DB (or temp-) table, you'll get a heads-up...
Thomas looks to be spot on. Also, it probably isn't the cause of your error, but in my book the buffer definition should be at the top of the block, not halfway through the logic.
Note that it doesn't have to be nested for eachs, but any reference to the buffer out of scope. For each has implied scope. DO blocks require explicit scope. The underlying principle here is that you want to limit scope as much as possible by implicit or explicit scoping and use named buffers to make the scoping very clear. COMPILE LISTING will show you the scoping.