I4GL循环查询

时间:2012-09-04 21:05:34

标签: informix 4gl

我试图在最近几天解决这个问题,但不知道该怎么做。我想要的是从表中获取3条记录。如果有任何Informix 4GL专家,我需要一些帮助。

        declare s_curs cursor for
          SELECT * FROM crcharge
                WHERE chargenum IN
                 (SELECT shtwrd_no FROM crbookid WHERE crbookid.book_no = rpt.book_no)

                  let chgkey_count = 1
            FOREACH s_curs into z_charge.*
                  let t_col = 15
               if  chgkey_count <= 3 then
                  let chgkey_count = chgkey_count + 1
                  let chgkey_count = t_chgkey
                  let scratch = z_charge.chgkey
                  let rpt.chgkey = scratch
                  call make_charge_section(scratch) returning rpt.chgkey
                  print
                     column 1, ESC, "&a15.5R",ESC,"&a12C", rpt.chgkey #t_col+2 ,

               end if
            END FOREACH

1 个答案:

答案 0 :(得分:0)

我认为您的问题是我在以下(温和)修订代码中注释掉的内容:

DECLARE s_curs CURSOR FOR
    SELECT * FROM crcharge
     WHERE chargenum IN
           (SELECT shtwrd_no FROM crbookid WHERE crbookid.book_no = rpt.book_no)

LET chgkey_count = 0
FOREACH s_curs INTO z_charge.*
    IF chgkey_count >= 3 THEN
        EXIT FOREACH
    END IF
    LET chgkey_count = chgkey_count + 1
    --LET chgkey_count = t_chgkey        -- Probable problem
    LET scratch = z_charge.chgkey
    LET rpt.chgkey = scratch
    CALL make_charge_section(scratch) RETURNING rpt.chgkey
    PRINT COLUMN 1, ESC, "&a15.5R",ESC,"&a12C", rpt.chgkey
END FOREACH

我认为我会通过编写以下内容来简化代码:

LET chgkey_count = 0
FOREACH s_curs INTO z_charge.*
    IF chgkey_count >= 3 THEN
        EXIT FOREACH
    END IF
    LET chgkey_count = chgkey_count + 1
    LET rpt.chgkey = make_charge_section(z_charge.chgkey)
    PRINT COLUMN 1, ESC, "&a15.5R",ESC,"&a12C", rpt.chgkey
END FOREACH