I have a column (chgkey) with 17 rows of record. How can I print first 3 records in the same line (like, raw1, raw2, raw3). Now I can print the raw1 without any problem. Any help would be appreciated. below is my code.
let rpt.chgkey = null
select * into z_charge.* from charge where charnum in
(select shtwrd_no from crbookid where
crbookid.book_no = rpt.book_no and crbookid.line_no = rpt.line_no )
let scratch = z_charge.chgkey
let rpt.chgkey = scratch
call make_charge_section(scratch) returning rpt.chgkey
print
column 1, ESC, "(s0p12h0s3b4099T", ESC, "&a0.5R"
print
print ESC,"&a15.1R", ESC,"&a15C", rpt.chgkey
If the SELECT statement (now with INTO clause) returns more than one row, you will get a runtime error unless you wrap it up in a FOREACH loop.
If you have the FOREACH loop inside the REPORT function, then it is fairly easy to deal with; if the data is provided via separate OUTPUT TO REPORT statements, it is harder.
Assuming life is easy, then:
DECLARE c CURSOR FOR
SELECT * INTO z_charge.*
FROM charge
WHERE charnum IN
(SELECT shtwrd_no FROM crbookid
WHERE crbookid.book_no = rpt.book_no AND crbookid.line_no = rpt.line_no
)
LET i = 0
FOREACH c
PRINT COLUMN (i * 20 + 1), z_charge.raw;
LET i = i + 1
IF i MOD 3 = 0 THEN PRINT END IF
END FOREACH
IF i MOD 3 != 0 THEN PRINT END IF
The loop prints the value in z_charge.raw
at an appropriate column (you can do calculations on column numbers like that). Of course, this assumes that the raw data fits inside 20 characters.
DECLARE c CURSOR FOR
SQL
SELECT FIRST 3 * INTO z_charge.*
FROM charge
WHERE charnum IN
(SELECT shtwrd_no FROM crbookid
WHERE crbookid.book_no = rpt.book_no AND crbookid.line_no = rpt.line_no
)
END SQL