To implement this, we first include two attributes in our ABAP class "customer", namely the amount and the currency of the balance:
ABAPdata:
open_balance_amount type dmbtr,
open_balance_currency type waers.
Next, we implement an ABAP method that calculates the balance. For this we use the standard function module "BAPI_AR_ACC_GETOPENITEMS":
ABAPmethod build_open_balance.
clear:
open_balance_amount,
open_balance_currency.
data:
items type table of bapi3007_2.
call function 'BAPI_AR_ACC_GETOPENITEMS'
exporting
customer = kunnr
companycode = '1010'
keydate = sy-datum
tables
lineitems = items.
loop at items assigning field-symbol(<item>)
* add debit/credit
if <item>-db_cr_ind = 'S'.
open_balance_amount = open_balance_amount + <item>-lc_amount.
else.
open_balance_amount = open_balance_amount - <item>-lc_amount.
endif.
* set company currency
open_balance_currency = <item>-loc_currcy.
endloop.
endmethod.
In the HTML file we output the balance:
HTML<!-- Balance -->
<div class="infoblock">
<label class='label'>Balance</label>
<br />
<span class='output'
name='open_balance_amount'></span>
<span class='output'
name='open_balance_currency'></span>
</div>
* display customer data
method display.
if not s10databaseread( ).
s10errormessage( 'Please enter a valid customer number' ).
endif.
* Calculate accounting balance
build_open_balance( ).
s10nextscreen( 'display').
endmethod.
This is how it can be done and it works. In the development of more complex applications, however, one runs into difficulties if one wants to provide such information derived from the key values at the earliest possible time:
methods:
build_open_balance
importing
kunnr type kna1-kunnr
exporting
open_balance_amount type dmbtr
open_balance_currency type waers.
We can now simply omit the "build_open_balance()" call: the S10 framework executes the method when one of the exporting attributes is to be displayed in an HTML page. You can now easily move the output of individual attributes from one screen to another and be sure that the associated build method is called in time and only once, as long as the key values do not change. To check the correct recalculation after changing the customer number, we add a "back" button on the "display" screen:
This works exactly like the "Display" button from Tutorial 1:
HTML<button type="button" class="toolbarbutton"
onclick="S10Apply('start');">
Back
</button>
In our ABAP class then still the method "start", which navigates to the screen "start":
ABAP* start again with customer number input
method start.
s10nextscreen( 'start').
endmethod.
Now we can change the customer within the application. The build method "build_open_balance" is automatically called again by the S10 framework to display the balance if the customer number has changed:

One could now write a separate build method for each attribute. However, this does not make sense because very often attributes can be obtained together without much additional effort, for example by calling a BAPI or with a database access. Therefore you better combine these attributes in a "build" method and specify all attributes that are calculated together in "exporting".
Tables can also be named in a "build" method under "exporting". As an example, we output a table of all open items of the customer in a separate screen. As a result we want to achieve the following:


For the general technique of table output, you can find all the details in the Tables documentation. For our example it looks like this:
In the "display" screen we add another button "Open items":
HTML<button type="button" class="toolbarbutton"
onclick="S10Apply('to_openitems');">
Open items
</button>
The button executes the ABAP method "to_openitems", with which we branch to the new screen "openitems":* display open items
method to_openitems.
s10nextscreen( 'openitems').
endmethod.
In our ABAP program we define a class "openitem" which contains the fields of the open accounting items to be displayed, i.e. a section of the BAPI structure:
class openitem definition inheriting from /s10/any.
public section.
data:
doc_no type bapi3007_2-doc_no, " Document Number
item_num type bapi3007_2-item_num, " Line item
pstng_date type bapi3007_2-pstng_date, " Posting Date
doc_type type bapi3007_2-doc_type, " Document type
lc_amount type dmbtr, " Amount in LC with 2 decimals
pmnttrms type bapi3007_2-pmnttrms, " Payment Terms
loc_currcy type bapi3007_2-loc_currcy. "Currency
endclass.
You can have this class generated in transaction /s10/util by ticking the required fields from BAPI structure "bapi3007_2".
data:
openitems type table of ref to openitem.
We fill the table in the method "build_open_balance", which is now declared as follows:methods:
build_open_balance
importing
kunnr type kna1-kunnr
exporting
open_balance_amount type dmbtr
open_balance_currency type waers
openitems type table.
That is, another exporting parameter has now been added, the table "openitems". Here please note that it is only declared with "type table".
method build_open_balance.
clear:
open_balance_amount,
open_balance_currency,
openitems.
data:
items type table of bapi3007_2.
call function 'BAPI_AR_ACC_GETOPENITEMS'
exporting
customer = kunnr
companycode = '1010'
keydate = sy-datum
tables
lineitems = items.
* sort items
sort items by doc_no item_num.
loop at items assigning field-symbol(- ).
* correct sign
if
- -db_cr_ind = 'H'.
- -lc_amount = -
- -lc_amount.
endif.
* add to total amount
open_balance_amount = open_balance_amount +
- -lc_amount.
* append to open items table
data(oi) = new openitem( ).
oi->s10copy(
- ).
append oi to openitems.
* set company currency
open_balance_currency =
- -loc_currcy.
endloop.
endmethod.
With this the ABAP program is ready and we only need the HTML file for the screen "openitems". If you want to save yourself some typing, you can use transaction /s10/util again, generate a list display for the BAPI structure "bapi3007_2" and then transfer this display to the HTML file "openitems".<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
<meta name="viewport"
content="width=400">
<link rel='stylesheet' type='text/css'
href='../../../style/s10.style.css'>
<link rel='stylesheet' type='text/css'
href='../../../style/custom.style.css'>
<script
src='../../synactiveS10/synactiveS10.java.js'>
</script>
<title>Customer information</title>
</head>
<body style="width: 100%; margin: 0px; padding: 0px;"
onload='init();'
class="colorscheme9">
<div class="headerarea"
style="width: 100%; padding: 10px;">
<b>
Open items
<span class='output'
type="text"
name='name1'>
</span>
</b>
<br />
<br />
<button type="button"
class="toolbarbutton"
onclick="S10Apply('to_display');">
Overview
</button>
<button type="button"
class="toolbarbutton"
onclick="S10Logoff();">
Logoff
</button>
</div>
<!-- column headers -->
<div class="colheaders">
<!-- Document number -->
<div class='colhead colheadup output'
style="width: 90px;"
name="doc_no">
</div>
<!-- Item number -->
<div class='colhead output'
style="width: 36px;"
name="item_num">
</div>
<!-- Posting date -->
<div class='colhead output'
style="width: 80px;"
name="pstng_date">
</div>
<!-- Payment terms -->
<div class='colhead output'
style="width: 48px;"
name="pmnttrms">
</div>
<!-- Amount -->
<div class='colhead output totals'
style="width: 200px;
--portrait-width: 90px;
text-align: right;"
name="lc_amount">
</div>
<div class="colhead"
style="width: 20px;
float: right;
margin-right: 4px;"
onclick="S10FilterTable(this);">
<img src="../../../icons/filter.png"
style="width: 18px;
height: 18px;">
</div>
</div>
<!-- list rows -->
<form class='table'
name='openitems'>
<div class="tablerow">
<!-- Document number -->
<div class='outputcelldiv'
style="width: 90px;"
name="doc_no">
</div>
<!-- Item number -->
<div class='outputcelldiv'
style="width: 36px;"
name="item_num">
</div>
<!-- Posting date -->
<div class='outputcelldiv'
style="width: 80px;"
name="pstng_date">
</div>
<!-- Payment terms -->
<div class='outputcelldiv'
style="width: 48px;"
name="pmnttrms">
</div>
<!-- Amount -->
<div class='outputcelldiv'
style="width: 200px;
--portrait-width: 90px;
text-align: right;"
name="lc_amount">
</div>
</div>
</form>
<!-- nothing selected -->
<div class="tablenocontent"
style="display: block;">
No items selected
</div>
</body>
</html>
To navigate back to the overview, we have defined the "Overview" button here, which calls a small ABAP method, as with the previous navigation buttons:* display general attributes
method to_display.
s10nextscreen( 'display').
endmethod.
With this, the list display of open items is ready and integrated into our application.