Simon Chia
Simon Chia

Reputation: 11

How to update an internal table with another internal table?

I have this table and you'll notice that column VKBUR is empty:

Main table

What is the best way to populate this column with entries from another table using column VKGRP as key?

In summary, I would like to populate column VKBUR using data from L_T_ZCUSTSL04 as source. Their key is VKGRP from both tables:

Look up table

Using this lookup table, I want to pass values from VKBUR into the above table.

Thank you so much for your assistance and have a good weekend.

Upvotes: 1

Views: 11722

Answers (2)

Suncatcher
Suncatcher

Reputation: 10621

Another possible way is to fill the table using table comprehensions and table expressions

TYPES: BEGIN OF ty_mara,
             matnr TYPE matnr,
             matkl TYPE matkl,
             maktx TYPE maktx,
           END OF ty_mara,
           BEGIN OF ty_text,
             matnr TYPE matnr,
             maktx TYPE maktx,
         END OF ty_text.

 DATA: gt_text TYPE STANDARD TABLE OF ty_text.
 DATA: gt_mara TYPE STANDARD TABLE OF ty_mara.
TYPES: tty_empty TYPE STANDARD TABLE OF ty_mara WITH EMPTY KEY.

SELECT matnr, matkl UP TO 10 ROWS
  FROM mara
  INTO TABLE @gt_mara.

SELECT matnr, maktx
  INTO TABLE @gt_text
  FROM makt
   FOR ALL ENTRIES IN @gt_mara
 WHERE matnr = @gt_mara-matnr.

  DATA(gt_result) = VALUE tty_empty( FOR wa IN gt_mara ( matnr = wa-matnr matkl = wa-matkl maktx = VALUE maktx( gt_text[ matnr = wa-matnr ]-maktx OPTIONAL ) ) ).

However, it has several disadvantages compared to Dan's way, because it requires static table declaration and it creates new itab instead of modifying the existing one. So I recommend to stick to Dan's way.

Of course, construction of new table can be avoided with old good loop and table expression:

LOOP AT gt_mara ASSIGNING FIELD-SYMBOL(<fs_mara>).
  maktx = VALUE maktx( gt_text[ matnr = <fs_mara>-matnr ]-maktx OPTIONAL ).
ENDLOOP.

Upvotes: 1

Danc
Danc

Reputation: 121

If you are working with 7.4 or newer, consider the following example based on CORRESPONDING constructor operator.

TYPES: BEGIN OF gs_report,
         equnr TYPE equnr,
         eqtyp TYPE eqtyp,
        anlage TYPE anlage,
         sernr TYPE serge,
       END OF gs_report.

DATA: gt_msrpoint TYPE SORTED TABLE OF gs_report WITH NON-UNIQUE key anlage.

SELECT equi~equnr, equi~eqtyp, eanl~anlage, sernr UP TO 50 rows
  INTO TABLE @gt_msrpoint
  FROM eanl
  JOIN eastl ON eastl~anlage     = eanl~anlage
  JOIN egerh ON egerh~logiknr    = eastl~logiknr
  LEFT JOIN equi ON  egerh~equnr = equi~equnr.

SELECT equi~matnr, equi~objnr, eanl~anlage, serge AS sernr UP TO 50 rows
  INTO TABLE @DATA(gt_msrpoint1)
  FROM eanl
  JOIN eastl ON  eastl~anlage    = eanl~anlage
  JOIN egerh ON  egerh~logiknr   = eastl~logiknr
  LEFT JOIN equi ON  egerh~equnr = equi~equnr.

gt_msrpoint1 = CORRESPONDING #( gt_msrpoint1 FROM gt_msrpoint USING anlage = anlage  ).

Tested and it works.

Upvotes: 1

Related Questions