Application Development and Automation 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: 
Read only

error in list

former_member841898
Participant
0 Likes
866

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 .

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.

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.

can u tell me where i m making the wrong logic in the given code

thanks

pankaj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
833

Hi,

i checked the below code and its working check and let me know

<b>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. "it_accno-accno

IF sy-subrc = 0.

v_bal = it_actual-bal.

ELSE.

DATA:zind TYPE sy-tabix.

IF sy-tabix NE 1.

zind = sy-tabix - 1 . "- 1.

READ TABLE it_actual INDEX zind.

if it_actual-accno = it_accno-accno.

v_bal = it_actual-bal.

else.

v_bal = 0.

endif.

else.

v_bal = 0.

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.</b>

Regards

Gururaj

6 REPLIES 6
Read only

Former Member
0 Likes
833

Hi

For the first problem

you are not making use of the s_gl any where in the program to select according to the account number

for the second one : its because of the same problem mentioned above. you are not making use of the rignt one from the Select options

and in the following section add this

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. "it_accno-accno

IF sy-subrc = 0.

v_bal = it_actual-bal.

ELSE.

DATA:zind TYPE sy-tabix.

<b> IF sy-tabix NE 1 and it_actual-date < itab-date and it_actual-accno eq it_accno-accno.</b>

zind = sy-tabix - 1.

READ TABLE it_actual INDEX zind.

v_bal = it_actual-bal.

else.

v_bal = 0.

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.

this should work

reward if useful

regards]

Gururaj

Read only

0 Likes
833

hi gururaj,

ihave tried ur code in my program but there arises a problem

say when im giving date range from 04.10.2007 <b>the bal for acc no. 1 becomes 0,

but it should be 400 , same is true for acc no 2 it becomes 0 but it should be 1500.</b>

pls help

regards

pankaj

Read only

Former Member
0 Likes
833

Hi,

You can use the delete statement to delete the Acc which are not in the selection screen.

Delete itab where accno not in s_hkont.

considering s_hkont as GL Account field in the selection screen.

And use the same logic for date range also.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
834

Hi,

i checked the below code and its working check and let me know

<b>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. "it_accno-accno

IF sy-subrc = 0.

v_bal = it_actual-bal.

ELSE.

DATA:zind TYPE sy-tabix.

IF sy-tabix NE 1.

zind = sy-tabix - 1 . "- 1.

READ TABLE it_actual INDEX zind.

if it_actual-accno = it_accno-accno.

v_bal = it_actual-bal.

else.

v_bal = 0.

endif.

else.

v_bal = 0.

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.</b>

Regards

Gururaj

Read only

0 Likes
833

hi gururaj,

the logic given by u solves out mu problem

thanks and well wishes

pankaj

Read only

0 Likes
833

hi gururaj

full reward to u

thanks

pankaj