Skip to Content

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

calculation of date

hi,

i want to know the code for following problem,

my code gives o/p of respective closing balance of the posting dates like on 1/2/2007 closing bal for a respective g/l acc. was 1300 , on 2/2/2007 was 1500

and on 6/2/2007 was 1400, but on 3/2/2007 , 4/2/2007 and 5/2/2007 there were no transactions at all and<b> these dates do not exist in the table(database).</b>

but in my o/p of code ihave to show all these dates with the closing bal of 2/2/2007ie 1500 as between 2/2/2007 and 6/2/2007 there were no transactions.

the report is to be run monthly ie from 1/2/2007 upto 28/2/2007 if between 5/2/2007 and 28/2/2007 there is no transactions my report should show all the dates of the month and the bal of each dates should be 1400 as there was last transaction on

6/2/2007.

urgent pls help me out. if possible send me the code.

thanks

pankaj

Tags:
Former Member
Former Member replied

Hi Pankaj,

first you select <b>budat and hkont</b> from the table <b>bsis</b> into the internal table <b>it_actual</b>.

At present i have filled <b>it_actual</b> with the dates and amounts provided by you.

<b>Use the below code.</b>

SELECT-OPTIONS: s_date FOR sy-datum.

DATA:BEGIN OF it_actual OCCURS 0,

date LIKE sy-datum,

bal TYPE i,

END OF it_actual.

DATA: it_final LIKE it_actual OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF itab OCCURS 0,

date TYPE sy-datum,

END OF itab.

DATA: v_bal TYPE i.

it_actual-date = '20071001'.

it_actual-bal = 500.

APPEND it_actual.

it_actual-date = '20071002'.

it_actual-bal = 400.

APPEND it_actual.

it_actual-date = '20071005'.

it_actual-bal = 900.

APPEND it_actual.

IF NOT it_actual[] IS INITIAL.

SORT it_actual BY date.

ENDIF.

*<b>To fill the internal table with the dates given on *the selection screen use the below logic.</b>

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

READ TABLE it_actual WITH KEY date = itab-date BINARY SEARCH.

IF sy-subrc = 0.

v_bal = it_actual-bal.

ENDIF.

it_final-date = itab-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.

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