1

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
MJJ3
  • 127
  • 1
  • 12
  • You need to be clearer about what you've got. It is not clear whether you have 3 columns in table `charge` called `raw1`, `raw2` and `raw3`, or whether you have a single column `raw` and you want to print information from records 1, 2 and 3 on line 1, followed by information from records 4, 5, 6 on line 2, and so on. I'm assuming the latter in my answer. You've not explained your control code hieroglyphs either. – Jonathan Leffler Aug 31 '12 at 17:12

2 Answers2

1

Use a semi-colon at the end of the print statement to supress the end of line character.

If you terminate a PRINT statement with a semicolon, however, you suppress the implicit LINEFEED character at the end of the line.

PRINT

James Allman
  • 40,573
  • 11
  • 57
  • 70
0

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
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Sorry not three row, I mean I have one column in the table with 17 rows of record, from that record what I want is only the first 3 records to print. – MJJ3 Aug 31 '12 at 19:47
  • SELECT FIRST 3 ... ORDER BY ...? The only trick is that in I4GL, you'll need to write that SELECT in an SQL ... END SQL block. – Jonathan Leffler Aug 31 '12 at 20:43