Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Management of Dat between 2 tables

amine_lamkaissi
Active Contributor
0 Kudos

Hi experts,

In BW, i have 2 tables:

Table 1:

Account

YesNo

Value1

A1

No

A2

Yes

A3

Yes

ABC

Table 2:

Account

Value2

ForcedValue

A1

XXX

A2

YYY

A3

ZZZ

The aim is to feed field Forced value of Table 2 by reading the table 1 by comparing the accounts (field Account).

The conditions are as following:

If field YesNo = No à Then let field Forced value empty

f field YesNo= Yes à then I have 2 cases to manage:

If Value1 is empty then  ForcedValue = Value2.

If Value1 containes a value then ForcedVaue = Value1.

Below my solution, let me know what do you think about it and how can I enhance it.

I am also concerned by performance, because my example containes only 3 records, but in reality I will have millions of records to treat.

Thanks.

Amine

5 REPLIES 5

amine_lamkaissi
Active Contributor
0 Kudos

What I expect regarding my example is:

Table 2:

Account

Value2

ForcedValue

A1

XXX

A2

YYY

A3

ZZZ

ABC

DATA: wt_table1    TYPE TABLE OF table1.


DATA: wt_table2   TYPE TABLE OF table2.


DATA: wa_ table     TYPE table2.


CLEAR wa_ table1  .


READ TABLE wt_table2  INTO wa_ table   WITH KEY
Account = Table1-Account
BINARY SEARCH.


If Table1-YesNo = ‘No’.

Clear wa_table-ForcedValue.


If Table1-YesNo = ‘Yes’.

If Table1-Value is initial.

                wa_table-ForcedValue = Table2-Value2.

          Else.

                wa_table-ForcedValue = Table1-Value1.

          Endif.

          Endif.

Endif.


Append wa_table to wt_table2.


Thanks to all.

Amine

0 Kudos

Hi Amine,

  • If you use BINARY SEARCH you must sort standard table first, or use sorted table type.
  • In READ TABLE I guess you should have wt_table1 instead of wt_table2 (you never use wa_table1, it is just cleared once).
  • I am not sure what do you mean by syntax if TABLE1-YesNo. If it is database table then you need to use SELECT statement or if internal table then you must use READ TABLE.

In general algorithm looks ok for me, just requires proper variables references and sorted table if you want have quick searching (in case of many rows are processed).

Regards,

Adam

0 Kudos

Hi Adam,

Thanks for your answer.

I have a question please. In the case of my read:

READ TABLE wt_table2  INTO wa_ table

If Table1-YesNo = ‘No’.

For my if statements, do i have to use work area insetad of table?

thanks.

Amine

0 Kudos

Yes, you should use a structure (or work area) in your IF statement.

An internal table is a table, so it can have multiple records and the system can't know on its own which particular record it should look at. On the other hand, a structure would only have one record and therefore there isn't any ambiguity.

There is an exception to what I wrote above. In old ABAP programming, internal tables with headers used to defined (using the OCCURS addition). In that case, the header used to act as a structure (or work area) and used to be referred using the same name as the internal table. In those cases, you could use the internal table name (although even then you would be referring to the header or work area) in an IF statement.

0 Kudos

Thanks Kumar for your clarifications.

Amine