Skip to Content
author's profile photo Former Member
Former Member

Itab Lookup Help

I am a BW programmer, not an ABAP-er. But I did manange to get an internal table loaded that looks like below. The first column contains a week number of a period, which is is in the 3 column.

I want to, given a year/week such as 2005 and 15, come back with either the lowest or highest (13 or 18), so that I can figure out that I need to add 2 weeks to 3/7, or subtract 3 from 4/4.

I would appreciate any hints on how to do a table lookup on an internal table.

This is how I defined the setup

l_cal_itab LIKE SORTED TABLE OF l_cal_s WITH UNIQUE KEY fiscyear poper accum_week

The contents:

2005 001 05 01/03/2005 02/06/2005
2005 002 09 02/07/2005 03/06/2005
2005 003 13 03/07/2005 04/03/2005
2005 004 18 04/04/2005 05/08/2005
2005 005 22 05/09/2005 06/05/2005
2005 006 26 06/06/2005 07/03/2005
2005 007 31 07/04/2005 08/07/2005
2005 008 35 08/08/2005 09/04/2005
2005 009 39 09/05/2005 10/02/2005
2005 010 44 10/03/2005 11/06/2005
2005 011 48 11/07/2005 12/04/2005
2005 012 52 12/05/2005 12/31/2005
2006 001 05 01/01/2006 02/05/2006
2006 002 09 02/06/2006 03/05/2006
2006 003 13 03/06/2006 04/02/2006
2006 004 18 04/03/2006 05/07/2006
2006 005 22 05/08/2006 06/04/2006
2006 006 26 06/05/2006 07/02/2006
2006 007 31 07/03/2006 08/06/2006
2006 008 35 08/07/2006 09/03/2006
2006 009 39 09/04/2006 10/01/2006
2006 010 44 10/02/2006 11/05/2006
2006 011 48 11/06/2006 12/03/2006
2006 012 52 12/04/2006 12/31/2006

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 05, 2005 at 12:32 PM

    hai,

    it would be helpfull if u expalin what is table lookup on an internal table.

    cheers

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      data: TheYear like l_cal_itab-fiscyear,

      TheWeek like l_cal_itab-accum_week.

      data: TheHigh_Index like sy-tabix.

      data: TheLow_Index like sy-tabix.

      TheYear = '2005'.

      TheWeek = '15'.

      Loop at l_cal_itab where fiscyear = TheYear and accum_week >= TheWeek.

      TheHigh_Index = sy-tabix.

      exit.

      endloop.

      TheLow_Index = TheHigh_index - 1.

      Please reward points accordingly.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 05, 2005 at 12:47 PM

    Hi

    Your table is just sorted by fiscyear poper accum_week, so you should find before highest and then lowest:

    DATA: WA_MAX LIKE l_cal_s,

    INDEX_OK TYPE SY-INDEX.

    LOOP AT l_cal_itab INTO WA_MAX WHERE fiscyear = 2005

    AND POPER > 15.

    INDEX_OK = SY-TABIX.

    EXIT.

    ENDLOOP.

    IF SY-SUBRC = 0.

    INDEX_OK = INDEX_OK - 1.

    DO.

    READ TABLE l_cal_itab INTO WA_MIN INDEX INDEX_OK.

    IF SY-SUBRC <> 0. EXIT. ENDIF.

    IF WA_MIN-fiscyear = 2005. "In the same year

    IF WA_MIN-POPER < 15. "OK

    EXIT.

    ENDIF.

    ELSE.

    EXIT. "In previous year OK

    ENDIF.

    INDEX_OK = INDEX_OK - 1.

    ENDDO.

    ELSE.

    • The highest is the first record of next year

    LOOP AT l_cal_itab INTO WA_MAX WHERE fiscyear = 2006.

    INDEX_OK = SY-TABIX.

    EXIT.

    ENDLOOP.

    INDEX_OK = INDEX_OK - 1.

    DO.

    READ TABLE l_cal_itab INTO WA_MIN INDEX INDEX_OK.

    IF SY-SUBRC <> 0. EXIT. ENDIF.

    IF WA_MIN-fiscyear = 2005. "In the same year

    IF WA_MIN-POPER < 15. "OK

    EXIT.

    ENDIF.

    ELSE.

    EXIT. "In previous year OK

    ENDIF.

    INDEX_OK = INDEX_OK - 1.

    ENDDO.

    ENDIF.

    max

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.