Application Development 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: 

simple logic from below internal tables

Former Member
0 Kudos
104

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
65

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

8 REPLIES 8

Former Member
0 Kudos
65

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

Former Member
0 Kudos
66

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

0 Kudos
65

Hi,

First we will check if ITAB's value field is 0.00 if yes then we have to get value from ITAB1 table starting from previous period 11, 10, 9, 8 etc.. till we get value # 0.00.

0 Kudos
65

Hi,

use the code given below...

sort ITAB1 by year ascending 
                    month descending.

Loop at ITAB.
If itab-value eq 0.
    Read table itab1 into 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.

Regards,

Siddarth

0 Kudos
65

Hi,

From year-2009 month-12 we will searh through year-2009 month-1 in ITAB1 if we did not found we should go to year-2008 month-12 to year-2008 month-1 etc... 2007 .. 2006 till we found value field # 0.00 in ITAB1.

Will this logic work for the same!

Thanks,

Deep.

0 Kudos
65

Hi,

use this code and it will work for your requirement...

sort ITAB1 by year descending 
                           month descending.
 
Loop at ITAB.
If itab-value eq 0.
    Read table itab1 into 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.

0 Kudos
65

Hi,

With READ TABLE we can't use LE/LT.

If i am using LOOP with LE/LT instead of READ it is not picking up other values than key fields in loop.

Other values are always blank.

What can be the solution!

Thanks,

Deep.

0 Kudos
65

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