2013 Feb 05 3:27 PM
Hi,
I have 5 columns in an internal table .
H1 H2 H3 H4 H5 Date
0 1 2017
0 2017
1 2017
1 2021
0 2021
My requirement is if date is 2017 i need out put in a single row
H1 H2 H3 H4 H5 Date
0 0 1 1 2017
Please help me if you have any logic.
Moderator Message:We do not consider it good style to ask questions before trying to find the solution yourself. Please refer in your text also to what you have done already to solve the problem and what resources you have searched or used.Please consider also SAP help at http://help.sap.com and reading Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers to learn the principles of asking questions.
Message was edited by: Kesavadas Thekkillath
2013 Feb 05 3:37 PM
Hello Vijay,
if H1..H4 is numeric, I would suggest, to use the collect-statement:
Assume, that the internal table lt_result consists of the columns H1..H5 and H5 is date and H1..H4 is numeric.
LOOP AT lt_source ASSIGNING <line>
COLLECT <line> INTO lt_result.
ENDLOOP.
If not, you will need, to go step by step and use read-table:
LOOP AT lt_source ASSIGNING <line>
READ TABLE lt_result ASSIGNING <res_line>
WITH KEY H5 = <line>-h5.
IF sy-subrc <> 0.
ls_resline-h5 = <line>-h5.
insert ls_resline into table lt_result assigning <res_line>.
ENDIF.
* Process the columsn H1..H4:
* OK, this could be done pretty much better... 😉
* but without knowing excatly what the columns are, and how
* they are collected, it is the best practice
IF NOT <line>-h1 is initial
<res_line>-h1 = <line>-h1.
ENDIF.
IF NOT <line>-h2 is initial
<res_line>-h2 = <line>-h2.
ENDIF.
IF NOT <line>-h3 is initial
<res_line>-h3 = <line>-h3.
ENDIF.
IF NOT <line>-h3 is initial
<res_line>-h3 = <line>-h3.
ENDIF.
ENDLOOP.
Kind regards,
Hendrik