Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Exercises - Solutions

SAP AG, 2012


Disclaimer

This presentation outlines our general product direction and should not be relied on in
making a purchase decision. This presentation is not subject to your license
agreement or any other agreement with SAP. SAP has no obligation to pursue any
course of business outlined in this presentation or to develop or release any
functionality mentioned in this presentation. This presentation and SAP's strategy and
possible future developments are subject to change and may be changed by SAP at
any time for any reason without notice. This document is provided without a warranty
of any kind, either express or implied, including but not limited to, the implied
warranties of merchantability, fitness for a particular purpose, or non-infringement.
SAP assumes no responsibility for errors or omissions in this document, except if
such damages were caused by SAP intentionally or grossly negligent.

© 2012 SAP AG. All rights reserved. 2


Exercises (1/2)

Exercise 1: Create Invoice Instances


Create report “ZCI_XX_CREATE_INVOICE_INSTANCES” (transaction se38).
It shall create new invoices with ID “123”. Finally, save the transaction.

Exercise 2: Query Invoice Instances


Create report “ZCI_XX_QUERY_INVOICE_INSTANCES”. It shall print the IDs of all
existing invoice instances.

Exercise 3: Convert Invoice ID


Create report “ZCI_XX_CONVERT_INVOICE_ID”. It shall convert the given invoice
ID “123” into the technical key and print the payment status of that invoice.

Exercise 4: Delete All Invoices


Create batch report “ZCI_XX_DELETE_ALL_INVOICES”. It shall delete all existing
invoices. Finally, save the transaction.

© 2012 SAP AG. All rights reserved. 3


Exercises (2/2)

Exercise 5: Update All Invoice Instances


Create report “ZCI_XX_UPDATE_ALL_INVOICES”. It shall update the
“PAYMENT_STATUS” of all existing invoices to “02”. Finally save the transaction.

Exercise 6: Execute Action “Invoice_Paid”


Create report “ZCI_XX_EXECUTE_INVOICE_PAID”. It shall execute the action
“INVOICE_PAID” on all existing invoices. Finally, save the transaction.

Exercise 7: Retrieve Invoice Items by Association


Create report “ZCI_XX_RETRIEVE_ITEMS”. It shall calculate the sum of all item
amounts of all invoices.

Exercise 8: Check Invoice Consistency


Create report “ZCI_XX_CHECK_INVOICE_CONSISTENCY”. It shall check the
consistency of all Invoices.

© 2012 SAP AG. All rights reserved. 4


Exercise 1: Create Invoice Instances
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager(iv_bo_key = zif_ci_00_customer_invoi
ce_c=>sc_bo_key ).

" create a new invoice with ID 123


DATA lt_modification TYPE /bobf/t_frw_modification.
DATA ls_modification TYPE /bobf/s_frw_modification.
DATA ls_ref_root_data TYPE REF TO zci_00_s_root.
CREATE DATA ls_ref_root_data.
ls_modification-node = zif_ci_00_customer_invoice_c=>sc_node-root.
ls_modification-change_mode = /bobf/if_frw_c=>sc_modify_create.
ls_modification-key = lo_customer_invoice->get_new_key( ).
ls_modification-data = ls_ref_root_data.
ls_ref_root_data->invoice_id = '123'.
APPEND ls_modification TO lt_modification.

" execute modification


DATA lo_change TYPE REF TO /bobf/if_tra_change.
lo_customer_invoice->modify(
EXPORTING it_modification = lt_modification
IMPORTING eo_change = lo_change ).

" check if the instance has been successfully created


IF lo_change->has_failed_changes( ) = abap_true. BREAK-POINT. ENDIF.

" save the transaction


DATA lo_transaction_manager TYPE REF TO /bobf/if_tra_transaction_mgr.
lo_transaction_manager = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).
lo_transaction_manager->save( ).

© 2012 SAP AG. All rights reserved. 5


Exercise 2: Query Invoice Instances
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" query all existing invoices


DATA ls_root_data TYPE zci_00_s_root.
DATA lt_root_data TYPE zci_00_t_root.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ci_00_customer_invoice_c=>sc_query-root-select_all
iv_fill_data = abap_true
IMPORTING
et_data = lt_root_data ).

" print all invoices ids


LOOP AT lt_root_data INTO ls_root_data.
WRITE / ls_root_data-invoice_id.
ENDLOOP.

© 2012 SAP AG. All rights reserved. 6


Exercise 3: Convert Invoice ID
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" use alternative key conversion to get technical key


DATA lv_alternative_key TYPE zti_invoice_id.
DATA lt_alternative_key TYPE zti_invoice_id_table_type.
DATA lt_root_key TYPE /bobf/t_frw_key.
lv_alternative_key = '123'.
APPEND lv_alternative_key TO lt_alternative_key.
lo_customer_invoice->convert_altern_key(
EXPORTING
iv_node_key = zif_ci_00_customer_invoice_c=>sc_node-root
iv_altkey_key = zif_ci_00_customer_invoice_c=>sc_alternative_key-root-invoice_id
it_key = lt_alternative_key
IMPORTING
et_key = lt_root_key ).

" retrieve the instance data


DATA ls_root_data TYPE zci_00_s_root.
DATA lt_root_data TYPE zci_00_t_root.
lo_customer_invoice->retrieve(
EXPORTING
iv_node_key = zif_ci_00_customer_invoice_c=>sc_node-root
it_key = lt_root_key " Key Table
IMPORTING
et_data = lt_root_data ).

" print the payment_status


LOOP AT lt_root_data INTO ls_root_data.
WRITE: / ls_root_data-invoice_id, ls_root_data-payment_status.
ENDLOOP.

© 2012 SAP AG. All rights reserved. 7


Exercise 4: Delete All Invoices
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" query all existing invoices


DATA ls_root_key TYPE /bobf/s_frw_key.
DATA lt_root_key TYPE /bobf/t_frw_key.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ci_00_customer_invoice_c=>sc_query-root-select_all
IMPORTING
et_key = lt_root_key ).

" delete all invoices


DATA ls_modification TYPE /bobf/s_frw_modification.
DATA lt_modification TYPE /bobf/t_frw_modification.
LOOP AT lt_root_key INTO ls_root_key.
ls_modification-node = zif_ci_00_customer_invoice_c=>sc_node-root.
ls_modification-key = ls_root_key-key.
ls_modification-change_mode = /bobf/if_frw_c=>sc_modify_delete.
APPEND ls_modification TO lt_modification.
ENDLOOP.

" execute modification


lo_customer_invoice->modify( it_modification = lt_modification ).

" save the transaction


DATA lo_transaction_manager TYPE REF TO /bobf/if_tra_transaction_mgr.
lo_transaction_manager = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).
lo_transaction_manager->save( ).

© 2012 SAP AG. All rights reserved. 8


Exercise 5: Update All Invoices
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" query all existing invoices


DATA ls_root_data TYPE zci_00_s_root.
DATA lt_root_data TYPE zci_00_t_root.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ci_00_customer_invoice_c=>sc_query-root-select_all
iv_fill_data = abap_true
IMPORTING
et_data = lt_root_data ).

" update all invoices


DATA ls_modification TYPE /bobf/s_frw_modification.
DATA lt_modification TYPE /bobf/t_frw_modification.
DATA lr_root_data TYPE REF TO zci_00_s_root.
LOOP AT lt_root_data REFERENCE INTO lr_root_data.
lr_root_data->payment_status = '02'.
ls_modification-node = zif_ci_00_customer_invoice_c=>sc_node-root.
ls_modification-key = lr_root_data->key.
ls_modification-change_mode = /bobf/if_frw_c=>sc_modify_update.
ls_modification-data = lr_root_data.
APPEND ls_modification TO lt_modification.
ENDLOOP.
" execute modification
lo_customer_invoice->modify( it_modification = lt_modification ).

" save the transaction


DATA lo_transaction_manager TYPE REF TO /bobf/if_tra_transaction_mgr.
lo_transaction_manager = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).
lo_transaction_manager->save( ).

© 2012 SAP AG. All rights reserved. 9


Exercise 6: Execute Action “Invoice Paid”
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key =
zif_ti_customer_invoice_c=>sc_bo_key ).

" get all invoice instances


DATA lt_root_key TYPE /bobf/t_frw_key.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ti_customer_invoice_c=>sc_query-root-select_all
IMPORTING
et_key = lt_root_key ).

" invoke the desired action


lo_customer_invoice->do_action(
EXPORTING
iv_act_key = zif_ti_customer_invoice_c=>sc_action-root-invoice_paid
it_key = lt_root_key ).

" retrieve the instance data and print data (all invoices must be set to "paid")
DATA ls_root_data TYPE zti_s_root8.
DATA lt_root_data TYPE zti_t_root8.
lo_customer_invoice->retrieve(
EXPORTING
iv_node_key = zif_ti_customer_invoice_c=>sc_node-root
it_key = lt_root_key
IMPORTING
et_data = lt_root_data ).

LOOP AT lt_root_data INTO ls_root_data.


WRITE / ls_root_data-invoice_paid.
ENDLOOP.

© 2012 SAP AG. All rights reserved. 10


Exercise 7: Retrieve Invoice Items
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" query all existing invoices


DATA lt_root_key TYPE /bobf/t_frw_key.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ci_00_customer_invoice_c=>sc_query-root-select_all
IMPORTING
et_key = lt_root_key ).

" get all items


DATA ls_invoice_item TYPE zci_00_s_item.
DATA lt_invoice_item TYPE zci_00_t_item.
lo_customer_invoice->retrieve_by_association(
EXPORTING
iv_node_key = zif_ci_00_customer_invoice_c=>sc_node-root
it_key = lt_root_key
iv_association = zif_ci_00_customer_invoice_c=>sc_association-root-item
iv_fill_data = abap_true
IMPORTING
et_data = lt_invoice_item ).

" calculate all items


DATA lv_sum TYPE int4.
LOOP AT lt_invoice_item INTO ls_invoice_item.
lv_sum = lv_sum + ls_invoice_item-amount.
ENDLOOP.
WRITE lv_sum.

© 2012 SAP AG. All rights reserved. 11


Exercise 8: Check Invoice Consistency
" get the service manager of the Invoice BO
DATA lo_customer_invoice TYPE REF TO /bobf/if_tra_service_manager.
lo_customer_invoice = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( iv_bo_key = zif_ci_00_customer_invo
ice_c=>sc_bo_key ).

" query all existing invoices


DATA lt_root_key TYPE /bobf/t_frw_key.
lo_customer_invoice->query(
EXPORTING
iv_query_key = zif_ci_00_customer_invoice_c=>sc_query-root-select_all
IMPORTING
et_key = lt_root_key ).

" execute consistency validations triggering on check


DATA lo_message TYPE REF TO /bobf/if_frw_message.
lo_customer_invoice->check_consistency(
EXPORTING
iv_node_key = zif_ci_00_customer_invoice_c=>sc_node-root
it_key = lt_root_key
iv_check_scope = /bobf/if_frw_c=>sc_scope_substructure
IMPORTING
eo_message = lo_message ).

" get messages


DATA ls_message TYPE /bobf/s_frw_message_k.
DATA lt_message TYPE /bobf/t_frw_message_k.
lo_message->get_messages( IMPORTING et_message = lt_message ).
LOOP AT lt_message INTO ls_message.
" ...
ENDLOOP.

© 2012 SAP AG. All rights reserved. 12


Thank you
© 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose Google App Engine, Google Apps, Google Checkout, Google Data API, Google Maps,
without the express permission of SAP AG. The information contained herein may be Google Mobile Ads, Google Mobile Updater, Google Mobile, Google Store, Google Sync,
changed without prior notice. Google Updater, Google Voice, Google Mail, Gmail, YouTube, Dalvik and Android are
trademarks or registered trademarks of Google Inc.
Some software products marketed by SAP AG and its distributors contain proprietary
software components of other software vendors. INTERMEC is a registered trademark of Intermec Technologies Corporation.
Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and Visual Studio are Wi-Fi is a registered trademark of Wi-Fi Alliance.
registered trademarks of Microsoft Corporation.
Bluetooth is a registered trademark of Bluetooth SIG Inc.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x,
System z, System z10, z10, z/VM, z/OS, OS/390, zEnterprise, PowerVM, Power Motorola is a registered trademark of Motorola Trademark Holdings LLC.
Architecture, Power Systems, POWER7, POWER6+, POWER6, POWER, PowerHA, Computop is a registered trademark of Computop Wirtschaftsinformatik GmbH.
pureScale, PowerPC, BladeCenter, System Storage, Storwize, XIV, GPFS, HACMP,
RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX, Intelligent Miner, WebSphere, Tivoli, SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer,
Informix, and Smarter Planet are trademarks or registered trademarks of IBM Corporation. StreamWork, SAP HANA, and other SAP products and services mentioned herein as well
as their respective logos are trademarks or registered trademarks of SAP AG in Germany
Linux is the registered trademark of Linus Torvalds in the United States and other countries. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are trademarks or registered Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal
trademarks of Adobe Systems Incorporated in the United States and other countries. Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services
Oracle and Java are registered trademarks of Oracle and its affiliates. mentioned herein as well as their respective logos are trademarks or registered trademarks
of Business Objects Software Ltd. Business Objects is an SAP company.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin products and services mentioned herein as well as their respective logos are trademarks or
are trademarks or registered trademarks of Citrix Systems Inc. registered trademarks of Sybase Inc. Sybase is an SAP company.
HTML, XML, XHTML, and W3C are trademarks or registered trademarks of W3C®, Crossgate, m@gic EDDY, B2B 360°, and B2B 360° Services are registered trademarks
World Wide Web Consortium, Massachusetts Institute of Technology. of Crossgate AG in Germany and other countries. Crossgate is an SAP company.
Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, Multi-Touch, Objective-C, All other product and service names mentioned are the trademarks of their respective
Retina, Safari, Siri, and Xcode are trademarks or registered trademarks of Apple Inc. companies. Data contained in this document serves informational purposes only. National
product specifications may vary.
IOS is a registered trademark of Cisco Systems Inc.
The information in this document is proprietary to SAP. No part of this document may be
RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold, BlackBerry Pearl, BlackBerry reproduced, copied, or transmitted in any form or for any purpose without the express prior
Torch, BlackBerry Storm, BlackBerry Storm2, BlackBerry PlayBook, and BlackBerry App written permission of SAP AG.
World are trademarks or registered trademarks of Research in Motion Limited.

© 2012 SAP AG. All rights reserved. 14

You might also like