Listing 7.19  ZPTB00_OBJ_DOC_BOOK  Buchen von Geschftsvorfllen
FUNCTION zptb00_obj_doc_book.
*"----------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(I_TAB_BTA) TYPE  ZPTB00_TTY_BTA
*"  EXPORTING
*"     REFERENCE(E_TAB_DOC) TYPE  ZPTB00_TTY_DOC
*"  EXCEPTIONS
*"      FAILED
*"----------------------------------------------------
  DATA:
* accounting document
    l_str_doc               TYPE zptb00_str_doc,
    l_str_doc_item          TYPE zptb00_docitem,
* business transaction
    l_str_bta               TYPE zptb00_btaheader.
  FIELD-SYMBOLS:
* business transaction
    <l_str_bta>             TYPE zptb00_str_bta,
    <l_str_bta_item>        TYPE zptb00_btaitem.
  CONSTANTS:
* business transaction field constants
    con_bta_bttype_purchase TYPE zptb00_dte_bta_bttype 
      VALUE 'PURCHASE',
    con_bta_bttype_sale     TYPE zptb00_dte_bta_bttype 
      VALUE 'SALE',
    con_bta_pstype_service  TYPE zptb00_dte_bta_pstype 
      VALUE 'SERVICE',
    con_bta_pstype_product  TYPE zptb00_dte_bta_pstype 
      VALUE 'PRODUCT',
* document field constants
    con_doc_debit  TYPE zptb00_dte_doc_debitcredit 
      VALUE 'D',
    con_doc_credit  TYPE zptb00_dte_doc_debitcredit 
      VALUE 'C',
    con_doc_account_BGA  TYPE zptb00_dte_doc_account 
      VALUE '001000',
    con_doc_account_cash    TYPE zptb00_dte_doc_account 
      VALUE '002000'.

* loop through every business transaction
  LOOP AT i_tab_bta ASSIGNING <l_str_bta>.
* direct move-corresponding <l_str_bta> TO l_str_doc 
* not possible, so use intermediate structure
    MOVE-CORRESPONDING <l_str_bta> TO l_str_bta.
    MOVE-CORRESPONDING l_str_bta TO l_str_doc.
* loop through every business transaction position
    LOOP AT <l_str_bta>-tab_item ASSIGNING 
      <l_str_bta_item>.
      MOVE-CORRESPONDING <l_str_bta_item> TO 
        l_str_doc_item.
* this is the accounting brain
* book every business transaction as an accounting 
* document
      IF <l_str_bta>-bttype = con_bta_bttype_purchase.
        IF <l_str_bta_item>-pstype = 
           con_bta_pstype_service.
        ELSEIF <l_str_bta_item>-pstype = 
          con_bta_pstype_product.
* For our project we implement only one example, but 
* more to come
          l_str_doc_item-debitcredit = con_doc_debit.
          l_str_doc_item-account = con_doc_account_BGA.
          APPEND l_str_doc_item TO l_str_doc-tab_item.
          CALL FUNCTION 'GUID_CREATE'
            IMPORTING
*             EV_GUID_16       =
*             EV_GUID_22       =
              ev_guid_32       = l_str_doc_item-id.
          l_str_doc_item-debitcredit = con_doc_credit.
          l_str_doc_item-account = 
             con_doc_account_cash.
          APPEND l_str_doc_item TO l_str_doc-tab_item.
        ENDIF.
      ENDIF.
    ENDLOOP.
    APPEND l_str_doc TO e_tab_doc.
  ENDLOOP.

ENDFUNCTION.