0% found this document useful (0 votes)
122 views18 pages

ABAP Program For Trade Partner Statement

This document defines variables and data structures for a report that prints trade partner account balances and transactions. It includes data declarations for tables, structures, ranges and internal tables to retrieve and store customer master data, account balances, transactions and other related information from the SAP system. Selection screen parameters and logic are also defined to filter the data for a specified fiscal year and date range.

Uploaded by

inasap
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
122 views18 pages

ABAP Program For Trade Partner Statement

This document defines variables and data structures for a report that prints trade partner account balances and transactions. It includes data declarations for tables, structures, ranges and internal tables to retrieve and store customer master data, account balances, transactions and other related information from the SAP system. Selection screen parameters and logic are also defined to filter the data for a specified fiscal year and date range.

Uploaded by

inasap
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 18

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

* PROGRAM : ZCUST_LEDGER
* Description : The report prints trade partners summary
************************************************************************
Report ZCUST_LEDGER no standard page heading line-size 132 Line-count 90 MESSAGE
-ID ZMSG.
tables : bsid, " Accounting: Secondary index for customers
bsad, " acct: secondary index for cust (cleared items)
bkpf, " Accounting document header
bseg, " Accounting document segment
kna1, " General Data in Customer Master
vbrp, " Billing: Item Data
mara, " material master
tspa, " Organizational Unit: Sales Divis
stxh, " STXD SAPscript text file header
tgsb, " Business Areas
tgsbt, " Business Areas text
t001, " Company code master table
t003t, " Document type text
vbak, " Sales document header
skat, " G/L Acc Master Table
skb1,tspat, " G/L Acc Planning level Table
vbfa,bsis ,t001w,knvv,tvkbt,
t074t.
data: v_debits like bseg-dmbtr,v_credits like bseg-dmbtr,
v_balance like bseg-dmbtr,
v_bal like bseg-dmbtr.
data: rv_debits like bseg-dmbtr,rv_credits like bseg-dmbtr.
ranges r_bschl for bseg-bschl.
ranges r_post_key for bseg-bschl.
ranges r_blart for bkpf-blart.
data : begin of ibkpf occurs 0,
belnr like bkpf-belnr,
blart like bkpf-blart,
budat like bkpf-budat,
xblnr like bkpf-xblnr,
zbelnr like bkpf-belnr,
end of ibkpf.
data v_qty like vbrp-fkimg.
data $count like sy-index.
data v_p_name(40).
data v_desc(50).
data : name like thead-tdname.
clear v_desc.
data: spl_gl_amount like bsad-dmbtr.
data: spl_gl_amount_na like bsad-dmbtr.
data: spl_gl_date like sy-datum.
data : begin of header1 occurs 0.
include structure thead.
data : end of header1.
data : begin of line1 occurs 0.
include structure tline.
data : end of line1.
data : begin of line2 occurs 0.
include structure tline.
data : end of line2.
************************************************************************
* SELECTION SCREEN
************************************************************************
selection-screen skip.
selection-screen begin of block b1 with frame title text-001.
select-options : s_kunnr for kna1-kunnr memory id kun,
av_vkbur for knvv-vkbur,
s_vtweg for knvv-vtweg.
select-options p_budat for bkpf-bldat obligatory default sy-datum
no-extension.
parameters : p_bukrs like bsid-bukrs obligatory memory id buk,
p_gjahr like bsad-gjahr obligatory memory id gjr.
parameters : o_po_txt radiobutton group radi default 'X',
po_txt radiobutton group radi,
inv_text radiobutton group radi.
selection-screen end of block b1 .
data s_date like sy-datum.
data: v_header(60),v_sdate(10),v_edate(10).
data : begin of ikna1 occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
vkbur like knvv-vkbur,
vtweg like knvv-vtweg,
bezei like tvkbt-bezei,
end of ikna1.
data begin of db_s_bal occurs 0.
include structure bapi3007_a.
data end of db_s_bal .
data begin of return occurs 0.
include structure bapireturn.
data end of return.
data : v_monat like bkpf-monat,v_index like sy-tabix.
data: begin of ar_items occurs 0.
include structure bapi3007_2.
data: end of ar_items.
data: begin of ar_items1 occurs 0.
include structure bapi3007_2.
data: end of ar_items1.
data: begin of ar_items_splgl occurs 0.
include structure bapi3007_2.
data: end of ar_items_splgl.
data : begin of p_data occurs 0,
name1 like kna1-name1,
kunnr like kna1-kunnr,
doc_date like bapi3007_2-doc_date,
doc_no like bapi3007_2-doc_no,
doc_type like bapi3007_2-doc_type ,
desc(50),
qty like vbrp-fkimg ,
amount like bseg-dmbtr,
bal like bseg-dmbtr,
item_text like bapi3007_2-item_text,
end of p_data.
data cnt(4).
data: begin of dtab occurs 0,
bukrs like bkpf-bukrs,
kunnr like kna1-kunnr ,
name1 like kna1-name1 ,
vkbur like knvv-vkbur,
vtweg like knvv-vtweg,
bezei like tvkbt-bezei,
open_bal like bapi3007_2-lc_amount,
debits like bapi3007_2-lc_amount,
credits like bapi3007_2-lc_amount,
clos_bal like bapi3007_2-lc_amount,
others like bapi3007_2-lc_amount,
splgl like bapi3007_2-lc_amount,
end of dtab.
data:ctr type i ,
ctr1 type i ,
rv_bal like p_data-bal, " RUNNING BALANCE
rcrdt like p_data-amount, " RUNNING CREDITS
rdebt like p_data-amount. " RUNNING DEBITS
data year1 like bseg-gjahr.
data: key_date like sy-datum.
data: begin of key_bal occurs 0.
include structure bapi3007_3.
data: end of key_bal.
data: zvamt like bseg-dmbtr.
data: begin of xperiod1,
gjahr like bkpf-gjahr,
monat like bkpf-monat,
end of xperiod1.
*----------------------------------------------------------------------*
* initialization.
*----------------------------------------------------------------------*
initialization.
if p_budat-high is initial .
loop at p_budat.
p_budat-low+6(2) = 01.
p_budat-high = sy-datum.
modify p_budat.
endloop.
endif.
*----------------------------------------------------------------------*
* top-of-page.
*----------------------------------------------------------------------*
top-of-page.
perform print_header.
*----------------------------------------------------------------------*
* at selection-screen .
*----------------------------------------------------------------------*
at selection-screen .
perform au_check_vkbur.
if p_budat-high is initial .
loop at p_budat.
p_budat-high = p_budat-low.
modify p_budat.
endloop.
endif.
perform get_customers.
if p_budat-low+6(2) ne '01'.
message e015 with 'From date should be first day of the month'.
endif.
call function 'FI_PERIOD_DETERMINE'
exporting
i_budat = p_budat-low
i_bukrs = 'PWPL'
i_periv = 'PL'
importing
e_gjahr = xperiod1-gjahr
e_monat = xperiod1-monat.
if xperiod1-gjahr ne p_gjahr.
message e015 with 'Incorrect Fiscal Year'.
endif.
call function 'FI_PERIOD_DETERMINE'
exporting
i_budat = p_budat-high
i_bukrs = 'PWPL'
i_periv = 'PL'
importing
e_gjahr = xperiod1-gjahr
e_monat = xperiod1-monat.
if xperiod1-gjahr ne p_gjahr.
message e015 with 'To date should be under fiscal year'.
endif.
*----------------------------------------------------------------------*
* start-of-selection.
*----------------------------------------------------------------------*
start-of-selection.
perform print_parameters.
key_date = p_budat-low - 1.
refresh dtab.
s_date = p_budat-low.
s_date+6(2) = 01.
spl_gl_date = s_date - 1.
perform fill_r_bschl.
perform fill_r_post_key.
perform get_cust_period_balances.
loop at dtab.
write: / dtab-vkbur,dtab-bezei.
uline.
format color col_key intensified on.
write :/ dtab-kunnr,12(35) dtab-name1,50 dtab-vkbur,55 dtab-bezei,
75 dtab-vtweg,
78 text-015, s_date,
(16) dtab-open_bal under text-009 decimals 2.
format color col_normal intensified off.
perform get_print_tp_ledger.
perform print_tp_ledger using ''.
perform print_total.
perform print_spl_gl.
refresh ar_items_splgl.clear ar_items_splgl.
format color col_key intensified on.
write:/ 'Other Transactions',64 text-015, s_date,
(16) dtab-splgl under text-009 decimals 2.
perform print_tp_ledger using 'X'.
perform print_splgl_total.
clear spl_gl_amount_na.
at end of kunnr.
clear spl_gl_amount_na.
new-page.
endat.
endloop.
*----------------------------------------------------------------------*
* at line-selection.
*----------------------------------------------------------------------*
at line-selection.
perform display_doc.
*&---------------------------------------------------------------------*
*& Form GET_CUST_PERIOD_BALANCES
*&---------------------------------------------------------------------*
form get_cust_period_balances.
refresh key_bal.
loop at ikna1.
call function 'BAPI_AR_ACC_GETKEYDATEBALANCE'
exporting
companycode = p_bukrs
customer = ikna1-kunnr
keydate = key_date
balancespgli = 'X'
importing
return = return
tables
keybalance = key_bal.
check sy-subrc = 0.
v_monat = p_budat-low+4(2) - 1.
read table key_bal with key sp_gl_ind = 'A'.
if sy-subrc eq 0.
spl_gl_amount = key_bal-lc_bal.
endif.
read table key_bal with key sp_gl_ind = 'X'.
if sy-subrc eq 0.
spl_gl_amount_na = key_bal-lc_bal.
endif.
loop at key_bal where sp_gl_ind ne 'A' and sp_gl_ind ne 'X'.
dtab-open_bal = dtab-open_bal + key_bal-lc_bal.
endloop.
dtab-open_bal = dtab-open_bal + spl_gl_amount.
dtab-kunnr = ikna1-kunnr.
dtab-name1 = ikna1-name1.
dtab-vkbur = ikna1-vkbur.
dtab-vtweg = ikna1-vtweg.
dtab-bezei = ikna1-bezei.
dtab-bukrs = p_bukrs.
dtab-splgl = spl_gl_amount_na.
append dtab.
refresh key_bal.
clear dtab.
clear spl_gl_amount.
clear spl_gl_amount_na.
endloop.
clear spl_gl_amount.
endform. " GET_CUST_PERIOD_BALANCES
*&---------------------------------------------------------------------*
*& Form GET_CUSTOMERS
*&---------------------------------------------------------------------*
form get_customers.
refresh ikna1.
clear: ikna1,$count.
select kunnr name1 into (ikna1-kunnr,ikna1-name1) from kna1
where kunnr in s_kunnr.
check sy-subrc = 0.
select single kunnr vkbur vtweg into (ikna1-kunnr,ikna1-vkbur,ikna1-vtweg)
from knvv where kunnr = ikna1-kunnr
and vkbur in av_vkbur
and vtweg in s_vtweg.
check sy-subrc = 0.
select single * from tvkbt where spras eq 'EN'
and vkbur eq ikna1-vkbur.
move tvkbt-bezei to ikna1-bezei.
append ikna1.
clear ikna1.
endselect.
sort ikna1 by kunnr.
describe table ikna1 lines $count.
if $count = 0.
message e015 with 'No data found '
'For given Customers'.
endif.
endform. " GET_CUSTOMERS
*&---------------------------------------------------------------------*
*& Form PRINT_HEADER
*&---------------------------------------------------------------------*
form print_header.
set left scroll-boundary column 32.
data : ps_dat like bkpf-budat.
ps_dat = p_budat-low.
ps_dat+6(2) = 01.
write ps_dat to v_sdate dd/mm/yyyy.
write p_budat-high to v_edate dd/mm/yyyy.
concatenate text-002 v_sdate ' TO ' v_edate
into v_header separated by space .
select single * from t001w. " where werks = '0001'.
write at /50 'ABC Company Ltd.' centered.
write at /48 'NEW DELHI, New Delhi'.
skip.
write :/'DEALER LEDGER ',v_header,115 'Page ',sy-pagno.
skip.
uline.
write :/ text-003,12 text-004,
16 text-005,29 text-006,
50 text-010 centered,72 text-008 centered,
92 text-007 centered,110 text-009 centered.
uline.
endform. " PRINT_HEADER
*&---------------------------------------------------------------------*
*& Form PRINT_TOTAL
*&---------------------------------------------------------------------*
form print_total.
format color col_total intensified off.
uline.
clear: v_debits, v_credits,v_qty,v_balance.
endform. " PRINT_TOTAL
*&---------------------------------------------------------------------*
*& Form FILL_R_BSCHL
*&---------------------------------------------------------------------*
form fill_r_bschl.
r_bschl-low = '15'.
r_bschl-option = 'EQ'.
r_bschl-sign = 'I'.
append r_bschl.
r_bschl-low = '17'.
r_bschl-option = 'EQ'.
r_bschl-sign = 'I'.
append r_bschl.
r_bschl-low = '08'.
r_bschl-option = 'EQ'.
r_bschl-sign = 'I'.
append r_bschl.
r_bschl-low = '18'.
r_bschl-option = 'EQ'.
r_bschl-sign = 'I'.
append r_bschl.
endform. " FILL_R_BSCHL
*&---------------------------------------------------------------------*
*& Form FILL_R_POST_KEY
*&---------------------------------------------------------------------*
form fill_r_post_key.
r_post_key-low = '06'.
r_post_key-option = 'EQ'.
r_post_key-sign = 'I'.
append r_post_key.
r_post_key-low = '09A'.
r_post_key-option = 'EQ'.
r_post_key-sign = 'I'.
append r_post_key.
r_post_key-low = '16'.
r_post_key-option = 'EQ'.
r_post_key-sign = 'I'.
append r_post_key.
r_post_key-low = '08'.
r_post_key-option = 'EQ'.
r_post_key-sign = 'I'.
append r_post_key.
endform. " FILL_R_POST_KEY
*&---------------------------------------------------------------------*
*& Form DISPLAY_DOC
*&---------------------------------------------------------------------*
form display_doc.
data : cursorfld(40) , cursorval(10) .
get cursor field cursorfld value cursorval .
if cursorfld = 'AR_ITEMS-DOC_NO' or cursorfld = 'P_DATA-DOC_NO'.
set parameter id 'BLN' field cursorval.
set parameter id 'BUK' field p_bukrs.
set parameter id 'GJR' field p_gjahr.
call transaction 'FB03' and skip first screen.
endif.
endform. " DISPLAY_DOC
*&---------------------------------------------------------------------*
*& Form PRINT_QTY
*&---------------------------------------------------------------------*
form print_qty.
select single vbeln into :bseg-vbeln from bseg
where bukrs = p_bukrs and belnr = ar_items-doc_no
and buzei = ar_items-item_num
and gjahr = p_gjahr .
select sum( fkimg ) into :vbrp-fkimg
from vbrp where vbeln = :bseg-vbeln.
write :vbrp-fkimg under text-010 no-zero decimals 2.
p_data-qty = :vbrp-fkimg .
v_qty = v_qty + :vbrp-fkimg.
endform. " PRINT_QTY
*&---------------------------------------------------------------------*
*& Form PRINT_TP_LEDGER
*&---------------------------------------------------------------------*
form print_tp_ledger using flag.
loop at p_data where doc_type eq 'AB' and desc eq ' '.
select single * from bseg where bukrs = p_bukrs
and belnr = p_data-doc_no
and gjahr = p_gjahr and koart ne 'D'.
if sy-subrc = 0.
select single * from skat where spras eq 'EN' and ktopl eq 'IN01'
and saknr eq bseg-hkont.
if sy-subrc = 0.
p_data-desc = skat-txt20.
modify p_data.
endif.
endif.
endloop.
sort p_data by doc_date doc_no desc.
if flag = 'X'.
rv_bal = dtab-splgl.
else.
rv_bal = dtab-open_bal. " RUNNING BALANCE
endif.
loop at p_data where doc_no ne space and kunnr = dtab-kunnr and amount
ne 0.
ctr1 = ( ctr mod 2 ) .
if ctr1 = 0 .
format color col_normal intensified .
else.
format color col_normal intensified off.
endif.
write :/ p_data-doc_date under text-003,
p_data-doc_no under text-005 hotspot on,
p_data-doc_type under text-004.
write:(40) p_data-desc under text-006 .
if p_data-doc_type = 'DZ' or p_data-doc_type = 'PD'.
perform read_other_line_items.
ctr = ctr + 1.
else.
if p_data-amount > 0.
rdebt = p_data-amount.
p_data-amount = abs( p_data-amount ).
write:(16) p_data-amount under text-008 decimals 2.
else.
rcrdt = p_data-amount.
p_data-amount = abs( p_data-amount ).
write:(16) p_data-amount under text-007 decimals 2.
endif.
rv_bal = rv_bal - abs( rcrdt ) + abs( rdebt ).
p_data-bal = rv_bal.
write:(16) p_data-bal under text-009 decimals 2.
clear: rcrdt,rdebt.
ctr = ctr + 1.
endif.
endloop.
clear : rv_bal,rdebt,rcrdt.
endform. " PRINT_TP_LEDGER
*&---------------------------------------------------------------------*
*& Form READ_OTHER_LINE_ITEMS
*&---------------------------------------------------------------------*
form read_other_line_items.
if ctr1 = 0 .
format color col_normal intensified .
else.
format color col_normal intensified off.
endif.
select * from bseg where bukrs = p_bukrs and belnr = p_data-doc_no
and gjahr = p_gjahr and koart ne 'D'. " and kunnr = p_dat
a-kunnr.
check sy-subrc = 0.
if bseg-shkzg = 'H'. "debits
rdebt = bseg-dmbtr.
bseg-dmbtr = abs( bseg-dmbtr ).
write:(16) bseg-dmbtr under text-008 decimals 2.
elseif bseg-shkzg = 'S'.
rcrdt = bseg-dmbtr .
bseg-dmbtr = abs( bseg-dmbtr ).
write:(16) bseg-dmbtr under text-007 decimals 2.
endif.
select single * from skat where spras eq 'EN' and ktopl eq 'in01'
and saknr eq bseg-hkont.

write:(40) p_data-desc under text-006.
rv_bal = rv_bal - abs( rcrdt ) + abs( rdebt ) .
p_data-bal = rv_bal.
write:(16) p_data-bal under text-009 decimals 2.
ctr = ctr + 1.
clear: rcrdt,rdebt.
new-line.
endselect.
endform. " READ_OTHER_LINE_ITEMS
*&---------------------------------------------------------------------*
*& Form GET_PRINT_TP_LEDGER
*&---------------------------------------------------------------------*
form get_print_tp_ledger.
refresh ar_items.
refresh ar_items1.
call function 'BAPI_AR_ACC_GETSTATEMENT'
exporting
companycode = dtab-bukrs
customer = dtab-kunnr
date_from = p_budat-low
date_to = p_budat-high
noteditems = 'X'
tables
lineitems = ar_items
exceptions
others = 1.
check sy-subrc = 0.
v_bal = dtab-open_bal.
delete ar_items where sp_gl_ind eq 'D'.
loop at ar_items.
if ar_items-sp_gl_ind eq 'X'.
move ar_items to ar_items_splgl.
append ar_items_splgl.
delete ar_items.
endif.
endloop.
loop at ar_items.
if ar_items-doc_type eq 'DO' or ar_items-doc_type eq 'DC' or
ar_items-doc_type eq 'DB'.
append ar_items to ar_items1.
clear ar_items1.
delete ar_items.
endif.
endloop.
sort ar_items1 by doc_no fisc_year.
delete adjacent duplicates from ar_items1 comparing
doc_no fisc_year.
describe table ar_items lines cnt.
clear: v_debits, v_credits,v_balance.
loop at ar_items.
ar_items-lc_amount = abs( ar_items-lc_amount ).
p_data-kunnr = dtab-kunnr.
p_data-name1 = dtab-name1.
p_data-doc_date = ar_items-pstng_date.
p_data-doc_no = ar_items-doc_no.
p_data-doc_type = ar_items-doc_type.
case ar_items-db_cr_ind.
when 'S'.
v_debits = v_debits + ar_items-lc_amount.
v_bal = v_bal + ar_items-lc_amount.
p_data-amount = ar_items-lc_amount.
when 'H'.
p_data-amount = ar_items-lc_amount * -1.
v_credits = v_credits + ar_items-lc_amount.
v_bal = v_bal - ar_items-lc_amount.
endcase.
perform get_account_code_01.
perform print_doc_desc_oir_01.
p_data-bal = v_bal.
perform print_qty_01.
format color col_normal intensified off.
collect p_data.
clear p_data.
endloop.
loop at ar_items1.
perform get_other_items_01.
if ar_items1-doc_type = 'ZV'.
if zvamt < 0.
v_credits = v_credits + abs( zvamt ).
else.
v_debits = v_debits + zvamt.
endif.
endif.
clear zvamt.
endloop.
endform. " GET_PRINT_TP_LEDGER
*&---------------------------------------------------------------------*
*& Form GET_OTHER_ITEMS_01
*&---------------------------------------------------------------------*
form get_other_items_01.
select * from bseg where bukrs = p_bukrs
and belnr = ar_items1-doc_no
and gjahr = p_gjahr
and koart ne 'D'.
format color col_normal intensified.
p_data-kunnr = dtab-kunnr.
p_data-name1 = dtab-name1.
p_data-doc_date = ar_items1-pstng_date.
p_data-doc_no = ar_items1-doc_no.
p_data-doc_type = ar_items1-doc_type.
if bseg-shkzg = 'S'.
if ar_items1-doc_type ne 'ZV'.
v_credits = v_credits + bseg-dmbtr.
else.
zvamt = zvamt - bseg-dmbtr.
endif.
v_bal = v_bal + bseg-dmbtr.
p_data-amount = ( bseg-dmbtr * -1 ).
elseif bseg-shkzg = 'H'.
if ar_items1-doc_type ne 'ZV'.
v_debits = v_debits + bseg-dmbtr.
else.
zvamt = zvamt + bseg-dmbtr.
endif.
v_bal = v_bal - bseg-dmbtr.
p_data-amount = bseg-dmbtr.
endif.
perform print_acc_description_01 .
p_data-bal = v_bal.
collect p_data.
clear p_data.
endselect.
endform. " GET_OTHER_ITEMS_01
*&---------------------------------------------------------------------*
*& Form PRINT_ACC_DESCRIPTION_01
*&---------------------------------------------------------------------*
form print_acc_description_01 .
case ar_items1-doc_type .
when 'DZ'.
v_desc = bseg-zuonr.
concatenate 'Check Rec' v_desc into v_desc separated by
' '.
when 'DC'.
v_desc = 'Early Pymnt Discount'.
when 'ZV'.
v_desc = :bkpf-xblnr.
when others.
v_desc = bseg-sgtxt.
endcase.
p_data-desc = v_desc.
endform. " PRINT_ACC_DESCRIPTION_01
*&---------------------------------------------------------------------*
*& Form PRINT_ACC_DESCRIPTION_02
*&---------------------------------------------------------------------*
form print_acc_description_02 .
case p_data-doc_type .
when 'DZ'.
v_desc = bseg-zuonr.
concatenate 'Cheque Recd.' v_desc into v_desc separated by ' '.
when 'DC'.
v_desc = 'Discount'.
when 'ZV'.
v_desc = :bkpf-xblnr.
when others.
v_desc = ar_items-item_text.
endcase.
p_data-desc = v_desc.
endform. " PRINT_ACC_DESCRIPTION_02
*&---------------------------------------------------------------------*
*& Form GET_ACCOUNT_CODE_01
*&---------------------------------------------------------------------*
form get_account_code_01.
endform. " GET_ACCOUNT_CODE_01
*&---------------------------------------------------------------------*
*& Form PRINT_DOC_DESC_OIR_01
*&---------------------------------------------------------------------*
form print_doc_desc_oir_01.
data zvbeln like vbrk-vbeln.
clear v_desc.
if ar_items-doc_type eq 'DD' or ar_items-doc_type eq 'DG' or ar_items-doc_type
eq 'DA' or ar_items-doc_type eq '3i' or ar_items-doc_type eq '3v'.
if ar_items-doc_type eq 'DD' or ar_items-doc_type eq 'DA'.
if ar_items-doc_type eq 'DA'.
select single * from bkpf where belnr = ar_items-doc_no
and gjahr = p_gjahr.
if bkpf-stblg ne ' '.
concatenate 'Reversed by' bkpf-stblg into v_desc separated by
space.
else.
ar_items-item_num = '001'.
select single sgtxt into :bseg-sgtxt from bseg
where bukrs = ar_items-comp_code
and belnr = ar_items-doc_no
and gjahr = p_gjahr
and buzei = ar_items-item_num.
if sy-subrc = 0.
v_desc = :bseg-sgtxt.
endif.
endif.
else.
if inv_text eq 'X' and ar_items-doc_type eq 'DD' .
select single * from t003t where spras = 'EN'
and blart = ar_items-doc_type.
v_desc = t003t-ltext.
else.
select single sgtxt into :bseg-sgtxt from bseg
where bukrs = ar_items-comp_code
and belnr = ar_items-doc_no
and gjahr = p_gjahr
and buzei = ar_items-item_num.
if sy-subrc = 0.
v_desc = :bseg-sgtxt.
endif.
endif.
endif.
else.
if inv_text eq 'X' and ar_items-doc_type eq 'DG'.
select single * from t003t where spras = 'EN'
and blart = ar_items-doc_type.
v_desc = t003t-ltext.
else.
select single vbeln into zvbeln from bseg
where bukrs = ar_items-comp_code
and belnr = ar_items-doc_no
and gjahr = p_gjahr
and buzei = ar_items-item_num.
check sy-subrc = 0.
select single * from vbrp where vbeln = zvbeln.
if sy-subrc = 0.
select single * from vbak where vbeln = vbrp-aubel.
v_desc = vbak-bstnk.
endif.
endif.
endif.
else.
if ar_items-doc_type eq 'ZD'.
select single * from t003t where spras eq 'EN'
and blart eq 'ZD'.
if sy-subrc = 0.
v_desc = t003t-ltext.
endif.
else.
clear line1.
free line1.
select single * from vbrp where vbeln = ar_items-doc_no.
if sy-subrc = 0.
select single * from vbak where vbeln = vbrp-aubel.
name = vbrp-aubel.
call function 'READ_TEXT'
exporting
* CLIENT = SY-MANDT
id = '0001'
language = 'E'
name = name
object = 'VBBK'
* ARCHIVE_HANDLE = 0
importing
header = header1
tables
lines = line1
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.
read table line1 index 1.
move line1-tdline to v_desc.
if v_desc <> ' ' and inv_text eq ' '.
if o_po_txt eq 'X'.
concatenate vbak-bstnk '-' line1-tdline into v_desc separated
by space.
else.
clear v_desc.
v_desc = vbak-bstnk.
endif.
else.
if inv_text eq 'X' and ( ar_items-doc_type eq 'RC' or
ar_items-doc_type eq 'RV' or
ar_items-doc_type eq 'RB' or
ar_items-doc_type eq 'DR' or
ar_items-doc_type eq 'DF' or
ar_items-doc_type eq '3i' or
ar_items-doc_type eq '3v' or
ar_items-doc_type eq 'DD' or
ar_items-doc_type eq 'DG' ) .
select single * from t003t where spras = 'EN' and blart = ar_items-
doc_type.
v_desc = t003t-ltext.
if v_desc = 'Invoice '
or v_desc = 'BILLING Doc. '.
clear v_desc.
v_desc = t003t-ltext(12).
endif.
else.
v_desc = vbak-bstnk.
endif.
endif.
else.
if inv_text eq 'X' and ( ar_items-doc_type eq 'DR' ).
select single * from t003t where spras = 'EN'
and blart = ar_items-doc_type.
v_desc = t003t-ltext.
else.
select single sgtxt into :bseg-sgtxt from bseg
where bukrs = ar_items-comp_code
and belnr = ar_items-doc_no
and gjahr = p_gjahr
and buzei = '002'.
if sy-subrc = 0.
v_desc = :bseg-sgtxt.
endif.
endif.
endif.
endif.
endif.
p_data-desc = v_desc.
endform. " PRINT_DOC_DESC_OIR_01
*&---------------------------------------------------------------------*
*& Form PRINT_QTY_01
*&---------------------------------------------------------------------*
form print_qty_01.
select single vbeln into :bseg-vbeln from bseg
where bukrs = p_bukrs and belnr = ar_items-doc_no
and gjahr = p_gjahr
and buzei = ar_items-item_num.
select sum( fkimg ) into :vbrp-fkimg
from vbrp where vbeln = :bseg-vbeln.
p_data-qty = :vbrp-fkimg .
v_qty = v_qty + :vbrp-fkimg.
endform. " PRINT_QTY_01
*&---------------------------------------------------------------------*
*& Form PRINT_PARAMETERS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form print_parameters.
call function 'SET_PRINT_PARAMETERS'
exporting
copies = '1'
immediately = 'X'
layout = 'X_90_120'
list_name = 'DLR Ledger'
exceptions
others = 1.
endform. " PRINT_PARAMETERS
*&---------------------------------------------------------------------*
*& Form PRINT_SPL_GL
*&---------------------------------------------------------------------*
form print_spl_gl.
refresh p_data.
clear: rcrdt,rdebt,rv_bal.
p_data-bal = spl_gl_amount_na.
loop at ar_items_splgl.
ar_items_splgl-lc_amount = abs( ar_items_splgl-lc_amount ).
p_data-kunnr = dtab-kunnr.
p_data-name1 = dtab-name1.
p_data-doc_date = ar_items_splgl-pstng_date.
p_data-doc_no = ar_items_splgl-doc_no.
p_data-doc_type = ar_items_splgl-doc_type.
case ar_items_splgl-db_cr_ind.
when 'S'.
v_debits = v_debits + ar_items_splgl-lc_amount.
v_bal = v_bal + ar_items_splgl-lc_amount.
p_data-amount = ar_items_splgl-lc_amount.
when 'H'.
p_data-amount = ar_items_splgl-lc_amount * -1.
v_credits = v_credits + ar_items_splgl-lc_amount.
v_bal = v_bal - ar_items_splgl-lc_amount.
endcase.
select single * from t074t where spras = sy-langu
and koart = 'D'
and shbkz = ar_items_splgl-sp_gl_ind.
move t074t-ltext to p_data-desc.
collect p_data.
endloop.
endform. " PRINT_SPL_GL
*&---------------------------------------------------------------------*
*& Form PRINT_SPLGL_TOTAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form print_splgl_total.
format color col_total intensified off.
reserve 6 lines.
uline.
write :/ text-013 under text-002.
write :(16) v_credits under text-007 decimals 2,
(16) v_debits under text-008 decimals 2.
v_balance = dtab-splgl + v_debits - v_credits .
uline.
write :/ text-014 under text-002.
write : v_balance under text-009 decimals 2.
clear: v_debits, v_credits,v_qty,v_balance.
uline.
write : / 'DA - Clearing document,',
'DD - Customer debit note,',
'DG - Customer credit note,' ,
'DR - Customer invoice,',
'DZ - Customer payment,',
'RV - Billing document,',
'ZD - Customer OI upload'.
endform. " PRINT_SPLGL_TOTAL
*---------------------------------------------------------------------*
* FORM au_check_vkbur *
*---------------------------------------------------------------------*
form au_check_vkbur.
" READ_T001
data : av_mcinf like tmc4-mcinf.
data: flg_avauthor,
flg_noauthor,
flg_select.
data: begin of av_hlp_tvbur occurs 20.
include structure tvbur.
data: end of av_hlp_tvbur.
data: av_flg_restrict.
clear: av_flg_restrict,
flg_avauthor,
flg_noauthor,
flg_select.
select * from tvbur into table av_hlp_tvbur
where vkbur in av_vkbur.
describe table av_vkbur lines sy-tfill.
if sy-tfill > 0.
flg_select = 'X'.
endif.
clear av_hlp_tvbur-vkbur.
collect av_hlp_tvbur.
loop at av_hlp_tvbur.
authority-check object 'M_IS_VKBUR'
id 'MCINF' field av_mcinf
id 'VKBUR' field av_hlp_tvbur-vkbur.
if sy-subrc <> 0.
clear av_vkbur.
flg_noauthor = 'X'.
delete av_hlp_tvbur.
if flg_select = 'X'.
av_vkbur-sign = 'E'.
av_vkbur-option = 'EQ'.
av_vkbur-low = av_hlp_tvbur-vkbur.
collect av_vkbur.
av_flg_restrict = 'X'.
endif.
else.
flg_avauthor = 'X'.
if flg_select = ' '.
av_vkbur-sign = 'I'.
av_vkbur-option = 'EQ'.
av_vkbur-low = av_hlp_tvbur-vkbur.
collect av_vkbur.
endif.
endif.
endloop.
read table av_hlp_tvbur index 1.
if sy-subrc ne 0.
clear av_vkbur.
av_vkbur-sign = 'E'.
av_vkbur-option = 'CP'.
av_vkbur-low = '*'.
collect av_vkbur.
endif.
if flg_select = ' '.
if flg_noauthor = ' '.
clear av_vkbur.
refresh av_vkbur.
else.
if flg_avauthor = ' '.
loop at av_vkbur where sign = 'I'
and option = 'EQ'.
delete av_vkbur.
endloop.
else.
loop at av_vkbur where sign = 'E'
and option = 'EQ'.
delete av_vkbur.
endloop.
endif.
endif.
endif.
endform.
*Text elements
*----------------------------------------------------------
* 001 General selection
* 003 Doc. Dt
* 004 DTy
* 005 Doc. No
* 006 Text
* 007 Credits
* 008 Debits
* 009 Balance
* 013 Total
* 014 Balance
* 015 Opening balance as on

You might also like