2013 Apr 18 11:48 AM
HI,
I need a help to get the logic inside an internal table to select the date range based on ORGEH & PLANS column. I have the below IT with a range of begin and end dates.
ORGEH PLANS BEGDA ENDDA
| 01013349 | 02065619 | 20090101 | 99991231 |
| 01013349 | 02065619 | 20080601 | 20081231 |
| 01013349 | 02065619 | 20080401 | 20080531 |
| 01007421 | 02065619 | 20080101 | 20080331 |
| 01007421 | 02065619 | 20070901 | 20071231 |
| 01007421 | 02065619 | 20070201 | 20070831 |
| 01007421 | 02065619 | 20060701 | 20070131 |
| 01007421 | 02065619 | 20060601 | 20060630 |
| 01007421 | 02065619 | 20060501 | 20060531 |
| 01007421 | 02065618 | 20050801 | 20060430 |
| 01007421 | 02065619 | 20040401 | 20050731 |
| 01007421 | 02065619 | 20030101 | 20040331 |
The logic should bring the below range for each specific ORGEH and PLANS entry
| 01013349 | 02065619 | 20080401 | 99991231 |
| 01007421 | 02065619 | 20030101 | 20080331 |
| 01007421 | 02065618 | 20050801 | 20060430 |
Help is appreciated !
Regards
Praneeth Kumar
2013 Apr 18 1:22 PM
Hello Praneeth,
You can try the below given logic, Hope this helps.
DATA: lv_tabix.
LOOP AT it_date INTO wa_date.
AT FIRST.
wa_date1-low = wa_date-low.
wa_date1-high = wa_date-high.
wa_date1-orgeh = wa_date-orgeh.
wa_date1-plans = wa_date-plans.
lv_tabix = 1
ENDAT.
IF lv_tabix NE 1.
If wa_date-orgeh = wa_date1_orgeh AND wa_date-plans = wa_date1_plans.
IF wa_date-low < wa_date1-low.
wa_date1-low = wa_date-low.
ENDIF.
IF wa_date-high >wa_date1-high
wa_date1-high = wa_date-high.
ENDIF.
ELSE.
APPEND wa_date1 TO it_date1.
CLEAR wa_date1.
wa_date1-low = wa_date-low.
wa_date1-high = wa_date-high.
wa_date1-orgeh = wa_date-orgeh.
wa_date1-plans = wa_date-plans.
ENDIF.
ENDIF.
AT LAST.
APPEND wa_date1 TO it_date1.
CLEAR wa_date1.
ENDAT.
CLEAR: wa_date,lv_tabix.
ENDLOOP.
it_date is your internal table.
Please revert if you have any questions.
Best Regards,
Praveenkumar T
2013 Apr 18 1:49 PM
wrote a sample program .. check if this works for you
TYPES: BEGIN OF ty_tab,
f1 TYPE char8,
f2 TYPE char8,
f3 TYPE datum,
f4 TYPE datum,
END OF ty_tab.
DATA : itab TYPE TABLE OF ty_tab,
ls TYPE ty_tab.
DATA : flag1 , flag2.
ls-f1 = '01013349'.
ls-f2 = '02065619'.
ls-f3 = '20090101'.
ls-f4 = '99991231'. APPEND ls TO itab. "1
ls-f1 = '01013349'.
ls-f2 = '02065619'.
ls-f3 = '20080601'.
ls-f4 = '20081231'. APPEND ls TO itab. "2
ls-f1 = '01013349'.
ls-f2 = '02065619'.
ls-f3 = '20080401'.
ls-f4 = '20080531'. APPEND ls TO itab. "3
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20080101'.
ls-f4 = '20080331'. APPEND ls TO itab. "4
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20070901'.
ls-f4 = '20071231'. APPEND ls TO itab. "5
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20070201'.
ls-f4 = '20070831'. APPEND ls TO itab."6
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20060701'.
ls-f4 = '20070131'. APPEND ls TO itab."7
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20060601'.
ls-f4 = '20060630'. APPEND ls TO itab."8
ls-f1 = '01007421'.
ls-f2 = '02065618'.
ls-f3 = '20050801'.
ls-f4 = '20060430'. APPEND ls TO itab."9
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20040401'.
ls-f4 = '20050731'. APPEND ls TO itab."10
ls-f1 = '01007421'.
ls-f2 = '02065619'.
ls-f3 = '20030101'.
ls-f4 = '20040331'. APPEND ls TO itab."11
SORT itab BY f1 f2 f3.
LOOP AT itab INTO ls.
AT NEW f2.
flag1 = 'X'.
ENDAT.
IF flag1 EQ 'X'.
WRITE:/ ls-f1, ls-f2, ls-f3.
CLEAR flag1.
ENDIF.
AT END OF f2.
flag2 = 'X'.
ENDAT.
IF flag2 EQ 'X'.
WRITE ls-f4.
CLEAR flag2.
ENDIF.
ENDLOOP.
o/p
br,
vijay
2013 Apr 18 1:58 PM
Try this,
sort itab by orgeh ASCENDING
plans ASCENDING
begda ASCENDING
endda DESCENDING.
LOOP AT itab INTO wa.
IF wa-orgeh NE lv_orgeh OR wa-plans NE lv_plans.
lv_orgeh = wa-orgeh.
lv_plans = wa-plans.
lv_tabix = lv_tabix + 1.
APPEND wa TO itab_final.
LOOP AT itab INTO wa_final WHERE orgeh = wa-orgeh AND plans = wa-plans.
IF wa_final-endda GT wa-endda.
wa-endda = wa_final-endda.
MODIFY itab_final FROM wa TRANSPORTING endda WHERE orgeh = wa-orgeh AND plans = wa-plans.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: lv_tabix.
ENDLOOP.
2013 Apr 22 9:42 AM
Hi,
For internal table processing you can use PROVIDE - ENDPROVIDE statement ( HR ABAP ).
Check if this useful for you.
REPORT yhr_test_provide.
TYPES: BEGIN OF ty_tab,
orgeh TYPE p0001-orgeh,
plans TYPE p0001-plans,
begda TYPE p0001-begda,
endda TYPE p0001-endda,
END OF ty_tab.
DATA : it1 TYPE TABLE OF ty_tab,
it2 TYPE TABLE OF ty_tab,
ls LIKE LINE OF it1,
ls1 LIKE LINE OF it1.
DATA: flag.
ls-orgeh = '01013349'. ls-plans = '02065619'. ls-begda = '20090101'. ls-endda = '99991231'.
APPEND ls TO it1. "1
ls-orgeh = '01013349'. ls-plans = '02065619'. ls-begda = '20080601'. ls-endda = '20081231'.
APPEND ls TO it1. "2
ls-orgeh = '01013349'. ls-plans = '02065619'. ls-begda = '20080401'. ls-endda = '20080531'.
APPEND ls TO it1. "3
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20080101'. ls-endda = '20080331'.
APPEND ls TO it1. "4
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20070901'. ls-endda = '20071231'.
APPEND ls TO it1. "5
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20070201'. ls-endda = '20070831'.
APPEND ls TO it1."6
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20060701'. ls-endda = '20070131'.
APPEND ls TO it1."7
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20060601'. ls-endda = '20060630'.
APPEND ls TO it1."8
ls-orgeh = '01007421'. ls-plans = '02065618'. ls-begda = '20050801'. ls-endda = '20060430'.
APPEND ls TO it1."9
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20040401'. ls-endda = '20050731'.
APPEND ls TO it1."10
ls-orgeh = '01007421'. ls-plans = '02065619'. ls-begda = '20030101'. ls-endda = '20040331'.
APPEND ls TO it1."11
SORT it1 BY orgeh plans begda .
LOOP AT it1 INTO ls.
AT NEW plans.
it2 = it1.
ls1-orgeh = ls-orgeh.
ls1-plans = ls-plans.
DELETE it2 WHERE orgeh NE ls1-orgeh
OR plans NE ls1-plans.
DELETE it1 WHERE orgeh EQ ls1-orgeh
AND plans EQ ls1-plans.
ENDAT.
PROVIDE FIELDS orgeh plans FROM it2 INTO ls
VALID flag
BOUNDS begda AND endda
BETWEEN '18000101' AND '99991231'.
WRITE: / ls-orgeh, ls-plans, ls-begda, ls-endda.
SKIP.
ENDPROVIDE.
ENDLOOP.
Regards