‎2012 Dec 12 7:46 PM
Hello Experts,
Sample data available in one table has the following format:
ID | Column1 | Column2 | Column3 |
1 | X1 | # | # |
1 | X2 | Y1 | # |
1 | # | # | Z1 |
1 | # | # | Z2 |
2 | X1 | # | # |
2 | # | Y1 | # |
2 | # | Y2 | # |
2 | # | # | Z1 |
Actual requirement is to display All column data in the same line item against each unique ID (suppressing the #(Not Assigned) value) in the target object(table) as given below:
ID | Column1 | Column2 | Column3 |
1 | X1 | Y1 | Z1 |
1 | X2 | # | Z2 |
2 | X1 | Y1 | Z1 |
2 | # | Y2 | # |
Can anyone please tell me the logic to implement the above scenario through ABAP code?
Responses would be appreciated.
Many thanks in advance..
Moderator message : Requirement dumping not allowed, discussion locked.
Message was edited by: Vinod Kumar
‎2012 Dec 13 4:13 AM
Hi,
It is only a pesudo code. I didn't test it. The idea is to search for a column in the input table. Erase the value in the input table after you move the value to the output table. The algorithm stops when the input table contains 0 lines.
I didn't optimize the algorithm, either. The performance is bad, O(M*N^2) where N is the lines of table and M is the number of columns. The pesudo code is just a briefing.
By the way, could anyone tell me how to write my code in an editor-like section in SDN? I read lots of code in an editor-like section. It is neat and beautiful, but I don't know how to use it in SDN.
LOOP AT itab_in ASSIGNING <fs_in>.
APPEND INITIAL LINE TO itab_out ASSIGNING <fs_out>.
lv_id = <fs_in>-id.
DO 3 TIMES.
lv_col_index = sy-index + 1.
PERFORM search_and_erase USING lv_col_index lv_id
CHANGING itab_in <fs_out>
ENDDO.
IF <fs_out> IS INITIAL.
DELETE itab_out INDEX lines( itab_out ).
ELSE.
<fs_out>-id = lv_id.
ENDIF.
ENDLOOP.
FORM search_and_erase
USING p_col_index p_id
CHANGING itab_in p_out.
ASSIGN COMPONENT p_col_index OF STRUCTURE p_out TO <fs_target>.
LOOP AT itab_in ASSIGNING <fs_in_2> WHERE id = p_id.
ASSIGN COMPONENT p_col_index OF STRUCTURE <fs_in_2> TO <fs_source>.
IF <fs_source> IS NOT INITIAL.
<fs_target> = <fs_source>.
CLEAR <fs_source>.
ENDIF.
ENDLOOP.
ENDFORM.