【问题标题】:How can I access more than 1 element from a field in Progress 4GL如何从 Progress 4GL 中的字段访问多个元素
【发布时间】:2020-12-09 19:59:32
【问题描述】:

所有。我想从一个字段中获取多个元素。例如,如果 SQL 代码如下:

SELECT cod_emit, nom_abrev FROM emit WHERE cod_emit IN ('101','102','500');

我正在尝试使用临时表将其转换为 Progress,因此代码如下

DEF TEMP-TABLE tt-emit NO-UNDO
FIELD cod-emit LIKE emit.cod-emit
FIELD nom-abrev LIKE emit.nom-abrev.
FOR EACH emit
WHERE emit.cod-emit = 101
OR emit.cod-emit = 102
OR emit.cod-emit = 500 NO-LOCK:
CREATE tt-emit.
ASSIGN tt-emit.cod-emit = emit.cod-emit
       tt-emit.nom-abrev = emit.nom-abrev.
END.

稍后,我将通过 JSON 获取临时表并将其用于我们的 .php。但是,我们需要使用的 cod-emit 将由用户插入到 .php 文件中。 我不知道在这种情况下我们是否可以使用逗号(但对于我尝试过的方法,我们不能),或者是否有任何其他解决方案来解决这个难题。感谢您的宝贵时间。

【问题讨论】:

    标签: openedge progress-4gl


    【解决方案1】:

    你可以这样做:

    define temp-table tt_emit no-undo    /* avoid using "-" in names */
      cod_emit  like emit.cod-emit
      nom_abrev like emit.nom-abrev
      /* it is not required but you really ought to define an index... */
    .
    
    define variable elist as character no-undo.
    define variable ecode as character no-undo.
    
    define variable i as integer no-undo.
    define variable n as integer no-undo.
    
    elist = '101,102,500'.
    n = num-entries( elist ).
    
    do i = 1 to n:
    
      ecode = entry( i, elist ).
    
      for each emit no-lock where emit.cod-emit = ecode:
        create tt_emit.
        assign
          tt_emit.cod_emit  = emit.cod-emit
          tt_emit.nom_abrev = emit.nom-abrev
        .
      end.
    
    end.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-05
      • 2021-02-22
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2015-08-05
      • 2014-11-10
      • 1970-01-01
      相关资源
      最近更新 更多