-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-let.abap
61 lines (54 loc) · 1.58 KB
/
04-let.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
* Usando a mesma tabela interna para atribuor novos dados
TYPES:
BEGIN OF ty_result,
po TYPE ekko-ebeln,
ccode TYPE ekko-bukrs,
uname TYPE ekko-ernam,
END OF ty_result,
tab_result TYPE STANDARD TABLE OF ty_result
WITH KEY po .
* Fill data
DATA(result1) = VALUE tab_result(
( po = '4000000001'
ccode = '0001'
uname = 'ABAP.DEV1' )
( po = '4000000002'
ccode = '2001'
uname = 'ABAP.DEV2' )
( po = '4000000003'
ccode = '3001'
uname = 'ABAP.DEV3' )
( po = '4000000004'
ccode = '0001'
uname = 'ABAP.DEV5' )
( po = '4000000005'
ccode = '2001'
uname = 'ABAP.DEV5' )
).
" Write stated data
cl_demo_output=>write_data( result1 ).
* Old way
* Change the company code to 0005 where company code is 0001
* LOOP AT result1 ASSIGNING <fs> WHERE ccode EQ '0001'.
* <fs>-ccode = '0005'.
* ENDLOOP.
* Proposed resolution
result1 = VALUE #(
LET lt_temp = result1
IN
FOR ls_temp IN lt_temp
( po = ls_temp-po
ccode = COND #( WHEN ls_temp-ccode EQ '0001'
THEN '0005'
ELSE ls_temp-ccode )
uname = ls_temp-uname ) ) .
* Write changed data
cl_demo_output=>write_data( result1 ).
* Display
cl_demo_output=>display( ).
* Expected result
* Populate sy-tabix in the additional fields within the for loop
DATA(lt_target2) = VALUE gtt_struct2( FOR lwa_source IN lt_source
INDEX INTO index
LET base = VALUE ty_struct2( field3 = index )
IN ( CORRESPONDING #( BASE ( base ) lwa_source ) ) ).