‎2015 Nov 19 5:20 PM
Hi,
I have a target table, which is wider (has more fields) than the source table. I just want to say: "move-corresponding from source itab to target itab AND fill additional fields of target itab with....."
types:
begin of source,
dummy type char01,
end of source,
begin of target,
dummy type char01,
date type d,
end of target,
sourcetab type standard table of source,
targettab type standard table of target.
targettab = value #( for <i> in sourcetab ( corresponding #( <i> ) ) ).
Question: How can I fill targettab-date with sy-datum for each record, created by this constructor?
‎2015 Nov 19 5:48 PM
Hi Ralf,
if I understood your question correctly, you have to loop at your source table, move corresponding fields, fill date and append structure to target table, e.g. something like this:
FIELD-SYMBOLS <source> TYPE source.
DATA: ls_target TYPE target.
LOOP AT sourcetab ASSIGNING <source>.
MOVE-CORRESPONDING <source> TO ls_target.
ls_target-date = sy-datum.
APPEND ls_target TO targettab.
ENDLOOP.
Regards,
Szymon
‎2015 Nov 19 5:55 PM
Sorry, my question was:
Question: How can I fill targettab-date with sy-datum for each record, created by this constructor?
I know I can loop, but I don't want to
I just want to use the command I mentioned.
‎2015 Nov 19 8:36 PM
This works:
targettab = value #( for <i> in sourcetab
( dummy = <i>-dummy
date = sy-datum
)
).
But might not be as flexible as you'd like. If you have control over your data definitions you could use a construction like:
types: begin of source,
s0 type char01,
s1 type char01,
s2 type char01,
end of source,
begin of sourcetarget,
s0 type char01,
s2 type char01,
end of sourcetarget,
begin of target.
include type sourcetarget as source.
types: date type d,
end of target.
data:
sourcetab type standard table of source,
targettab type standard table of target.
sourcetab = value #( ( s0 = 'A' s1 = 'n' s2 = 't' )
( s0 = 'B' s1 = 'o' s2 = 'b' )
).
targettab = value #( for <i> in sourcetab
( source = corresponding #( <i> )
date = sy-datum
)
).
cl_demo_output=>display( targettab ).
If target contains all fields in source you can forego the sourcetarget structure and also change the corresponding construct to a direct assignment, e.g:
targettab = value #( for <i> in sourcetab
( source = <i>
date = sy-datum
)
).
‎2015 Nov 20 8:30 AM
Hi Ralf,
i think the base addition of the corresponding operator can help.
Something like this:
TYPES:
BEGIN OF source,
dummy TYPE char01,
END OF source,
BEGIN OF target,
dummy TYPE char01,
date TYPE d,
END OF target,
sourcetab TYPE STANDARD TABLE OF source
WITH NON-UNIQUE DEFAULT KEY,
targettab TYPE STANDARD TABLE OF target
WITH NON-UNIQUE DEFAULT KEY.
DATA(sourcetab) = VALUE sourcetab( ( dummy = 'X' )
( dummy = 'Y' )
( dummy = 'Z' ) ).
DATA(targettab) = VALUE targettab(
FOR wa IN sourcetab (
CORRESPONDING #(
" important stuff here:
BASE ( VALUE #( date = sy-datum ) )
wa ) ) ).
cl_demo_output=>display( targettab ).
Result:
Regards Christian
‎2015 Nov 20 9:11 AM
‎2015 Nov 20 9:20 AM
Volker Wegert wrote:
Result: Write-only Coding unless commented appropriately...
I still can not believe, that appropriate comments are only used for complex commands. Every single untrivial command has to be commented! In particular, a developer shouldn't explain WHAT he es doing, but WHY he is doing that.
‎2015 Nov 20 9:21 AM
yes, or as i prefer modularized properly with meaningful method names...
‎2015 Nov 20 9:26 AM
The new operators enable us to write very "dense" coding - more "logic" with less code. Since the amount of comments should be a function of the actual logic involved, the new operators require proportionally more comments per instruction than the legacy workarounds.
Note that I wrote "require" - I totally agree on the WHY part, but it doesn't hurt to put the WHAT in plain english as well:
" transfer foo to bar and fill baz with default values BECAUSE X
‎2015 Nov 20 11:25 AM
... Words of wisdom, these! I will keep these points in mind
‎2015 Nov 20 5:27 PM
Interesting, useful, and not valid on our 740 system on kernel SP level 7...
‎2015 Nov 20 5:46 PM