2009 Feb 19 7:04 PM
My internal table ITAB contains two columns NODE and VALUE.
The contents are as follows
NODE VALUE
A 1
B 2
C 3
D 4
E 5
F 6
D 7
E 8
F 9
G 10
H 11
I 12
G 13
H 14
I 15
G 16
H 17
I 18
J 19
K 20
L 21
J 22
K 23
L 24
My requirement is I need to move the values to JTAB such that JTAB should have columns as D E F and should be having the following values filled in the columns.
JTAB
D E F
4 5 6
7 8 9
Similarly I need to move the values to KTAB such that KTAB should have columns as G H I and should be having the following values filled in the columns.
KTAB
G H I
10 11 12
13 14 15
16 17 18
Similarly I need to move the values to NTAB such that NTAB should have columns as G H I and should be having the following values filled in the columns.
NTAB
J K L
19 20 21
22 23 24
Please help. Any help is higly appreciated. if dont want to put several if conditions as it will effect performance. is there a simple way to do this
2009 Feb 20 6:20 AM
Hi,
I have done this with the IF statement, As such usinf if will not efftect ur performance.
Check out the coad below it works.
TYPES: BEGIN OF t_itab,
node TYPE c,
value TYPE c,
END OF t_itab.
TYPES: BEGIN OF t_jtab,
d TYPE c,
e TYPE c,
f TYPE c,
END OF t_jtab.
DATA: i_itab TYPE STANDARD TABLE OF t_itab,
wa_itab LIKE LINE OF i_itab,
i_jtab TYPE STANDARD TABLE OF t_jtab,
wa_jtab LIKE LINE OF i_jtab,
copyy TYPE C.
LOOP AT i_itab INTO wa_itab.
IF wa_itab-node = 'D' OR wa_itab-node = 'E' OR wa_itab-node = 'F'.
IF wa_itab-node = 'D'.
wa_jtab-d = wa_itab-value.
APPEND wa_jtab TO i_jtab.
COPYY = WA_ITAB-VALUE.
CLEAR wa_jtab.
CONTINUE.
ELSEIF wa_itab-node = 'E'..
wa_jtab-e = wa_itab-value.
MODIFY I_JTAB FROM WA_JTAB
TRANSPORTING E
WHERE D = COPYY.
CLEAR wa_jtab.
ELSEIF wa_itab-node = 'F'..
wa_jtab-f = wa_itab-value.
MODIFY I_JTAB FROM WA_JTAB
TRANSPORTING F
WHERE D = COPYY.
CLEAR wa_jtab.
ENDIF.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.
I hope this will help,
Suraj
****after getting the data in the internal table.********
2009 Feb 19 7:15 PM
In looking at your example, the requirement is not clear to me. But your statement about multiple "IF" statements affecting performance is completely wrong.
Unless you're running on a 8088 chip from 1983, the CPU time to process multiple IF statements is not measurable by any instruments within 1000 miles of where I am located.
2009 Feb 19 7:34 PM
U can go ahead with using if or case with even worrying about performance, if u still have doubts write ur code using if statements and execute ur program using se30 and analyse its performance there.
2009 Feb 19 7:40 PM
Check for logic creation of JTAB
i_ref_descr1 ?= cl_abap_tabledescr=>describe_by_data( jtab ).
i_details1[] = i_ref_descr1->components[].
sort itab by node.
loop at itab.
read table i_details1 into wa_details1
with key name = itab-node.
if sy-subrc eq 0.
assign component sy-tabix of structure jtab to <fs>.
move itab-value to <fs>.
append jtab.
endif.
endloop.
After this code your jtab looks like
D E F
4
7
5
8
6
9
But still you need to Jtab look like this way
D E F
4 5 6
7 8 9
I am seeing that's where is issue.
a®
2009 Feb 19 8:07 PM
a@rs actually there is no logic involved with the VALUE field.. I just gave numbers in ascending orders for simplicity. My requirement is if I have repetitive values in NODE column then I should group the value of NODE field and respective value of VALUE field in an internal table.
Any cules how to do this?
2009 Feb 19 8:58 PM
Hello,
How itab is sorted ?
- For example table jtab has 3 fields D E F. D is the first one and F the last one.
-- Are itab entries sorted like that :
D 5 <--- 1st field of structure jtab
E 4
F 7 <--- last field of structure jtab
or like that
E 4
D 5
F 77
or something else
?
re-using the code of a®s. You can do something like that :
loop at itab.
CASE itab-node.
WHEN 'D' OR 'E' OR 'F'. "jtab fields
CASE itab-node.
WHEN 'D'. "1st field
CLEAR wa_jtab.
MOVE itab-value TO wa_jtab-d.
WHEN 'F'. "last field
MOVE itab-value TO wa_jtab-f.
APPEND wa_jtab TO jtab.
WHEN OTHERS.
ASSIGN COMPONENT itab-node OF STRUCTURE wa_jtab TO <fs>.
IF sy-subrc IS INITIAL.
MOVE itab-value TO <fs>.
ENDIF.
ENDCASE.
WHEN 'G' OR 'H' OR 'I'. "ktab fields
CASE itab-node.
WHEN 'G'. "1st field
CLEAR wa_ktab.
MOVE itab-value TO wa_ktab-g.
WHEN 'I'. "last field
MOVE itab-value TO wa_ktab-i.
APPEND wa_ktab TO ktab.
WHEN OTHERS.
ASSIGN COMPONENT itab-node OF STRUCTURE wa_ktab TO <fs>.
IF sy-subrc IS INITIAL.
MOVE itab-value TO <fs>.
ENDIF.
ENDCASE.
ENDCASE.
ENDLOOP.
Pre requisite: itab must be sorted by field position in structure of each target tables (jtab ktab ...)
Remark : if target tables have lot of fields you can use range instead of WHEN 'D' OR 'E' OR 'F'.
Cordialement,
Chaouki.
Edited by: Chaouki AKIR on Feb 19, 2009 9:59 PM
2009 Feb 20 6:20 AM
Hi,
I have done this with the IF statement, As such usinf if will not efftect ur performance.
Check out the coad below it works.
TYPES: BEGIN OF t_itab,
node TYPE c,
value TYPE c,
END OF t_itab.
TYPES: BEGIN OF t_jtab,
d TYPE c,
e TYPE c,
f TYPE c,
END OF t_jtab.
DATA: i_itab TYPE STANDARD TABLE OF t_itab,
wa_itab LIKE LINE OF i_itab,
i_jtab TYPE STANDARD TABLE OF t_jtab,
wa_jtab LIKE LINE OF i_jtab,
copyy TYPE C.
LOOP AT i_itab INTO wa_itab.
IF wa_itab-node = 'D' OR wa_itab-node = 'E' OR wa_itab-node = 'F'.
IF wa_itab-node = 'D'.
wa_jtab-d = wa_itab-value.
APPEND wa_jtab TO i_jtab.
COPYY = WA_ITAB-VALUE.
CLEAR wa_jtab.
CONTINUE.
ELSEIF wa_itab-node = 'E'..
wa_jtab-e = wa_itab-value.
MODIFY I_JTAB FROM WA_JTAB
TRANSPORTING E
WHERE D = COPYY.
CLEAR wa_jtab.
ELSEIF wa_itab-node = 'F'..
wa_jtab-f = wa_itab-value.
MODIFY I_JTAB FROM WA_JTAB
TRANSPORTING F
WHERE D = COPYY.
CLEAR wa_jtab.
ENDIF.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.
I hope this will help,
Suraj
****after getting the data in the internal table.********