20240106

FOR (inline)

** F O R
** FOR
**
** Uma forma de looping mas como expressão

* T_X = VALUE dtype|#(FOR wa IN t_base(field = wa-field))


** Criando uma tabela à partir de outra
** (T_CUSTOMER à partir de T_ORDER)
**
  typesbegin of y_t_customer,
           kunnr type kunnr ,
         end of y_t_customer.
  typesbegin of y_customer,
           kunnr type kunnr ,
         end of y_customer.
  data t_order type table of y_customer WITH HEADER LINE.
  data s_order type y_customer .
  data t_customer type table of kunnr WITH HEADER LINE.
* Sem FOR:  LOOP como instrução
  LOOP AT t_order into data(ls_order).
     APPEND value y_customerkunnr s_order-kunnr )
     to t_customer.
  ENDLOOP.



* COM FOR:  LOOP como instrução
  t_customer =
     VALUE y_t_customer(
       FOR s_order IN t_order kunnr s_order-kunnr )
     ).



* COM FOR:  LOOP como instrução + clasula WHERE
  t_customer =
     VALUE y_t_customer(
       FOR s_order IN t_order
       WHERE AUART 'AB' )
             kunnr s_order-kunnr )
     ).



** Quando a base não é uma tabela interna
** (criar tabela com o quadrado do numero (de 1 a 10)
**

typesbegin of y_sqr,
          nbase   type i,
          sqr     type i,
       end of y_sqr,

       y_t_sqr type STANDARD TABLE OF y_sqr WITH DEFAULT KEY .

data(t_srq10=
   VALUE y_t_sqr(
      FOR then UNTIL 10
      (
         nbase i
         sqr   )
      )
   ).