‎2014 May 31 11:03 PM
Hi experts,
I need function module to split a table of date intervals, like picture below:
in the result internal table like picture below:
Regards,
André Nunes.
‎2014 Jun 01 7:53 AM
Try this logic.
Your input (in_tab) and output table (out_tab) would be the structure given above (workarea - wa_tab).
There would be an intermediate table sort_tab (work area wa_sort) with just one date field.
I am using two field symbols <c_sort> and <p_sort> to access the current and previous contents of sort table.
types : begin of w_tab,
dat type datum,
end of w_tab.
data : sort_tab type TABLE OF w_tab,
wa_sort type w_tab.
FIELD-SYMBOLS : <p_sort> type w_tab,
<c_sort> type w_tab.
* First move all the dates in the input table to the sort table.
clear wa_tab.
loop at in_tab into wa_tab.
wa_sort-dat = wa_tab-begda.
append wa_sort to sort_tab.
clear wa_sort.
wa_sort-dat = wa_tab-endda.
append wa_sort to sort_tab.
clear : wa_sort, wa_tab.
endloop.
* Sort sort_tab.
sort sort_tab by dat.
* Now in pairs add the contents to the output table.
loop at sort_tab ASSIGNING <c_sort>.
if sy-tabix = 1.
ASSIGN <c_sort> to <p_sort>.
CONTINUE.
endif.
wa_tab-begda = <p_sort>-dat.
wa_tab-endda = <c_sort>-dat.
append wa_tab to out_tab.
ASSIGN <c_sort> to <p_sort>.
endloop.
‎2014 Jun 01 7:25 AM
Hi Andre,
i don't know of a standard function module or method to achieve this. However, you can write one fairly easy yourself. What you need to do is:
Best,
Christian
‎2014 Jun 01 7:28 AM
‎2014 Jun 01 7:38 AM
Hi Andre,
You can apply this logic:
STEP 1. SORT the date table based on START DATE.
STEP 2. LOOP at sorted date table.
STEP 3. Store first entry of date table into result table
STEP 4. READ inside the same LOOP. Logic will be START DATE of current line will be LAST date of privious line. Store the entry in result table.
Hope its clear. Let me know if you need more input.
BR,
Prakash
‎2014 Jun 01 7:53 AM
Try this logic.
Your input (in_tab) and output table (out_tab) would be the structure given above (workarea - wa_tab).
There would be an intermediate table sort_tab (work area wa_sort) with just one date field.
I am using two field symbols <c_sort> and <p_sort> to access the current and previous contents of sort table.
types : begin of w_tab,
dat type datum,
end of w_tab.
data : sort_tab type TABLE OF w_tab,
wa_sort type w_tab.
FIELD-SYMBOLS : <p_sort> type w_tab,
<c_sort> type w_tab.
* First move all the dates in the input table to the sort table.
clear wa_tab.
loop at in_tab into wa_tab.
wa_sort-dat = wa_tab-begda.
append wa_sort to sort_tab.
clear wa_sort.
wa_sort-dat = wa_tab-endda.
append wa_sort to sort_tab.
clear : wa_sort, wa_tab.
endloop.
* Sort sort_tab.
sort sort_tab by dat.
* Now in pairs add the contents to the output table.
loop at sort_tab ASSIGNING <c_sort>.
if sy-tabix = 1.
ASSIGN <c_sort> to <p_sort>.
CONTINUE.
endif.
wa_tab-begda = <p_sort>-dat.
wa_tab-endda = <c_sort>-dat.
append wa_tab to out_tab.
ASSIGN <c_sort> to <p_sort>.
endloop.
‎2014 Jun 02 9:41 AM
‎2014 Jun 01 11:01 AM
Hello,
Where come those dates in the first place?
Was there a merge already of several tables records to build that input table?
If yes, the output could also be reached with the statement PROVIDE on the internal tables with unique intervals. (just for info).
Br,
Manu.
‎2014 Jun 01 11:20 AM
‎2014 Jun 02 9:44 AM