To implement this, we first include two attributes in our ABAP class "customer", namely the amount and the currency of the balance:
data: 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":
method 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:
<!-- 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.
methods: build_open_balance importing kunnr type kna1-kunnr exporting open_balance_amount type dmbtr open_balance_currency type waers.
This works exactly like the "Display" button from Tutorial 1:
<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":
* 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":
<button type="button" class="toolbarbutton" onclick="S10Apply('to_openitems');"> Open items </button>
* 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.
data: openitems type table of ref to openitem.
methods: build_open_balance importing kunnr type kna1-kunnr exporting open_balance_amount type dmbtr open_balance_currency type waers openitems 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(<item>). * correct sign if <item>-db_cr_ind = 'H'. <item>-lc_amount = - <item>-lc_amount. endif. * add to total amount open_balance_amount = open_balance_amount + <item>-lc_amount. * append to open items table data(oi) = new openitem( ). oi->s10copy( <item> ). append oi to openitems. * set company currency open_balance_currency = <item>-loc_currcy. endloop. endmethod.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | <!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> |
* display general attributes method to_display. s10nextscreen( 'display'). endmethod.