on 04-12-2006 1:41 PM
Hi all,
I have two internal tables.
In the first table (itab) I have some values which I have to "decode" using the second table (itabtext).
This means that I have to pick every line and replace in the itab a value like "01" with "text for 01" from itabtext.
In the itabtext "01" is the key for "text for 01".
What is the best way to handle this?
Thanks a lot,
Fabian
Hi,
If you want single table with key and corresponding text then do the following text.
Tab1--key
--Text
--etc
--etc
Tab2--key
--text
sort tab2 by key.
loop at tab1.
raed table tab2 with key = tab1-key
binary search.
if sy-subrc = 0.
tab1-text = tab2-text.
modify tab1.
endif.
endloop.
if you can do away with two tables then dont replace or decode; just use this query where you want the decoded value.
sort tab2 by key. " before use only once
raed table tab2 with key = tab1-key
binary search.
if sy-subrc = 0.
tab2-text. " use this value where u want
endif.
if its possible dont collect in one table .
if it is neccesssary use binary search only to optimize the performance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your answer but I still have the problem. The tables (two texttables instead of one what I wrote in the first message) are the following:
DATA: BEGIN OF lt_proclocktexts OCCURS 0.
DATA: lockprocid(2) TYPE c,
text(40) TYPE c.
DATA: END OF lt_proclocktexts.
DATA: BEGIN OF lt_lockreastexts OCCURS 0.
DATA: lockprocid(2) TYPE c,
lockreason(2) TYPE c,
text(40) TYPE c.
DATA: END OF lt_lockreastexts.
The table where I want to replace fields are the following:
DATA: BEGIN OF lt_proclocks OCCURS 0.
DATA: mandt type MANDT,
lockreason(40) TYPE c,
lockprocid(40) TYPE c,
GPART type GPART_KK,
LOOBJ type LOOBJ_KK.
DATA: END OF lt_proclocks.
When lt_proclocks-lockprocid similar to a lt_proclocktexts-lockprocid the lt_proclocks-lockprocid should be replaced by the lt_proclocktexts-text.
When lt_proclocks-lockreason AND lt_proclocks-lockprocid is similar to a combination in the lt_lockreastexts the ID in field lt_proclocks-lockreason should be also replaced (additionally to the lt_proclocks-lockprocid field).
Thanks,
Fabian
Hello,
Loop at lt_proclocktexts.
loop at lt_proclocks where lockprocid = lt_proclocktexts-lockprocid.
if lt_proclocks-lockreason = lt_proclocks-lockprocid.
lt_proclocks-lockprocid = lt_proclocktexts-text.
endif.
lt_proclocks -lockprocid = lt_proclocktexts-text.
modify lt_proclocks .
clear lt_proclocks .
endloop.
clear lt_proclocktexts.
endloop.
Regards,
Naimesh
Reward points, if it is useful..!
Hi all,
Thanks for your help, but finally I found a solution by myself:
LOOP AT lt_proclocks.
idx = sy-tabix.
READ TABLE lt_lockreastexts WITH KEY lockprocid = lt_proclocks-process
lockreason = lt_proclocks-lockreason.
IF sy-subrc EQ 0.
lt_proclocks-lockreason = lt_lockreastexts-text.
MODIFY lt_proclocks INDEX idx.
ENDIF.
ENDLOOP.
LOOP AT lt_proclocks.
idx = sy-tabix.
READ TABLE lt_proclocktexts WITH KEY lockprocid = lt_proclocks-process.
IF sy-subrc EQ 0.
lt_proclocks-process = lt_proclocktexts-text.
MODIFY lt_proclocks INDEX idx.
ENDIF.
ENDLOOP.
Best,
Fabian
Hello,
Loop at itabtext.
itab-text = itabtext-text.
modify itab transporting text where id = itabtext-id.
endloop.
Regards,
Naimesh
reward points,if it is helpful..!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi fabian,
1. this is one way.
2. Loop at itab.
indx = sy-tabix.
read table itabext with key field1 = itab-field1.
if sy-subrc = 0.
itab-text = itabext-text.
modify itab index INDX.
endif.
endloop.
3. Note, INDX is important.
regards,
amit m.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.