Skip to Content

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

select-option

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

Tags:
Former Member
replied

'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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question