2007 Oct 16 1:11 PM
hi frnds,
i could not make out a logic, my code is as follows
&----
*& Report ZGL3 *
*& *
&----
*& *
*& *
&----
REPORT ZGL3 .
DATA:BEGIN OF it_actual OCCURS 0,
accno type i,
date LIKE sy-datum,
bal TYPE i,
END OF it_actual.
data: it_accno LIKE it_actual OCCURS 0 WITH HEADER LINE.
DATA: it_final LIKE it_actual OCCURS 0 with header line,
wa like it_actual.
DATA: BEGIN OF itab OCCURS 0,
date TYPE sy-datum,
END OF itab.
SELECT-OPTIONS: s_date FOR sy-datum,
s_gl for it_actual-accno.
DATA: v_bal TYPE i.
it_actual-accno = 1. " accno means account no
it_actual-date = '20071001'.
it_actual-bal = 500.
APPEND it_actual.
clear it_actual.
it_actual-accno = 1.
it_actual-date = '20071002'.
it_actual-bal = 400.
APPEND it_actual.
clear it_actual.
it_actual-accno = 1.
it_actual-date = '20071005'.
it_actual-bal = 900.
APPEND it_actual.
clear it_actual.
it_actual-accno = 2.
it_actual-date = '20071003'.
it_actual-bal = 1500.
APPEND it_actual.
clear it_actual.
it_actual-accno = 2.
it_actual-date = '20071006'.
it_actual-bal = 2400.
APPEND it_actual.
clear it_actual.
it_actual-accno = 3.
it_actual-date = '20071009'.
it_actual-bal = 3900.
APPEND it_actual.
clear it_actual.
IF NOT it_actual[] IS INITIAL.
SORT it_actual BY accno date.
it_accno[] = it_actual[].
delete adjacent duplicates from it_accno comparing accno.
ENDIF.
*To fill the internal table with the dates given on *the selection screen use the below logic.
LOOP AT s_date.
IF s_date-option = 'BT' AND
s_date-sign = 'I'.
IF NOT s_date-low IS INITIAL AND
NOT s_date-high IS INITIAL.
WHILE s_date-low LE s_date-high.
itab-date = s_date-low.
COLLECT itab.
s_date-low = s_date-low + 1.
ENDWHILE.
ENDIF.
ENDIF.
IF s_date-option = 'EQ' AND
s_date-sign = 'I'.
IF NOT s_date-low IS INITIAL.
LOOP AT s_date.
itab-date = s_date-low.
COLLECT itab.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
ENDIF.
*main process starts from here
loop at it_accno.
clear : it_final, v_bal.
loop at itab.
READ TABLE it_actual WITH KEY accno = it_accno-accno date = itab-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = it_actual-bal.
ELSE.
DATA:zind TYPE sy-tabix.
IF sy-tabix NE 1.
zind = sy-tabix - 1.
READ TABLE it_actual INDEX zind.
v_bal = it_actual-bal.
ENDIF.
ENDIF.
it_final-accno = it_accno-accno.
it_final-date = itab-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
endloop.
endloop.
LOOP AT it_final.
write:/20 it_final-date,
40 it_final-bal , it_final-accno.
ENDLOOP.
here in the table as u see there are
3 acc nos 1 , 2 & 3.
my selection -screen consists of date & account no.
now the following problem arises .
when i m giving date range from 30.09.2007 to 09.10.2007 (say) it has following o/p.
date bal accont no
30.09.2007 0 1
01.10.2007 500 1
02.10.2007 400 1
03.10.2007 400 1
04.10.2007 400 1
05.10.2007 900 1
06.10.2007 900 1
07.10.2007 900 1
08.10.2007 900 1
09.10.2007 900 1
<b>30.09.2007 900 2
01.10.2007 900 2
02.10.2007 900 2</b>
03.10.2007 1,500 2
04.10.2007 1,500 2
05.10.2007 1,500 2
06.10.2007 2,400 2
07.10.2007 2,400 2
08.10.2007 2,400 2
09.10.2007 2,400 2
<b>30.09.2007 2,400 3
01.10.2007 2,400 3
02.10.2007 2,400 3
03.10.2007 2,400 3
04.10.2007 2,400 3
05.10.2007 2,400 3
06.10.2007 2,400 3
07.10.2007 2,400 3
08.10.2007 2,400 3</b>
09.10.2007 3,900 3
see for 30.09.2007 and for accno 1 no balance exists so it is 0 ok
but for accno 2 no bal exists for 30.09.2007 , 01.10.2007 , 02.10.2007 but is coming 900 ( marked as bold) same is true for accno 3.
again if i should give the date range from say 04.01.4007 to 10.10.2007 the o/p should come like this-
04.10.2007 400 1
05.10.2007 900 1
06.10.2007 900 1
07.10.2007 900 1
08.10.2007 900 1
09.10.2007 900 1
10.10.2007 900 1
04.10.2007 1,500 2
05.10.2007 1,500 2
06.10.2007 2,400 2
07.10.2007 2,400 2
08.10.2007 2,400 2
09.10.2007 2,400 2
10.10.2007 2,400 2
04.10.2007 0 3
05.10.2007 0 3
06.10.2007 0 3
07.10.2007 0 3
08.10.2007 0 3
09.10.2007 3,900 3
10.10.2007 3,900 3
can u tell me where i m making the wrong logic in the given code
thanks
pankaj
2007 Oct 16 2:04 PM
Hi Pankaj,
The problem might be in the below mentioned part
READ TABLE it_actual WITH KEY accno = it_accno-accno date = itab-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = it_actual-bal.
ELSE.
<b>DATA:zind TYPE sy-tabix.
IF sy-tabix NE 1.
zind = sy-tabix - 1.
READ TABLE it_actual INDEX zind.
v_bal = it_actual-bal.
ENDIF.</b>
ENDIF.
If the first read statment fails then you are using the sy-tabix which will have the index of the record which is greater than the date given in the condition since explicitly binary search is mentioned and searched is stoped returns has the read fails. So try to put v_bal = 0 in the else part of the first read statement if condition.
READ TABLE it_actual WITH KEY accno = it_accno-accno date = itab-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = it_actual-bal.
ELSE.
<b>v_bal = 0.</b>
ENDIF.
ENDIF.
2007 Oct 16 2:06 PM
IF sy-tabix NE 1.
zind = sy-tabix - 1.
READ TABLE it_actual INDEX zind.
v_bal = it_actual-bal.
ENDIF.
could not understand the need of this one
2007 Oct 17 5:39 AM
hi sayan,
it has the following use say on 12.10.2007(posting date-budat) balance was 1000 next on 14.12.2007 balance was 2000 ok.
<b>now on 13.10.2007 balance should come 1000 & not 0,</b> the logic makes out this
regards
pankaj
2010 Dec 23 6:55 AM