Skip to Content
avatar image
Former Member

simple logic from below internal tables

Hi,

I have one i.table ITAB.

entries as:

Year Month value

2008 12 0.00

I have another i.table ITAB1

entries as:

Year Month value

2008 1 12.00

2008 2 15.00

2008 3 10.00

2008 4 11.00

2008 11 0.00

2008 12 0.00

Both these i.tables are retrieved from same table.

Now i required logic such that i should be able check each month 12-1, 11-1 etc.. till the month have some value other than 0.00.

Note: i should not use

Loop at ITAB.

If itab-value eq 0.

  • logic should pick up value from previous available month which have value from ITAB1

endif.

endloop.

can anybody provide simple logic for this!

Thanks,

Deep.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 30, 2009 at 05:59 AM

    Hi,

    do we have to get a non zero value for a record in ITAB, from a previous period record, as here, from ITAB1? And wat we can't use ? please clarify..

    If yes...

    SORT ITAB BY ASCENDING YEAR MONTH.

    SORT ITAB1 BY DESCENDING YEAR MONTH.

    FLAG = 0.

    LOOP AT ITAB.

    FLAG = 0.

    IF ITAB-VALUE EQ 0.

    LOOP AT ITAB1.

    IF ITAB1-YEAR = ITAB-YEAR AND ITAB1-MONTH AND ITAB-MONTH.

    FALG = 1. " matching record found

    ENDIF.

    IF FLAG EQ 1. " once record found we need to go further nd find a non-zero value as

    " sorted descending order we will get value from previous possible record.

    IF ITAB1-VALUE NE 0.

    MODIFY ITAB FROM ITAB1.

    FLAG = 0.

    ENDIF.

    ENDLOOP.

    ENDLOOP.

    -pranav

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      The solution can be like this.....

      LOOP AT itab.
        IF itab-value EQ 0.
         CLEAR itab1.
          LOOP AT itab1 WHERE year <= itab-year AND month < itab-month AND value <> 0.
            EXIT.
          ENDLOOP.
      *    READ TABLE itab1 WITH KEY year = itab-year
      *                              month = itab-month
      *                              value  = 0.
          "   this read statement will give you the record where the value is not eq 0 for the month which is less
          "   than the month in itab and year <= itab-year.
        ENDIF.
      ENDLOOP.

      this is something similar to read statement...

      as soon as the cursor goes inside the loop it exits from the loop.... which says that the record which it fetched was the record which was required by the condition ...

      Regards,

      Siddarth

  • avatar image
    Former Member
    Apr 30, 2009 at 05:31 AM

    hi Deep,

    first sort the tables.

    sort itab1 by year month values.

    sort itab2 by year month value.

    loop at itab1.

    If itab-value eq 0.

    loop at itab2 where year = itab2-year and month ge itab2-month.

    append to itab3.

    endloop.

    endif.

    endloop.

    regards,

    Prabhudas

    Add comment
    10|10000 characters needed characters exceeded