10-11-2007 5:57 AM
hi frnds ,
i have the following code,
==================================
REPORT YGL .
DATA:BEGIN OF itab OCCURS 0,
date LIKE sy-datum,
bal TYPE p decimals 2 ,
END OF itab.
DATA: it_final LIKE itab OCCURS 0 WITH HEADER LINE,
wa_d1 like itab.
DATA: BEGIN OF id OCCURS 0,
date TYPE sy-datum,
END OF id.
DATA: v_bal TYPE p decimals 2.
SELECT-OPTIONS: s_date FOR sy-datum.
itab-date = '20070930'.
itab-bal = 500.
APPEND itab.
itab-date = '20071002'.
itab-bal = 400.
APPEND itab.
itab-date = '20071005'.
itab-bal = 900.
APPEND itab.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
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.
id-date = s_date-low.
COLLECT id.
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.
id-date = s_date-low.
COLLECT id.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT id[] IS INITIAL.
SORT id BY date.
ENDIF.
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
LOOP AT it_final .
WRITE:/5 it_final-date,
20 it_final-bal.
ENDLOOP.
when i m giving the date range in select-options from 30.09.2007 to 05.10.2007
it is working fine all the dates are coming with their balance amount like
30.09.2007 500
01.10.2007 500
02.10.2007 400
03.10.2007 400
04.10.2007 400
05.10.2007 900
but when im trying to give range from 01.10.2007 to 05.10.2007 o/p is coming like this
<b>01.10.2007 0.00</b>
02.10.2007 400
03.10.2007 400
04.10.2007 400
05.10.2007 900
<b> i want balance on 01.10.2007 should come 500.
what additional logic should i use in my given code</b>
pls help me
regards
pankaj
10-11-2007 6:21 AM
Hi,
Try this code..Modified code for the loop statement..
data: v_last_day type sydatum.
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
********************NAREN CHANGES**********************
If it is the first day of the month..
IF SY-TABIX = 1 AND id+6(2) = 1.
Get the previous day's amount.
id = id - 1.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
ENDIF.
********************NAREN CHANGES**********************
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
Thanks
Naren
10-11-2007 6:09 AM
Hi Pankaj,
As far as i can c, the READ statement on itab is gving sy-subrc = 4. So the value in v_bal is 0.00 for date 01.10.2007.
If u still want to have output as 500, add the else condition:
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
<b>else.
v_bal = 500.</b>
ENDIF.
10-11-2007 6:22 AM
HI SIR,
i have tried ur code but sir dont do any hard coding bal 0n 01.10.2007 will come 500 but see for 03.10.2007 , 03.10.2007 it will also modified to 500,
but act they should be 400 as their is no new bal bal between 02.10.2007 to 05.10.2007 again all the dates after 05.10.2007 will become 500 and not 900 which should be as their is no new bal after 05.10.2007.
pls help me urgent
pankaj
10-11-2007 6:24 AM
ive sent u code wid corrections..it works fine...check it!!!!!!!
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
<b>else.
data:zind type sy-tabix.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.</b>ENDIF.
Message was edited by:
abapuser
10-11-2007 6:17 AM
make da following changes
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
else.
data:zind type sy-tabix.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.
ENDIF.
rest of program remains same.
u'll get desired output.
plz reward if dis helps
10-11-2007 6:43 AM
hi abapuser
i have used ur code it is ok when im giving date range 01.10.2007 it is coming 500 but see say i m giving date range from<b> 01.09.2007 to 15.09.2007
bal is comin 900 for each date but actually they should be 0 .</b> it is fetching bal from 05.10.2007 what should i do.
pls help
regards
pankaj
10-11-2007 6:52 AM
make following more changes:
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
<b>else.
data:zind type sy-tabix.
if sy-tabix ne 1.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.
endif.
ENDIF.</b>
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
10-11-2007 6:19 AM
try dis, it works..no need to hardcode ny values..
DATA:BEGIN OF itab OCCURS 0,
date LIKE sy-datum,
bal TYPE p decimals 2 ,
END OF itab.
DATA: it_final LIKE itab OCCURS 0 WITH HEADER LINE,
wa_d1 like itab.
DATA: BEGIN OF id OCCURS 0,
date TYPE sy-datum,
END OF id.
DATA: v_bal TYPE p decimals 2.
SELECT-OPTIONS: s_date FOR sy-datum.
itab-date = '20070930'.
itab-bal = 500.
APPEND itab.
itab-date = '20071002'.
itab-bal = 400.
APPEND itab.
itab-date = '20071005'.
itab-bal = 900.
APPEND itab.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
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.
id-date = s_date-low.
COLLECT id.
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.
id-date = s_date-low.
COLLECT id.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT id[] IS INITIAL.
SORT id BY date.
ENDIF.
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
else.
data:zind type sy-tabix.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
LOOP AT it_final .
WRITE:/5 it_final-date,
20 it_final-bal.
ENDLOOP.
10-11-2007 6:21 AM
Hi,
Try this code..Modified code for the loop statement..
data: v_last_day type sydatum.
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
********************NAREN CHANGES**********************
If it is the first day of the month..
IF SY-TABIX = 1 AND id+6(2) = 1.
Get the previous day's amount.
id = id - 1.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
ENDIF.
********************NAREN CHANGES**********************
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
Thanks
Naren
10-11-2007 7:01 AM
10-11-2007 7:07 AM
've u tried my code which i've sent u?
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
else.
data:zind type sy-tabix.
if sy-tabix ne 1.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.
endif.
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
10-15-2007 12:02 PM
hi abapuser
thanks for ur previous code.....can u give a solution i m facing a difficulty as follows.......................pls see the following code ( modification of previous one)
&----
*& 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 i have added an extra field accno(account no) ., as u see there are
3 acc nos 1 , 2 & 3.
my selection -screen consists of date & account no.
now the following problem arises .
1> when i m giving acc no from 1 to 2 or 2 to 3 in select-options the o/p is showing all the accnos. ie 1 , 2 & 3 <b>select-option is not working.</b>
2> when i m giving date range from 30.09.2007 to 09.10.2007 (say) it has following o/p.
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.
can u tell me where i m making the wrong logic in the given code
thanks
pankaj
10-11-2007 6:23 AM
Hi Pankaj,
If you want to provide the values of the previous day incase today's read is not present, eg : 30.09.2007 500 and 01.10.2007 00, but you want to provide the value as 500.
If this is the case , then you can add a logic like ,
LOOP AT id.
READ TABLE itab into wa_itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
else.
get the previous date of the date in wa_itab using FM "month_plus_determine" or "RP_CALC_DATE_IN_INTERVAL"
get the value of tat day from the table using a SELECT statement
and display it against todays date.
ENDIF.
endloop.
Reward if Useful.
Regards,
Chitra
10-11-2007 6:27 AM
Hi pankaj,
Otherwise include this piece of code,
DATA:BEGIN OF itab OCCURS 0,
date LIKE sy-datum,
bal TYPE p decimals 2 ,
END OF itab.
DATA: it_final LIKE itab OCCURS 0 WITH HEADER LINE,
wa_d1 like itab.
DATA: BEGIN OF id OCCURS 0,
date TYPE sy-datum,
END OF id.
DATA: v_bal TYPE p decimals 2.
SELECT-OPTIONS: s_date FOR sy-datum.
itab-date = '20070930'.
itab-bal = 500.
APPEND itab.
<b>
itab-date = '20071001'.
itab-bal = 500.
APPEND itab.</b>
itab-date = '20071002'.
itab-bal = 400.
APPEND itab.
itab-date = '20071005'.
itab-bal = 900.
APPEND itab.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
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.
id-date = s_date-low.
COLLECT id.
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.
id-date = s_date-low.
COLLECT id.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT id[] IS INITIAL.
SORT id BY date.
ENDIF.
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
LOOP AT it_final .
WRITE:/5 it_final-date,
20 it_final-bal.
ENDLOOP.
<b>Regards,
Azhar</b>
10-11-2007 6:52 AM
hi azhar
why u have put this code manually in table this date and its balance
should be calculated dynamically.
regards
pankaj
10-11-2007 6:53 AM
complete code:
DATA:BEGIN OF itab OCCURS 0,
date LIKE sy-datum,
bal TYPE p decimals 2 ,
END OF itab.
DATA: it_final LIKE itab OCCURS 0 WITH HEADER LINE,
wa_d1 like itab.
DATA: BEGIN OF id OCCURS 0,
date TYPE sy-datum,
END OF id.
DATA: v_bal TYPE p decimals 2.
SELECT-OPTIONS: s_date FOR sy-datum.
CLEAR itab[].
itab-date = '20070930'.
itab-bal = 500.
APPEND itab.
itab-date = '20071002'.
itab-bal = 400.
APPEND itab.
itab-date = '20071005'.
itab-bal = 900.
APPEND itab.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
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.
id-date = s_date-low.
COLLECT id.
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.
id-date = s_date-low.
COLLECT id.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT id[] IS INITIAL.
SORT id BY date.
ENDIF.
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
else.
data:zind type sy-tabix.
if sy-tabix ne 1.
zind = sy-tabix - 1.
READ TABLE itab index zind.
v_bal = itab-bal.
endif.
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
LOOP AT it_final .
WRITE:/5 it_final-date,
20 it_final-bal.
ENDLOOP.
<b>plz reward points if dis helps</b>
10-11-2007 8:27 AM
hi abap user
ur code works in my program.
thanks and well wishes
pankaj
10-11-2007 7:04 AM
Hi Pankaj,
Check the below code in Bold and add that code in your program. It will work 100%.
DATA:BEGIN OF itab OCCURS 0,
date LIKE sy-datum,
bal TYPE p decimals 2 ,
END OF itab.
<b>DATA: itab1 LIKE itab OCCURS 0 WITH HEADER LINE.</b>
DATA: it_final LIKE itab OCCURS 0 WITH HEADER LINE,
wa_d1 like itab.
DATA: BEGIN OF id OCCURS 0,
date TYPE sy-datum,
END OF id.
DATA: v_bal TYPE p decimals 2.
<b>DATA: v_count type i.</b>
SELECT-OPTIONS: s_date FOR sy-datum.
itab-date = '20070930'.
itab-bal = 500.
APPEND itab.
itab-date = '20071002'.
itab-bal = 400.
APPEND itab.
itab-date = '20071005'.
itab-bal = 900.
APPEND itab.
IF NOT itab[] IS INITIAL.
SORT itab BY date.
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.
id-date = s_date-low.
COLLECT id.
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.
id-date = s_date-low.
COLLECT id.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
IF NOT id[] IS INITIAL.
SORT id BY date.
ENDIF.
<b>itab1[] = itab[].</b>
*main process starts from here
LOOP AT id.
READ TABLE itab WITH KEY date = id-date BINARY SEARCH.
IF sy-subrc = 0.
v_bal = itab-bal.
<b>else.
if v_count = 0.
loop at itab1 where date lt id-date.
endloop.
v_bal = itab1-bal.
v_count = v_count + 1.
endif.</b>
ENDIF.
it_final-date = id-date.
it_final-bal = v_bal.
APPEND it_final.
CLEAR it_final.
ENDLOOP.
LOOP AT it_final .
WRITE:/5 it_final-date,
20 it_final-bal.
ENDLOOP.
10-11-2007 8:31 AM
10-11-2007 7:21 AM
hi pankaj,
its very easy to sove this problem.. see wat the problem wid ur code is that instead of giving option as "bt" give it "gt" or if u are using thing high valure then use it as "lt"
i m sure it ll help u
reward if helpful
nikesh kumar