Skip to Content
-1
Former Member
Jul 11, 2007 at 10:14 AM

who is patient it is difficult

95 Views

well i have this program ( about 3000 rows) when i execute it , it is displayed the balance carry forward for each vendor and customer. this is my problem. i want it to be displayed right down of the header the whole balance carry forward for all customers and vendors ( not for each vendor-customer) . i will reward with points for helpful answers. pls it's urgent. here is the code:

&----


*&

*&

&----


*& Written by: Antonis Nezos

*&

&----


REPORT z_1gvcl000_v1 NO STANDARD PAGE HEADING

MESSAGE-ID 00

LINE-COUNT 58(3).

- Global declarations -


TABLES : kna1, knb1, knc1, bsid, bsad, bkpf, t001, t001a, t000,

t005, t880, t004, ska1, skb1, tbslt, bsec, j_2gmd, tcurt.

TABLES : lfa1, lfb1, lfc1, bsik, bsak.

INCLUDE j_1gspledger.

  • << AN

DATA: BEGIN OF ilifnr OCCURS 0,

lifnr LIKE lfa1-lifnr,

kunnr LIKE lfa1-kunnr.

DATA: END OF ilifnr.

RANGES:r_kunnr FOR lfa1-kunnr.

DATA:w_lines TYPE p DECIMALS 0.

  • >> AN

  • FIELD GROUPS ***

FIELD-GROUPS : header, daten.

DATA :

BEGIN OF f_group,

bukrs LIKE lfb1-bukrs,

lifnr LIKE lfa1-lifnr,

kunnr LIKE kna1-kunnr,

akont LIKE lfb1-akont,

umskz LIKE bsik-umskz,

id(1), " 1 = Previous year 2 = Previous dates 3 = Current dates

otcname LIKE bsec-name1, " One time vendor name

budat LIKE bsik-budat,

xblnr LIKE bsik-xblnr,

belnr LIKE bsik-belnr,

buzei LIKE bsik-buzei,

blart LIKE bsik-blart,

bschl LIKE bsik-bschl,

bldat LIKE bsik-bldat,

waers LIKE bsik-waers, " Transaction currency

sgtxt LIKE bsik-sgtxt,

debitt LIKE bseg-wrbtr, " In transaction currency

creditt LIKE bseg-wrbtr,

balancet LIKE bseg-wrbtr,

debitl LIKE bseg-dmbtr, " In local currency

creditl LIKE bseg-dmbtr,

balancel LIKE bseg-dmbtr,

END OF f_group.

INSERT f_group-bukrs f_group-lifnr f_group-kunnr f_group-akont "SPOT

f_group-umskz

f_group-id f_group-otcname f_group-budat f_group-belnr

f_group-buzei

INTO header.

INSERT f_group-blart f_group-bschl f_group-xblnr

f_group-bldat f_group-waers f_group-sgtxt

f_group-debitt f_group-creditt f_group-balancet

f_group-debitl f_group-creditl f_group-balancel

INTO daten.

  • DATA DECLARATIONS ***

DATA : success.

DATA : method(1) TYPE n. " Read standard or extended ledger

DATA : msgtab LIKE fimsg OCCURS 100 WITH HEADER LINE.

DATA : no_headers.

DATA : g_curr LIKE bsik-waers.

DATA : g_curr_t LIKE tcurt-ktext.

DATA : wrote_previous_year.

DATA : wrote_previous_dates.

DATA : g_header(255).

DATA : g_len TYPE i.

DATA : date_string(100).

DATA : h_bukrs LIKE bsik-bukrs.

DATA : h_belnr LIKE bsik-belnr.

DATA : h_gjahr LIKE bsik-gjahr.

DATA : h_akont LIKE bsik-hkont.

DATA : h_lifnr LIKE bsik-lifnr.

DATA : h_kunnr LIKE bsid-kunnr. "SPOT

RANGES : valid_accounts FOR bsis-hkont.

RANGES : r_umskz FOR bsik-umskz.

  • Internal table with companies and chart of account used

DATA : BEGIN OF charts_tab OCCURS 10,

bukrs LIKE t001-bukrs,

chart LIKE t001-ktopl,

sakln LIKE t004-sakln,

END OF charts_tab.

  • Currencies tables

DATA : BEGIN OF currency_tab OCCURS 100,

bukrs LIKE t001-bukrs,

waers LIKE t001-waers,

curtp LIKE t001-waers, " Type of currency

END OF currency_tab.

  • Ranges and variables that dictate time periods to read.

DATA : last_previous_period LIKE bkpf-monat. " last previous period.

RANGES : previous_dates FOR sy-datum.

RANGES : all_dates FOR sy-datum.

  • Summation tables

DATA : BEGIN OF sum_bukrs, " Summation on local currency

debitl LIKE lfc1-umsav,

creditl LIKE lfc1-umsav,

balancel LIKE lfc1-umsav,

END OF sum_bukrs.

DATA : BEGIN OF sum_bukrs_t OCCURS 5, " Summations on transaction curr

waers LIKE bsik-waers,

debitt LIKE lfc1-umsav,

creditt LIKE lfc1-umsav,

balancet LIKE lfc1-umsav,

END OF sum_bukrs_t.

DATA : sum_umskz LIKE sum_bukrs.

DATA : sum_umskz_t LIKE sum_bukrs_t OCCURS 5 WITH HEADER LINE.

  • For previous years

DATA : sum_umskz_py LIKE sum_bukrs.

DATA : sum_umskz_t_py LIKE sum_bukrs_t OCCURS 5 WITH HEADER LINE.

  • For previous dates

DATA : sum_umskz_pd LIKE sum_bukrs.

DATA : sum_umskz_t_pd LIKE sum_bukrs_t OCCURS 5 WITH HEADER LINE.

  • Vendor totals

DATA : sum_lifnr LIKE sum_bukrs.

DATA : sum_lifnr_t LIKE sum_bukrs_t OCCURS 5 WITH HEADER LINE.

  • Customer totals

DATA : sum_kunnr LIKE sum_bukrs.

DATA : sum_kunnr_t LIKE sum_bukrs_t OCCURS 5 WITH HEADER LINE.

  • For page and carry forward totals.

DATA : sum_page LIKE sum_bukrs.

DATA : sum_cfw LIKE sum_bukrs.

  • Summation structures ON XBLNR ( reference document )

DATA : items LIKE f_group OCCURS 100 WITH HEADER LINE.

DATA : BEGIN OF xblnr_sum OCCURS 10,

xblnr LIKE bsik-xblnr,

budat LIKE bsik-budat,

bschl LIKE bsik-bschl,

waers LIKE bsik-waers, " Currency of transaction

debitl LIKE lfc1-umsav,

creditl LIKE lfc1-umsav,

balancel LIKE lfc1-umsav,

debitt LIKE lfc1-umsav,

creditt LIKE lfc1-umsav,

balancet LIKE lfc1-umsav,

counter TYPE i, " How many collects where done

END OF xblnr_sum.

  • OUTPUT STRUCTURES ***

DATA : BEGIN OF out_1, " General info

budat(10),

v1(1),

bldat(10), "gleventis 12.07.2006

v5(1), "gleventis 12.07.2006

xblnr LIKE bsik-xblnr,

v2(1),

belnr LIKE bsik-belnr,

v3(1),

sgtxt(50),

v4(1),

bschl LIKE bsik-bschl,

END OF out_1,

BEGIN OF out_2, " Local currency

v1(1),

debitl(16),

v2(1),

creditl(16),

v3(1),

balancel(17),

END OF out_2,

BEGIN OF out_3, " Transaction currency

v1(1),

debitt(16),

v2(1),

creditt(16),

v3(1),

balancet(17),

v4(1),

waers(4),

END OF out_3.

DATA : cfw_1 LIKE out_1. " For carry forwards

DATA : cfw_2 LIKE out_2.

DATA : pg_1 LIKE out_1. " For page totals

DATA : pg_2 LIKE out_2.

DATA : bukrs_page LIKE sy-pagno.

- Selection screen definitions -


PARAMETERS: s_ledger LIKE t881-rldnr DEFAULT 'ZD'.

SELECT-OPTIONS: s_bukrs FOR lfb1-bukrs MEMORY ID buk.

SELECT-OPTIONS s_lifnr FOR lfb1-lifnr MATCHCODE OBJECT kred.

SELECTION-SCREEN ULINE.

SELECT-OPTIONS: s_akont FOR lfb1-akont. " Reconciliation accounts

  • In which chart of accounts the results will be displayed

SELECTION-SCREEN COMMENT /1(60) text-004.

PARAMETERS s_chart RADIOBUTTON GROUP y." Chart of accounts of company

PARAMETERS s_altk RADIOBUTTON GROUP y. " Alternative chart of accounts

PARAMETERS s_group RADIOBUTTON GROUP y." Group chart of accounts

  • In which chart of accounts the range of reconciliation accounts

  • where given by the user

SELECTION-SCREEN COMMENT /1(60) text-019.

PARAMETERS s_acch RADIOBUTTON GROUP j.

PARAMETERS s_asch RADIOBUTTON GROUP j DEFAULT 'X'.

  • Use 2nd parallel currency

PARAMETERS : s_2curr AS CHECKBOX.

SELECTION-SCREEN ULINE.

  • Selections on special G/Ls

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS : s_umskzn RADIOBUTTON GROUP c DEFAULT 'X'. " Normal G/Ls

SELECTION-SCREEN COMMENT (30) text-001.

PARAMETERS : s_umskzs RADIOBUTTON GROUP c. " Special G/Ls

SELECTION-SCREEN COMMENT (30) text-002.

PARAMETERS : s_umskzb RADIOBUTTON GROUP c. " Both

SELECTION-SCREEN COMMENT (30) text-003.

SELECTION-SCREEN END OF LINE.

  • Range of special g/L transactions

SELECT-OPTIONS : s_umskz FOR bsik-umskz.

SELECTION-SCREEN ULINE.

  • Posting dates

PARAMETERS:

s_gjahr LIKE bkpf-gjahr OBLIGATORY DEFAULT sy-datum(4).

SELECT-OPTIONS:

s_budat FOR bkpf-budat OBLIGATORY NO-EXTENSION DEFAULT sy-datum.

SELECTION-SCREEN ULINE.

  • Read previous year balance

PARAMETERS : s_rprevy AS CHECKBOX DEFAULT 'X'.

  • Read previous dates

PARAMETERS : s_rprevd AS CHECKBOX DEFAULT 'X'.

  • Print vendors not posted to.

PARAMETERS : s_nonpos AS CHECKBOX.

  • The following vendors not posted to

SELECT-OPTIONS : s_cusnon FOR lfb1-lifnr MATCHCODE OBJECT kred.

  • Print one time vendor data.

PARAMETERS : s_onetim AS CHECKBOX.

  • Amounts in transaction currency

PARAMETERS : s_tran AS CHECKBOX.

  • Sums on XBLNR

PARAMETERS : s_sxblnr AS CHECKBOX.

  • Show same XBLNRS as one line

PARAMETERS : s_xblnr AS CHECKBOX.

*<<< DDS Exclude documents with doc type 'CL'

PARAMETERS : s_cl AS CHECKBOX.

*>>> DDS

SELECTION-SCREEN ULINE.

  • Print user selections.

PARAMETERS : s_psel AS CHECKBOX.

- Selection screen processing -


  • { au1++

**********************************************TEST temp

AT SELECTION-SCREEN ON s_bukrs.

call function 'J_1GBUKRS_AUTH_CHECK'

exporting

i_xdb = 'KB'

tables

it_buksel = s_bukrs.

AT SELECTION-SCREEN.

AUTHORITY-CHECK OBJECT 'F_BKPF_KOA'

ID 'KOART' FIELD 'K'

ID 'ACTVT' FIELD '03'.

IF sy-subrc <> 0.

MESSAGE e482(f4).

ENDIF.

  • } au1

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_akont-low.

CALL FUNCTION 'FI_F4_AKONT'

EXPORTING

i_bukrs = s_bukrs-low

i_mitkz = 'K'

IMPORTING

e_akont = s_akont-low

EXCEPTIONS

invalid_call = 1

nothing_found = 2

internal_error = 3

OTHERS = 4.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_akont-high.

CALL FUNCTION 'FI_F4_AKONT'

EXPORTING

i_bukrs = s_bukrs-low

i_mitkz = 'K'

IMPORTING

e_akont = s_akont-high

EXCEPTIONS

invalid_call = 1

nothing_found = 2

internal_error = 3

OTHERS = 4.

- Data Selection part -


START-OF-SELECTION.

********************************

  • << AN

r_kunnr-sign = 'I'.

r_kunnr-option = 'EQ'.

SELECT * FROM lfa1 WHERE lifnr IN s_lifnr.

IF NOT lfa1-kunnr IS INITIAL.

ilifnr-kunnr = lfa1-kunnr.

ilifnr-lifnr = lfa1-lifnr.

APPEND ilifnr.

CLEAR: ilifnr.

r_kunnr-low = lfa1-kunnr.

COLLECT r_kunnr.

ENDIF.

ENDSELECT.

*>> AN

*********************************************

CALL FUNCTION 'FI_MESSAGE_INIT'.

PERFORM create_headers.

PERFORM setup_glind.

  • get spl summary table

IF NOT s_ledger IS INITIAL.

PERFORM get_ledger_table USING s_ledger

CHANGING table.

IF table IS INITIAL.

MESSAGE s000(8n1) WITH text-s01 s_ledger.

LEAVE PROGRAM.

ENDIF.

  • compare spl summary table with program data type

PERFORM check_summary_table CHANGING l_table_differs.

IF l_table_differs = c_true.

IF sy-batch <> 'X'. " (Running in dialog mode)

string = text-s02.

REPLACE '$' WITH table INTO string.

CONDENSE string.

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

titel = sy-title

textline1 = string

textline2 = text-s03.

ENDIF.

ENDIF.

ENDIF. " not s_ledger is initial

SELECT * FROM t001 WHERE bukrs IN s_bukrs.

PERFORM check_posting USING t001 success.

CHECK success = 'X'.

PERFORM setup_periods USING t001-bukrs s_gjahr success.

CHECK success = 'X'.

PERFORM setup_currency USING t001 success.

CHECK success = 'X'.

PERFORM set_up_chart USING t001 success.

CHECK success = 'X'.

PERFORM setup_accounts USING t001. " Setup valid accounts

IF s_rprevy = 'X' OR s_rprevd = 'X'.

PERFORM determine_method USING t001.

  • << AN

method = 2.

  • >> AN

IF method = 1. " Read from standard ledger "SPOT

PERFORM collect_knc1 USING t001-bukrs.

PERFORM collect_lfc1 USING t001-bukrs.

ELSE. " Read from special ledger

PERFORM collect_extended USING t001-bukrs success.

CHECK success = 'X'.

ENDIF.

ENDIF.

PERFORM collect_transactions USING t001-bukrs 'BSIK'.

PERFORM collect_transactions USING t001-bukrs 'BSAK'.

PERFORM collect_transactions_bsid USING t001-bukrs 'BSID'.

PERFORM collect_transactions_bsid USING t001-bukrs 'BSAD'.

IF s_nonpos = 'X' AND ( s_umskzn = 'X' OR s_umskzb = 'X' ).

PERFORM create_dummy_entries USING t001.

ENDIF.

ENDSELECT.

- Processing part -


END-OF-SELECTION.

IF s_tran = ' '.

NEW-PAGE LINE-SIZE 170.

ELSE.

NEW-PAGE LINE-SIZE 255.

ENDIF.

PERFORM set_headers(sapfj1glbh)

USING '' '' '' '' '' '' '' '' '*' 'X'.

SORT.

LOOP.

AT NEW f_group-bukrs.

CLEAR bukrs_page. " Page counter for company

PERFORM create_bukrs_info.

CLEAR sum_cfw.

CLEAR : sum_bukrs, sum_bukrs_t[], sum_bukrs_t.

READ TABLE currency_tab WITH KEY bukrs = f_group-bukrs.

g_curr = currency_tab-waers.

CLEAR tcurt.

SELECT SINGLE * FROM tcurt WHERE spras = sy-langu AND

waers = g_curr.

g_curr_t = tcurt-ktext.

NEW-PAGE.

ENDAT.

AT NEW f_group-lifnr.

PERFORM write_lifnr.

CLEAR : sum_lifnr, sum_lifnr_t[], sum_lifnr_t.

ENDAT.

AT NEW f_group-kunnr.

PERFORM write_kunnr.

CLEAR : sum_kunnr, sum_kunnr_t[], sum_kunnr_t.

ENDAT.

AT NEW f_group-umskz.

PERFORM write_umskz.

CLEAR : sum_umskz, sum_umskz_t[], sum_umskz_t.

CLEAR : sum_umskz_py, sum_umskz_t_py[], sum_umskz_t_py.

CLEAR : sum_umskz_pd, sum_umskz_t_pd[], sum_umskz_t_pd.

CLEAR : wrote_previous_year, wrote_previous_dates.

ENDAT.

AT NEW f_group-otcname.

IF f_group-id = '3'. " Line items

IF f_group-otcname NE space.

PERFORM write_one_time_vendor USING f_group.

PERFORM write_one_time_customer USING f_group.

ENDIF.

CLEAR : items[], items, xblnr_sum[], xblnr_sum.

ENDIF.

ENDAT.

IF ( f_group-id = '1' ).

ADD-CORRESPONDING f_group TO sum_umskz_py.

MOVE-CORRESPONDING f_group TO sum_umskz_t_py.

COLLECT sum_umskz_t_py.

ELSEIF ( f_group-id = '2' ).

ADD-CORRESPONDING f_group TO sum_umskz_pd.

MOVE-CORRESPONDING f_group TO sum_umskz_t_pd.

COLLECT sum_umskz_t_pd.

ELSE. " Line items

IF s_sxblnr = 'X'. " Sums on XBLNR

MOVE-CORRESPONDING f_group TO items.

APPEND items.

MOVE-CORRESPONDING f_group TO xblnr_sum.

IF s_tran NE 'X'. " No transaction currency necessary

CLEAR xblnr_sum-waers.

ENDIF.

xblnr_sum-counter = 1.

COLLECT xblnr_sum.

ELSE.

ADD-CORRESPONDING f_group TO sum_umskz.

MOVE-CORRESPONDING f_group TO sum_umskz_t.

COLLECT sum_umskz_t.

PERFORM write_line USING f_group.

ENDIF.

ENDIF.

AT END OF f_group-otcname.

IF f_group-id = '3'.

IF s_sxblnr = 'X'. " Sums on XBLNR

PERFORM process_xblnr.

ENDIF.

ENDIF.

ENDAT.

AT END OF f_group-id.

IF ( f_group-id = '1' ).

ADD-CORRESPONDING sum_umskz_py TO sum_umskz.

PERFORM pass_trans TABLES sum_umskz_t_py sum_umskz_t.

PERFORM write_previous TABLES sum_umskz_t_py

USING sum_umskz_py '1'.

ELSEIF ( f_group-id = '2' ).

ADD-CORRESPONDING sum_umskz_pd TO sum_umskz.

PERFORM pass_trans TABLES sum_umskz_t_pd sum_umskz_t.

PERFORM write_previous TABLES sum_umskz_t_pd

USING sum_umskz_pd '2'.

ENDIF.

ENDAT.

AT END OF f_group-umskz.

PERFORM write_end_account.

ADD-CORRESPONDING sum_umskz TO sum_bukrs.

PERFORM pass_trans TABLES sum_umskz_t sum_bukrs_t.

ENDAT.

AT END OF f_group-akont.

ENDAT.

AT END OF f_group-lifnr.

ENDAT.

AT END OF f_group-kunnr.

ENDAT.

AT END OF f_group-bukrs.

PERFORM print_company_totals.

ENDAT.

ENDLOOP.

PERFORM write_errors.

IF s_psel = 'X'.

PERFORM print_user_selections.

ENDIF.

CLEAR : h_bukrs, h_lifnr, h_kunnr, h_gjahr, h_akont, h_belnr.

  • TOP OF PAGE PROCESSING ***

TOP-OF-PAGE.

CLEAR sum_page.

ADD 1 TO bukrs_page.

IF no_headers = space.

  • Create the header lines

PERFORM write_headers(sapfj1glbh)

USING t001

text-p01 ''

bukrs_page

date_string

g_curr

g_header ' '.

ULINE.

  • Write carry forwards.

IF bukrs_page NE 1.

CLEAR : cfw_1, cfw_2.

cfw_1-sgtxt = text-205.

WRITE sum_cfw-debitl TO cfw_2-debitl CURRENCY g_curr.

WRITE sum_cfw-creditl TO cfw_2-creditl CURRENCY g_curr.

WRITE sum_cfw-balancel TO cfw_2-balancel CURRENCY g_curr.

WRITE : / cfw_1 NO-GAP, cfw_2 NO-GAP.

ENDIF.

SKIP 1.

ENDIF.

  • END OF PAGE PROCESSING ***

END-OF-PAGE.

IF no_headers = space.

SKIP 1.

  • Write page totals

CLEAR : pg_1, pg_2.

pg_1-sgtxt = text-203.

WRITE sum_page-debitl TO pg_2-debitl CURRENCY g_curr.

WRITE sum_page-creditl TO pg_2-creditl CURRENCY g_curr.

WRITE sum_page-balancel TO pg_2-balancel CURRENCY g_curr.

WRITE : / pg_1 NO-GAP, pg_2 NO-GAP.

  • Write carry forwards

CLEAR : cfw_1, cfw_2.

cfw_1-sgtxt = text-206.

WRITE sum_cfw-debitl TO cfw_2-debitl CURRENCY g_curr.

WRITE sum_cfw-creditl TO cfw_2-creditl CURRENCY g_curr.

WRITE sum_cfw-balancel TO cfw_2-balancel CURRENCY g_curr.

WRITE : / cfw_1 NO-GAP, cfw_2 NO-GAP.

ENDIF.

- User Interaction part -


AT LINE-SELECTION.

IF h_belnr NE space AND h_belnr NE '**********'.

SET PARAMETER ID 'BLN' FIELD h_belnr.

SET PARAMETER ID 'BUK' FIELD h_bukrs.

SET PARAMETER ID 'GJR' FIELD h_gjahr.

CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.

ELSEIF h_akont NE space.

IF s_chart = 'X'.

SET PARAMETER ID 'SAK' FIELD h_akont.

SET PARAMETER ID 'BUK' FIELD h_bukrs.

SET PARAMETER ID 'GJR' FIELD h_gjahr.

CALL TRANSACTION 'FS10N' AND SKIP FIRST SCREEN.

ENDIF.

ELSEIF h_lifnr NE space.

SET PARAMETER ID 'LIF' FIELD h_lifnr.

SET PARAMETER ID 'BUK' FIELD h_bukrs.

SET PARAMETER ID 'GJR' FIELD h_gjahr.

CALL TRANSACTION 'FK10N' AND SKIP FIRST SCREEN.

ELSEIF h_kunnr NE space. "SPOT

SET PARAMETER ID 'KUN' FIELD h_kunnr.

SET PARAMETER ID 'BUK' FIELD h_bukrs.

SET PARAMETER ID 'GJR' FIELD h_gjahr.

CALL TRANSACTION 'FD10N' AND SKIP FIRST SCREEN.

ENDIF.

CLEAR : h_bukrs, h_lifnr, h_kunnr, h_gjahr, h_akont, h_belnr.

- S u b r o u t i n e s -


************************************************************************

  • Determine if we should read from General Ledger or Special *

  • Further criteria in the selection screen should be tested here, *

  • if they create the necessity to read form an extended ledger *

  • It is advisable if an extended ledger exists to set up method *

  • always to 2 ( always to read from extended ledger ) *

  • --- Read program documentation --- *

************************************************************************

FORM determine_method USING value(v_t001) STRUCTURE t001.

READ TABLE currency_tab WITH KEY bukrs = v_t001-bukrs.

IF ( s_umskzn EQ 'X' ) AND

( currency_tab-curtp = '10' ) AND

( s_tran NE 'X' ).

method = 1. " No need to read from special ledger

ELSE.

method = 2. " Need to read from special ledger

ENDIF.

IF NOT s_ledger IS INITIAL.

method = 2.

ENDIF.

ENDFORM. "determine_method

************************************************************************

  • Set up the last previous period and the current periods. *

************************************************************************

FORM setup_periods USING value(pbukrs)

value(pgjahr)

success.

DATA : period_l LIKE t009b-poper.

DATA : BEGIN OF the_periods OCCURS 20.

INCLUDE STRUCTURE periods.

DATA : END OF the_periods.

DATA : date_low LIKE sy-datum.

DATA : date_high LIKE sy-datum.

DATA : w_date LIKE sy-datum.

DATA : 1st_date LIKE sy-datum.

DATA : t001_wa LIKE t001.

success = 'X'.

  • Clear all date structures

CLEAR last_previous_period.

CLEAR previous_dates. REFRESH previous_dates.

CLEAR all_dates. REFRESH all_dates.

  • Put selected dates into all_dates.

LOOP AT s_budat.

MOVE s_budat TO all_dates.

APPEND all_dates.

ENDLOOP.

  • No need to read periods balance

IF s_rprevy = space AND s_rprevd = space.

EXIT.

ENDIF.

SELECT SINGLE * FROM t001 INTO t001_wa WHERE bukrs = pbukrs.

CALL FUNCTION 'G_PERIODS_OF_YEAR_GET'

EXPORTING

variant = t001_wa-periv

year = pgjahr

IMPORTING

last_normal_period = period_l

TABLES

i_periods = the_periods

EXCEPTIONS

variant_not_defined = 1

year_not_defined = 2

OTHERS = 3.

IF sy-subrc NE 0.

CLEAR msgtab.

msgtab-msort = '5'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = pbukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

CLEAR success.

EXIT.

ENDIF.

READ TABLE s_budat INDEX 1.

date_low = s_budat-low.

IF s_budat-high NE 0.

date_high = s_budat-high.

ELSE.

date_high = s_budat-low.

ENDIF.

SORT the_periods BY buper.

LOOP AT the_periods.

IF date_low > the_periods-datbi.

last_previous_period = the_periods-buper.

ENDIF.

ENDLOOP.

  • Set up dates

LOOP AT the_periods.

IF date_low BETWEEN the_periods-datab AND

the_periods-datbi.

IF date_low GT the_periods-datab.

CLEAR previous_dates.

previous_dates-sign = 'I'.

previous_dates-option = 'BT'.

previous_dates-low = the_periods-datab.

previous_dates-high = date_low - 1.

APPEND previous_dates.

MOVE previous_dates TO all_dates.

APPEND all_dates.

ENDIF.

EXIT.

ENDIF.

ENDLOOP.

ENDFORM. "setup_periods

************************************************************************

  • Write errors that occured *

************************************************************************

FORM write_errors.

DATA xfeld.

no_headers ='X'.

CALL FUNCTION 'FI_MESSAGE_CHECK'

EXCEPTIONS

no_message = 01.

IF sy-subrc = 0.

NEW-PAGE.

ULINE.

WRITE text-f00.

ULINE.

CALL FUNCTION 'FI_MESSAGE_SORT'.

CLEAR msgtab.

REFRESH msgtab.

CALL FUNCTION 'FI_MESSAGE_GET_MSORT'

IMPORTING

e_xinit = xfeld

TABLES

s_fimsg = msgtab

EXCEPTIONS

no_message = 1.

IF sy-subrc = 0.

LOOP AT msgtab.

CASE msgtab-msort.

WHEN '1'.

WRITE text-f01 COLOR 3.

WHEN '2'.

WRITE text-f02 COLOR 3.

WHEN '3'.

WRITE text-f03 COLOR 3.

WHEN '4'.

WRITE text-f04 COLOR 3.

WHEN '5'.

WRITE text-f05 COLOR 3.

WHEN '6'.

WRITE text-f06 COLOR 3.

WHEN '7'.

WRITE text-f07 COLOR 3.

WHEN '8'.

WRITE text-f08 COLOR 3.

WHEN '9'.

WRITE text-f09 COLOR 3.

ENDCASE.

CALL FUNCTION 'FI_MESSAGE_PRINT'

EXPORTING

i_msort = msgtab-msort

i_xausn = ' '

i_xeaus = 'X'

i_xskip = ' '.

SKIP.

ENDLOOP.

ENDIF.

ENDIF.

ENDFORM. "write_errors

************************************************************************

  • Setup currencies

************************************************************************

FORM setup_currency USING

value(v_t001) STRUCTURE t001

p_success.

PERFORM test_currency USING v_t001 p_success.

CHECK p_success = space. " Currency determination failed

CLEAR msgtab.

msgtab-msort = '2'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = v_t001-bukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

ENDFORM. "setup_currency

************************************************************************

  • test if 2nd currency exists if user selected to display amounts *

  • in 2nd Company code currency. *

  • Also update the currencies_tab. *

************************************************************************

FORM test_currency USING

value(v_t001) STRUCTURE t001

p_success.

CLEAR p_success.

IF s_2curr = space.

currency_tab-bukrs = v_t001-bukrs.

currency_tab-waers = v_t001-waers.

currency_tab-curtp = '10'.

APPEND currency_tab.

p_success = 'X'.

EXIT.

ENDIF.

SELECT SINGLE * FROM t001a WHERE bukrs = v_t001-bukrs.

CHECK sy-subrc = 0.

CHECK t001a-curtp NE space.

CASE t001a-curtp.

WHEN '30'. " Group currency

SELECT SINGLE * FROM t000 WHERE mandt = sy-mandt.

CHECK sy-subrc = 0.

CHECK t000-mwaer NE space.

currency_tab-bukrs = v_t001-bukrs.

currency_tab-waers = t000-mwaer.

currency_tab-curtp = '30'.

APPEND currency_tab.

WHEN '40'. " Hard currency

SELECT SINGLE * FROM t005 WHERE land1 = v_t001-land1.

CHECK sy-subrc = 0.

CHECK t005-curha NE space.

currency_tab-bukrs = v_t001-bukrs.

currency_tab-waers = t005-curha.

currency_tab-curtp = '40'.

APPEND currency_tab.

WHEN '50'. " Index-based currency

SELECT SINGLE * FROM t005 WHERE land1 = v_t001-land1.

CHECK sy-subrc = 0.

CHECK t005-curin NE space.

currency_tab-bukrs = v_t001-bukrs.

currency_tab-waers = t005-curin.

currency_tab-curtp = '50'.

APPEND currency_tab.

WHEN '60'. " Global company currency

SELECT SINGLE * FROM t880 WHERE rcomp = v_t001-rcomp.

CHECK sy-subrc = 0.

CHECK t880-curr NE space.

currency_tab-bukrs = v_t001-bukrs.

currency_tab-waers = t880-curr.

currency_tab-curtp = '60'.

APPEND currency_tab.

WHEN OTHERS. EXIT.

ENDCASE.

p_success = 'X'.

ENDFORM. "test_currency

************************************************************************

  • Set up chart of accounts *

************************************************************************

FORM set_up_chart USING value(v_t001) STRUCTURE t001

p_success.

CLEAR p_success.

IF s_chart = 'X'. " Normal chart of accounts

charts_tab-bukrs = v_t001-bukrs.

charts_tab-chart = v_t001-ktopl.

CLEAR t004.

SELECT SINGLE * FROM t004 WHERE ktopl = v_t001-ktopl.

charts_tab-sakln = t004-sakln.

IF charts_tab-sakln = 0.

charts_tab-sakln = 10.

ENDIF.

APPEND charts_tab.

p_success = 'X'.

EXIT.

ENDIF.

IF s_altk = 'X'. " Alternative chart of accounts

charts_tab-bukrs = v_t001-bukrs.

IF v_t001-ktop2 = space.

charts_tab-chart = v_t001-ktopl.

ELSE.

charts_tab-chart = v_t001-ktop2.

ENDIF.

CLEAR t004.

SELECT SINGLE * FROM t004 WHERE ktopl = charts_tab-chart.

charts_tab-sakln = t004-sakln.

IF charts_tab-sakln = 0.

charts_tab-sakln = 10.

ENDIF.

APPEND charts_tab.

p_success = 'X'.

EXIT.

ENDIF.

IF s_group = 'X'. " Group chart of accounts

charts_tab-bukrs = v_t001-bukrs.

CLEAR t004.

SELECT SINGLE * FROM t004 WHERE ktopl = v_t001-ktopl.

IF sy-subrc NE 0 OR t004-kktpl = space.

CLEAR msgtab.

msgtab-msort = '3'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = v_t001-bukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

EXIT.

ENDIF.

charts_tab-chart = t004-kktpl.

CLEAR t004.

SELECT SINGLE * FROM t004 WHERE ktopl = charts_tab-chart.

charts_tab-sakln = t004-sakln.

IF charts_tab-sakln = 0.

charts_tab-sakln = 10.

ENDIF.

APPEND charts_tab.

p_success = 'X'.

EXIT.

ENDIF.

ENDFORM. "set_up_chart

************************************************************************

  • Set up account *

************************************************************************

FORM determine_account USING value(v_bukrs)

value(v_hkont)

p_hkont

p_success.

CLEAR p_success.

  • If account ranges are given in company chart of accounts.

IF s_acch = 'X' OR s_chart = 'X'.

CHECK v_hkont IN s_akont.

ENDIF.

IF s_chart = 'X'. " Company accounts

p_hkont = v_hkont.

p_success = 'X'.

ELSEIF s_altk = 'X'. " Alternative accounts

PERFORM find_alternative_account USING v_bukrs v_hkont

p_hkont p_success.

CHECK p_success = 'X'.

ELSE. " Group accounts

PERFORM find_group_account USING v_bukrs v_hkont

p_hkont p_success.

CHECK p_success = 'X'.

ENDIF.

IF s_asch = 'X' AND s_chart NE 'X'.

IF NOT ( p_hkont IN s_akont ).

CLEAR p_success.

ENDIF.

ENDIF.

ENDFORM. "determine_account

************************************************************************

  • Find alternative account *

************************************************************************

FORM find_alternative_account USING value(v_bukrs)

value(v_hkont)

p_alt_account

p_success.

DATA : altkt_not_found LIKE skb1-xkres.

DATA : p_sakan LIKE ska1-sakan.

DATA : ktext LIKE skat-txt20.

DATA : ltext LIKE skat-txt50.

DATA : text_not_found LIKE skb1-xkres.

p_success = 'X'.

CALL FUNCTION 'READ_SACHKONTO_ALTKT'

EXPORTING

bukrs = v_bukrs

saknr = v_hkont

xmass = 'X'

xskan = 'X'

IMPORTING

altkt = p_alt_account

altkt_not_found = altkt_not_found

altkt_sakan = p_sakan

ktext = ktext

ltext = ltext

text_not_found = text_not_found

EXCEPTIONS

bukrs_not_found = 1

saknr_not_found = 2

OTHERS = 3.

IF altkt_not_found = 'X'.

CLEAR msgtab.

msgtab-msort = '1'.

msgtab-msgid = 'FR'.

msgtab-msgty = 'E'.

msgtab-msgno = '274'.

msgtab-msgv1 = v_hkont.

msgtab-msgv2 = v_bukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

CLEAR p_success.

ENDIF.

ENDFORM. "find_alternative_account

************************************************************************

  • Find account according to group chart of accounts *

************************************************************************

FORM find_group_account USING value(v_bukrs)

value(v_hkont)

p_group_account

p_success.

DATA : t001_wa LIKE t001.

p_success = 'X'.

CLEAR charts_tab.

READ TABLE charts_tab WITH KEY bukrs = v_bukrs.

SELECT SINGLE * FROM t001 INTO t001_wa WHERE bukrs = v_bukrs.

SELECT SINGLE * FROM ska1 WHERE ktopl = t001_wa-ktopl AND

saknr = v_hkont.

p_group_account = ska1-bilkt.

IF sy-subrc NE 0 OR ska1-bilkt = space.

CLEAR msgtab.

msgtab-msort = '4'.

msgtab-msgid = 'FR'.

msgtab-msgty = 'E'.

msgtab-msgno = '274'.

msgtab-msgv1 = v_bukrs.

msgtab-msgv2 = v_hkont.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

CLEAR p_success.

ENDIF.

ENDFORM. "find_group_account

  • SPOT

************************************************************************

  • Collect information from lfc1 *

************************************************************************

FORM collect_lfc1 USING value(pbukrs).

DATA : amount LIKE lfc1-um01s.

DATA : l_success.

SELECT * FROM lfc1 WHERE bukrs = pbukrs AND

lifnr IN s_lifnr AND

gjahr = s_gjahr.

CLEAR f_group.

f_group-bukrs = lfc1-bukrs.

f_group-lifnr = lfc1-lifnr.

  • { au1++

CLEAR: lfa1, lfb1.

SELECT SINGLE * FROM lfa1 WHERE lifnr = lfc1-lifnr.

call function 'J_1GACCOUNT_AUTH_CHECK'

exporting

i_xdb = 'K'

i_begru = lfa1-begru

i_aktvt = '03'

exceptions

no_authorization = 1

others = 2.

check sy-subrc = 0.

  • } au1

SELECT SINGLE * FROM lfb1 WHERE lifnr = lfc1-lifnr AND

bukrs = pbukrs.

IF sy-subrc NE 0.

f_group-akont = '##########'.

ELSE.

PERFORM determine_account USING pbukrs lfb1-akont

f_group-akont l_success.

CHECK l_success = 'X'.

ENDIF.

  • { au1++

call function 'J_1GACCOUNT_AUTH_CHECK'

exporting

i_xdb = 'K'

i_begru = lfb1-begru

i_aktvt = '03'

exceptions

no_authorization = 1

others = 2.

check sy-subrc = 0.

  • } au1

f_group-umskz = space.

IF lfc1-umsav NE 0 AND s_rprevy = 'X'.

f_group-balancel = lfc1-umsav. "BCF

f_group-id = '1'.

EXTRACT daten.

ENDIF.

IF last_previous_period > 0.

CLEAR : amount, f_group-debitl, f_group-creditl,

f_group-balancel.

DO last_previous_period TIMES

VARYING amount FROM lfc1-um01s NEXT lfc1-um02s.

ADD amount TO f_group-debitl.

ENDDO.

  • f_group-debitl = abs( f_group-debitl ).

CLEAR amount.

DO last_previous_period TIMES

VARYING amount FROM lfc1-um01h NEXT lfc1-um02h.

ADD amount TO f_group-creditl.

ENDDO.

  • f_group-creditl = abs( f_group-creditl ).

IF ( f_group-debitl NE 0 OR f_group-creditl NE 0 ) AND

( s_rprevd = 'X' ).

f_group-balancel = f_group-debitl - f_group-creditl.

f_group-id = '2'.

EXTRACT daten.

ENDIF.

ENDIF.

ENDSELECT.

ENDFORM. "collect_lfc1

  • SPOT

************************************************************************

  • Collect information from KNC1 *

************************************************************************

FORM collect_knc1 USING value(pbukrs).

DATA : amount LIKE knc1-um01s.

DATA : l_success.

  • A.NEZ

  • select * from lfa1 where lifnr in s_lifnr.

*

*

*ilifnr-kunnr = lfa1-kunnr.

*append ilifnr.

*clear: ilifnr.

*endselect.

LOOP AT ilifnr.

SELECT * FROM knc1 WHERE bukrs = pbukrs AND

kunnr = ilifnr-kunnr AND

gjahr = s_gjahr.

CLEAR f_group.

f_group-bukrs = knc1-bukrs.

f_group-kunnr = knc1-kunnr.

  • { au1++

CLEAR: kna1, knb1. "SPOT K

SELECT SINGLE * FROM kna1 WHERE kunnr = knc1-kunnr.

call function 'J_1GACCOUNT_AUTH_CHECK'

exporting

i_xdb = 'D'

i_begru = kna1-begru

i_aktvt = '03'

exceptions

no_authorization = 1

others = 2.

check sy-subrc = 0.

  • } au1

SELECT SINGLE * FROM knb1 WHERE kunnr = knc1-kunnr AND

bukrs = pbukrs.

IF sy-subrc NE 0.

f_group-akont = '##########'.

ELSE.

PERFORM determine_account USING pbukrs knb1-akont

f_group-akont l_success.

CHECK l_success = 'X'.

ENDIF.

  • { au1++

call function 'J_1GACCOUNT_AUTH_CHECK'

exporting

i_xdb = 'D'

i_begru = knb1-begru

i_aktvt = '03'

exceptions

no_authorization = 1

others = 2.

check sy-subrc = 0.

  • } au1

f_group-umskz = space.

IF knc1-umsav NE 0 AND s_rprevy = 'X'.

f_group-balancel = knc1-umsav . "BCF

f_group-id = '1'.

EXTRACT daten.

ENDIF.

IF last_previous_period > 0.

CLEAR : amount, f_group-debitl, f_group-creditl,

f_group-balancel.

DO last_previous_period TIMES

VARYING amount FROM knc1-um01s NEXT knc1-um02s.

ADD amount TO f_group-debitl.

ENDDO.

  • f_group-debitl = abs( f_group-debitl ).

CLEAR amount.

DO last_previous_period TIMES

VARYING amount FROM knc1-um01h NEXT knc1-um02h.

ADD amount TO f_group-creditl.

ENDDO.

  • f_group-creditl = abs( f_group-creditl ).

IF ( f_group-debitl NE 0 OR f_group-creditl NE 0 ) AND

( s_rprevd = 'X' ).

f_group-balancel = f_group-debitl - f_group-creditl.

f_group-id = '2'.

EXTRACT daten.

ENDIF.

ENDIF.

ENDSELECT.

ENDLOOP.

ENDFORM. "collect_knc1

************************************************************************

  • Collect information from extended ledger *

************************************************************************

FORM collect_extended USING value(pbukrs)

p_success.

CLEAR p_success.

IF s_ledger IS INITIAL.

CLEAR msgtab.

msgtab-msort = '7'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = pbukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

EXIT.

ENDIF.

  • Check if ledger is assigned to company

DATA : jt882 LIKE t882.

SELECT SINGLE * FROM t882 INTO jt882

WHERE bukrs = pbukrs

AND rldnr = s_ledger.

IF sy-subrc <> 0.

CLEAR msgtab.

msgtab-msort = '8'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = pbukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

EXIT.

ENDIF.

  • Check if ledger stores amounts in the local curr.

READ TABLE currency_tab WITH KEY bukrs = pbukrs.

IF currency_tab-waers <> jt882-curr1 AND

currency_tab-waers <> jt882-curr2.

CLEAR msgtab.

msgtab-msort = '9'.

msgtab-msgid = '00'.

msgtab-msgty = 'E'.

msgtab-msgno = '398'.

msgtab-msgv1 = pbukrs.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

i_fimsg = msgtab.

EXIT.

ENDIF.

  • Select previous dates

  • data : lh_type type spl_type. "DDS

*<<< DDS

DATA: spl_type TYPE spl_type.

DATA: BEGIN OF lh_type.

INCLUDE STRUCTURE spl_type.

DATA: rzzblart LIKE zzdvft-rzzblart,

END OF lh_type.

*>>> DDS

DATA : amount LIKE glreft-hslvt.

DATA : pyear LIKE glreft-hslvt.

DATA : previous LIKE glreft-hslvt.

DATA : amountt LIKE glreft-hslvt. " Transaction currency

DATA : pyeart LIKE glreft-hslvt. " Transaction currency

DATA : previoust LIKE glreft-hslvt. " Transaction currency

DATA : l_success.

p_success = 'X'.

  • << AN

DESCRIBE TABLE s_lifnr LINES w_lines.

IF w_lines = 0.

s_lifnr-sign = 'I'.

s_lifnr-option = 'BT'.

s_lifnr-low = '0000000001'.

s_lifnr-high = 'ZZZZZZZZZZ'.

COLLECT s_lifnr.

ENDIF.

  • >> AN

  • read from the summary table.

  • SELECT * FROM (table) INTO CORRESPONDING FIELDS OF lh_type

    WHERE rldnr = s_ledger

    AND rrcty = '0'

    AND rvers = '001'

    AND ryear = s_gjahr

    AND rbukrs = pbukrs

    AND racct IN valid_accounts

    AND ( rzzlifnr IN s_lifnr OR rzzkunnr IN

    r_kunnr )

    • AND rzzlifnr NE space "AN

    AND rzzkoart IN ('K','D') "AN

    AND rzzumskz IN r_umskz.

    • check status of special G/L

    *<< AN.

    IF NOT lh_type-rzzkunnr IS INITIAL.

    READ TABLE ilifnr WITH KEY kunnr = lh_type-rzzkunnr.

    IF sy-subrc = 0.

    lh_type-rzzlifnr = ilifnr-lifnr.

    ENDIF.

    ENDIF.

    CHECK lh_type-rzzlifnr NE space.

    *>> AN.

    IF s_umskzn EQ 'X'.

    CHECK lh_type-rzzumskz EQ space.

    ELSEIF s_umskzs EQ 'X'.

    CHECK lh_type-rzzumskz NE space AND lh_type-rzzumskz IN s_umskz.

    ELSE.

    CHECK lh_type-rzzumskz IN s_umskz OR lh_type-rzzumskz EQ space.

    ENDIF.

    *<<< DDS

    IF s_cl = ' '.

    CHECK lh_type-rzzblart NE 'CL'.

    ENDIF.

    *>>> DDS

    • { au1++

    CLEAR: lfa1, lfb1.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = lh_type-rzzlifnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfa1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    SELECT SINGLE * FROM lfb1 WHERE bukrs = pbukrs

    AND lifnr = lh_type-rzzlifnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfb1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    • } au1

    CLEAR f_group.

    CLEAR : amount, pyear, previous.

    CLEAR : amountt, pyeart, previoust.

    f_group-bukrs = lh_type-rbukrs.

    PERFORM determine_account USING pbukrs lh_type-racct

    f_group-akont l_success.

    CHECK l_success = 'X'.

    f_group-lifnr = lh_type-rzzlifnr.

    f_group-waers = lh_type-rtcur.

    f_group-umskz = lh_type-rzzumskz.

    pyeart = lh_type-tslvt.

    IF currency_tab-waers = jt882-curr1.

    pyear = lh_type-hslvt.

    ELSEIF currency_tab-waers = jt882-curr2.

    pyear = lh_type-kslvt.

    ENDIF.

    IF last_previous_period > 0.

    DO last_previous_period TIMES

    VARYING amountt FROM lh_type-tsl01 NEXT lh_type-tsl02.

    ADD amountt TO previoust.

    ENDDO.

    IF currency_tab-waers = jt882-curr1.

    DO last_previous_period TIMES

    VARYING amount FROM lh_type-hsl01 NEXT lh_type-hsl02.

    ADD amount TO previous.

    ENDDO.

    ELSEIF currency_tab-waers = jt882-curr2.

    DO last_previous_period TIMES

    VARYING amount FROM lh_type-ksl01 NEXT lh_type-ksl02.

    ADD amount TO previous.

    ENDDO.

    ENDIF.

    ENDIF.

    IF ( pyear NE 0 OR pyeart NE 0 ) AND ( s_rprevy = 'X' ).

    f_group-id = '1'.

    f_group-balancel = pyear.

    f_group-balancet = pyeart.

    EXTRACT daten.

    ENDIF.

    IF ( previous NE 0 OR previoust NE 0 ) AND ( s_rprevd = 'X' ).

    CLEAR : f_group-debitl, f_group-creditl, f_group-balancel.

    CLEAR : f_group-debitt, f_group-creditt, f_group-balancet.

    f_group-id = '2'.

    IF lh_type-drcrk EQ 'S'.

    f_group-debitl = previous.

    f_group-debitt = previoust.

    ELSE.

    f_group-creditl = - previous.

    f_group-creditt = - previoust.

    ENDIF.

    f_group-balancet = f_group-debitt - f_group-creditt.

    f_group-balancel = f_group-debitl - f_group-creditl.

    EXTRACT daten.

    ENDIF.

    ENDSELECT.

    ENDFORM. "collect_extended

    ************************************************************************

    • Collect BSIK

    • *

    ************************************************************************

    FORM collect_transactions USING value(pbukrs)

    value(tabname).

    DATA : l_success.

    SELECT * FROM (tabname) INTO bsik WHERE

    bukrs = pbukrs AND

    lifnr IN s_lifnr AND

    budat IN all_dates AND

    hkont IN valid_accounts AND

    umskz IN r_umskz AND

    gjahr = s_gjahr AND

    bstat = ' '.

    • and blart ne 'CL'. "Z.Katis 02-04-07

    • Check status of special G/L

    IF s_umskzn EQ 'X'.

    CHECK bsik-umskz EQ space.

    ELSEIF s_umskzs EQ 'X'.

    CHECK bsik-umskz NE space.

    CHECK bsik-umskz IN s_umskz.

    ELSE.

    CHECK bsik-umskz IN s_umskz OR bsik-umskz EQ space.

    ENDIF.

    *<<< DDS

    IF s_cl = ' '.

    CHECK: bsik-blart NE 'CL'.

    ENDIF.

    *>>> DDS

    • { au1++

    CLEAR: lfa1, lfb1.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = bsik-lifnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfa1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    SELECT SINGLE * FROM lfb1 WHERE bukrs = pbukrs

    AND lifnr = bsik-lifnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfb1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    • } au1

    CLEAR f_group.

    IF bsik-budat IN s_budat.

    f_group-id = '3'.

    ELSE.

    CHECK s_rprevd = 'X'.

    f_group-id = '2'.

    ENDIF.

    f_group-bukrs = pbukrs.

    PERFORM determine_account USING pbukrs bsik-hkont

    f_group-akont l_success.

    CHECK l_success = 'X'.

    f_group-lifnr = bsik-lifnr.

    IF bsik-xblnr NE space.

    f_group-xblnr = bsik-xblnr.

    ELSE.

    f_group-xblnr = bsik-belnr.

    ENDIF.

    f_group-budat = bsik-budat.

    f_group-bldat = bsik-bldat.

    f_group-belnr = bsik-belnr.

    f_group-bschl = bsik-bschl.

    f_group-buzei = bsik-buzei.

    f_group-blart = bsik-blart.

    f_group-waers = bsik-waers.

    f_group-umskz = bsik-umskz.

    IF bsik-sgtxt = space.

    CLEAR tbslt.

    SELECT SINGLE * FROM tbslt

    WHERE spras = sy-langu

    AND bschl = bsik-bschl

    AND umskz = bsik-umskz.

    MOVE tbslt-ltext TO f_group-sgtxt.

    ELSE.

    f_group-sgtxt = bsik-sgtxt.

    ENDIF.

    IF bsik-xcpdd = 'X' "if it is a one-time, get name

    AND s_onetim = 'X'.

    CLEAR bsec.

    SELECT SINGLE * FROM bsec

    WHERE bukrs = bsik-bukrs

    AND gjahr = bsik-gjahr

    AND belnr = bsik-belnr

    AND buzei = bsik-buzei.

    CLEAR j_2gmd.

    CALL FUNCTION 'J_2GMDM_K'

    EXPORTING

    • I_LFA1 =

    i_lifnr = bsik-lifnr

    i_bsec = bsec

    • I_SPLIT = 'X'

    IMPORTING

    e_md = j_2gmd

    • E_ADDR =

    .

    f_group-otcname = j_2gmd-name1.

    IF f_group-otcname = space.

    f_group-otcname = text-w01.

    ENDIF.

    ELSE.

    f_group-otcname = space.

    ENDIF.

    IF s_2curr = space.

    PERFORM format_amount USING bsik-xnegp

    bsik-shkzg

    bsik-dmbtr

    CHANGING f_group-debitl

    f_group-creditl.

    ELSE.

    PERFORM format_amount USING bsik-xnegp

    bsik-shkzg

    bsik-dmbe2

    CHANGING f_group-debitl

    f_group-creditl.

    ENDIF.

    PERFORM format_amount USING bsik-xnegp

    bsik-shkzg

    bsik-wrbtr

    CHANGING f_group-debitt

    f_group-creditt.

    f_group-balancel = f_group-debitl - f_group-creditl.

    f_group-balancet = f_group-debitt - f_group-creditt.

    EXTRACT daten.

    ENDSELECT.

    ENDFORM. "collect_transactions

    ************************************************************************

    • Collect BSID *

    ************************************************************************

    FORM collect_transactions_bsid USING value(pbukrs)

    value(tabname).

    DATA : l_success.

    LOOP AT ilifnr.

    SELECT * FROM (tabname) INTO bsid WHERE

    bukrs = pbukrs AND

    • kunnr IN r_kunnr AND

    kunnr = ilifnr-kunnr AND

    budat IN all_dates AND

    hkont IN valid_accounts AND

    umskz IN r_umskz AND

    gjahr = s_gjahr AND

    bstat = ' '.

    • and blart ne 'CL'. "Z.Katis 02-04-07

    *<< AN.

    READ TABLE ilifnr WITH KEY kunnr = bsid-kunnr.

    IF sy-subrc = 0.

    f_group-lifnr = ilifnr-lifnr.

    ENDIF.

    *>> AN.

    • Check status of special G/L

    IF s_umskzn EQ 'X'.

    CHECK bsid-umskz EQ space.

    ELSEIF s_umskzs EQ 'X'.

    CHECK bsid-umskz NE space.

    CHECK bsid-umskz IN s_umskz.

    ELSE.

    CHECK bsid-umskz IN s_umskz OR bsid-umskz EQ space.

    ENDIF.

    *<<< DDS

    IF s_cl = ' '.

    CHECK: bsid-blart NE 'CL'.

    ENDIF.

    *>>> DDS

    • { au1++

    CLEAR: kna1, knb1.

    SELECT SINGLE * FROM kna1 WHERE kunnr = bsid-kunnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = kna1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    SELECT SINGLE * FROM knb1 WHERE bukrs = pbukrs

    AND kunnr = bsid-kunnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = knb1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    • } au1

    CLEAR f_group.

    IF bsid-budat IN s_budat.

    f_group-id = '3'.

    ELSE.

    CHECK s_rprevd = 'X'.

    f_group-id = '2'.

    ENDIF.

    f_group-bukrs = pbukrs.

    PERFORM determine_account USING pbukrs bsid-hkont

    f_group-akont l_success.

    CHECK l_success = 'X'.

    f_group-kunnr = bsid-kunnr.

    *<< AN.

    READ TABLE ilifnr WITH KEY kunnr = bsid-kunnr.

    IF sy-subrc = 0.

    f_group-lifnr = ilifnr-lifnr.

    ENDIF.

    *>> AN.

    IF bsid-xblnr NE space.

    f_group-xblnr = bsid-xblnr.

    ELSE.

    f_group-xblnr = bsid-belnr.

    ENDIF.

    f_group-budat = bsid-budat.

    f_group-bldat = bsid-bldat.

    f_group-belnr = bsid-belnr.

    f_group-bschl = bsid-bschl.

    f_group-buzei = bsid-buzei.

    f_group-blart = bsid-blart.

    f_group-waers = bsid-waers.

    f_group-umskz = bsid-umskz.

    IF bsid-sgtxt = space.

    CLEAR tbslt.

    SELECT SINGLE * FROM tbslt

    WHERE spras = sy-langu

    AND bschl = bsid-bschl

    AND umskz = bsid-umskz.

    MOVE tbslt-ltext TO f_group-sgtxt.

    ELSE.

    f_group-sgtxt = bsid-sgtxt.

    ENDIF.

    IF bsid-xcpdd = 'X' "if it is a one-time, get name

    AND s_onetim = 'X'.

    CLEAR bsec.

    SELECT SINGLE * FROM bsec

    WHERE bukrs = bsid-bukrs

    AND belnr = bsid-belnr

    AND gjahr = bsid-gjahr

    AND buzei = bsid-buzei.

    CLEAR j_2gmd.

    CALL FUNCTION 'J_2GMDM_D'

    EXPORTING

    • I_KNA1 =

    i_kunnr = bsid-kunnr

    i_bsec = bsec

    • I_SPLIT = 'X'

    IMPORTING

    e_md = j_2gmd

    • E_ADDR =

    .

    f_group-otcname = j_2gmd-name1.

    IF f_group-otcname = space.

    f_group-otcname = text-w01.

    ENDIF.

    ELSE.

    f_group-otcname = space.

    ENDIF.

    IF s_2curr = space.

    PERFORM format_amount USING bsid-xnegp

    bsid-shkzg

    bsid-dmbtr

    CHANGING f_group-debitl

    f_group-creditl.

    ELSE.

    PERFORM format_amount USING bsid-xnegp

    bsid-shkzg

    bsid-dmbe2

    CHANGING f_group-debitl

    f_group-creditl.

    ENDIF.

    PERFORM format_amount USING bsid-xnegp

    bsid-shkzg

    bsid-wrbtr

    CHANGING f_group-debitt

    f_group-creditt.

    f_group-balancel = f_group-debitl - f_group-creditl.

    f_group-balancet = f_group-debitt - f_group-creditt.

    EXTRACT daten.

    ENDSELECT.

    ENDLOOP.

    ENDFORM. "collect_transactions_BSID

    ************************************************************************

    • Update sums in transaction data *

    ************************************************************************

    FORM pass_trans TABLES source STRUCTURE sum_bukrs_t

    destination STRUCTURE sum_bukrs_t.

    LOOP AT source.

    MOVE-CORRESPONDING source TO destination.

    COLLECT destination.

    ENDLOOP.

    ENDFORM. "pass_trans

    ************************************************************************

    • Write a line item *

    ************************************************************************

    FORM write_line USING v_data STRUCTURE f_group.

    IF wrote_previous_dates NE 'X'.

    PERFORM write_previous TABLES sum_umskz_t_pd

    USING sum_umskz_pd '2'.

    ENDIF.

    CLEAR : out_1, out_2, out_3.

    WRITE v_data-budat TO out_1-budat.

    WRITE v_data-bldat TO out_1-bldat. "gleventis 12.07.2006

    out_1-xblnr = v_data-xblnr.

    out_1-belnr = v_data-belnr.

    out_1-sgtxt = v_data-sgtxt(39).

    out_1-bschl = v_data-bschl.

    WRITE v_data-debitl TO out_2-debitl CURRENCY g_curr.

    WRITE v_data-creditl TO out_2-creditl CURRENCY g_curr.

    WRITE sum_umskz-balancel TO out_2-balancel CURRENCY g_curr.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    • update page and carry forward totals.

    ADD-CORRESPONDING v_data TO sum_page.

    ADD-CORRESPONDING v_data TO sum_cfw.

    IF s_tran = 'X'.

    WRITE v_data-debitt TO out_3-debitt CURRENCY v_data-waers.

    WRITE v_data-creditt TO out_3-creditt CURRENCY v_data-waers.

    READ TABLE sum_umskz_t WITH KEY waers = v_data-waers.

    WRITE sum_umskz_t-balancet TO out_3-balancet CURRENCY v_data-waers.

    out_3-waers = v_data-waers.

    WRITE : out_3 NO-GAP.

    ENDIF.

    h_bukrs = v_data-bukrs.

    h_belnr = v_data-belnr.

    h_gjahr = s_gjahr.

    HIDE : h_bukrs, h_belnr, h_gjahr.

    ENDFORM. "write_line

    ************************************************************************

    • Write balance carry forward and previous dates *

    ************************************************************************

    FORM write_previous TABLES t_sum_t STRUCTURE sum_bukrs_t

    USING t_sum STRUCTURE sum_bukrs

    value(v_type).

    IF wrote_previous_year NE 'X' AND v_type NE '1'.

    PERFORM write_previous TABLES sum_umskz_t_py

    USING sum_umskz_py '1'.

    ENDIF.

    IF v_type = '1'.

    wrote_previous_year = 'X'.

    ELSE.

    wrote_previous_dates = 'X'.

    ENDIF.

    IF s_rprevy = space AND v_type = '1'." No previous balance

    EXIT.

    ENDIF.

    IF s_rprevd = space AND v_type = '2'." No previous balance

    EXIT.

    ENDIF.

    CLEAR : out_1, out_2, out_3.

    • ----> A.NEZ

    IF v_type = '1'.

    out_1-sgtxt = text-200. " Previous year

    ELSE.

    out_1-sgtxt = text-201. " Previous dates

    ENDIF.

    • <----- A.NEZ

    IF v_type = '2'.

    WRITE t_sum-debitl TO out_2-debitl CURRENCY g_curr.

    WRITE t_sum-creditl TO out_2-creditl CURRENCY g_curr.

    ENDIF.

    WRITE t_sum-balancel TO out_2-balancel CURRENCY g_curr.

    ADD-CORRESPONDING t_sum TO sum_page.

    ADD-CORRESPONDING t_sum TO sum_cfw.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'. " Write transaction currency

    CLEAR : out_1, out_2, out_3.

    LOOP AT t_sum_t.

    CHECK ( ( t_sum_t-debitt NE 0 ) OR ( t_sum_t-creditt NE 0 ) OR

    ( t_sum_t-balancet NE 0 ) ).

    CLEAR out_3.

    IF v_type = '2'.

    WRITE t_sum_t-debitt TO out_3-debitt CURRENCY t_sum_t-waers.

    WRITE t_sum_t-creditt TO out_3-creditt CURRENCY t_sum_t-waers.

    ENDIF.

    WRITE t_sum_t-balancet TO out_3-balancet CURRENCY t_sum_t-waers.

    out_3-waers = t_sum_t-waers.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP, out_3 NO-GAP.

    ENDLOOP.

    ENDIF.

    ENDFORM. "write_previous

    ************************************************************************

    • Process XBLNRs *

    ************************************************************************

    FORM process_xblnr.

    DATA w_items LIKE items.

    DATA my_index LIKE sy-tabix.

    DATA w_index LIKE sy-tabix.

    SORT items BY budat xblnr bschl waers.

    SORT xblnr_sum BY budat xblnr bschl waers.

    w_index = 0.

    LOOP AT xblnr_sum.

    IF xblnr_sum-counter > 1 AND s_xblnr = space.

    ULINE AT /(g_len).

    ENDIF.

    my_index = w_index + 1.

    LOOP AT items FROM my_index WHERE xblnr = xblnr_sum-xblnr AND

    budat = xblnr_sum-budat AND

    bschl = xblnr_sum-bschl.

    IF s_tran = 'X'.

    IF items-waers NE xblnr_sum-waers.

    EXIT.

    ENDIF.

    ENDIF.

    ADD-CORRESPONDING items TO sum_umskz.

    MOVE-CORRESPONDING items TO sum_umskz_t.

    COLLECT sum_umskz_t.

    IF s_xblnr = space OR xblnr_sum-counter = 1.

    PERFORM write_line USING items.

    ENDIF.

    w_index = sy-tabix.

    w_items = items.

    ENDLOOP.

    IF xblnr_sum-counter > 1.

    w_items-belnr = '**********'.

    MOVE-CORRESPONDING xblnr_sum TO w_items.

    PERFORM write_line USING w_items.

    ENDIF.

    IF xblnr_sum-counter > 1 AND s_xblnr = space.

    ULINE AT /(g_len).

    ENDIF.

    ENDLOOP.

    ENDFORM. "process_xblnr

    ************************************************************************

    • Write name of one time vendor. *

    ************************************************************************

    FORM write_one_time_vendor USING v_data STRUCTURE f_group.

    CLEAR out_1.

    out_1-sgtxt = v_data-otcname.

    WRITE : / out_1.

    ENDFORM. "write_one_time_vendor

    ************************************************************************

    • Write name of one time customer. *

    ************************************************************************

    FORM write_one_time_customer USING v_data STRUCTURE f_group.

    CLEAR out_1.

    out_1-sgtxt = v_data-otcname.

    WRITE : / out_1.

    ENDFORM. "write_one_time_customer

    ************************************************************************

    • Write name of vendor. *

    ************************************************************************

    FORM write_lifnr.

    DATA : string(255).

    DATA : change(2).

    DATA : ww(10).

    change+1(1) = sy-uline.

    RESERVE 9 LINES.

    CLEAR lfa1.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = f_group-lifnr.

    CLEAR j_2gmd.

    CALL FUNCTION 'J_2GMDM_K'

    EXPORTING

    i_lfa1 = lfa1

    • I_SPLIT = 'X'

    IMPORTING

    e_md = j_2gmd

    • E_ADDR =

    .

    string = text-600.

    WRITE f_group-lifnr TO ww.

    REPLACE '$' WITH ww INTO string.

    REPLACE '$' WITH j_2gmd-nametxt INTO string.

    REPLACE '$' WITH j_2gmd-taxcode INTO string.

    WRITE : / string.

    h_lifnr = f_group-lifnr.

    h_bukrs = f_group-bukrs.

    h_gjahr = s_gjahr.

    HIDE : h_bukrs, h_lifnr, h_gjahr.

    CLEAR : out_1, out_2, out_3.

    TRANSLATE out_1 USING change.

    TRANSLATE out_2 USING change.

    TRANSLATE out_3 USING change.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'.

    WRITE : out_3 NO-GAP.

    ENDIF.

    ENDFORM. "write_lifnr

    ************************************************************************

    • Write name of customer. *

    ************************************************************************

    FORM write_kunnr.

    DATA : string(255).

    DATA : change(2).

    DATA : ww(10).

    change+1(1) = sy-uline.

    RESERVE 9 LINES.

    CLEAR kna1.

    SELECT SINGLE * FROM kna1 WHERE kunnr = f_group-kunnr.

    CLEAR j_2gmd.

    CALL FUNCTION 'J_2GMDM_D'

    EXPORTING

    i_kna1 = kna1

    • I_SPLIT = 'X'

    IMPORTING

    e_md = j_2gmd

    • E_ADDR =

    .

    string = text-600.

    WRITE f_group-kunnr TO ww.

    REPLACE '$' WITH ww INTO string.

    REPLACE '$' WITH j_2gmd-nametxt INTO string.

    REPLACE '$' WITH j_2gmd-taxcode INTO string.

    WRITE : / string.

    h_kunnr = f_group-kunnr.

    h_bukrs = f_group-bukrs.

    h_gjahr = s_gjahr.

    HIDE : h_bukrs, h_kunnr, h_gjahr.

    CLEAR : out_1, out_2, out_3.

    TRANSLATE out_1 USING change.

    TRANSLATE out_2 USING change.

    TRANSLATE out_3 USING change.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'.

    WRITE : out_3 NO-GAP.

    ENDIF.

    ENDFORM. "write_kunnr

    ************************************************************************

    • Write Account/umskz title *

    ************************************************************************

    FORM write_umskz.

    • DATA string LIKE out_1-sgtxt.

    • DATA change(2).

    • DATA ww(10).

    *

    • change+1(1) = sy-uline.

    • RESERVE 6 LINES.

    • CLEAR : out_1, out_2, out_3.

    • WRITE f_group-akont TO ww.

    • IF f_group-umskz NE space.

    • string = text-601.

    • REPLACE '$' WITH ww INTO string.

    • REPLACE '$' WITH f_group-umskz INTO string.

    • ELSE.

    • string = text-602.

    • REPLACE '$' WITH ww INTO string.

    • ENDIF.

    *

    • out_1-sgtxt = string.

    • WRITE : / out_1.

    • h_akont = f_group-akont.

    • h_bukrs = f_group-bukrs.

    • h_gjahr = s_gjahr.

    • HIDE : h_akont, h_bukrs, h_gjahr.

    *

    • CLEAR out_1.

    • TRANSLATE out_1 USING change.

    • CLEAR : out_1-budat, out_1-xblnr, out_1-belnr, out_1-v1,

    • out_1-v2, out_1-v3.

    • TRANSLATE out_2 USING change.

    • TRANSLATE out_3 USING change.

    *

    • WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    • IF s_tran = 'X'.

    • WRITE : out_3 NO-GAP.

    • ENDIF.

    ENDFORM. "write_umskz

    ************************************************************************

    • Write Account totals *

    ************************************************************************

    FORM write_end_account.

    DATA : lino TYPE i.

    DATA : change(2).

    IF wrote_previous_dates NE 'X'.

    PERFORM write_previous TABLES sum_umskz_t_pd

    USING sum_umskz_pd '2'.

    ENDIF.

    change+1(1) = sy-uline.

    CLEAR : out_1, out_2, out_3.

    DESCRIBE TABLE sum_umskz_t LINES lino.

    ADD 2 TO lino.

    IF s_tran = 'X'.

    RESERVE lino LINES.

    ELSE.

    RESERVE 2 LINES.

    ENDIF.

    TRANSLATE out_2 USING change. CLEAR out_2-v1.

    TRANSLATE out_3 USING change.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'.

    WRITE : out_3 NO-GAP.

    ENDIF.

    CLEAR : out_1, out_2, out_3.

    out_1-sgtxt = text-202.

    WRITE sum_umskz-debitl TO out_2-debitl CURRENCY g_curr.

    WRITE sum_umskz-creditl TO out_2-creditl CURRENCY g_curr.

    WRITE sum_umskz-balancel TO out_2-balancel CURRENCY g_curr.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'. " Write transaction currency

    CLEAR : out_1, out_2, out_3.

    LOOP AT sum_umskz_t.

    CHECK ( ( sum_umskz_t-debitt NE 0 ) OR ( sum_umskz_t-creditt NE 0

    )

    OR ( sum_umskz_t-balancet NE 0 ) ).

    CLEAR out_3.

    WRITE sum_umskz_t-debitt TO out_3-debitt

    CURRENCY sum_umskz_t-waers.

    WRITE sum_umskz_t-creditt TO out_3-creditt

    CURRENCY sum_umskz_t-waers.

    WRITE sum_umskz_t-balancet TO out_3-balancet

    CURRENCY sum_umskz_t-waers.

    out_3-waers = sum_umskz_t-waers.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP, out_3 NO-GAP.

    ENDLOOP.

    ENDIF.

    SKIP 1.

    ENDFORM. "write_end_account

    ************************************************************************

    • Determine if the posting range is in within one fiscal year *

    ************************************************************************

    FORM check_posting USING value(v_t001) STRUCTURE t001

    success.

    DATA last_period LIKE t009b-poper.

    DATA : BEGIN OF the_periods OCCURS 20.

    INCLUDE STRUCTURE periods.

    DATA : END OF the_periods.

    DATA : low_in, high_in.

    DATA : period_l LIKE t009b-poper.

    DATA : period_f LIKE t009b-poper.

    DATA : 1st_day LIKE sy-datum.

    DATA : last_day LIKE sy-datum.

    CALL FUNCTION 'G_PERIODS_OF_YEAR_GET'

    EXPORTING

    variant = v_t001-periv

    year = s_gjahr

    IMPORTING

    last_normal_period = period_l

    TABLES

    i_periods = the_periods

    EXCEPTIONS

    variant_not_defined = 1

    year_not_defined = 2

    OTHERS = 3.

    IF sy-subrc NE 0.

    CLEAR msgtab.

    msgtab-msort = '5'.

    msgtab-msgid = '00'.

    msgtab-msgty = 'E'.

    msgtab-msgno = '398'.

    msgtab-msgv1 = v_t001-bukrs.

    CALL FUNCTION 'FI_MESSAGE_COLLECT'

    EXPORTING

    i_fimsg = msgtab.

    CLEAR success.

    EXIT.

    ENDIF.

    SORT the_periods BY buper.

    READ TABLE s_budat INDEX 1.

    IF s_budat-high EQ '00000000'.

    high_in = 'X'.

    ENDIF.

    LOOP AT the_periods.

    IF s_budat-low BETWEEN the_periods-datab AND the_periods-datbi.

    low_in = 'X'.

    ENDIF.

    IF high_in NE 'X'.

    IF s_budat-high BETWEEN the_periods-datab

    AND the_periods-datbi.

    high_in = 'X'.

    ENDIF.

    ENDIF.

    ENDLOOP.

    IF low_in = 'X' AND high_in = 'X'.

    success = 'X'.

    ELSE.

    CLEAR msgtab.

    msgtab-msort = '6'.

    msgtab-msgid = '00'.

    msgtab-msgty = 'E'.

    msgtab-msgno = '398'.

    msgtab-msgv1 = v_t001-bukrs.

    CALL FUNCTION 'FI_MESSAGE_COLLECT'

    EXPORTING

    i_fimsg = msgtab.

    CLEAR success.

    EXIT.

    ENDIF.

    ENDFORM. "check_posting

    ************************************************************************

    • Create Headers

    ************************************************************************

    FORM create_headers.

    DATA : up_length(3) TYPE p.

    DATA : up_offset(3) TYPE p.

    DATA : date1(10).

    DATA : date2(10).

    CLEAR : out_1, out_2, out_3.

    out_1-budat = text-h01.

    out_1-bldat = text-h13. "gleventis 12/07/2006

    out_1-xblnr = text-h02.

    out_1-belnr = text-h03.

    out_1-sgtxt = text-h04.

    out_1-bschl = text-h05.

    WRITE out_1 TO g_header.

    DESCRIBE FIELD out_1 LENGTH up_length IN CHARACTER MODE.

    ADD up_length TO up_offset.

    out_2-debitl = text-h06.

    out_2-creditl = text-h07.

    out_2-balancel = text-h08.

    g_header+up_offset = out_2.

    DESCRIBE FIELD out_2 LENGTH up_length IN CHARACTER MODE.

    ADD up_length TO up_offset.

    IF s_tran = 'X'.

    out_3-debitt = text-h09.

    out_3-creditt = text-h10.

    out_3-balancet = text-h11.

    out_3-waers = text-h12.

    g_header+up_offset = out_3.

    DESCRIBE FIELD out_3 LENGTH up_length IN CHARACTER MODE.

    ADD up_length TO up_offset.

    ENDIF.

    g_len = up_offset.

    CLEAR date_string.

    CLEAR : date1, date2.

    IF s_budat-high EQ '00000000'.

    date_string = text-p04.

    WRITE s_budat-low TO date1.

    REPLACE '$' WITH date1 INTO date_string.

    ELSE.

    date_string = text-p05.

    WRITE s_budat-low TO date1.

    WRITE s_budat-high TO date2.

    REPLACE '$' WITH date1 INTO date_string.

    REPLACE '$' WITH date2 INTO date_string.

    ENDIF.

    ENDFORM. "create_headers

    ***************************SPOT

    ************************************************************************

    • Create dummy entries for non moved accounts

    ************************************************************************

    FORM create_dummy_entries USING value(v_t001) STRUCTURE t001.

    DATA : l_success.

    SELECT * FROM lfb1 WHERE bukrs = v_t001-bukrs AND

    lifnr IN s_cusnon AND

    lifnr IN s_lifnr.

    CLEAR f_group.

    CHECK lfb1-loevm = space.

    • { au1++

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfb1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    CLEAR lfa1.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = lfb1-lifnr.

    call function 'J_1GACCOUNT_AUTH_CHECK'

    exporting

    i_xdb = 'K'

    i_begru = lfa1-begru

    i_aktvt = '03'

    exceptions

    no_authorization = 1

    others = 2.

    check sy-subrc = 0.

    • } au1

    PERFORM determine_account USING v_t001-bukrs lfb1-akont

    f_group-akont l_success.

    CHECK l_success = 'X'.

    f_group-bukrs = t001-bukrs.

    f_group-lifnr = lfb1-lifnr.

    READ TABLE currency_tab WITH KEY bukrs = v_t001-bukrs.

    f_group-waers = currency_tab-waers.

    f_group-id = '1'.

    EXTRACT daten.

    ENDSELECT.

    ENDFORM. "create_dummy_entries

    ************************************************************************

    • Create bukrs info *

    ************************************************************************

    FORM create_bukrs_info.

    CLEAR t001.

    SELECT SINGLE * FROM t001 WHERE bukrs = f_group-bukrs.

    ENDFORM. "create_bukrs_info

    ************************************************************************

    • Print user selections. *

    ************************************************************************

    FORM print_user_selections.

    NEW-PAGE.

    no_headers ='X'.

    SKIP 1.

    WRITE : / text-800.

    ULINE.

    SKIP 2.

    • Print company code selections.

    ULINE.

    WRITE : / text-801 COLOR 3.

    SKIP 1.

    LOOP AT s_bukrs.

    WRITE : / s_bukrs-sign, s_bukrs-option, s_bukrs-low, s_bukrs-high.

    ENDLOOP.

    IF s_bukrs IS INITIAL.

    WRITE : / text-802.

    ENDIF.

    ULINE.

    • Print vendor selections.

    ULINE.

    WRITE : / text-804 COLOR 3.

    SKIP 1.

    LOOP AT s_lifnr.

    WRITE : / s_lifnr-sign, s_lifnr-option, s_lifnr-low, s_lifnr-high.

    ENDLOOP.

    IF s_lifnr IS INITIAL.

    WRITE : / text-802.

    ENDIF.

    ULINE.

    • Print account selections

    SKIP 1.

    ULINE.

    WRITE : / text-803 COLOR 3.

    SKIP 1.

    LOOP AT s_akont.

    WRITE : / s_akont-sign, s_akont-option, s_akont-low, s_akont-high.

    ENDLOOP.

    IF s_akont IS INITIAL.

    WRITE : / text-802.

    ENDIF.

    ULINE.

    WRITE : / text-805.

    IF s_altk EQ 'X'. " Alternative accounts

    WRITE : text-828.

    ELSEIF s_chart = 'X'. " Company accounts

    WRITE : text-829.

    ELSE.

    WRITE : text-841. " Group accounts

    ENDIF.

    WRITE : / text-806.

    IF s_acch = 'X'.

    WRITE text-820.

    ELSE.

    WRITE text-821.

    ENDIF.

    IF s_2curr EQ 'X'. " Currency

    WRITE : / text-830.

    ELSE.

    WRITE : / text-831.

    ENDIF.

    • Transaction selection

    SKIP 1.

    ULINE.

    IF s_umskzn = 'X'.

    WRITE : / text-850.

    ELSEIF s_umskzs = 'X'.

    WRITE : / text-851.

    ELSE.

    WRITE : / text-852.

    ENDIF.

    IF s_umskzn NE 'X'.

    WRITE : / text-853 COLOR 3.

    SKIP 1.

    LOOP AT s_umskz.

    WRITE : / s_umskz-sign, s_umskz-option,

    s_umskz-low, s_umskz-high.

    ENDLOOP.

    IF s_umskz IS INITIAL.

    WRITE : / text-802.

    ENDIF.

    ENDIF.

    ULINE.

    • Print dates/Period selections

    SKIP 1.

    ULINE.

    WRITE : / text-807 COLOR 3.

    SKIP 1.

    READ TABLE s_budat INDEX 1.

    IF s_budat-high NE '00000000'.

    WRITE : / text-810, s_budat-low, '-', s_budat-high.

    ELSE.

    WRITE : / text-810, s_budat-low.

    ENDIF.

    ULINE.

    IF s_rprevy = 'X'. " Read previous year balance

    WRITE : / text-854.

    ELSE.

    WRITE : / text-855.

    ENDIF.

    IF s_rprevd = 'X'. " Read previous year balance

    WRITE : / text-864.

    ELSE.

    WRITE : / text-865.

    ENDIF.

    SKIP 1.

    ULINE.

    IF s_nonpos = 'X'. " Read previous

    WRITE : / text-856.

    ELSE.

    WRITE : / text-857.

    ENDIF.

    IF s_nonpos = 'X'.

    WRITE : / text-858 COLOR 3.

    SKIP 1.

    LOOP AT s_cusnon.

    WRITE : / s_cusnon-sign, s_cusnon-option,

    s_cusnon-low, s_cusnon-high.

    ENDLOOP.

    IF s_cusnon IS INITIAL.

    WRITE : / text-802.

    ENDIF.

    ENDIF.

    ULINE.

    SKIP 1.

    IF s_onetim = 'X'.

    WRITE : / text-859.

    ELSE.

    WRITE : / text-860.

    ENDIF.

    SKIP 1.

    IF s_sxblnr = 'X'.

    WRITE : / text-861.

    ELSE.

    WRITE : / text-862.

    ENDIF.

    IF s_sxblnr = 'X' AND s_xblnr = 'X'.

    WRITE : / text-863.

    ENDIF.

    ENDFORM. "print_user_selections

    ************************************************************************

    • Write Report totals *

    ************************************************************************

    FORM print_company_totals.

    DATA : lino TYPE i.

    DATA : change(2).

    SKIP 3.

    change+1(1) = sy-uline.

    CLEAR : out_1, out_2, out_3.

    DESCRIBE TABLE sum_bukrs_t LINES lino.

    ADD 7 TO lino.

    IF s_tran = 'X'.

    RESERVE lino LINES.

    ELSE.

    RESERVE 5 LINES.

    ENDIF.

    • Write page totals.

    ULINE AT /(g_len).

    CLEAR : out_1, out_2, out_3.

    out_1-sgtxt = text-203.

    WRITE sum_page-debitl TO out_2-debitl CURRENCY g_curr.

    WRITE sum_page-creditl TO out_2-creditl CURRENCY g_curr.

    WRITE sum_page-balancel TO out_2-balancel CURRENCY g_curr.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    • Write company totals

    CLEAR : out_1, out_2, out_3.

    out_1-sgtxt = text-204.

    WRITE sum_bukrs-debitl TO out_2-debitl CURRENCY g_curr.

    WRITE sum_bukrs-creditl TO out_2-creditl CURRENCY g_curr.

    WRITE sum_bukrs-balancel TO out_2-balancel CURRENCY g_curr.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP.

    IF s_tran = 'X'. " Write transaction currency

    CLEAR : out_1, out_2, out_3.

    LOOP AT sum_bukrs_t.

    CHECK ( ( sum_bukrs_t-debitt NE 0 ) OR ( sum_bukrs_t-creditt NE 0

    )

    OR ( sum_bukrs_t-balancet NE 0 ) ).

    CLEAR out_3.

    WRITE sum_bukrs_t-debitt TO out_3-debitt

    CURRENCY sum_bukrs_t-waers.

    WRITE sum_bukrs_t-creditt TO out_3-creditt

    CURRENCY sum_bukrs_t-waers.

    WRITE sum_bukrs_t-balancet TO out_3-balancet

    CURRENCY sum_bukrs_t-waers.

    out_3-waers = sum_bukrs_t-waers.

    WRITE : / out_1 NO-GAP, out_2 NO-GAP, out_3 NO-GAP.

    ENDLOOP.

    ENDIF.

    ULINE AT /(g_len).

    no_headers = 'X'.

    ENDFORM. "print_company_totals

    ************************************************************************

    • Set up valid accounts *

    ************************************************************************

    FORM setup_accounts USING value(v_t001) STRUCTURE t001.

    DATA : BEGIN OF itab OCCURS 100,

    saknr LIKE skb1-saknr,

    include(1),

    END OF itab.

    DATA : w_hkont LIKE skb1-saknr.

    DATA : first_on.

    DATA : l_success.

    DATA : first LIKE skb1-saknr.

    DATA : last LIKE skb1-saknr.

    DATA : lino TYPE i.

    REFRESH valid_accounts. CLEAR valid_accounts.

    IF s_acch = 'X' " Account ranges are specified in

    OR " company chart of accounts

    s_chart = 'X'.

    LOOP AT s_akont.

    CLEAR valid_accounts.

    valid_accounts = s_akont.

    APPEND valid_accounts.

    ENDLOOP.

    EXIT.

    ENDIF.

    DESCRIBE TABLE s_akont LINES lino.

    IF lino = 0.

    EXIT.

    ENDIF.

    SELECT * FROM skb1 WHERE bukrs = v_t001-bukrs.

    CLEAR itab.

    PERFORM determine_account USING v_t001-bukrs skb1-saknr

    w_hkont l_success.

    IF l_success = 'X'.

    itab-include = 'X'.

    ENDIF.

    itab-saknr = skb1-saknr.

    APPEND itab.

    ENDSELECT.

    SORT itab BY saknr.

    first_on = 'X'.

    LOOP AT itab.

    IF itab-include = 'X'.

    IF first_on = 'X'.

    first = itab-saknr.

    last = itab-saknr.

    CLEAR first_on.

    ELSE.

    last = itab-saknr.

    ENDIF.

    ELSEIF first_on = space.

    valid_accounts-sign = 'I'.

    valid_accounts-option = 'BT'.

    valid_accounts-low = first.

    valid_accounts-high = last.

    APPEND valid_accounts.

    first_on = 'X'.

    ENDIF.

    ENDLOOP.

    IF first_on = space.

    valid_accounts-sign = 'I'.

    valid_accounts-option = 'BT'.

    valid_accounts-low = first.

    valid_accounts-high = last.

    APPEND valid_accounts.

    ENDIF.

    DESCRIBE TABLE valid_accounts LINES lino.

    IF lino = 0.

    CLEAR valid_accounts.

    valid_accounts-sign = 'E'.

    valid_accounts-option = 'CP'.

    valid_accounts-low = '*'.

    APPEND valid_accounts.

    ELSEIF lino > 500. " The select will crash

    REFRESH valid_accounts. CLEAR valid_accounts.

    ENDIF.

    ENDFORM. "setup_accounts

    ************************************************************************

    • Set up valid GL indicators *

    ************************************************************************

    FORM setup_glind.

    DATA : lino TYPE i.

    IF s_umskzn = 'X'.

    CLEAR r_umskz.

    r_umskz-sign = 'I'.

    r_umskz-option = 'EQ'.

    r_umskz-low = space.

    APPEND r_umskz.

    ELSEIF s_umskzs = 'X'.

    LOOP AT s_umskz.

    CLEAR r_umskz.

    r_umskz = s_umskz.

    APPEND r_umskz.

    ENDLOOP.

    CLEAR r_umskz.

    r_umskz-sign = 'E'.

    r_umskz-option = 'EQ'.

    r_umskz-low = space.

    APPEND r_umskz.

    ELSE.

    DESCRIBE TABLE s_umskz LINES lino.

    IF lino NE 0.

    LOOP AT s_umskz.

    CLEAR r_umskz.

    r_umskz = s_umskz.

    APPEND r_umskz.

    ENDLOOP.

    ELSE.

    CLEAR r_umskz.

    r_umskz-sign = 'I'.

    r_umskz-option = 'CP'.

    r_umskz-low = '*'.

    APPEND r_umskz.

    ENDIF.

    CLEAR r_umskz.

    r_umskz-sign = 'I'.

    r_umskz-option = 'EQ'.

    r_umskz-low = space.

    APPEND r_umskz.

    ENDIF.

    ENDFORM. "setup_glind

    ----


    • FORM FORMAT_AMOUNT *

    ----


    • ........ *

    ----


    • --> VALUE(P_XNEGP) *

    • --> VALUE(P_SHKZG) *

    • --> VALUE(P_DMBTR) *

    • --> P_AMOUNT *

    ----


    FORM format_amount USING value(p_xnegp)

    value(p_shkzg)

    value(p_dmbtr)

    CHANGING p_debit

    p_credit.

    IF p_xnegp = 'X'.

    p_dmbtr = - p_dmbtr.

    ENDIF.

    IF ( p_shkzg = 'S' AND p_xnegp = ' ' ) OR

    ( p_shkzg = 'H' AND p_xnegp = 'X' ).

    p_debit = p_dmbtr.

    p_credit = 0.

    ELSE.

    p_credit = p_dmbtr.

    p_debit = 0.

    ENDIF.

    ENDFORM. " FORMAT_AMOUNT

    ----


    • FORM get_ledger_table *

    ----


    • --> P_LEDGER *

    • --> P_TABNAM *

    ----


    FORM get_ledger_table USING p_ledger

    CHANGING p_tabnam.

    DATA: lh_881 LIKE t881.

    CLEAR p_tabnam.

    SELECT SINGLE * FROM t881 INTO lh_881

    WHERE rldnr = p_ledger.

    CHECK sy-subrc = 0.

    p_tabnam = lh_881-tab.

    ENDFORM. " GET_TABLE_A

    ----


    • FORM check_summary_table *

    ----


    • --> PF_DIFFERS *

    ----


    FORM check_summary_table CHANGING pf_differs.

    DATA:

    lt_tabstr LIKE x031l OCCURS 0 WITH HEADER LINE,

    descr_ref TYPE REF TO cl_abap_structdescr.

    FIELD-SYMBOLS:

    <comp_wa> TYPE abap_compdescr.

    • Get DDIC table structure

    CALL FUNCTION 'DD_GET_NAMETAB'

    EXPORTING

    • STATUS = 'A'

    tabname = table

    • GET_ALL = ' '

    • IMPORTING

    • F_STATUS =

    • R_MODEFLAG =

    • R_STATUS =

    • X030L_WA =

    TABLES

    x031l_tab = lt_tabstr

    EXCEPTIONS

    not_found = 1

    no_fields = 2

    OTHERS = 3.

    • Get ABAP type structure

    descr_ref ?= cl_abap_typedescr=>describe_by_name( 'SPL_TYPE' ).

    • Do the check

    pf_differs = c_false.

    LOOP AT descr_ref->components ASSIGNING <comp_wa>.

    READ TABLE lt_tabstr WITH KEY fieldname = <comp_wa>-name.

    IF sy-subrc <> 0.

    pf_differs = c_true.

    EXIT.

    ENDIF.

    ENDLOOP.

    ENDFORM. " CHECK_SUMMARY_TABLE