Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

select-opt

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

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question