Posted: Wed Oct 24, 2007 10:29 pm Post subject: Give Open Balance for a given GL account
Code:
REPORT y_test NO STANDARD PAGE HEADING LINE-COUNT 55(2) LINE-SIZE 215 .
*** table declaration ***
TABLES: glt0, " G/L account master record transaction figures "#EC *
bseg, " Accounting Document Segment for Line Items "#EC *
bkpf, " Accounting Document Header "#EC *
ska1,
skat. " G/L Account Master Record
"(Chart of Accounts: Description) "#EC
*
*** DATA declaration ***
DATA: count TYPE i,
count1 TYPE i,
l_len(4) TYPE n,
month(2) TYPE n,
value(4) TYPE n,
debit LIKE glt0-hslvt,
credit LIKE glt0-hslvt,
result LIKE glt0-hslvt.
DATA: v_day(2) TYPE c,
v_dat1 TYPE p, "#EC *
v_mon(2) TYPE c,
v_year(4) TYPE c,
v_date LIKE sy-datum, "#EC NEEDED
f_date TYPE sy-datum,
l_date TYPE sydatum, "#EC NEEDED
v_total LIKE bseg-dmbtr,
sum0 LIKE glt0-hslvt,
sum1 LIKE glt0-hslvt,
sum2 LIKE glt0-hslvt,
sum3 LIKE glt0-hslvt,
grand LIKE glt0-hslvt. "#EC *
* GLT0 table for opening balance from 16 periods
TYPES: BEGIN OF g_data,
rclnt LIKE glt0-rclnt,
bukrs LIKE glt0-bukrs,
drcrk LIKE glt0-drcrk,
ryear LIKE glt0-ryear,
racct LIKE glt0-racct,
hslvt LIKE glt0-hslvt,
hsl01 LIKE glt0-hsl01,
hsl02 LIKE glt0-hsl02,
hsl03 LIKE glt0-hsl03,
hsl04 LIKE glt0-hsl04,
hsl05 LIKE glt0-hsl05,
hsl06 LIKE glt0-hsl06,
hsl07 LIKE glt0-hsl07,
hsl08 LIKE glt0-hsl08,
hsl09 LIKE glt0-hsl09,
hsl10 LIKE glt0-hsl10,
hsl11 LIKE glt0-hsl11,
hsl12 LIKE glt0-hsl12,
hsl13 LIKE glt0-hsl13,
hsl14 LIKE glt0-hsl14,
hsl15 LIKE glt0-hsl15,
hsl16 LIKE glt0-hsl16,
start_balance LIKE glt0-hslvt,
end_balance LIKE glt0-hslvt,
open_balance LIKE glt0-hslvt,
END OF g_data.
DATA : gt_data TYPE STANDARD TABLE OF g_data WITH HEADER LINE,
wa_gt_data TYPE g_data.
DATA : gt_data1 TYPE STANDARD TABLE OF g_data WITH HEADER LINE,
wa_gt_data1 TYPE g_data.
DATA: BEGIN OF obal OCCURS 0,
bukrs LIKE glt0-bukrs,
racct LIKE glt0-racct,
txt50 LIKE skat-txt50,
open_bal LIKE glt0-hslvt,
END OF obal.
TYPES: BEGIN OF t_skat,
mandt TYPE mandt,
saknr TYPE saknr,
txt50 TYPE txt50,
END OF t_skat.
DATA: it_skat TYPE STANDARD TABLE OF t_skat WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK blk.
SELECT-OPTIONS: so_racct FOR ska1-saknr,
so_bukrs FOR glt0-bukrs NO INTERVALS NO-EXTENSION.
PARAMETERS: p_date LIKE sy-datum.
SELECTION-SCREEN END OF BLOCK blk.
AT SELECTION-SCREEN ON so_bukrs.
IF so_bukrs-low IS INITIAL.
MESSAGE e002(zglm).
ELSEIF bkpf-bukrs = so_bukrs AND glt0-bukrs = so_bukrs.
IF sy-subrc <> 0.
MESSAGE e003(zglm).
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON p_date.
v_day = '01'.
v_mon = p_date+4(2).
v_year = p_date+0(4).
CONCATENATE v_year v_mon v_day INTO v_date.
IF p_date IS INITIAL.
MESSAGE e004(zglm).
* ELSEIF P_DATE > V_DATE.
* MESSAGE E005(ZGLM).
ENDIF.
*&---------------------------------------------------------------------*
*& Form GETDATA *
*&---------------------------------------------------------------------*
* subroutine for getting data from DB tables *
*----------------------------------------------------------------------*
FORM getdata.
SELECT * FROM glt0 INTO
CORRESPONDING FIELDS OF
TABLE gt_data1 WHERE
racct IN so_racct AND
bukrs IN so_bukrs AND ryear = l_len.
DELETE ADJACENT DUPLICATES FROM gt_data1.
SELECT * FROM glt0 INTO
CORRESPONDING FIELDS OF
TABLE gt_data WHERE
racct IN so_racct AND
bukrs IN so_bukrs AND ryear = l_len.
DELETE ADJACENT DUPLICATES FROM gt_data.
SELECT mandt
saknr
txt50
FROM skat INTO TABLE it_skat
FOR ALL ENTRIES IN gt_data1
WHERE saknr EQ gt_data1-racct.
LOOP AT gt_data1.
wa_gt_data1 = gt_data1.
AT NEW racct.
READ TABLE it_skat WITH KEY saknr = gt_data1-racct.
IF sy-subrc EQ 0.
obal-txt50 = it_skat-txt50.
ENDIF.
IF sy-tabix NE 1.
NEW-PAGE.
ENDIF.
LOOP AT gt_data INTO wa_gt_data WHERE racct = gt_data1-racct.
CLEAR wa_gt_data-start_balance.
MOVE wa_gt_data-end_balance TO sum3.
PERFORM display_data.
ENDCASE.
ENDLOOP.
AT END OF racct.
count1 = count1 + 1.
obal-bukrs = wa_gt_data-bukrs.
obal-racct = wa_gt_data-racct.
obal-open_bal = result.
APPEND obal.
SORT obal BY racct.
DELETE ADJACENT DUPLICATES FROM obal.
CLEAR: debit,
credit,
result.
ENDAT.
ENDAT.
ENDLOOP.
count1 = count1 - 1.
ENDFORM. " end of getdata
*&---------------------------------------------------------------------*
*& Form PRINTDATA *
*&---------------------------------------------------------------------*
* subroutine for printing data from DB tables *
*----------------------------------------------------------------------*
FORM printdata.
LOOP AT obal.
* NEW-PAGE.
SKIP 3.
WRITE: /30 'GL ACCOUNT :', obal-racct COLOR 7, obal-txt50.
WRITE: /30 'COMP CODE :', obal-bukrs COLOR 7.
WRITE: /30 'POSTING DATE:',p_date COLOR 7.
WRITE: /50 'OPENING BALANCE ' , obal-open_bal COLOR 3."#EC UOM_IN_ME
MOVE obal-open_bal TO sum0.
CLEAR obal-open_bal.
ENDLOOP. " end of obal loop
ENDFORM. " end of print data
*&---------------------------------------------------------------------*
*& Form display_data *
*&---------------------------------------------------------------------*
* subroutine for calclating opening balance *
*----------------------------------------------------------------------*
FORM display_data.
IF wa_gt_data-drcrk = 'H'.
debit = debit + wa_gt_data-start_balance.
ELSE.
credit = credit + wa_gt_data-start_balance.
ENDIF.
result = debit + credit.
ENDFORM. " end of display_data
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.