这里需要的循环方法

时间:2018-12-14 08:03:17

标签: openedge progress-4gl

我已经在进度4GL的一位经验丰富的人的帮助下写了一个查询,但是我错过了一个要问的概念。我已经分享了查询。在这里,我需要根据每个班次的开始和结束时间(总计21 seq)计算总订单并将其分配给变量。例如看下面的

 DEFINE VARIABLE StartHour06 AS INTEGER NO-UNDO.
 DEFINE VARIABLE StartHour07 AS INTEGER NO-UNDO

FIND FIRST gdmf_shift WHERE gdmf_shift.shft_sequence = 1 NO-LOCK NO-ERROR.
StartHour06 = gdmf_shift.shft_start_hour.
StopHour07 =  gdmf_shift.shft_stop_hour.

像这样,我需要编写查询最多21个移位序列..实际上它不是一个好的代码..我需要使其简单并尝试一种方法,但是从那以后,我不知道如何分配变量。请在下面查看我尝试过的内容

DEFINE VARIABLE sSeq AS INTEGER EXTENT 21 NO-UNDO. /* start hour */
DEFINE VARIABLE eSeq AS INTEGER EXTENT 21 NO-UNDO. /* end hour */ 
FOR EACH gdmf_shift WHERE gdmf_shift.shft_sequence LE 21 NO-LOCK BY gdmf_shift.shft_sequence:
sSeq[1] = gdmf_shift.shft_start_hour.
eSeq[21] =  gdmf_shift.shft_stop_hour.
DISP sSeq[1] eSeq[21].

END。

1 个答案:

答案 0 :(得分:2)

如果要跟踪多达21个单独的换档序列。也许您应该做类似下面的代码。

现在,您只需为循环的每次迭代更新sSeq [1]和eSeq [21]。

插入移位序列作为instad数组的索引:

DEFINE VARIABLE sSeq AS INTEGER EXTENT 21 NO-UNDO. /* start hour */
DEFINE VARIABLE eSeq AS INTEGER EXTENT 21 NO-UNDO. /* end hour */ 
FOR EACH gdmf_shift WHERE gdmf_shift.shft_sequence LE 21 NO-LOCK BY gdmf_shift.shft_sequence:
  sSeq[gdmf_shift.shft_sequence] = gdmf_shift.shft_start_hour.
  eSeq[gdmf_shift.shft_sequence] =  gdmf_shift.shft_stop_hour.
  DISP sSeq[gdmf_shift.shft_sequence] eSeq[gdmf_shift.shft_sequence].
END.

如果您绝对需要单个变量,那么在范围上会更多代码和一个CASE语句(也可以是IF)来确定要分配的变量:

DEFINE VARIABLE sSeq1 AS INTEGER NO-UNDO. /* start hour */
DEFINE VARIABLE eSeq1 AS INTEGER NO-UNDO. /* end hour */ 
DEFINE VARIABLE sSeq2 AS INTEGER NO-UNDO. /* start hour */
DEFINE VARIABLE eSeq2 AS INTEGER NO-UNDO. /* end hour */ 
/* More variables here... */
DEFINE VARIABLE sSeq21 AS INTEGER NO-UNDO. /* start hour */
DEFINE VARIABLE eSeq21 AS INTEGER NO-UNDO. /* end hour */ 


 FOR EACH gdmf_shift WHERE gdmf_shift.shft_sequence LE 21 NO-LOCK BY gdmf_shift.shft_sequence:
   CASE gdmf_shift.shft_sequence:
     WHEN 1 THEN DO:
      sSeq1 = gdmf_shift.shft_start_hour.
      eSeq1 =  gdmf_shift.shft_stop_hour.
    END.
     WHEN 2 THEN DO:
      sSeq2 = gdmf_shift.shft_start_hour.
      eSeq2 =  gdmf_shift.shft_stop_hour.
    END.
    /* more code here */
    WHEN 21 THEN DO:
       sSeq21 = gdmf_shift.shft_start_hour.
       eSeq21 =  gdmf_shift.shft_stop_hour.
    END.
  END CASE.
END.

但这将是很多代码。如果您不喜欢该数组,请考虑使用诸如临时表之类的东西。如果像表中的名称一样命名临时表中的字段,则可以使用BUFFER-COPY,否则可以ASSIGN任意字段。

DEFINE TEMP-TABLE tt NO-UNDO
  FIELD shft_sequence   LIKE gdmf_shift.shft_sequence
  FIELD shft_start_hour LIKE gdmf_shift.s.shft_start_hour
  FIELD shft_stop_hour LIKE gdmf_shift.s.shft_stop_hour.


FOR EACH gdmf_shift WHERE gdmf_shift.shft_sequence LE 21 NO-LOCK BY gdmf_shift.shft_sequence:

  CREATE tt.
  BUFFER-COPY gdmf_shift TO tt.

END.