Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date range

Former Member
0 Likes
757

I am looking to write some logic which works with data in a table. Sample of data is as follows:

Hotel Room Lock id Date

Ascot 12 51 01.02.2009

Ascot 12 51 02.02.2009

Ascot 12 51 03.02.2009

Ascot 12 51 04.02.2009

I need to write some logic so that, the four records are represented on one line with a start date and and an end date. Could someone advise on how this can be done? Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
721

<itab>

Hotel Room Lock id Date

Ascot 12 51 01.02.2009

Ascot 12 51 02.02.2009

Ascot 12 51 03.02.2009

Ascot 12 51 04.02.2009

Data Itab1 consists Hotel, room, Lock Id , from date and to date
data Wa_hotel like itab,
        from_date like sy-datum.

Sort Itab by Hotel room lockid date


Loop at Itab.
    if wa_hotel is not initial and
      ( wa_hotel-hotel NE itab1-hoel or
         wa_hotel-room NE itab1-room or
          wa_hotel-lockid NE itab1-lockid ).

         itab1-hotel = wa_hotel-hotel
         itab1-room = wa_hotel-room
         itab1-lockid = wa_hotel-lockid
         itab1-fromdate = fromdate
         itab1-todate = wa_hotel--date
         append itab1.

         from_date = itab_hotel-date 

      endif.
     Wa_hotel = itab.
Endloop.

Try with this

Regards

Sasi

Edited by: sasikumar palanichamy on Dec 26, 2008 6:23 PM

Edited by: sasikumar palanichamy on Dec 26, 2008 6:24 PM

Edited by: sasikumar palanichamy on Dec 26, 2008 6:24 PM

6 REPLIES 6
Read only

Former Member
0 Likes
722

<itab>

Hotel Room Lock id Date

Ascot 12 51 01.02.2009

Ascot 12 51 02.02.2009

Ascot 12 51 03.02.2009

Ascot 12 51 04.02.2009

Data Itab1 consists Hotel, room, Lock Id , from date and to date
data Wa_hotel like itab,
        from_date like sy-datum.

Sort Itab by Hotel room lockid date


Loop at Itab.
    if wa_hotel is not initial and
      ( wa_hotel-hotel NE itab1-hoel or
         wa_hotel-room NE itab1-room or
          wa_hotel-lockid NE itab1-lockid ).

         itab1-hotel = wa_hotel-hotel
         itab1-room = wa_hotel-room
         itab1-lockid = wa_hotel-lockid
         itab1-fromdate = fromdate
         itab1-todate = wa_hotel--date
         append itab1.

         from_date = itab_hotel-date 

      endif.
     Wa_hotel = itab.
Endloop.

Try with this

Regards

Sasi

Edited by: sasikumar palanichamy on Dec 26, 2008 6:23 PM

Edited by: sasikumar palanichamy on Dec 26, 2008 6:24 PM

Edited by: sasikumar palanichamy on Dec 26, 2008 6:24 PM

Read only

0 Likes
721

Thanks for this. I am still not clear how are you creating the range in the example shown could you provide a comment where and how the range is identified:

Data Itab1 consists Hotel, room, Lock Id , from date and to date

data Wa_hotel like itab,

from_date like sy-datum.

Sort Itab by Hotel room lockid date

Loop at Itab.

if wa_hotel is not initial and

( wa_hotel-hotel NE itab1-hoel or

wa_hotel-room NE itab1-room or

wa_hotel-lockid NE itab1-lockid ).

itab1-hotel = wa_hotel-hotel

itab1-room = wa_hotel-room

itab1-lockid = wa_hotel-lockid

itab1-fromdate = fromdate

itab1-todate = wa_hotel--date

append itab1.

from_date = itab_hotel-date

endif.

Wa_hotel = itab.

Endloop.

Read only

0 Likes
721
Ascot 12 51 01.02.2009
Ascot 12 51 02.02.2009
Ascot 12 51 03.02.2009
Ascot 12 51 04.02.2009

With the given above example, I assumed you required the output like

Hotel           Room         Lock key            From date          Todate
Ascot          12               51                     01.02.2009         04.02.2009

Hotel, Rook and Lock key are the key fields, If any value changes in the three fields the new entry will be inserted (Is that right)

Based on that I have provided that pseuodo code

Regards

Sasi

Read only

0 Likes
721

Hi Sasi,

Thanks very much for this. You are right the fields that you have indicated are key fields. What I was hoping to get from the question was that it can be done (exactly how you intrepreted multi - one line). The psuedo is a bonus and will help me make a start next week. Will post questions once I try and hit issues have awarded points

Guys, thanks otherwise have also awarded

Edited by: Niten Shah on Dec 26, 2008 2:59 PM

Read only

joginder_singh
Active Participant
0 Likes
721

Hi

You can do like this

field1

field2

field3

field4

Loop at itab

wa_itab = itab.

at new field3.

write : / field1,field2,fiel3

endat.

write : sy-lil field4.

Endloop.

u can get a position for field4 by some system field ,i did not remember right now as i am at home.

Hope this helps.

Cheers

Joginder

Read only

Former Member
0 Likes
721

Hi,

You could code in the following way.


SORT itab BY hotel room lockid date.
LOOP AT itab INTO wa_itab.
  AT END OF lockid.
  LOOP AT itab WHERE hotel = wa_itab-hotel and room = .. lockid = ..
    IF itab-date > wa_itab-date.
      wa_enddate = itab-date.
    ENDIF.
  ENDLOOP.
    wa_final_tab = wa_itab.
    IF wa_enddate IS NOT INITIAL.
    wa_final_tab-end_date = wa_enddate.
    ELSE.
     wa_final_tab-end_date = wa_itab-date.
    ENDIF.
    APPEND wa_final_tab TO final_tab.
    CLEAR wa_final_tab.
  ENDAT.
ENDLOOP.

This would ensure final_tab has one entry per hotel room lockid with start and end date as required.

Revert if you have any doubt.