ABL插入和显示表数据

时间:2012-08-09 11:17:40

标签: progress-4gl openedge

我为这是一个非常简单的问题而道歉,但作为ABL的第一次用户开放边缘并且我卡住了。我已经将值输入到像这样的表中

METHOD PRIVATE VOID POPULATETABLE ( ):
    DEFINE VARIABLE I AS INTEGER. 
    DO I = 0 TO 100:
    CREATE TEST.

    ASSIGN TEST.CUSTOMER_NAME="SMITH"
    TEST.ORDER_NUMBER=I  
    TEST.ORDER="BOOKS" 
    TEST.COST=45.00  
    TEST.CUSTOMER_NAME = "JACKSON" 
    TEST.ORDER_NUMBER=I 
    TEST.ORDER="PAPER CLIPS"  
    TEST.COST=1.7. 
    ASSIGN TEST.CUSTOMER_NAME="JONES"  
    TEST.ORDER_NUMBER =I 
    TEST.ORDER="PENCILS"
    TEST.COST=2.50
    TEST.CUSTOMER_NAME = "TURNER"
    TEST.ORDER_NUMBER = I  
    TEST.ORDER="PENS"
    TEST.COST=0.7. 
    END.
    END METHOD.

我试图用这个

显示它们
 FOR EACH TEST:   
        DISPLAY TEST.COST TEST.CUSTOMER_NAME TEST.ORDER TEST.ORDER_NUMBER.
        RETURN.
END.

但是结果只显示输入的最后一行数据。任何人都可以帮忙,我甚至不确定显示功能是否正确或分配是否。

3 个答案:

答案 0 :(得分:3)

我会避免分配#0的订单。这只是要求让人迷惑。

define variable i as integer no-undo.

do i = 1 to 100:

  create test.

  assign
    test.order_number = i
    test.customer     = "smith"             /* you need some way to get   */
    test.order        = "books"             /* actual data for the rest   */
    test.cost         = random( 10, 100)    /* of the fields...           */
  .

end.

然后查看订单:

for each test no-lock:
  display test.
end.

答案 1 :(得分:3)

FOR FOR EACH中的“return”导致代码在第一条记录之后离开循环。删除该语句,您将看到所有记录。

FOR EACH TEST:
DISPLAY TEST.COST 
        TEST.CUSTOMER_NAME 
        TEST.ORDER 
        TEST.ORDER_NUMBER. 
RETURN.   /* this is why you're only seeing one record -  */
          /* get rid of this and you'll see all the records */
END.

答案 2 :(得分:1)

是的,我需要的只是每个记录的每个分配的创建语句,并且有效。谢谢大家,工作编码看起来像:

 CREATE TEST.

ASSIGN TEST.CUSTOMER_NAME="SMITH"
TEST.ORDER_NUMBER=I  
TEST.ORDER="BOOKS" 
TEST.COST=45.00.  
CREATE TEST.
ASSIGN  TEST.CUSTOMER_NAME = "TAYLOR" 
TEST.ORDER_NUMBER=I 
TEST.ORDER="PAPER CLIPS"  
TEST.COST=1.7.
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME="THOMPSON"  
TEST.ORDER_NUMBER =I 
TEST.ORDER="PENCILS"
TEST.COST=2.50.
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME = "TURNER"
TEST.ORDER_NUMBER = 2 
TEST.ORDER="PENS"
TEST.COST=0.7. 

FOR EACH TEST WHERE TEST.COST> 1.3 BY TEST.ORDER_NUMBER:   显示测试。   END。