Diego
Diego

Reputation: 57

How can I access more than 1 element from a field in Progress 4GL

all. I want to get more than one element from a field. If, for instance, the SQL code is as folow:

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

I'm trying to transform it into Progress using temp-tables so code would be as follows

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.

Later, I would get the temp-table through a JSON and use it on our .php. However, the cod-emit we need to use will be inserted by the user in a .php. I don't know if we can use a comma in this case (but for what I tried, we can't) or if there's any other solution to this conundrum. Thanks for your time.

Upvotes: 1

Views: 161

Answers (1)

Tom Bascom
Tom Bascom

Reputation: 14020

You might do something like this:

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.

Upvotes: 1

Related Questions