CRM BUPA SAP

144
Quickstart Extension of the Business Partner CRM

description

Business Partners in CRM (SAP)

Transcript of CRM BUPA SAP

Page 1: CRM BUPA SAP

Quickstart

Extension of the Business Partner CRM

Page 2: CRM BUPA SAP

© Copyright 2001 SAP AG. All rights reserved.

No part of this publication may be reproduced or

transmitted in any form or for any purpose without the

express permission of SAP AG. The information

contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its

distributors contain proprietary software components

of other software vendors.

Microsoft®, WINDOWS®, NT®, EXCEL®, Word®,

PowerPoint® and SQL Server® are registered

trademarks of Microsoft Corporation.

IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®,

MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®,

OS/390®, and OS/400® are registered trademarks of

IBM Corporation.

ORACLE® is a registered trademark of ORACLE

Corporation.

INFORMIX®-OnLine for SAP and Informix®

Dynamic ServerTM are registered trademarks of

Informix Software Incorporated.

UNIX®, X/Open®, OSF/1®, and Motif ® are registered

trademarks of the Open Group.

Citrix®, the Citrix logo, ICA®, Program

Neighborhood ®, MetaFrame®, WinFrame®,

VideoFrame®, MultiWin® and other Citrix product

names referenced herein are trademarks of Citrix

Systems, Inc.

HTML, DHTML, XML, XHTML are trademarks or

registered trademarks of W3C®, World Wide Web

Consortium, Massachusetts Institute of Technology.

JAVA® is a registered trademark of Sun Microsystems,

Inc.

JAVASCRIPT® is a registered trademark of Sun

Microsystems, Inc., used under license for technology

invented and implemented by Netscape.

SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink,

SAP Business Workflow, WebFlow, SAP

EarlyWatch, BAPI, SAPPHIRE, Management

Cockpit, mySAP, mySAP.com, and other SAP

products and services mentioned herein as well as

their respective logos are trademarks or registered

trademarks of SAP AG in Germany and in several

other countries all over the world. MarketSet and

Enterprise Buyer are jointly owned trademarks of SAP

Markets and Commerce One. All other product and

service names mentioned are the trademarks of their

respective owners.

SAP AGNeurottstraße 1669190 WalldorfGermanyT +49/18 05/34 34 24F +49/18 05/34 34 20www.sap.com

Page 3: CRM BUPA SAP

Contents

Introduction................................................................................................................................ 3

Step-by-step Instructions...........................................................................................................3

Extension Scenarios.................................................................................................................. 3

Notes......................................................................................................................................... 3

Preconditions............................................................................................................................. 3

Creating Data Elements and Domains.......................................................................................3

Extending and Creating R/3 Tables...........................................................................................3

Registering Extension Modules..................................................................................................3

R/3 Customer Master-Use.........................................................................................................3

R/3 Customer Master Data Exchange.......................................................................................3

Extension and Creation of CRM Tables.....................................................................................3

Short Introduction to the BDT.....................................................................................................3

Creating a BDT Application........................................................................................................3

Creating a BDT Function Group.................................................................................................3

Function Module for the ISSTA Event........................................................................................3

Function Module for the ISDST Event........................................................................................3

Function Module for the XCHNG Event.....................................................................................3

Function Module for the DSAVB Event......................................................................................3

Function Module for the DLVE1 Event.......................................................................................3

Function Module for the ISDAT Event........................................................................................3

Function Module for the DTAKE Event......................................................................................3

Function Module for the DSAVC Event......................................................................................3

Function Module for the DSAVE Event......................................................................................3

Function Module for the DLVE2 Event.......................................................................................3

Function Module for the FCODE Event......................................................................................3

Function Module for the DCUAC Event.....................................................................................3

Creating a BDT Screen..............................................................................................................3

ABAP Coding for the PBO Flow Logic.......................................................................................3

ABAP Coding for the PAI Process.............................................................................................3

ABAP Coding for the PBC Process............................................................................................3

Creating New BDT Field Groups................................................................................................3

Creating a New View in the BDT................................................................................................3

Creating a BDT Section.............................................................................................................3

Creating a BDT Screen..............................................................................................................3

Page 4: CRM BUPA SAP

Registering BDT Event Functions..............................................................................................3

Structures for Data Exchange....................................................................................................3

CRM Business Partner: Outbound.............................................................................................3

CRM Business Partner Inbound.................................................................................................3

Programming CRM Middleware Exits........................................................................................3

Page 5: CRM BUPA SAP

IntroductionIn CRM 3.0 customers can extend Business Objects. To do this, customers can either append fields to existing tables or define new tables. In this way additional information can be created for these Business Objects.

This applies not only to the CRM Online application, but also for connected R/3 OLTP Sys-tems, applications on Mobile Clients or Business Information Warehouses.

If, for example, you want to enter and analyze the promotional events that prompted a cus-tomer to buy something, then you not only need to extend the CRM Sales Order but also the Mobile Sales application and the CRM Middleware that transports the order to the Mobile Client and the Business Information Warehouse.

This documentation describes such extensions for the CRM Business Partner. For the Busi-ness Partner it is possible to extend the standard tables BUT000 and BUT020 as well as add user-defined tables.

This documentation will grow step by step. The first version, which you read here, describes only extensions to the CRM Business Partner interacting with the R/3 Customer Master. CRM Mobile and BW have not yet been described here.

This documentation is valid for CRM 3.0, CRM 3.1 and CRM 4.0.

Also see Notes on Copyright and Support.

Page 6: CRM BUPA SAP

Step-by-step InstructionsThis unit describes all single steps you need to take in order to understand the process behind a customer enhancement. In addition to the explanations there are also several concrete Ex-ample Scenarios, the source code for which is contained in this documentation.

Preconditions

Activities in the R/3 OLTP

1. Creating Data Elements and Domains

2. Extending and Creating Customer Tables

3. Registering Extension Function Modules

4. Extending the R/3 Customer Master: Application

5. Extending the R/3 Customer Master: Data Exchange

Activities in the CRM Server

Extending the CRM Online Data Model

1. Creating Data Elements and Domains

2. Extending and Creating Business Partner Tables

Extending the Business Data Toolset (BDT)

3. Creating a BDT Application

4. Creating a New Function Group

5. Function Module for the ISSTA Event

6. Function Module for the ISDST Event

7. Function Module for the XCHNG Event

8. Function Module for the DSAVB Event

9. Function Module for the DLVE1 Event

10. Function Module for the ISDAT Event

11. Function Module for the DTAKE Event

12. Function Module for the DSAVC Event

13. Function Module for the DSAVE Event

14. Function Module for the DLVE2 Event

15. Function Module for the FCODE Event

16. Function Module for the DCUAC Event

17. Creating a Screen

18. ABAP Coding for the PBO Process

19. ABAP Coding for the PAI Process

20. ABAP Coding for the PBC Process

21. Creating BDT Field Groups

22. Creating a New View in the BDT

23. Creating a New BDT Section

Page 7: CRM BUPA SAP

24. Creating a BDT Screen

25. Registering the event function module

Extending the Data Exchange CRM Online <-> R/3 OLTP

26. Structures for Data Exchange

27. Registering Extension Function Modules

28. CRM Business Partner: Outbound

29. CRM Business Partner: Inbound

30. Exits in the CRM Middleware

Page 8: CRM BUPA SAP

Extension Scenarios

UseSeveral example extension scenarios have been prepared in order to give you some practical examples of CRM object extensions and facilitate your initial steps.

These scenarios have been tested carefully, including the data exchange between the OLTP R/3, the CRM Online application and the Mobile Client when uploading and downloading.

However, you should regard these scenarios as demonstration examples only, and not as proposed solutions to customer enhancements. When modifying or reusing coding you should note that it has been tailored specifically to one scenario.

In this documentation you access the extension scenarios via the icon above, never di-rectly via the general description of the extension process. In this way the extension scenario is kept separate from the general description. In case of doubt, all objects in the customer namespace ’Z’ belong to an extension scenario.

Note: Several coding examples are valid for several scenarios, particularly in the units on Middleware. In this case you may ignore superfluous coding when implementing a scenario. The comment lines in the coding will tell you when this is so.

At present there are the following extension scenarios:

Business Partner - New Fields for BUT000A new field – “ZZSAPCUSTMR” (which should specify if the customer is an SAP cus-tomer) is appended in the CRM to the Business Partner Database Table BUT000 by Append technique and can bring this to the interface.

It also shows how a connected R/3 OLTP can be extended accordingly. This takes into account both „R/3 Running with Customer Master“ and, in future, „R/3 Running with Business Partner“.

This document focuses on the extension of the data exchange between R/3 and the CRM.

The procedure for doing this is described in the units on the CRM Business Partner. If this unit is also valid for another example scenario, you will see the header “Example: Business Partner - New Fields for BUT000”.

Business Partner - New Fields for BUT020A new field – “ZZADRKIND” (which specifies the address type concerned) is appended in the CRM to the Business Partner Database Table BUT020 and several other internal

Page 9: CRM BUPA SAP

structures. All relevant screens are extended too and permit maintenance of the new fields.

It also shows how a connected R/3 OLTP can be extended accordingly. This takes into account both „R/3 running with Customer Master“ and, in future, „R/3 running with Business Partner“.

This document focuses on the extension of the data exchange between R/3 and the CRM.

The procedure for doing this is described in the units on the CRM Business Partner. If this unit is also valid for another example scenario, you will see the header “Example: Business Partner - New Fields for BUT020”.

Business Partner - New TablesThe new table “ZSAP_PRODUCTS” is created in the CRM. It contains a relationship between the Business Partner and the SAP products in use (for example, R/3, R/2, APO…). It describes how this extension can be incorporated into the Business Partner Maintenance.

It also shows how a connected R/3 OLTP can be extended accordingly. This takes into account both „R/3 Running with Customer Master“ and, in future, „R/3 Running with Business Partner“.

This document focuses on the extension of the data exchange between R/3 and the CRM.

The procedure for doing this is described in the units on the CRM Business Partner. If this unit is also valid for another example scenario, you will see the header “Example: Business Partner - New Tables”.

Page 10: CRM BUPA SAP

Notes

SupportYou can create error reports on the extension examples presented here in the OSS com-ponent CRM-BF-EEW. This will not, however, give you general advice on customer en-hancements here.

You will find current information on this documentation in OSS Note 484597.

Page 11: CRM BUPA SAP

Preconditions

Before you carry out the extensions, you need to fulfill several preconditions listed here.

Creating a System LandscapeRefer to the Installation Guide and read the OSS Notes on the Release and Support Pack-ages you are using

Make sure that you have the correct setting for the customizing of your CRM and R/3 OLTP Systems. Also read OSS Note 181958, the Setup and Download Guide as well as the instructions for the R/3 Adapter.

These include not only the appropriate application- and Middleware customizing (particu-larly Tables SMOFPARSFA and CRMRFCPAR/CRMPAROLTP) but also technical settings such as RFC connection and logical systems.

It is essential that all systems in the system landscape use different names as a logical system, otherwise there will be problems when exchanging data.

Creating a UserMake sure that the User created by you has the necessary authorization for development activities, in particular authorization for the creation of APPEND structures in the ABAP Dictionary as well as for creating packages (development classes), function groups and ABAP Dictionary objects.

The appropriate roles are SAPCRM_DEVELOPER in the CRM Server and S_DEVELOP in the R/3 OLTP System.

Additionally you should create Users in the R/3 OLTP and on the CRM Server to be used exclusively for data exchange. These Users are necessary for the RFC connection of the R/3 Adapter, for carrying out the upload and download of data to the R/3 OLTP.

The authorizations you need are listed in OSS Note 338537.

Make sure that the Users you create are also registered in the OSS as developers. This is imperative for modifying SAP objects and extending BDocs.

Creating a Development ClassAt least one development class, to which all customer objects and all modifications to SAP objects are assigned, is necessary in the R/3 OLTP as well as in the CRM System.

Use the Z-namespace for all your Objects, or the /*/ namespace requested by you.

Page 12: CRM BUPA SAP

Creating Data Elements and DomainsUse

Before you can extend tables and structures you must create the necessary domains and data el-ements in the ABAP Dictionary.

A domain describes the technical properties of a field, for example, the number of places in the field. Foremost a domain describes a value range that describes the valid data values for the field that refer to this domain. Fixed values may therefore be appended to a domain.

Data elements are „semantic domains“. They describe special properties and screen relevant information (field texts, documentation, input help) for unstructured data objects. Their techni-cal properties are derived from the domain they belong to.

The creation of data elements and eomains is optional. You may also use existing data ele-ments and domains that are suitable for the purpose.

Creating Domains1. Start transaction SE11 (ABAP Dictionary: Initial Screen)

2. Choose the Domain radio button.

3. Enter the name of your new domain. It should begin with a "Y" or a "Z", i.e., be in the cus-tomer namespace. Alternatively, the name may also be in a registered customer names-pace (Example /VW/*).

4. Choose the Create button.

5. Enter a description for the domain in the Short text field.

6. Enter a valid Data type and the No. Characters desired (and also Decimal places for nu-meric domains).

7. If desired, click on the Value range tabstrip and enter Single vals. and/or Intervals permit-ted values for the domain.

8. Choose the Activate button.

9. Enter the name of the package you created.

10. Choose the transport request for your project or create a new one.

Creating Data Elements1. Start transaction SE11 (ABAP Dictionary: Initial Screen)

2. Choose the Domain radio button.

3. Enter the name of your new domain. It should begin with a "Y" or a "Z", i.e., be in the cus-tomer namespace. Alternatively, the name may also be in a registered customer namespace (Example /VW/*).

4. Choose the Create button.

5. Enter a description for the domain in the Short text field.

6. Specify the domain you want.

Page 13: CRM BUPA SAP

7. Set the flag „Change Document“ if you want to create change documents.

8. Specify short-, medium- and long texts as well as the header in the section “Field Label”.

9. Choose the Activate button.

10. Enter the name of the package you created.

11. Choose the transport request for your project or create a new one.

Example: Business Partner – New Fields for BUT000Create domain ZSAP_CUSTOMER (Indicator SAP Customer), Type CHAR and length 1 with the fixed values ‘X’ and ‘ ‘. Create a data element with the same name that uses this domain.

Example: Business Partner – New Tables

Create data element ZSAPPRODUCT that uses domain CHAR3.

Example: Business Partner – New Fields for BUT020Create domain ZADRKIND (Address Type), Type CHAR and length 1. Create a data element with the same name that uses this domain.

Page 14: CRM BUPA SAP

Extending and Creating R/3 Tables

UseCustomers may safely extend the SAP-delivered data model by using the APPEND technique. To directly “modify” an SAP-delivered object means that subsequent implementations of future SAP software releases will overlay that modification. It will have to be reapplied following the upgrade.

The Append method enables you to append user-defined fields to SAP structures and data-base tables without modification. So extensions are preserved through a software release up-grade. Customers may have multiple APPENDs attached to the same DDIC object or place all of their additional fields into a single APPEND structure.

This can be done with the Customer master table KNA1.

It is also possible to incorporate user-defined tables in the SAP applications.

PreconditionsThe data elements and domains you want must already exist.

Extending a Table by Append Technique1. Start transaction SE11 (ABAP Dictionary: Initial Screen)

2. Choose the Database Table radio button for the extension of Database tables or the Data Type Radio Button for extensions to structures.

3. Click on the Display button to display the table or structure.

4. Choose Goto Append structure. Here you can specify the name of the Append structure or select existing Append structures. The name must be in the customer namespace, i.e. be-ginning with ’Y’ or ’Z’. Alternatively, the name may also be in a registered customer names-pace (Example /VW/*).

5. Specify the fields for the Append structure. The fields in an Append structure must be in the customer namespace, i.e. the field name must begin with YY or ZZ. Additionally, an Append structure must be linear, i.e. each field in the Append structure must refer either to a data el-ement, or be furnished directly with data type, length, decimal places and short text.Note: It is best that you do not enter the new fields directly, but combine them in an IN-CLUDE. You can then use this for extensions to the CRM Middleware and Mapping pro-cesses. Note that the INCLUDE structure must be linear too.

6. If you want to create foreign keys or search help attachments for existing fields in the table, you can display these fields via Show Append. Proceed in exactly the same way as for cre-ating a foreign key or search help attachment in the source table.

7. Choose the Activate button.

8. Enter the name of the package you created (development class).

9. Choose the transport request for your project or create a new one.

Conversions necessary are carried out automatically when extending database tables. The extension is kept when upgrading.

Page 15: CRM BUPA SAP

Procedure for Creating a Table 1. Start transaction SE11 (ABAP Dictionary: Initial Screen)

2. Choose the Database Table radio button and specify the name of the table you want to create. The name must be in the customer namespace, i.e. beginning with ’Y’ or ’Z’ or be in a customer namespace (Example /VW/*).

3. Click on the Create button to create the table.

4. Specify a short description for the table and select delivery class “A“ for the application ta-ble.

5. Using the table tab title „Fields“ you can define the fields with the data elements you cre-ated earlier.

6. Save the table by clicking on the Save button.

7. Enter the name of the package you created (development class).

8. Choose the transport request for your project or create a new one.

9. Choose „Goto -> Technical settings“. Specify „APPL0“ as the data type for master data (for Business Partners) and select a suitable size category.

10. Save the table with the Save Button and return to table maintenance.

11. Click on the Activate button to activate the table.

Example: Business Partner – New Fields for BUT000Extend table KNA1 by field ZZSAPCUSTMR as described above. Use data element ZSAP_CUSTOMER.

Create the structure ZSAPCUSTOMER as a BAPIMTCS container for the data exchange. This contains only the field ZZSAPCUSTMR with data element ZSAP_CUSTOMER.

Example: Business Partner – New Fields for BUT020Extend table KNA1 by field ZZADRKIND as described above. Use data element ZADRKIND.

Create the structure ZADR_KIND as a BAPIMTCS container for the data exchange. This con-tains only the field ZZADRKIND with data element ZADRKIND.

Example: Business Partner - New Tables

Create database table ZSAPPROD with delivery class A:

Fields Key Data Element Short Description

CLIENT X MANDT Client

Page 16: CRM BUPA SAP

PARTNER X CHAR10 Character field length 10

SAPPROD X ZSAPPRODUCT SAP products

SELLER CHAR40 Character, 40-figure

CTR_DATE DATS Field, type DATS

Remark: The field PARTNER is defined by the data element CHAR10 for simplicity’s sake so the table can be used both for the Business Partner as well as for the Customer Master. In practice you should decide on either the data element (for the Customer Master) or BU_PARTNER (for the Business Partner). You should then name the field according to the appropriate SAP table (i.e. PARTNER or KUNNR) and set up a foreign key check in KNA1 / BUT000.

Create the structure ZSAPPROD_KZ for the update task:

Fields Data Element Short Description

.INCLUDE ZSAPPROD Data record

KZ CHAR1 I, O, D for Insert, Overwrite or Delete

Create two structures as a BAPIMTCS container for the data exchange:

1. ZSPRD_R3A1 contains the field CURSTAT with the data element XFIELD. This indicator should notify the CRM System whether the „Current State“, i.e. the complete data record, will be sent.

2. ZSPRD_R3A2 contains the following fields:

Fields Data Element Short Description

TASK CHAR1 I, C, D for Insert, Change or Delete

DATA_KEY ZSAPPRODUCT Character field length 10

SELLER CHAR40 Character, 40-figure

CTR_DATE DATS Field, type DATS

SELLERX CHAR1 X-Flag

CTR_DATEX CHAR1 X-Flag

This structure transports the data in the table ZSAPPROD to the CRM System. If the Cur-rentState Flag is not set, the task field gives instructions what to do with the data record in the CRM (Insert, Change, Delete). In the case of a change, only fields set with an X-Flag will be overwritten.

Page 17: CRM BUPA SAP

Registering Extension ModulesNoteThis procedure and other extensions to the R/3 Adapter are described in other documentation, listed in OSS Note 338623.

UseThe R/3 Adapter and the R/3 Customer Master use the BTE technique (Business Transaction Event, derived from Open FI) for extensions. To do this new function modules are entered for process interfaces in the table TPS* and for event interfaces in the table TBE*.

Warning: The interface definition of these function modules given in the examples below can be different in your system, dependent on your release and plugin. The best choice is to use the interface definition of the caller function module. It has the naming convention:

OPEN_FI_PERFORM_<Interface>_<P|E>

Table TBE34 defines Events (several implementations possible) and table TPS34 defines Pro-cesses (only one implementation possible).

Available process interfaces are:

System Reg. Interface Description

R/3 TBE34 00001310 Processing a customer master extension

R/3 TBE34 00001320 Updating added customer master tables

R/3 TBE34 00001330 Displaying the customer master menu

R/3 TBE34 DE_AALE After Inbound updating of the customer master via ALE

R/3 TPS34 CRM0_200 Before sending the data to the Middleware

R/3 TBE31 00001321 Calling the R/3 Adapter from the customer mas-ter

CRM TPS34 SMOUTIL2 Outbound from the Middleware to the R/3 Adapter

CRM TPS34 SMOUTIL3 Inbound Middleware from the R/3 Adapter

Procedure1. Start transaction SM30 (Menu path System Services Table maintenance Ex-

tended table maintenance.

2. Enter Table/View TPS*/TBE*.

3. Click on the Maintain button.

4. Enter New entries for the process interface you want or change existing data as follows:

Parameter Value

Process Name of the process interface (e.g. SMOUTIL1)

Page 18: CRM BUPA SAP

Country Initial

Application Initial

Function Module E.g. Z_USER_EXIT_BAPI_CRM_SAVE

Product Entry from TBE24

If there are no entries in table TBE24, then you must create them. Table TBE24 controls whether customer enhancements are active or not:

Parameter Value

Product (Any unique name)

Text (Description)

RFC Destination Initial

Active X(This activates the appropriate extensions in the ta-ble TPS34)

5. Click on the Save button and leave the transaction.

You will find further information in the [R/3 Adapter Extension].

You must make the following entries for the extension scenarios on offer:

Sys. Interface Function Module Extension Scenario

R/3 00001310 Z_OPFI1310 Business Partner / Customer Master

R/3 00001320 Z_OPFI1320 Business Partner / Customer Master

R/3 00001330 Z_OPFI1330 Business Partner / Customer Master

R/3 DE_AALE Z_OPFIDE_AALE Business Partner / Customer Master

R/3 00001321 Z_OPFI1321 Business Partner / Customer Master, remove PI_BP_CUS-TOMER_BTE_1321 at all costs!

R/3 CRM0_200 Z_OPFICRM0_200 All

CRM SMOUTIL2 Z_OPFI_SMOUTIL2 All

CRM SMOUTIL3 Z_OPFI_SMOUTIL3 All

Page 19: CRM BUPA SAP

R/3 Customer Master-UseUseThe OPEN-FI extension technique allows you to add new components to the R/3 Customer Master. It is possible to make extensions to the Customer Master table KNA1 as well as to added user-defined tables.

The maintenance of user-defined data takes place in its own screen. You can call this via the menu in transactions VD01, VD02 and VD03.

Example (Business Partner New Field for BUT000)Create a function group for the function module of the application extension with the following instructions in the TOP-Include:

CONSTANTS: gc_actvt_delete LIKE bus000flds-char1 VALUE 'D', gc_actvt_insert LIKE bus000flds-char1 VALUE 'I', gc_actvt_update LIKE bus000flds-char1 VALUE 'U', gc_aktyp_change LIKE tbz0k-aktyp VALUE '02', gc_aktyp_display LIKE tbz0k-aktyp VALUE '03', gc_fstat_optional LIKE bus000flds-fldstat VALUE '.', gc_fstat_required LIKE bus000flds-fldstat VALUE '+', gc_fstat_display LIKE bus000flds-fldstat VALUE '*', gc_fstat_nonspecif LIKE bus000flds-fldstat VALUE '', gc_fstat_suppressed LIKE bus000flds-fldstat VALUE '-', gc_messg_cancel LIKE mesg-msgty VALUE 'A', gc_messg_error LIKE mesg-msgty VALUE 'E', gc_x LIKE boole-boole VALUE 'X'.

* ----------- generalTABLES: kna1, knb1, knvv, zsapprod.

DATA: gv_aktyp LIKE t020-aktyp, gv_kunnr LIKE kna1-kunnr, gv_bukrs LIKE knb1-bukrs, gv_vkorg LIKE knvv-vkorg, gv_vtweg LIKE knvv-vtweg, gv_spart LIKE knvv-spart.

DATA: gv_ok_code LIKE sy-tcode, gv_ok_save LIKE sy-tcode.

DATA: gf_xchgn TYPE flag, gf_dynpstart TYPE flag, gf_firstcall TYPE flag.

Page 20: CRM BUPA SAP

* Current memoryDATA: gs_kna1o LIKE kna1, " old, global for extension gs_kna1 LIKE kna1. " global for extension

* -------- Business Partner - New tables

CONSTANTS: lc_custab1_bupa LIKE cdpos-tabname VALUE 'ZSAPPROD'.

* Current memoryDATA: BEGIN OF lt_ctab OCCURS 0. " new, local INCLUDE STRUCTURE zsapprod.DATA: xmark LIKE boole-boole, END OF lt_ctab.

DATA: gt_ctab LIKE ZSAPPROD_KZ OCCURS 0 WITH HEADER LINE. "newDATA: gt_ctabo LIKE ZSAPPROD_KZ OCCURS 0 WITH HEADER LINE. "old

* ControlsCONTROLS: tc_ctab TYPE TABLEVIEW USING SCREEN 0001.DATA gv_tclin TYPE sy-index.DATA: gs_tccol LIKE LINE OF tc_ctab-cols.

The following function module adds the new components to the Customer Master:

FUNCTION Z_OPFI1330.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_SPRAS) LIKE SY-LANGU*" EXPORTING*" VALUE(E_FTEXT) LIKE FTEXTS-FTEXT*"----------------------------------------------------------------------

* Register this function in table TBE34

E_FTEXT = 'Customer Extension'.

ENDFUNCTION.

The following module calls the user-defined screen and supplies it with initial data. In the case of a change, a change indicator is set that ensures the call for the update event (see below).

FUNCTION z_opfi1310.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_KUNNR) LIKE KNA1-KUNNR*" VALUE(I_BUKRS) LIKE KNB1-BUKRS OPTIONAL*" VALUE(I_VKORG) LIKE KNVV-VKORG OPTIONAL

Page 21: CRM BUPA SAP

*" VALUE(I_VTWEG) LIKE KNVV-VTWEG OPTIONAL*" VALUE(I_SPART) LIKE KNVV-SPART OPTIONAL*" VALUE(I_AKTYP) LIKE OFIWA-AKTYP OPTIONAL*" EXPORTING*" VALUE(E_XCHNG) LIKE BOOLE-BOOLE*"----------------------------------------------------------------------

* Register this function in table TBE34

DATA lf_chg(1) TYPE c.

* 1. write parameter to global memory gv_kunnr = i_kunnr. gv_bukrs = i_bukrs. gv_vkorg = i_vkorg. gv_vtweg = i_vtweg. gv_spart = i_spart. gv_aktyp = i_aktyp.* I_AKTYP:* V - Verändern / Change* A - Anzeigen / Display* H - Hinzufügen / Create

* 2. read current state IF gf_firstcall IS INITIAL. IF gv_aktyp = 'V' OR gv_aktyp = 'A'.

* (Business Partner - New fields) SELECT SINGLE * FROM kna1 INTO gs_kna1 WHERE kunnr = gv_kunnr. gs_kna1o = gs_kna1.

* (Business Partner - New Tables) SELECT * FROM zsapprod INTO CORRESPONDING FIELDS OF TABLE gt_ctab WHERE partner = gv_kunnr. gt_ctabo[] = gt_ctab[]. ENDIF. gf_firstcall = 'X'.

ENDIF.

* 3. Call customer screen CALL SCREEN '0001'.

* 4. Return wether customer data were changed or not CLEAR gf_xchgn.

* (business partner - new fields) IF gs_kna1o <> gs_kna1. gf_xchgn = 'X'. ENDIF.

* (Business Partner - New tables) SORT gt_ctab. SORT gt_ctabo. CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES' EXPORTING

Page 22: CRM BUPA SAP

check_indicator = 'X' tablename = lc_custab1_bupa IMPORTING result = lf_chg TABLES table_new = gt_ctab table_old = gt_ctabo EXCEPTIONS nametab_error = 1 OTHERS = 2. IF sy-subrc <> 0. ENDIF.

IF lf_chg = 'F'. gf_xchgn = 'X'. ENDIF.

e_xchng = gf_xchgn.

ENDFUNCTION.

The following module ensures a post-run update of the user-defined fields in table KNA1:

FUNCTION zkna1_update.*"----------------------------------------------------------------------*"*"Update function module:*"*"*"Local interface:*" IMPORTING*" VALUE(I_KUNNR) LIKE KNA1-KUNNR*" VALUE(S_KNA1) LIKE KNA1 STRUCTURE KNA1*"----------------------------------------------------------------------

* Add all your fields appended to KNA1 here!

SELECT SINGLE * FROM kna1 WHERE kunnr = i_kunnr. IF sy-subrc = 0. UPDATE kna1 SET zzsapcustmr = s_kna1-zzsapcustmr zzadrkind = s_kna1-zzadrkind WHERE kunnr = i_kunnr. IF sy-dbcnt NE 1. MESSAGE a802(f2) WITH 'KNA1'. ENDIF. ENDIF.

ENDFUNCTION.

The following module is the update task for a user-defined table:

FUNCTION zsapprod_update.*"----------------------------------------------------------------------*"*"Update function module:*"*"*"Local interface:*" TABLES*" T_ZSAPPROD STRUCTURE ZSAPPROD_KZ

Page 23: CRM BUPA SAP

*" T_ZSAPPROD_OLD STRUCTURE ZSAPPROD_KZ*"----------------------------------------------------------------------*------ Local data declaration -------------------------------------- DATA: lt_zsapprod LIKE zsapprod OCCURS 0 WITH HEADER LINE.

*------ Insert new data sentences ------------------------------------- REFRESH lt_zsapprod. LOOP AT t_zsapprod WHERE kz = gc_actvt_insert. lt_zsapprod = t_zsapprod. APPEND lt_zsapprod. ENDLOOP. INSERT zsapprod FROM TABLE lt_zsapprod ACCEPTING DUPLICATE KEYS. IF sy-subrc <> 0. UPDATE zsapprod FROM TABLE lt_zsapprod. ENDIF.

*------ Change existing data sentences --------------------------------- REFRESH lt_zsapprod. LOOP AT t_zsapprod WHERE kz = gc_actvt_update. lt_zsapprod = t_zsapprod. APPEND lt_zsapprod. ENDLOOP. UPDATE zsapprod FROM TABLE lt_zsapprod. IF sy-subrc <> 0. INSERT zsapprod FROM TABLE lt_zsapprod ACCEPTING DUPLICATE KEYS. ENDIF.

*------ Delete existing data sentences -------------------------------- REFRESH lt_zsapprod. LOOP AT t_zsapprod_old WHERE kz = gc_actvt_delete. lt_zsapprod = t_zsapprod_old. APPEND lt_zsapprod. ENDLOOP. DELETE zsapprod FROM TABLE lt_zsapprod.

ENDFUNCTION.

This module returns the contents of the global application function group memory for the user-defined table in a data exchange:

FUNCTION ZSAPPROD_CALLBACK .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(IV_PARTNER) TYPE ZSAPPROD-PARTNER*" TABLES*" T_ZSAPPROD STRUCTURE ZSAPPROD_KZ*"----------------------------------------------------------------------

REFRESH: t_zsapprod.

* Read from global memory LOOP AT gt_ctab.

Page 24: CRM BUPA SAP

IF iv_partner IS INITIAL OR gt_ctab-partner = iv_partner. APPEND gt_ctab TO t_zsapprod. ENDIF. ENDLOOP.

LOOP AT gt_ctabo WHERE kz = 'D'. IF iv_partner IS INITIAL OR gt_ctabo-partner = iv_partner. APPEND gt_ctabo TO t_zsapprod. ENDIF. ENDLOOP.

ENDFUNCTION.

This module returns the contents of the global application function group memory for the KNA1 extension in a data exchange:

FUNCTION zkna1_callback.*"----------------------------------------------------------------------*"*"Update function module:*"*"*"Local interface:*" EXPORTING*" REFERENCE(ES_KNA1) TYPE KNA1*" REFERENCE(ES_KNA1_OLD) TYPE KNA1*"----------------------------------------------------------------------

es_kna1 = gs_kna1. es_kna1_old = gs_kna1o.

ENDFUNCTION.

This module writes to the global application function group memory for the KNA1 extension:

FUNCTION zkna1_fill.*"----------------------------------------------------------------------*"*"Update function module:*"*"*"Local interface:*" IMPORTING*" REFERENCE(IS_KNA1) TYPE KNA1 OPTIONAL*" REFERENCE(IS_KNA1_OLD) TYPE KNA1 OPTIONAL*"----------------------------------------------------------------------

IF NOT is_kna1 IS INITIAL. gs_kna1 = is_kna1. ENDIF.

IF NOT is_kna1_old IS INITIAL. gs_kna1o = is_kna1_old. ENDIF.

ENDFUNCTION.

Page 25: CRM BUPA SAP

This module determines the change indicator for the customer enhancement:

FUNCTION zcusext_changed.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" REFERENCE(EV_CHANGED) TYPE FLAG*"----------------------------------------------------------------------

ev_changed = gf_xchgn.

ENDFUNCTION.

The following form routines are necessary for the maintenance of customer data via field en-tries and table control:

*&---------------------------------------------------------------------**& Form tc_ctab_modify*&---------------------------------------------------------------------** Modify current global table from table control*&---------------------------------------------------------------------*

FORM tc_ctab_modify. DATA tc_lines TYPE i.

MODIFY lt_ctab INDEX tc_ctab-current_line. IF sy-subrc <> 0. DESCRIBE TABLE lt_ctab LINES tc_lines. tc_lines = tc_lines + 1. lt_ctab-client = sy-mandt. lt_ctab-partner = gv_kunnr. INSERT lt_ctab INDEX tc_lines. ENDIF.

ENDFORM. " tc_ctab_modify

*&---------------------------------------------------------------------**& Form tc_ctab_clean*&---------------------------------------------------------------------*FORM tc_ctab_clean. LOOP AT lt_ctab WHERE sapprod IS INITIAL. DELETE lt_ctab. ENDLOOP.ENDFORM. " tc_ctab_clean

*&---------------------------------------------------------------------**& Form copy_global_to_local*&---------------------------------------------------------------------** copy global FuGr data to local dynpro data*----------------------------------------------------------------------*FORM copy_global_to_local.

* (Business Partner - New fields) kna1 = gs_kna1.

* (Business Partner - New tables)

Page 26: CRM BUPA SAP

REFRESH lt_ctab. LOOP AT gt_ctab. CLEAR lt_ctab. MOVE-CORRESPONDING gt_ctab TO lt_ctab. APPEND lt_ctab. ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------**& Form copy_local_to_global*&---------------------------------------------------------------------** copy local screen data to global FuGr data*----------------------------------------------------------------------*FORM copy_local_to_global.

* (Business Partner - New fields) gs_kna1 = kna1.

* (Business Partner - New tables) REFRESH gt_ctab. LOOP AT lt_ctab. CLEAR gt_ctab. MOVE-CORRESPONDING lt_ctab TO gt_ctab. APPEND gt_ctab. ENDLOOP.

ENDFORM.

Next, create a screen with the number ’0001’. The technical function of this will be explained in greater detail in the CRM unit „Creating a screen“. The screen should contain the fields KNA1-ZZSAPCUSTMR, KNA1-ZZADRKIND and GV_OK_CODE.

If a user-defined table should also be implemented (in this case ZSAPPROD), add a table control with the name TC_CTAB too. Its fields are mapped to the structure LT_CTAB, i.e.: XMARK, SAPPROD, SELLER and CTR_DATE.

In addition you need a status (’001’) with command codes ’BACK’ and ’CANCEL’ and a title (’001’).

The flow logic for the screen looks something like this:

PROCESS BEFORE OUTPUT. module status_0001. LOOP WITH CONTROL tc_ctab. MODULE tc_ctab_init. ENDLOOP.

PROCESS AFTER INPUT. LOOP WITH control tc_ctab. module TC_CTAB_MODIFY. ENDLOOP. module tc_ctab_clean.

MODULE USER_COMMAND_0001.

*&---------------------------------------------------------------------**& Module STATUS_0001 OUTPUT

Page 27: CRM BUPA SAP

*&---------------------------------------------------------------------*MODULE status_0001 OUTPUT. SET PF-STATUS '001'. SET TITLEBAR '001'. DESCRIBE TABLE lt_ctab LINES gv_tclin. tc_ctab-lines = gv_tclin.

IF gf_dynpstart IS INITIAL. " start only once

PERFORM copy_global_to_local.

IF gv_aktyp = 'A'. " Set display-only mode LOOP AT SCREEN. screen-input = '0'. MODIFY SCREEN. ENDLOOP.

LOOP AT tc_ctab-cols INTO gs_tccol. gs_tccol-screen-input = '0'. MODIFY tc_ctab-cols FROM gs_tccol. ENDLOOP. ELSE. " Set modify mode LOOP AT SCREEN. screen-input = '1'. MODIFY SCREEN. ENDLOOP.

LOOP AT tc_ctab-cols INTO gs_tccol. gs_tccol-screen-input = '1'. MODIFY tc_ctab-cols FROM gs_tccol. ENDLOOP. ENDIF.

gf_dynpstart = 'X'. ENDIF.

ENDMODULE. " STATUS_0001 OUTPUT

*&---------------------------------------------------------------------**& Module TC_CTAB_init OUTPUT*&---------------------------------------------------------------------*MODULE tc_ctab_init OUTPUT. READ TABLE lt_ctab INDEX tc_ctab-current_line.ENDMODULE. " TC_CTAB_init OUTPUT

*&---------------------------------------------------------------------**& Module USER_COMMAND_0001 INPUT*&---------------------------------------------------------------------*MODULE user_command_0001 INPUT. gv_ok_save = gv_ok_code. CLEAR gv_ok_code. CASE gv_ok_save.

WHEN 'BACK'. CLEAR gf_dynpstart. PERFORM copy_local_to_global. LEAVE TO SCREEN 0. WHEN 'CANCEL'. CLEAR gf_dynpstart.

Page 28: CRM BUPA SAP

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0001 INPUT

*---------------------------------------------------------------------** MODULE TC_CTAB_MODIFY INPUT **---------------------------------------------------------------------*MODULE tc_ctab_modify INPUT. PERFORM tc_ctab_modify.ENDMODULE.

*&---------------------------------------------------------------------**& Module tc_ctab_clean INPUT*&---------------------------------------------------------------------*module tc_ctab_clean input. PERFORM tc_ctab_clean.endmodule. " tc_ctab_clean INPUT

Finally, the update of the customer tables and fields must be implemented. This takes place in event 1320, which is called after the standard update call. In the following module the data from the global function groups is formatted and transferred to the update task in the case of a data change.

FUNCTION z_opfi1320.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_KUNNR) LIKE KNA1-KUNNR*" VALUE(I_BUKRS) LIKE KNB1-BUKRS OPTIONAL*" VALUE(I_VKORG) LIKE KNVV-VKORG OPTIONAL*" VALUE(I_VTWEG) LIKE KNVV-VTWEG OPTIONAL*" VALUE(I_SPART) LIKE KNVV-SPART OPTIONAL*" VALUE(I_XVBUP) LIKE OFIWA-XVBUP DEFAULT 'X'*" VALUE(I_AKTYP) LIKE OFIWA-AKTYP DEFAULT 'V'*"----------------------------------------------------------------------

* Register this function in table TBE34

DATA lf_result(1) TYPE c.

* -------- Business Partner - New fields IF gs_kna1o <> gs_kna1. CALL FUNCTION 'ZKNA1_UPDATE' IN UPDATE TASK EXPORTING i_kunnr = i_kunnr s_kna1 = gs_kna1. ENDIF.

* -------- Business Partner - New tables SORT gt_ctab. SORT gt_ctabo. CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES' EXPORTING tablename = lc_custab1_bupa

Page 29: CRM BUPA SAP

IMPORTING result = lf_result TABLES table_new = gt_ctab table_old = gt_ctabo EXCEPTIONS nametab_error = 1 OTHERS = 2. IF sy-subrc <> 0.*TODO: Errorhandling ENDIF.

IF lf_result = 'F'. CALL FUNCTION 'ZSAPPROD_UPDATE' IN UPDATE TASK TABLES t_zsapprod = gt_ctab t_zsapprod_old = gt_ctabo. ENDIF.

ENDFUNCTION.

Page 30: CRM BUPA SAP

R/3 Customer Master Data ExchangeUseThis document describes the extensions you must program in order to connect a customer master application running in an R/3 system with the CRM.

The Customer Master is supplied with data in the Inbound via the ALE interface and thereby via batch input. The Event DE_AALE is then called in order to unpack the user-defined fields and tables from the BAPIMTCS containers and call for them to be updated.

You can subscribe one function module to this event only. If necessary, write a higher-level module that calls several special modules one after another.

Then the added fields and tables are packed in a BAPIMTCS container, which is sent to the CRM. The data must not be read by SELECT from the databank (except during initial down-load) because no COMMIT has yet taken place. Instead, it is obtained via callback from the global memory of the application function group.

It is often the case that the R/3 customer master has already been extended in some different manner to that described here, and now in addition a data exchange with the CRM needs to be made. The existing extension must then be adapted to provide a callback module that makes available the data for the data exchange.

Note:

Ensure that the name of your BAPIMTCS container exists with the same definition in the ABAP Dictionary of the CRM and the R/3. Refer to this BAPIMTCS-names only in capital let-ters in your ABAP coding!

For BUT000 and BUT020 extensions, the names of the BAPIMTCS containers must be the same as the data types of he append-structures in the extended CRM Bdoc structure. This is necessary to enable automatical packing and depacking. So you must adapt the names ZADR_KIND and ZSAPCUSTOMER in your projects.

Example (All Business Partner Scenarios)The R/3 Adapter call must be screened in the Outbound so that a download to the CRM can take place regardless of exclusive changes to user-defined fields in the application, or non-changes to standard fields. In this case the old status (i.e. before the application call) of the standard fields in memory are changed so that the R/3 adapter assumes a change has been made and initiates a download.

To make sure that the new function module will be called, the calling function module OPEN_FI_PERFORM_00001321_E must be changed. For this purpose just uncomment the first CHECK-statement in it.

Warning: Strictly speaking this represents a modification, because standard coding is changed, the module is registered in table TBE31 and the standard module PI_BP_CUS-

Page 31: CRM BUPA SAP

TOMER_BTE_1321 is removed from this table. You should check the correct status after an up-grade!

Create a function group for the function module of the data exchange with the following in-structions in the TOP-Include:

TYPE-POOLS busei.

* Macro MOVE_CASTING *************************************FIELD-SYMBOLS: <unicode_x1> TYPE x, <unicode_x2> TYPE x.DEFINE move_casting. assign &1 to <unicode_x1> casting. assign &2 to <unicode_x2> casting. move <unicode_x1> to <unicode_x2>.END-OF-DEFINITION.

CONSTANTS: lc_custab1_bupa LIKE cdpos-tabname VALUE 'ZSAPPROD'.

After successfully updating the customer master tables, the following function module updates the extensions to the KNA1 and user-defined tables.

FUNCTION z_opfide_aale .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(IS_COMPLEX_STRUCTURE) TYPE BUSEI_COM_EXTERN*" VALUE(IS_COMPLEX_STRUCTURE_RELATIONS) TYPE BUSEI_RCOM_EXTERN*" VALUE(IV_CUSTOMER) LIKE KNA1-KUNNR*" TABLES*" CT_IDOC_CONTROL STRUCTURE EDIDC*" CT_IDOC_DATA STRUCTURE EDIDD*" IT_BAPIMTCS STRUCTURE BAPIMTCS*"----------------------------------------------------------------------

* Register this function in table TBE34

DATA: ls_kna1 TYPE kna1, ls_bapimtcs TYPE bapimtcs, lv_bpartnerguid TYPE char32.* -------- Business Partner - New Fields in BUT000 DATA: ls_zsapcustomer TYPE zsapcustomer.* -------- Business Partner - New Fields in BUT020 DATA: ls_zadr_kind TYPE zadr_kind, ls_bupa_addresses TYPE busei_com_bupa_address, lv_addressguid TYPE char32, lv_bpguid_adressguid TYPE char64.* -------- Business Partner - New Tables DATA: ls_zsprd_r3a1 TYPE zsprd_r3a1, ls_zsprd_r3a2 TYPE zsprd_r3a2, ls_zsapprod TYPE zsapprod_kz, lt_zsapprod LIKE zsapprod_kz OCCURS 0 WITH HEADER LINE, lt_zsapprodo LIKE zsapprod_kz OCCURS 0 WITH HEADER LINE, lf_currentstate TYPE char1,

Page 32: CRM BUPA SAP

lf_kz TYPE char1, lv_tabix LIKE sy-tabix.

lv_bpartnerguid = is_complex_structure-header-object_instance-bpartnerguid.

SELECT SINGLE * FROM kna1 INTO ls_kna1 WHERE kunnr = iv_customer.

* -------- Business Partner - New Fields in BUT000 IF NOT ls_kna1 IS INITIAL.* Get automatically created BAPIMTCS for BUT000-Append READ TABLE it_bapimtcs WITH KEY tabname = 'ZSAPCUSTOMER' relkey = lv_bpartnerguid.

IF sy-subrc = 0. move_casting it_bapimtcs-data ls_zsapcustomer. MOVE-CORRESPONDING ls_zsapcustomer TO ls_kna1. ENDIF.

ENDIF.

* -------- Business Partner - New Fields in BUT020 IF NOT ls_kna1 IS INITIAL.

* Get Adressguid LOOP AT is_complex_structure-central_data-address-addresses INTO ls_bupa_addresses.

IF ls_bupa_addresses-data-postal-data-stand_ard = 'X'. lv_addressguid = ls_bupa_addresses-data_key-guid. EXIT. ENDIF.

ENDLOOP.

MERGE lv_bpartnerguid lv_addressguid INTO lv_bpguid_adressguid.

* Get automatically created BAPIMTCS for BUT020-Append READ TABLE it_bapimtcs WITH KEY tabname = 'ZADR_KIND' relkey = lv_bpguid_adressguid. IF sy-subrc = 0. move_casting it_bapimtcs-data ls_zadr_kind. MOVE-CORRESPONDING ls_zadr_kind TO ls_kna1. ENDIF.

ENDIF.

* -------- Business Partner - New Fields in general IF NOT ls_kna1 IS INITIAL.

* Call Update Function CALL FUNCTION 'ZKNA1_UPDATE' EXPORTING i_kunnr = iv_customer s_kna1 = ls_kna1.

ENDIF.

Page 33: CRM BUPA SAP

* Errors: PI_BP_COLLECT_MESSAGE_FOR_BP

* -------- Business Partner - New Tables

* get old status SELECT * FROM zsapprod INTO CORRESPONDING FIELDS OF TABLE lt_zsapprodo WHERE partner = iv_customer. CLEAR ls_zsapprod. MODIFY lt_zsapprodo FROM ls_zsapprod TRANSPORTING client WHERE NOT client IS INITIAL.

* Get current-state flag READ TABLE it_bapimtcs WITH KEY tabname = 'ZSPRD_R3A1' relkey = lv_bpartnerguid. IF sy-subrc = 0. move_casting it_bapimtcs-data ls_zsprd_r3a1. lf_currentstate = ls_zsprd_r3a1-curstat. ENDIF.

* Add old status to new if no current state given IF lf_currentstate IS INITIAL AND NOT ls_kna1 IS INITIAL. lt_zsapprod[] = lt_zsapprodo[]. ENDIF.

IF ls_kna1 IS INITIAL.* Leave new status empty to delete everything,* because KNA1 was deleted.

ELSE.* Create new status regarding current state, task flags* and x-flags LOOP AT it_bapimtcs WHERE tabname = 'ZSPRD_R3A2' AND relkey = lv_bpartnerguid.

* Copy data from BAPIMTCS CLEAR: ls_zsprd_r3a2, ls_zsapprod. move_casting it_bapimtcs-data ls_zsprd_r3a2. CLEAR ls_zsapprod-client. ls_zsapprod-partner = iv_customer. ls_zsapprod-sapprod = ls_zsprd_r3a2-data_key. ls_zsapprod-seller = ls_zsprd_r3a2-seller. ls_zsapprod-ctr_date = ls_zsprd_r3a2-ctr_date. lf_kz = ls_zsprd_r3a2-task.

* Add data to new status if current state is given IF NOT lf_currentstate IS INITIAL AND lf_kz <> 'D'. APPEND ls_zsapprod TO lt_zsapprod. ELSE.* Otherwise: Read existing data with same key CLEAR: lt_zsapprod, lv_tabix. READ TABLE lt_zsapprod WITH KEY sapprod = ls_zsapprod-sapprod.

Page 34: CRM BUPA SAP

IF sy-subrc = 0. lv_tabix = sy-tabix. ENDIF.

* If fields are not sent, use initial or old value IF ls_zsprd_r3a2-ctr_datex IS INITIAL. ls_zsapprod-ctr_date = lt_zsapprod-ctr_date. ENDIF.

IF ls_zsprd_r3a2-sellerx IS INITIAL. ls_zsapprod-seller = lt_zsapprod-seller. ENDIF.

* If data should be updated or inserted: add/modify to new status IF lf_kz CA 'IUC' OR lf_kz IS INITIAL. IF lv_tabix IS INITIAL. APPEND ls_zsapprod TO lt_zsapprod. ELSE. MODIFY lt_zsapprod FROM ls_zsapprod INDEX lv_tabix. ENDIF.* If data should be deleted: delete from new status ELSEIF lf_kz = 'D'. DELETE lt_zsapprod WHERE sapprod = ls_zsapprod-sapprod. ENDIF. ENDIF.

ENDLOOP.

ENDIF.

* Prepare tables for update SORT lt_zsapprod. SORT lt_zsapprodo. CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES' EXPORTING tablename = lc_custab1_bupa TABLES table_new = lt_zsapprod table_old = lt_zsapprodo EXCEPTIONS nametab_error = 1 OTHERS = 2. IF sy-subrc <> 0.*TODO: Errorhandling ENDIF.

* Update table CALL FUNCTION 'ZSAPPROD_UPDATE' TABLES t_zsapprod = lt_zsapprod t_zsapprod_old = lt_zsapprodo.

ENDFUNCTION.

The following module implements the screening of the R/3 Adapter call:

FUNCTION z_opfi1321.

Page 35: CRM BUPA SAP

*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_KNA1) LIKE KNA1 STRUCTURE KNA1 OPTIONAL*" VALUE(I_KNA1_OLD) LIKE KNA1 STRUCTURE KNA1 OPTIONAL*" VALUE(I_KNB1) LIKE KNB1 STRUCTURE KNB1 OPTIONAL*" VALUE(I_KNB1_OLD) LIKE KNB1 STRUCTURE KNB1 OPTIONAL*" VALUE(I_KNVV) LIKE KNVV STRUCTURE KNVV OPTIONAL*" VALUE(I_KNVV_OLD) LIKE KNVV STRUCTURE KNVV OPTIONAL*" VALUE(UPD_KNA1) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNAS) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNAT) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNB1) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNB5) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNBK) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNBW) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNEX) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVA) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVD) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVI) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVK) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVL) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVP) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVS) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNVV) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_KNZA) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(UPD_VCKUN) LIKE CDPOS-CHNGIND OPTIONAL*" VALUE(I_ADD_ON_DATA) LIKE CRMCUSTADD STRUCTURE CRMCUSTADD*" OPTIONAL*" VALUE(UPD_TIBAN) LIKE CDPOS-CHNGIND OPTIONAL*" TABLES*" T_XKNAS STRUCTURE FKNAS OPTIONAL*" T_YKNAS STRUCTURE FKNAS OPTIONAL*" T_XKNAT STRUCTURE FKNAT OPTIONAL*" T_YKNAT STRUCTURE FKNAT OPTIONAL*" T_XKNB5 STRUCTURE FKNB5 OPTIONAL*" T_YKNB5 STRUCTURE FKNB5 OPTIONAL*" T_XKNBK STRUCTURE FKNBK OPTIONAL*" T_YKNBK STRUCTURE FKNBK OPTIONAL*" T_XKNBW STRUCTURE FKNBW OPTIONAL*" T_YKNBW STRUCTURE FKNBW OPTIONAL*" T_XKNEX STRUCTURE FKNEX OPTIONAL*" T_YKNEX STRUCTURE FKNEX OPTIONAL*" T_XKNVA STRUCTURE FKNVA OPTIONAL*" T_YKNVA STRUCTURE FKNVA OPTIONAL*" T_XKNVD STRUCTURE FKNVD OPTIONAL*" T_YKNVD STRUCTURE FKNVD OPTIONAL*" T_XKNVI STRUCTURE FKNVI OPTIONAL*" T_YKNVI STRUCTURE FKNVI OPTIONAL*" T_XKNVK STRUCTURE FKNVK OPTIONAL*" T_YKNVK STRUCTURE FKNVK OPTIONAL*" T_XKNVL STRUCTURE FKNVL OPTIONAL*" T_YKNVL STRUCTURE FKNVL OPTIONAL*" T_XKNVP STRUCTURE FKNVP OPTIONAL*" T_YKNVP STRUCTURE FKNVP OPTIONAL*" T_XKNVS STRUCTURE FKNVS OPTIONAL*" T_YKNVS STRUCTURE FKNVS OPTIONAL*" T_UPD_TXT STRUCTURE PITEXTUPD OPTIONAL*" T_XTIBAN STRUCTURE ITIBAN OPTIONAL*" T_YTIBAN STRUCTURE ITIBAN OPTIONAL*"----------------------------------------------------------------------

Page 36: CRM BUPA SAP

* register this function in Table TBE31

DATA: ls_kna1 LIKE kna1, ls_kna1_old LIKE kna1, ls_kna1_tmp LIKE kna1, lf_xchgn TYPE flag, lt_adrc TYPE adrc_tab, ls_adrc TYPE vadrc, ls_addr1_val TYPE addr1_val, ls_addr_sel TYPE addr1_sel.

* Get KNA1 extensions via Callback CALL FUNCTION 'ZKNA1_CALLBACK' IMPORTING es_kna1 = ls_kna1.

* First case: SAP data was not changed* => Exit if customer data was also not changed* => Fill KNA1 - otherwise KUNNR will be empty! IF upd_kna1 = space AND upd_knas = space AND upd_knat = space AND upd_knb1 = space AND upd_knb5 = space AND upd_knbk = space AND upd_knbw = space AND upd_knex = space AND upd_knva = space AND upd_knvd = space AND upd_knvi = space AND upd_knvk = space AND upd_knvl = space AND upd_knvp = space AND upd_knvs = space AND upd_knvv = space AND upd_knza = space.

CALL FUNCTION 'ZCUSEXT_CHANGED' IMPORTING ev_changed = lf_xchgn.

CHECK lf_xchgn NE space.

ls_kna1_old = ls_kna1.

* Cheat download routine and modify old status in memory IF ls_kna1_old-name2 IS INITIAL. ls_kna1_old-name2 = 'X'. ELSE. CLEAR ls_kna1_old-name2. ENDIF.

ls_addr_sel-addrnumber = ls_kna1-adrnr.

CALL FUNCTION 'ADDR_GET' EXPORTING address_selection = ls_addr_sel IMPORTING address_value = ls_addr1_val

Page 37: CRM BUPA SAP

EXCEPTIONS parameter_error = 1 address_not_exist = 2 version_not_exist = 3 internal_error = 4 OTHERS = 5.

IF sy-subrc = 0. MOVE-CORRESPONDING ls_addr1_val TO ls_adrc. APPEND ls_adrc TO lt_adrc.

CALL FUNCTION 'PI_BP_ADDR_APPEND_GLOBAL_MEM' EXPORTING it_xadrc = lt_adrc. ENDIF.

* Second case: SAP data was changed,* but not customer extension* => Fill extension's global KNA1 memory, it's empty ELSEIF ls_kna1 IS INITIAL. ls_kna1 = i_kna1. ls_kna1_old = i_kna1_old.

CALL FUNCTION 'ZKNA1_FILL' EXPORTING is_kna1 = ls_kna1 is_kna1_old = ls_kna1_old.

* Third case: SAP and customer data were changed* => Rebuild standard + ext global KNA1 memory, it's not up to date! ELSE. ls_kna1_tmp = ls_kna1. ls_kna1 = i_kna1. ls_kna1_old = i_kna1_old.

* TODO: Add your fields here!!! ls_kna1-zzsapcustmr = ls_kna1_tmp-zzsapcustmr. ls_kna1-zzadrkind = ls_kna1_tmp-zzadrkind.

CALL FUNCTION 'ZKNA1_FILL' EXPORTING is_kna1 = ls_kna1.

ENDIF.

* Call SAP Standard

CALL FUNCTION 'PI_BP_CUSTOMER_BTE_1321' EXPORTING i_kna1 = ls_kna1 i_kna1_old = ls_kna1_old i_knb1 = i_knb1 i_knb1_old = i_knb1_old i_knvv = i_knvv i_knvv_old = i_knvv_old upd_kna1 = upd_kna1 upd_knas = upd_knas upd_knat = upd_knat upd_knb1 = upd_knb1 upd_knb5 = upd_knb5

Page 38: CRM BUPA SAP

upd_knbk = upd_knbk upd_knbw = upd_knbw upd_knex = upd_knex upd_knva = upd_knva upd_knvd = upd_knvd upd_knvi = upd_knvi upd_knvk = upd_knvk upd_knvl = upd_knvl upd_knvp = upd_knvp upd_knvs = upd_knvs upd_knvv = upd_knvv upd_knza = upd_knza upd_vckun = upd_vckun i_add_on_data = i_add_on_data TABLES t_xknas = t_xknas t_yknas = t_yknas t_xknat = t_xknat t_yknat = t_yknat t_xknb5 = t_xknb5 t_yknb5 = t_yknb5 t_xknbk = t_xknbk t_yknbk = t_yknbk t_xknbw = t_xknbw t_yknbw = t_yknbw t_xknex = t_xknex t_yknex = t_yknex t_xknva = t_xknva t_yknva = t_yknva t_xknvd = t_xknvd t_yknvd = t_yknvd t_xknvi = t_xknvi t_yknvi = t_yknvi t_xknvk = t_xknvk t_yknvk = t_yknvk t_xknvl = t_xknvl t_yknvl = t_yknvl t_xknvp = t_xknvp t_yknvp = t_yknvp t_xknvs = t_xknvs t_yknvs = t_yknvs t_upd_txt = t_upd_txt t_xtiban = t_xtiban t_ytiban = t_ytiban.

ENDFUNCTION.

The following module controls the treatment during download (initial and delta) independent of object class and object:

FUNCTION z_opficrm0_200.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_OBJ_CLASS) LIKE BAPICRMOBJ-OBJCLASS*" VALUE(I_OBJ_NAME) LIKE BAPICRMOBJ-OBJ_NAME*" VALUE(I_BAPICRMDH2) LIKE BAPICRMDH2*" STRUCTURE BAPICRMDH2

Page 39: CRM BUPA SAP

*" VALUE(I_KEYWORD_IN) LIKE CRM_PARA-KEYWORD_IN*" VALUE(I_CRMRFCPAR) LIKE CRMRFCPAR STRUCTURE CRMRFCPAR*" EXPORTING*" VALUE(E_DO_NOT_SEND) LIKE CRM_PARA-XFIELD*" TABLES*" T_INT_TABLES STRUCTURE BAPIMTCS*" T_BAPISTRUCT STRUCTURE BAPIMTCS*" T_MESSAGES STRUCTURE BAPICRMMSG*" T_KEY_INFO STRUCTURE BAPICRMKEY*" T_OTHER_INFO STRUCTURE BAPIEXTC*" T_BAPIIDLIST STRUCTURE BAPIIDLIST*"----------------------------------------------------------------------

* Register this funcion in Table TPS34

* I_BAPICRMDH2:* REF_ID empty, DWNLOADTYP = D: Delta-Download after Change in R/3* REF_ID filled, DWNLOADTYP = D: Delta Download after Upload from CRM* REF_ID filled, DWNLOADTYP = I: Initial Download

CASE i_obj_class.

* (Business Transaction) WHEN 'SALESDOCUMENT'.

WHEN 'BUPA'.

CASE i_obj_name.

* (Business Partner - R/3 runs Business Partner) WHEN 'BUPA_MAIN'.

* (Business Partner - R/3 runs Customer) WHEN 'CUSTOMER_MAIN'.

CALL FUNCTION 'Z_MAP_CUSTOMER_TO_MW' EXPORTING i_obj_class = i_obj_class i_obj_name = i_obj_name i_bapicrmdh2 = i_bapicrmdh2 i_keyword_in = i_keyword_in i_crmrfcpar = i_crmrfcpar IMPORTING e_do_not_send = e_do_not_send TABLES t_int_tables = t_int_tables t_bapistruct = t_bapistruct t_messages = t_messages t_key_info = t_key_info t_other_info = t_other_info t_bapiidlist = t_bapiidlist.

ENDCASE.

ENDCASE.

Page 40: CRM BUPA SAP

ENDFUNCTION.

The following module packs the added fields and tables in a BAPIMTCS container:

FUNCTION z_map_customer_to_mw .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_OBJ_CLASS) LIKE BAPICRMOBJ-OBJCLASS*" VALUE(I_OBJ_NAME) LIKE BAPICRMOBJ-OBJ_NAME*" VALUE(I_BAPICRMDH2) LIKE BAPICRMDH2 STRUCTURE BAPICRMDH2*" VALUE(I_KEYWORD_IN) LIKE CRM_PARA-KEYWORD_IN*" VALUE(I_CRMRFCPAR) LIKE CRMRFCPAR STRUCTURE CRMRFCPAR*" EXPORTING*" VALUE(E_DO_NOT_SEND) LIKE CRM_PARA-XFIELD*" TABLES*" T_INT_TABLES STRUCTURE BAPIMTCS*" T_BAPISTRUCT STRUCTURE BAPIMTCS*" T_MESSAGES STRUCTURE BAPICRMMSG*" T_KEY_INFO STRUCTURE BAPICRMKEY*" T_OTHER_INFO STRUCTURE BAPIEXTC*" T_BAPIIDLIST STRUCTURE BAPIIDLIST*"----------------------------------------------------------------------

DATA: lt_bapimtcs TYPE TABLE OF bapimtcs, ls_bapimtcs TYPE bapimtcs, ls_r3a_main TYPE r3a_main, lv_partner TYPE r3a_main-custome_no, lv_partner_guid TYPE r3a_main-partn_guid, next_free_currdno TYPE currdno VALUE 1, ls_kna1 LIKE kna1,

* -------- Business Partner - New Fields and Standard Fields ls_zsapcustomer LIKE zsapcustomer, ls_zadr_kind LIKE zadr_kind,* -------- Business Partner - New tables ls_zsprd_r3a1 TYPE zsprd_r3a1, ls_zsprd_r3a2 TYPE zsprd_r3a2, lt_zsapprod TYPE TABLE OF zsapprod_kz, ls_zsapprod TYPE zsapprod_kz, lf_currstat(1) TYPE c.

* Determine next free CURRDNO LOOP AT t_bapistruct. IF t_bapistruct-currdno > next_free_currdno. next_free_currdno = t_bapistruct-currdno + 1. ENDIF. ENDLOOP.

* get KUNNRs from BAPIMTCS LOOP AT t_bapistruct WHERE tabname = 'R3A_MAIN'.

move_casting t_bapistruct-data ls_r3a_main. lv_partner = ls_r3a_main-custome_no.

Page 41: CRM BUPA SAP

lv_partner_guid = ls_r3a_main-partn_guid.

* The logic to distinguish between delta- and initial download* that is used here works only in this given context!* In standard case you must check REF_ID and DWNLOADTYP.

* Try reading from global memory. (delta download)

CALL FUNCTION 'ZKNA1_CALLBACK' IMPORTING es_kna1 = ls_kna1.

IF ls_kna1-kunnr = lv_partner. CLEAR lf_currstat.

CALL FUNCTION 'ZSAPPROD_CALLBACK' EXPORTING iv_partner = lv_partner TABLES t_zsapprod = lt_zsapprod.

* Otherwise: Read from database (initial download) ELSE. lf_currstat = 'X'.

SELECT SINGLE * FROM kna1 INTO ls_kna1 WHERE kunnr = lv_partner. IF sy-subrc <> 0.* TODO: Raise A-Message ENDIF.

SELECT * FROM zsapprod INTO CORRESPONDING FIELDS OF TABLE lt_zsapprod WHERE partner = lv_partner.

LOOP AT lt_zsapprod INTO ls_zsapprod. ls_zsapprod-kz = 'I'. "TODO: Oder C? MODIFY lt_zsapprod FROM ls_zsapprod. ENDLOOP.

ENDIF.

* Add new BAPIMTCS

* -------- Business Partner - New Fields in BUT000 CLEAR: ls_bapimtcs, ls_zsapcustomer. ls_bapimtcs-tabname = 'ZSAPCUSTOMER'.

ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid. ls_bapimtcs-relkey = lv_partner_guid. next_free_currdno = next_free_currdno + 1. MOVE-CORRESPONDING ls_kna1 TO ls_zsapcustomer. move_casting ls_zsapcustomer ls_bapimtcs-data. APPEND ls_bapimtcs TO lt_bapimtcs.

* -------- Business Partner - New Fields in BUT020 CLEAR: ls_bapimtcs, ls_zadr_kind.

Page 42: CRM BUPA SAP

ls_bapimtcs-tabname = 'ZADR_KIND'.

ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid. ls_bapimtcs-relkey = lv_partner_guid. ls_bapimtcs-hierno = 1. next_free_currdno = next_free_currdno + 1. MOVE-CORRESPONDING ls_kna1 TO ls_zadr_kind. move_casting ls_zadr_kind ls_bapimtcs-data. APPEND ls_bapimtcs TO lt_bapimtcs.

* -------- Business Partner - New tables* pack current state flag of ZSAP_PRODUCTS CLEAR: ls_bapimtcs, ls_zsprd_r3a1. ls_bapimtcs-tabname = 'ZSPRD_R3A1'. ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid. ls_bapimtcs-relkey = lv_partner_guid. next_free_currdno = next_free_currdno + 1. ls_zsprd_r3a1-curstat = lf_currstat. move_casting ls_zsprd_r3a1 ls_bapimtcs-data. APPEND ls_bapimtcs TO lt_bapimtcs.

LOOP AT lt_zsapprod INTO ls_zsapprod. CLEAR: ls_bapimtcs, ls_zsprd_r3a2. ls_bapimtcs-tabname = 'ZSPRD_R3A2'. ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid. ls_bapimtcs-relkey = lv_partner_guid. next_free_currdno = next_free_currdno + 1. ls_zsprd_r3a2-task = ls_zsapprod-kz. ls_zsprd_r3a2-data_key = ls_zsapprod-sapprod. ls_zsprd_r3a2-seller = ls_zsapprod-seller. ls_zsprd_r3a2-ctr_date = ls_zsapprod-ctr_date. ls_zsprd_r3a2-sellerx = 'X'. ls_zsprd_r3a2-ctr_datex = 'X'. move_casting ls_zsprd_r3a2 ls_bapimtcs-data. APPEND ls_bapimtcs TO lt_bapimtcs. ENDLOOP.

ENDLOOP.

APPEND LINES OF lt_bapimtcs TO t_bapistruct.

ENDFUNCTION.

Note: There is often a requirement for loading fields that are not transferred in standard set-tings from the KNA1 into the CRM. This can be realized in the same way as for adding fields to KNA1. The value of the field can be obtained with the function ZKNA1_CALLBACK and be packed in its own BAPIMTCS container. It is then unpacked again in the CRM and is best writ-ten to a field added to BUT000.

Page 43: CRM BUPA SAP

Extension and Creation of CRM TablesUseThe SAP Business Partner can be extended by adding new fields to existing tables or by cre-ating new tables. This enables a 1:1 mapping, or a 1:n mapping of the extension to the Busi-ness Partner.

The extensible tables are:

BUT000 Business Partner main table

BUT020 Business Partner addresses

The extension of both these tables should take place using the Append technique of the ABAP Dictionary. This makes it possible to append user-defined fields to SAP structures and data-bank tables without modification. These remain after an upgrade and need not be merged with SAP changes.

PreconditionsYou must create the necessary data elements and domains. (Creating Data Elements and Do-mains)

Extending TablesThis process is described in „Extending a Table by Append Technique“.

Creating TablesThis process is described in „Procedure for Creating a Table“.

Create a new table; the following criteria suffice:

The key fields „Client“ and „Partner“ are mandatory. Check tables for these fields are ta-ble T000 for the Client and table BUT000 for the Business Partner number.

The name may have a maximum length of 10 characters.

The delivery class should be ’A’ (Application table).

You can add further key- and data fields according to your requirements.

Example: Business Partner – New Fields for BUT000Create the structure ZSAPCUSTOMER. This contains only the field ZZSAPCUSTMR with the data element ZSAP_CUSTOMER.

Add an Append structure with the name ZABUT000TEST1 to table BUT000 as described above. Include the structure ZSAPCUSTOMER you just created.

Page 44: CRM BUPA SAP

Example: Business Partner – New Fields for BUT020Create the structure ZADR_KIND. This contains only the field ZZADRKIND with the data ele-ment ZADRKIND.

Add an Append structure with the name ZABUT020TEST1 to table BUT020 as described above. Include the structure ZADR_KIND you just created.

Example: Business Partner – New TablesFirst create the structure ZBUS_EI_STRUC_SAPPROD. This will be used for the definition of the database table as well as for data exchange.

Structure ZBUS_EI_STRUC_SAPPROD

Component Component Type

SELLER BU_NAMEP_L

CONTRACT_DATE CRMT_CONTRACT_START_DATE

The create database table ZSAP_PRODUCTS with delivery class A:

Fields Key Data Element Short Description

CLIENT X MANDT Client

PARTNER X BU_PARTNER Business Partner number

SAP_PRODUCTS X ZSAP_PRODUCT SAP Products

.INCLUDE ZBUS_EI_STRUC_SAPPROD

Create structure ZSAP_PRODUCTS_KZ for the update task:

Fields Data Element Short Description

.INCLUDE ZSAP_PRODUCTS Data Record

KZ CHAR1 I, O, D for Insert, Overwrite or Delete

Page 45: CRM BUPA SAP

Short Introduction to the BDTThe BDT (Business Data Toolset) is a central controlling mechanism for maintaining master data and simple transaction data. The BDT is not restricted to supporting the maintenance of dialogs, but also deltas with maintenance in the background via direct input or function mod-ule.

In addition the BDT provides generic services for recurring requirements (e.g. change docu-ment lists, field modification and delete program). The BDT takes over control as well as generic parts and calls the application via fixed specified interfaces (tax tables and times). The applications themselves import application specific developments (for example, for reading and writing application tables).

Within SAP the BDT is used for maintaining several application objects. Development partners and customers can extend these via the BDT interfaces. Objects from development partners and customers may not be displayed via the BDT because the controls for this have not been released.

The available documentation describes an extension to the SAP Business Partner using the BDT. The following application parts are extensible by the BDT without modification:

Screen layout Screen sequence Program logic Menu Search help Field modification

Structure of the BDTThe term application lies at the heart of the BDT. Applications are, for example, central data on the Business Partner, Business Partner Relationships, or Business Partner Addresses. An application may have one or more tables and may also participate in the tables of other appli-cations.

Each application is based technically on a function group containing screens (screens includ-ing PBO and PAI), function modules and data structures.

During runtime the application saves the current memory (for all relevant application data) and the global memory (only for application-defined data) in the data structures.

The application must provide the following function modules for each table:

GET function: This enables participating applications and the BDT to determine the cur-rent contents of tables during data maintenance. The data is taken from the global mem-ory of the owner application.

COLLECT function: This enables an application to participate in a table by transferring values from appended fields to the application that owns the table.

The behavior of the applications is controlled by the BDT via events. For various events the application can thereby offer function modules that can be called dependent on the control ta-bles in the BDT. The flow of events is depicted in the following diagram:

Page 46: CRM BUPA SAP

The presentation hierarchy of the BDT is structured as follows:

A picture (for example, of a table tab title) consists of sections that in turn may contain several views. A view contains filed groups in which individual fields are contained. Design criteria are, for example, field groups that belong together contextually, or common verification. A view be-longs to an application, technically it corresponds to a subscreen.

This hierarchy structure is maintained in BDT Customizing. Further details, such as screen se-quence and screen structure, can be set in the Visual Configuration Tool (VCT).

The application function group can provide function modules for PBO, PAI and PBC (Process Before Call) according to view.

Page 47: CRM BUPA SAP

Creating a BDT Application

UseFor extending the Business Partner you should create a new application in the BDT. However, a new application is not an urgent requirement for extending BUT000. You can use the appli-cation BUP for the extension. You can use the application BUA for extending BUT020. You can use the application BUP for the examples of new tables described in this documentation.

Data sets are the possibility for the BDT to merge data at the BDT view level. Before you cre-ate a new data set you should check whether your data would not fit in an existing data set. You can use data set BUP010 as a standard.

Preconditions A Business Partner table must have been extended or created as new (Extending and

Creating Business Partner Tables).

Creating a New ApplicationDetermine the name of the application. It should consist of four letters and begin with ’Z’. Ac-cording to the current naming convention the name of the application will flow into other BDT object names.

You can access the interface for maintaining the BDT control tables by entering /NBUPT in the command entry field of the SAP GUI. Alternatively you can call the maintenance transactions by their transaction codes.

Carry out the steps described below for each function module.

1. To create an application, select the menu option Business Partner->Tax->Applications (transaction BUS1).

2. Click on the pushbutton „New entries“.

3. Enter the name of your application and a description.

4. Check the field Active.

5. Save your data.

Creating a New Data SetIf your data belongs to none of the data sets created earlier, create a new data set.

1. Choose the menu option Business Partner->Tax->Data sets (transaction BUS23).

2. Click on the pushbutton „New entries“.

3. Enter the name of your new data set. This should be in the customer namespace, i.e. begin with ’Z’.

4. Save your data.

Page 48: CRM BUPA SAP

Assigning Applications and Data Sets to RolesRepeat the steps described below for each role you want. If you have not created a data set you need only carry out steps 1 – 6.

1. To assign your application and data set to a Business Partner role, select the menu option Business Partner->Tax->Divisibility->BP Roles (transaction BUSD).

2. Flag the role you want and go by double-clicking to the menu option „Assign BP Role -> Call-ing Applications“.

3. Click on the pushbutton „New entries“.

4. Enter the name of your application.

5. Leave the field “Call only?“ initial.

6. Save your data.

7. Return to the main screen for the maintenance transaction

8. Flag the role you want and go by double-clicking to the menu option „Assign BP role -> Data sets“.

9. Click on the pushbutton „New entries“.

10. Enter the name of your data set.

11. Save your data.

Example: Business Partner New TableCreate the application ZOE2.

Page 49: CRM BUPA SAP

Creating a BDT Function GroupUseA Business Partner extension in the BDT requires the creation of a new BDT application. An ABAP function group containing the coding and screens is necessary for this. You must create a new function group even if you use application BUP. However, an application or function group can be used for several tables in the function group.

Preconditions A Business Partner table must have been extended or created as new (Extending and

Creating Business Partner Tables).

A BDT application must have been created (Creating a BDT Application) or an existing application (Standard: BUP) must have been used.

Creating a Function Group1. Start the ABAP Workbench (transaction SE80)

2. Display the development classes (packages) belonging to your project.

3. Call the context menu for the development class in the navigation tree by selecting Create->Function group.

4. Enter the name of the function group. This should begin with ‘Y’ or ‘Z’. The application name should also be included in order to improve clarity.

5. Enter a short text description.

6. Click on the Save button.

7. Choose the transport request for your project or create a new one.

Example (Business Partner New Field for BUT000)Create a function group (for example, ZCRM_BP_OBJECTEXTENSION_FG) with the follow-ing TOP Include:

* TablesTABLES: BUT000.

* ConstantsCONSTANTS: GC_ACTVT_DELETE LIKE BUS000FLDS-CHAR1 VALUE 'D', GC_ACTVT_INSERT LIKE BUS000FLDS-CHAR1 VALUE 'I', GC_ACTVT_UPDATE LIKE BUS000FLDS-CHAR1 VALUE 'U', GC_AKTYP_CHANGE LIKE TBZ0K-AKTYP VALUE '02', GC_AKTYP_DISPLAY LIKE TBZ0K-AKTYP VALUE '03', GC_FSTAT_OPTIONAL LIKE BUS000FLDS-FLDSTAT VALUE '.', GC_FSTAT_REQUIRED LIKE BUS000FLDS-FLDSTAT VALUE '+',

Page 50: CRM BUPA SAP

GC_FSTAT_DISPLAY LIKE BUS000FLDS-FLDSTAT VALUE '*', GC_FSTAT_NONSPECIF LIKE BUS000FLDS-FLDSTAT VALUE '', GC_FSTAT_SUPPRESSED LIKE BUS000FLDS-FLDSTAT VALUE '-', GC_MESSG_CANCEL LIKE MESG-MSGTY VALUE 'A', GC_MESSG_ERROR LIKE MESG-MSGTY VALUE 'E', GC_OBJAP_PARTNER LIKE TBZ1-OBJAP VALUE 'BUPA', GC_STATUS_DISPLAY LIKE TBZ0K-AKTYP VALUE '*', GC_X LIKE BOOLE-BOOLE VALUE 'X'.

* VariablesDATA: GV_AKTYP LIKE TBZ0K-AKTYP, GV_XSAVE LIKE BOOLE-BOOLE, GV_XUPDTASK LIKE BOOLE-BOOLE.

* WorkareaDATA: GL_BUT000_OLD LIKE BUT000.DATA: GT_RLTYP LIKE BUS0RLTYP OCCURS 0 WITH HEADER LINE.DATA: GV_TEXT LIKE DD07V-DDTEXT, GV_DOMNAME LIKE DD07L-DOMNAME.

CONSTANTS: GC_MESSG_ARBGB LIKE MESG-ARBGB VALUE 'ZOE1'.INCLUDE LSVIMDAT. "general data decl.

Example (Business Partner New Field for BUT020)Create a function group (for example, ZCRM_BP_OBJEXTENSION_FG2) with the following TOP Include:

* ConstantsCONSTANTS: GC_ACTVT_DELETE LIKE BUS000FLDS-CHAR1 VALUE 'D', GC_ACTVT_INSERT LIKE BUS000FLDS-CHAR1 VALUE 'I', GC_ACTVT_UPDATE LIKE BUS000FLDS-CHAR1 VALUE 'U', GC_AKTYP_CHANGE LIKE TBZ0K-AKTYP VALUE '02', GC_AKTYP_DISPLAY LIKE TBZ0K-AKTYP VALUE '03', GC_FSTAT_OPTIONAL LIKE BUS000FLDS-FLDSTAT VALUE '.', GC_FSTAT_REQUIRED LIKE BUS000FLDS-FLDSTAT VALUE '+', GC_FSTAT_DISPLAY LIKE BUS000FLDS-FLDSTAT VALUE '*', GC_FSTAT_NONSPECIF LIKE BUS000FLDS-FLDSTAT VALUE '', GC_FSTAT_SUPPRESSED LIKE BUS000FLDS-FLDSTAT VALUE '-', GC_MESSG_CANCEL LIKE MESG-MSGTY VALUE 'A', GC_MESSG_ERROR LIKE MESG-MSGTY VALUE 'E', GC_OBJAP_PARTNER LIKE TBZ1-OBJAP VALUE 'BUPA', GC_STATUS_DISPLAY LIKE TBZ0K-AKTYP VALUE '*', GC_X LIKE BOOLE-BOOLE VALUE 'X'.

* VariablesDATA: GV_AKTYP LIKE TBZ0K-AKTYP, GV_XSAVE LIKE BOOLE-BOOLE, GV_XUPDTASK LIKE BOOLE-BOOLE.

* WorkareaDATA: GT_RLTYP LIKE BUS0RLTYP OCCURS 0 WITH HEADER LINE, GT_BUT020 LIKE BUT020 OCCURS 0 WITH HEADER LINE,

Page 51: CRM BUPA SAP

GT_BUT020_OLD LIKE BUT020 OCCURS 0 WITH HEADER LINE, GS_BUT020 LIKE BUT020.

DATA: GV_ZZADRKIND LIKE BUT020-ZZADRKIND, GV_ADDRNUMBER LIKE BUT020-ADDRNUMBER, GV_PAI_CHECK LIKE BOOLE-BOOLE.

CONSTANTS: GC_TRUE LIKE BOOLE-BOOLE VALUE 'X'.

INCLUDE LSVIMDAT. "general data decl.

Example (Business Partner New Table)Create a function group (for example, ZCRM_BP_OBJEXTENSION_FG3) with the following TOP Include:

************************************************************************ Variables ************************************************************************

CONSTANTS: gc_actvt_delete LIKE bus000flds-char1 VALUE 'D', gc_actvt_insert LIKE bus000flds-char1 VALUE 'I', gc_actvt_update LIKE bus000flds-char1 VALUE 'U', gc_aktyp_change LIKE tbz0k-aktyp VALUE '02', gc_aktyp_display LIKE tbz0k-aktyp VALUE '03', gc_fstat_optional LIKE bus000flds-fldstat VALUE '.', gc_fstat_required LIKE bus000flds-fldstat VALUE '+', gc_fstat_display LIKE bus000flds-fldstat VALUE '*', gc_fstat_nonspecif LIKE bus000flds-fldstat VALUE '', gc_fstat_suppressed LIKE bus000flds-fldstat VALUE '-', gc_messg_cancel LIKE mesg-msgty VALUE 'A', gc_messg_error LIKE mesg-msgty VALUE 'E',* gc_objap_partner LIKE tbz1-objap VALUE 'BUPA',* gc_status_display LIKE tbz0k-aktyp VALUE '*', gc_x LIKE boole-boole VALUE 'X'.

DATA: gv_aktyp LIKE tbz0k-aktyp, gv_xsave LIKE boole-boole, gv_xupdtask LIKE boole-boole.*set by BUS_PARAMETERS_ISSTA_GET

* WorkareasTABLES: but000, zsap_products.

CONSTANTS: gc_fcode_sappr_dele LIKE tbz4-fcode VALUE 'PUSH_ZOE2_SAPPR_DEL', gc_messg_arbgb LIKE mesg-arbgb VALUE 'ZOE2',* gc_cdobjclas like cdhdr-objectclas "Änd.bel.objekt* value 'ZBUPA_HOBBY_KVO', gc_cdobjid_max TYPE i "ÄndBelege: Max. Objekt-IDs VALUE '50'.

DATA: gt_rltyp LIKE bus0rltyp OCCURS 0 WITH HEADER LINE.

Page 52: CRM BUPA SAP

DATA: gv_zsap_products_linact LIKE sy-index.

* ---------- Global Data of function group -------------------

* BDT Current memoryDATA: BEGIN OF gt_zsap_products OCCURS 0. INCLUDE STRUCTURE zsap_products.DATA: xmark LIKE boole-boole, END OF gt_zsap_products.DATA: gt_zsap_products_old LIKE zsap_products OCCURS 0 WITH HEADER LINE.

* BDT Complete MemoryDATA: mem_zsap_products LIKE zsap_products_kz OCCURS 0 WITH HEADER LINE, mem_zsap_products_old LIKE mem_zsap_products OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF mem_partner OCCURS 0, partner LIKE but000-partner, END OF mem_partner.

* PERSIST ("BAPI") Global MemoryDATA: gt_zsapprod LIKE zsap_products_kz OCCURS 0 WITH HEADER LINE, gt_zsapprod_old LIKE zsap_products_kz OCCURS 0 WITH HEADER LINE.

* ---------- Table Control -------------------

CONTROLS: tctrl_zsap_products TYPE TABLEVIEW USING SCREEN '0020'.

INCLUDE lsvimdat . "general data decl.

Page 53: CRM BUPA SAP

Function Module for the ISSTA EventUseAt specific points in the program flow, application-dependent coding must be imported from each Business Partner application into the BDT function process in order to ensure a com-plete and error-free integration of application-specific data. To do this, BDT events were de-fined that are filled with application function modules (known as event function modules).

See also Short Introduction to the BDT.

Event ISSTA: Initialization – In this event an application „gets“ important control parameters from the BDT control. This event should be supplied for new tables as well as for Appends to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

Procedure for Creating a Function Module1. Start the ABAP Workbench (transaction SE80)

2. Display your function group.

3. Call the context menu for the function group in the navigation tree by selecting Create->Function module. Specify the name of your function module.Naming convention: Z_<application>_<BDT application object>_EVENT_<Event>The BDT application object is ’BUPA’ in this case. Example name: Z_ZCUS_BUPA_EVENT_ISSTA

4. Enter a short text description.

5. Click on the Save button.

6. Choose the transport request for your project or create a new one.

Example (Business Partner New Field BUT000 or BUT020)The following coding can be used for the example scenario “Business Partner New Field”: (for BUT020 copy Function Module Z_ZOE1_BUPA_EVENT_ISSTA to Z_ZOE3_BUPA_EVENT_ISSTA):

FUNCTION Z_ZOE1_BUPA_EVENT_ISSTA.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

Page 54: CRM BUPA SAP

*------ Set parameters --------------------------------------------------

  CALL FUNCTION 'BUS_PARAMETERS_ISSTA_GET'    IMPORTING*   E_OBJAP            =      e_aktyp            = gv_aktyp*   E_ACTION           =      e_xsave            = gv_xsave*   E_XINIT            =      e_xupdtask         = gv_xupdtask*   E_XDINP            =*   E_XBAPI            =*   E_XFRGN            =*   E_FRGID            =*   E_VALDT            =*   E_NODATA           =*   E_PLANCHNGNR       =*   E_XCHDOC           =*   E_XARCHIVE         =    TABLES      t_rltyp            = gt_rltyp*   T_RLTYP_SEL        =*   T_RLTGR_SEL        =*   T_TBZ0Q            =*   T_FLDVL            =            .

* Remark: The interface might be much broader, depending*         on chosen functionality. See BDT documentation.

ENDFUNCTION.

Example (Business Partner New Table)Copy the Function Module Z_ZOE1_BUPA_EVENT_ISSTA to Z_ZOE2_BUPA_EVENT_ISSTA for the example scenario “Business Partner New Table”.

Page 55: CRM BUPA SAP

Function Module for the ISDST EventUseEvent ISDST: Getting data from the table-possessing application. Because all data in a table can be read by the table-possessing application from the database (also in an Append struc-ture), the application data must be distributed to the corresponding application function groups because both display and processing take place here. Data is displayed after this event.

Programming of this event is only necessary when appending new fields to existing tables, not when creating new tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Field BUT000)The following coding can be used for the example scenario „Business Partner New Field BUT000“:

FUNCTION Z_ZOE1_BUPA_EVENT_ISDST.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

**------ Fetch data from possessing application ------------------------  CALL FUNCTION 'BUP_BUPA_BUT000_GET'       IMPORTING            E_BUT000      = BUT000.

*------ Save old state  ---------------------------  GL_BUT000_OLD = BUT000.

ENDFUNCTION.

Example (Business Partner New Field BUT020)The following coding can be used for the example scenario “Business Partner New Field BUT020”:

FUNCTION Z_ZOE3_BUPA_EVENT_ISDST.

*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

Page 56: CRM BUPA SAP

*------ Fetch data from possessing application -------------------------- CALL FUNCTION 'BUA_BUPA_BUT020_GET' TABLES T_BUT020 = GT_BUT020. "Alle Adressen werden benötigt

*------ Save old state------------------------- GT_BUT020_OLD = GT_BUT020.

ENDFUNCTION.

Page 57: CRM BUPA SAP

Function Module for the XCHNG EventUseEvent XCHNG: Data changed? In this event an application must determine whether data for which it is accountable has changed. In this case the BDT control can then react to this. In ad-dition a parameter is transferred that is set when changes are recognized.

Programming of this event is only necessary when appending new fields to existing tables, not when creating new tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Field BUT000)

FUNCTION Z_ZOE1_BUPA_EVENT_XCHNG.*"----------------------------------------------------------------------*"*"Local interface:*"  EXPORTING*"     REFERENCE(E_XCHNG) LIKE  BUS000FLDS-XCHNG*"----------------------------------------------------------------------

*------ Return parameter initialization  -------------------------------  CLEAR E_XCHNG.

*------ Set indicator E_XCHNG if field values have changed  IF BUT000 <> GL_BUT000_OLD.    E_XCHNG = GC_X.  ENDIF.

ENDFUNCTION.

Example (Business Partner New Field BUT020)

FUNCTION Z_ZOE3_BUPA_EVENT_XCHNG.

*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" REFERENCE (E_XCHNG) LIKE BUS000FLDS-XCHNG

Page 58: CRM BUPA SAP

*"----------------------------------------------------------------------

*------ Return parameter initialization ------------------------------- CLEAR E_XCHNG.

*------ Set mark ‘change available’ ------------------------ IF GT_BUT020[] <> GT_BUT020_OLD[]. E_XCHNG = GC_X. ENDIF.

ENDFUNCTION.

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_XCHNG.

*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" REFERENCE (E_XCHNG) LIKE BUS000FLDS-XCHNG*"----------------------------------------------------------------------

*------ Local data declaration ----------------------------------------- DATA: LT_ZSAP_PRODUCTS LIKE ZSAP_PRODUCTS OCCURS 0 WITH HEADER LINE.

*------ Return parameter initialization -------------------------------- CLEAR E_XCHNG.

*------ Notice new state in LT_ZSAP_PRODUCTS --------------------------- REFRESH LT_ZSAP_PRODUCTS. LOOP AT GT_ZSAP_PRODUCTS. CLEAR LT_ZSAP_PRODUCTS. MOVE-CORRESPONDING GT_ZSAP_PRODUCTS TO LT_ZSAP_PRODUCTS. APPEND LT_ZSAP_PRODUCTS. ENDLOOP.

*------ Set mark 'change available' ------------------------------------ IF LT_ZSAP_PRODUCTS[] <> GT_ZSAP_PRODUCTS_OLD[]. E_XCHNG = GC_X. ENDIF.

ENDFUNCTION.

Page 59: CRM BUPA SAP

Function Module for the DSAVB EventUseEvent DSAVB: Collect data. In this event data is returned to the table-possessing application for updating. To recognize the structure during transfer the name of the Append must also be transferred in this position.

Programming of this event is only necessary when appending new fields to existing tables, not when creating new tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Field BUT000)The following coding can be used for the example scenario „Business Partner New Field BUT000”:

FUNCTION Z_ZOE1_BUPA_EVENT_DSAVB.*"-------------------------------------------------------------------*"*"Local interface:*"-------------------------------------------------------------------

*------ Local data declaration--------------------------------------  CONSTANTS: LC_SUBNAME LIKE DD02D-TABNAME VALUE 'ZABUT000'.

*------ Data return to possessing Application----------------------  CALL FUNCTION 'BUP_BUPA_BUT000_COLLECT'       EXPORTING            I_SUBNAME = LC_SUBNAME            I_BUT000  = BUT000.

ENDFUNCTION.

Example (Business Partner New Field BUT020)The following coding can be used for the example scenario „Business Partner New Field BUT020”:

FUNCTION Z_ZOE3_BUPA_EVENT_DSAVB.

Page 60: CRM BUPA SAP

*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Local data declaration -------------------------------------- CONSTANTS: LC_SUBNAME LIKE DD02D-TABNAME VALUE 'ZABUT020TEST1'.

*------ Data return to possessing Application ---------------------- CALL FUNCTION 'BUA_BUPA_BUT020_COLLECT' EXPORTING I_SUBNAME = LC_SUBNAME TABLES T_BUT020 = GT_BUT020.

ENDFUNCTION.

Page 61: CRM BUPA SAP

Function Module for the DLVE1 EventUseEvent DLVE1: Delete current memory. To prepare the dialog for a new Partner, the field string of the BUT000/BUT020 must be initialized with the data of the most recently processed Part-ners (when appending new fields to BUT000/BUT020). In this event all data belonging to the Business Partner being processed in the new tables is deleted from current memory.

This event is executed in the Business Partner dialog, for example, after clicking on the „Back“ button (green arrow). This does not end the LUW, but simply goes back to the initial screen.

Programming of this event is necessary when appending new fields to existing tables as well as when creating new fields.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Field BUT000)The following coding can be used for the example scenario „Business Partner New Field BUT000“:

FUNCTION Z_ZOE1_BUPA_EVENT_DLVE1.*"-------------------------------------------------------------------*"*"Local interface:*"-------------------------------------------------------------------  CLEAR BUT000.  CLEAR GL_BUT000_OLD.ENDFUNCTION.

Example (Business Partner New Field BUT020)The following coding can be used for the example scenario „Business Partner New Field BUT020“:

FUNCTION Z_ZOE3_BUPA_EVENT_DLVE1.

*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

CLEAR GT_BUT020. CLEAR GT_BUT020_OLD.

REFRESH GT_BUT020. REFRESH GT_BUT020_OLD.

Page 62: CRM BUPA SAP

ENDFUNCTION.

Example (Business Partner New Table)The following coding can be used for the example scenario „Business Partner New Table“:

FUNCTION Z_ZOE2_BUPA_EVENT_DLVE1.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

  CLEAR GT_ZSAP_PRODUCTS.  REFRESH GT_ZSAP_PRODUCTS.

  CLEAR GT_ZSAP_PRODUCTS_OLD.  REFRESH GT_ZSAP_PRODUCTS_OLD.

ENDFUNCTION.

Page 63: CRM BUPA SAP

Function Module for the ISDAT EventUseEvent ISDAT: Read data – In this event the table-possessing application reads data from the database to the „Memory“ (Memory) of its function group.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables (this applies generally; there may be rare exceptions).

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_ISDAT.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

* ----- Obtain the values of the BUT000 in this dialog ----------------  CALL FUNCTION 'BUP_BUPA_BUT000_GET'       IMPORTING            E_BUT000      = BUT000.

*------ Partner was previously prepared: read local memory -  READ TABLE MEM_PARTNER WITH KEY but000-partner.  IF SY-SUBRC = 0.    REFRESH GT_ZSAP_PRODUCTS.    LOOP AT MEM_ZSAP_PRODUCTS WHERE PARTNER = BUT000-PARTNER.      CLEAR GT_ZSAP_PRODUCTS.      MOVE-CORRESPONDING MEM_ZSAP_PRODUCTS TO GT_ZSAP_PRODUCTS.      APPEND GT_ZSAP_PRODUCTS.    ENDLOOP.

*------ Partner was not previously prepared: read Database ---------  ELSE.    SELECT * FROM ZSAP_PRODUCTS             INTO TABLE GT_ZSAP_PRODUCTS             WHERE PARTNER = BUT000-PARTNER.  ENDIF.

*------ Save old state of the current preparation -------------------  GT_ZSAP_PRODUCTS_OLD[] = GT_ZSAP_PRODUCTS[].

Page 64: CRM BUPA SAP

ENDFUNCTION.

Page 65: CRM BUPA SAP

Function Module for the DTAKE EventUseEvent DTAKE. Transfer data to the global memory. Saving data using the BDT takes place in several stages. Data for several instances can be saved together and is used both in transfer mode as well as in background maintenance. In this first stage the table-possessing applica-tion writes data from its current memory to its global memory.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_DTAKE.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Receive new state -----------------------------------------  DELETE MEM_ZSAP_PRODUCTS WHERE PARTNER = BUT000-PARTNER.  LOOP AT GT_ZSAP_PRODUCTS.    CLEAR MEM_ZSAP_PRODUCTS.    MOVE-CORRESPONDING GT_ZSAP_PRODUCTS TO MEM_ZSAP_PRODUCTS.    APPEND MEM_ZSAP_PRODUCTS.  ENDLOOP.

*------ Receive old state -----------------------------------------  READ TABLE MEM_PARTNER WITH KEY PARTNER = BUT000-PARTNER.  IF SY-SUBRC <> 0.    LOOP AT GT_ZSAP_PRODUCTS_OLD.      CLEAR MEM_ZSAP_PRODUCTS_OLD.      MOVE-CORRESPONDING GT_ZSAP_PRODUCTS_OLD TO MEM_ZSAP_PRODUCTS_OLD.      APPEND MEM_ZSAP_PRODUCTS_OLD.    ENDLOOP.

*------ Notice partner number in the index of the processed partners ---    MEM_PARTNER-PARTNER = BUT000-PARTNER.    APPEND MEM_PARTNER.

Page 66: CRM BUPA SAP

  ENDIF.

ENDFUNCTION.

Page 67: CRM BUPA SAP

Function Module for the DSAVC EventUseEvent DSAVC. Complete data for saving. In this event, for example, temporary numbers are replaced by definitive ones. After this event the data should be consistent, i.e. without errors, so updating can be triggered in Event DSAVE.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_DSAVC.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Local data declaration --------------------------------------CONSTANTS: LC_TABLE_PRODUCTS LIKE CDPOS-TABNAME VALUE 'ZSAP_PRODUCTS'.  DATA: LV_INDEX LIKE SY-TABIX.  DATA: LT_PARTNER LIKE BUS_PARTNR OCCURS 0 WITH HEADER LINE.

*------ Get Assign 'temporarily number-> final number' --------  CALL FUNCTION 'BUP_BUPA_NUMBERS_READ'       TABLES            T_PARTNER = LT_PARTNER.*------ Notice internal assigned Number: final number ---------------  LOOP AT MEM_ZSAP_PRODUCTS.    READ TABLE LT_PARTNER WITH KEY PARTNR_TMP                                        = MEM_ZSAP_PRODUCTS-PARTNER.    IF SY-SUBRC = 0.      MEM_ZSAP_PRODUCTS-PARTNER = LT_PARTNER-PARTNER.      MODIFY MEM_ZSAP_PRODUCTS.    ENDIF.  ENDLOOP.

*----- Determine type of the change per data sentence ------------------  SORT MEM_ZSAP_PRODUCTS.  SORT MEM_ZSAP_PRODUCTS_OLD.

Page 68: CRM BUPA SAP

  CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES'       EXPORTING            TABLENAME       = LC_TABLE_PRODUCTS       TABLES            TABLE_NEW       = MEM_ZSAP_PRODUCTS            TABLE_OLD       = MEM_ZSAP_PRODUCTS_OLD       EXCEPTIONS            NAMETAB_ERROR   = 1            OTHERS          = 2.  IF SY-SUBRC <> 0.    PERFORM EXCEPTION_MESSAGE_SEND USING GC_MESSG_CANCEL                                         SPACE.  ENDIF.

ENDFUNCTION.

Form EXCEPTION_MESSAGE_SEND:*&---------------------------------------------------------------------**& Form EXCEPTION_MESSAGE_SEND*&---------------------------------------------------------------------** Exception message issue over Message Handler **----------------------------------------------------------------------** --> I_MSGTY Message type ** --> I_TBFLD_STRG Cursorfield And/or. fields highlighted **----------------------------------------------------------------------*FORM EXCEPTION_MESSAGE_SEND USING I_MSGTY I_TBFLD_STRG. CALL FUNCTION 'BUS_MESSAGE_STORE' EXPORTING ARBGB = SY-MSGID MSGTY = I_MSGTY TXTNR = SY-MSGNO MSGV1 = SY-MSGV1 MSGV2 = SY-MSGV2 MSGV3 = SY-MSGV3 MSGV4 = SY-MSGV4 TBFLD_STRG = I_TBFLD_STRG.

ENDFORM. " EXCEPTION_MESSAGE_SEND

Page 69: CRM BUPA SAP

Function Module for the DSAVE EventUseEvent DSAVE. Save event data. In this event current data from the global memory is written to the database.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_DSAVE.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Data secure on the Database --------------------------------*------ ... Asynchronous (with COMMIT) ---------------------------------  IF GV_XUPDTASK = GC_X.    CALL FUNCTION 'Z_ZOE2_BUPA_UPDATE' IN UPDATE TASK         TABLES              T_ZSAP_PRODUCTS     = MEM_ZSAP_PRODUCTS              T_ZSAP_PRODUCTS_OLD = MEM_ZSAP_PRODUCTS_OLD.

*------ ... Synchronous (without COMMIT) ---------------------------------  ELSE.    CALL FUNCTION 'Z_ZOE2_BUPA_UPDATE'         TABLES              T_ZSAP_PRODUCTS     = MEM_ZSAP_PRODUCTS              T_ZSAP_PRODUCTS_OLD = MEM_ZSAP_PRODUCTS_OLD.  ENDIF.

ENDFUNCTION.

In this example we have used a current database update that is executed in another, general, function module. The database update logic in our example is as follows:

FUNCTION Z_ZOE2_BUPA_UPDATE.*"----------------------------------------------------------------------*"*"Update Function Module:

Page 70: CRM BUPA SAP

*"*"*"Local interface:*" TABLES*" T_ZSAP_PRODUCTS STRUCTURE ZSAP_PRODUCTS_KZ*" T_ZSAP_PRODUCTS_OLD STRUCTURE ZSAP_PRODUCTS_KZ*"----------------------------------------------------------------------

* analog BUP_BUPA_UPDATE

*------ Local data declaration -------------------------------------- DATA: LT_ZSAP_PRODUCTS LIKE ZSAP_PRODUCTS OCCURS 0 WITH HEADER LINE.

*------ Insert new data sentences ------------------------------------- REFRESH LT_ZSAP_PRODUCTS. LOOP AT T_ZSAP_PRODUCTS WHERE KZ = GC_ACTVT_INSERT. LT_ZSAP_PRODUCTS = T_ZSAP_PRODUCTS. APPEND LT_ZSAP_PRODUCTS. ENDLOOP. INSERT ZSAP_PRODUCTS FROM TABLE LT_ZSAP_PRODUCTS ACCEPTING DUPLICATE KEYS. IF SY-SUBRC <> 0. UPDATE ZSAP_PRODUCTS FROM TABLE LT_ZSAP_PRODUCTS. ENDIF.

*------ Change existing data sentences --------------------------------- REFRESH LT_ZSAP_PRODUCTS. LOOP AT T_ZSAP_PRODUCTS WHERE KZ = GC_ACTVT_UPDATE. LT_ZSAP_PRODUCTS = T_ZSAP_PRODUCTS. APPEND LT_ZSAP_PRODUCTS. ENDLOOP. UPDATE ZSAP_PRODUCTS FROM TABLE LT_ZSAP_PRODUCTS. IF SY-SUBRC <> 0. INSERT ZSAP_PRODUCTS FROM TABLE LT_ZSAP_PRODUCTS ACCEPTING DUPLICATE KEYS. ENDIF.

*------ Delete existing data sentences -------------------------------- REFRESH LT_ZSAP_PRODUCTS. LOOP AT T_ZSAP_PRODUCTS_OLD WHERE KZ = GC_ACTVT_DELETE. LT_ZSAP_PRODUCTS = T_ZSAP_PRODUCTS_OLD. APPEND LT_ZSAP_PRODUCTS. ENDLOOP. DELETE ZSAP_PRODUCTS FROM TABLE LT_ZSAP_PRODUCTS.

ENDFUNCTION.

NOTE: This function module must be created with process type “Update Module”.

Page 71: CRM BUPA SAP

Function Module for the DLVE2 EventUseEvent DLVE2. Delete global memory. Deletes all data in the global memory, for example, after an update.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_DLVE2.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

  CLEAR MEM_ZSAP_PRODUCTS.     REFRESH MEM_ZSAP_PRODUCTS.

  CLEAR MEM_ZSAP_PRODUCTS_OLD. REFRESH MEM_ZSAP_PRODUCTS_OLD.

  CLEAR MEM_PARTNER.       REFRESH MEM_PARTNER.

ENDFUNCTION.

Page 72: CRM BUPA SAP

Function Module for the FCODE EventUseEvent FCODE: In this event function codes are processed. Because application-specific FCODES are added here (for example, delete row) it is necessary to implement a module that can process the User’s FCODES.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_FCODE.*"----------------------------------------------------------------------*"*"Local interface:*"  IMPORTING*"     REFERENCE (I_FCODE) LIKE  TBZ4-FCODE*"  EXPORTING*"     REFERENCE(E_XHANDLE) LIKE  BOOLE-BOOLE*"----------------------------------------------------------------------

*------ E_XHANDLE default value set to 'X' --------------------------  E_XHANDLE = 'X'.

*------ Work characteristic functions-----------------------------------*------ ... SAP Products deleted ---------------------------------------  CASE I_FCODE.    WHEN gc_fcode_sappr_dele.      PERFORM GT_ZSAP_PRODUCTS_DELETE.

*------ ... Do not handle other functions: -------------------------    WHEN OTHERS.      CLEAR E_XHANDLE.  ENDCASE.

ENDFUNCTION.

*&---------------------------------------------------------------------**&      Form  GT_ZSAP_PRODUCTS_DELETE*&---------------------------------------------------------------------*FORM gt_zsap_products_delete.

Page 73: CRM BUPA SAP

  DELETE gt_zsap_products WHERE xmark = gc_x.

ENDFORM.                    " GT_ZSAP_PRODUCTS_DELETE

Page 74: CRM BUPA SAP

Function Module for the DCUAC EventUseEvents DCUAD and DCUAC set or change the menu. Additionally, menu options and display status can be switched to active or inactive when the rules applying to this function cannot be displayed in the control table settings.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions A Business Partner table must have been extended or created new (Extending and Cre-

ating Business Partner Tables).

A function group for the application must have been created (Creating a BDT Function Group).

The exact procedure for creating a BDT event function module is described in: Function Module for the ISSTA Event

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_EVENT_DCUAC.*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Local data declaration --------------------------------------  DATA: LT_CUA_EXC   LIKE BUS000CUAF  "Standard function to be faded out               OCCURS 10 WITH HEADER LINE,        LT_CUA_INC   LIKE BUS000CUAF  "Addition functions to be faded in               OCCURS 10 WITH HEADER LINE,        LV_STATUS(1) TYPE C.

*------ CUA-Read functions to the current screen -----------------------  CALL FUNCTION 'BUS_CUA_FUNCTIONS_GET'       TABLES            T_STND_EXCL = LT_CUA_EXC            T_FRTH_INCL = LT_CUA_INC.

*------ Function 'SAP Product delete':*------   Inactive, if SAP Products are not enterable ------------------*------ ... Read field status ------------------------------------------  READ TABLE LT_CUA_INC WITH KEY FCODE = GC_FCODE_SAPPR_DELE.  IF SY-SUBRC = 0.    CALL FUNCTION 'BUS_FMOD_STATUS_GET'         EXPORTING              I_FLDGR  = '703'    " <== Enter your own Field Group here         IMPORTING              E_STATUS = LV_STATUS.

Page 75: CRM BUPA SAP

*------ ... Field Groups not-enterable: function deactivated ----------    IF LV_STATUS = GC_FSTAT_SUPPRESSED    OR LV_STATUS = GC_FSTAT_DISPLAY.      DELETE LT_CUA_INC WHERE FCODE = GC_FCODE_SAPPR_DELE.    ENDIF.  ENDIF.

*------ CUA-Set functions to the current screen -----------------------  CALL FUNCTION 'BUS_CUA_FUNCTIONS_SET'       TABLES            T_STND_EXCL = LT_CUA_EXC            T_FRTH_INCL = LT_CUA_INC.

ENDFUNCTION.

Page 76: CRM BUPA SAP

Creating a BDT ScreenUseSo that the newly added fields are visible and can be used for data maintenance, the fields must be included in a screen.

The screens are in the same function group as the function module for the BDT Events. So that the screens are executable in the BDT they must always be declared as subscreens and always possess a BDT-specific flow logic.

Preconditions Newly added fields must exist (Extending and Creating R/3 Tables).

A function group must have been created (Creating a new BDT Function Group).

Procedure for Creating a Screen1. Start the ABAP Workbench (transaction SE80)

2. Specify the function group belonging to your application.

3. Call up the context menu for the function group in the navigation tree and choose

Create->Screen.

4. Enter a screen number of your choice and a description.

5. Save your data.

6. Choose the transport request for your project or create a new one.

7. Specify your screen in the Workbench navigation tree and call it by double-clicking on the maintenance screen.

8. The flow logic was generated earlier so you only need to create the PBO and PAI Modules. You create a Module by double-clicking on the PBO instructions (PAI) in MODULE PBO (MODULE PAI). Confirm the popup.

9. Save your data.

10. Create your new fields in the screen using the Layout Editor.

Example (Business Partner New Field BUT000/020)Choose the respective function group and create Screen 0001 as follows. Add field BUT000-ZZSAPCUSTMR to example BUT000. For the BUT020 example add field GV_ZZADRKIND.

The flow logic might look like this:

PROCESS BEFORE OUTPUT.  MODULE PBO.*PROCESS AFTER INPUT.

Page 77: CRM BUPA SAP

  MODULE PAI.*PROCESS ON VALUE-REQUEST.*

*--------------------------------------------------------------**      Module  PBO      OUTPUT                                 **--------------------------------------------------------------**   Carry out actions of the Control on the Subscreen to PBO   **--------------------------------------------------------------*MODULE PBO OUTPUT.  CALL FUNCTION 'BUS_PBO'.ENDMODULE.

*---------------------------------------------------------------------**      Module  PAI                                                    **---------------------------------------------------------------------**      Carry out actions of the Control on the Subscreen to PAI       **---------------------------------------------------------------------*MODULE PAI.  CALL FUNCTION 'BUS_PAI'.ENDMODULE.

Example (Business Partner New Table)For the Example (Business Partner New Table), choose your function group and create Screen 0020:

Add a text field ZSAP_PRODUCTS-SAP_PRODUCTS as a title.

Add a table control with the name TCTRL_ZSAP_PRODUCTS. Select the control and press F6: enter GT_ZSAP_PRODUCTS-SAP_PRODUCTS as table/field name and press the button „Get from program“. Select the column and place it on your con-trol. Then double-click on the control and choose „Listbox“ from the dropdown. Re-peat this stage (but without the last stage: Choose „Listbox“ from the dropdown) for field names GT_ZSAP_PRODUCTS-SELLER and GT_ZSAP_PRODUCTS-CON-TRACT_DATE. Set the column headers via text field over the individual columns. Goto Control Names in the element list and then press the pushbutton „Attributes“. Tick „With selection column“ and enter the name GT_ZSAP_PRODUCTS-XMARK.

Add a pushbutton PUSH_ZOE2_SAPPR_DEL with the text “Delete selected row” and FCODE “PUSH_ZOE2_SAPPR_DEL”.

The flow logic might look like this:

PROCESS BEFORE OUTPUT.  MODULE PBO_0020.  LOOP AT GT_ZSAP_PRODUCTS WITH CONTROL TCTRL_ZSAP_PRODUCTS                       CURSOR GV_ZSAP_PRODUCTS_LINACT.    MODULE GT_ZSAP_PRODUCTS_INIT.  ENDLOOP.*PROCESS AFTER INPUT.  MODULE PAI.  LOOP AT GT_ZSAP_PRODUCTS.    MODULE GT_ZSAP_PRODUCTS_MODIFY.  ENDLOOP.  MODULE GT_ZSAP_PRODS_LINACT_DETERMINE.

Page 78: CRM BUPA SAP

*&--------------------------------------------------------------------**&      Module  PBO_0020  OUTPUT*&--------------------------------------------------------------------**      Carry out actions of the Control on the Subscreen to PBO       **---------------------------------------------------------------------*MODULE PBO_0020 OUTPUT.

  CALL FUNCTION 'BUS_PBO'           CHANGING                C_TC1 = TCTRL_ZSAP_PRODUCTS.

ENDMODULE.                 " PBO_0020  OUTPUT

*&--------------------------------------------------------------------**&      Module  GT_ZSAP_PRODUCTS_INIT  OUTPUT*&--------------------------------------------------------------------**      Initialize table lines                                         **---------------------------------------------------------------------*MODULE GT_ZSAP_PRODUCTS_INIT OUTPUT.

  PERFORM GT_ZSAP_PRODUCTS_INIT.

ENDMODULE.                 " GT_ZSAP_PRODUCTS_INIT  OUTPUT

In this example it is necessary to use form routines that are called by the modules. If you want to structure their functional logic in this way too, then:

Double-click on the form routine names within the PERFORM instruction(s) in the module pro-gram code and choose “Yes” in the popup “Create object”.

In the popup “Create module” accept the proposal to create a new Include member “...FGF01”.

*&--------------------------------------------------------------------**&      Form  GT_ZSAP_PRODUCTS_INIT*&--------------------------------------------------------------------**      Initialize table lines                                         **---------------------------------------------------------------------*FORM gt_zsap_products_init.

*------ Local data declaration --------------------------------------  DATA: lv_number(3) TYPE c,        lv_lines     LIKE sy-tfill,        lv_lines_max LIKE sy-tfill,        lv_text(30)  TYPE c.

*------ Count the number of lines in functioning table ----------------  DESCRIBE TABLE gt_zsap_products LINES lv_lines.  IF lv_lines = 0.    lv_lines_max = lv_lines + sy-loopc.  ELSE.    lv_lines_max = lv_lines + sy-loopc - 1.  ENDIF.

*------ All visible lines of the Step-Loop must be ready for entry, ----

Page 79: CRM BUPA SAP

*------ plus make empty lines visible below           ------------------  IF sy-stepl = 1.    tctrl_zsap_products-lines = gv_zsap_products_linact + sy-loopc - 1.    IF tctrl_zsap_products-lines > lv_lines_max.      tctrl_zsap_products-lines = lv_lines_max.    ENDIF.

*------ Display Status text 'entry X of Y' ----------------------------    lv_text = text-xx1.      " <== What should be in this TEXT literal?    lv_number = gv_zsap_products_linact.    REPLACE '&1' WITH lv_number INTO lv_text.    lv_number = lv_lines.    REPLACE '&2' WITH lv_number INTO lv_text.  ENDIF.

ENDFORM.                    " GT_ZSAP_PRODUCTS_INIT

*&---------------------------------------------------------------------**&      Module  PAI  INPUT*&---------------------------------------------------------------------**      Carry out actions of the Control on the Subscreen to PAI        **----------------------------------------------------------------------*MODULE PAI INPUT.

*------ BDT-Function module for PAI Calls -------------------------  CALL FUNCTION 'BUS_PAI'.

ENDMODULE.                 " PAI  INPUT

*&---------------------------------------------------------------------**&      Module  GT_ZSAP_PRODUCTS_MODIFY  INPUT*&---------------------------------------------------------------------**      Notice changes                                              **---------------------------------------------------------------------*MODULE GT_ZSAP_PRODUCTS_MODIFY.

  PERFORM GT_ZSAP_PRODUCTS_MODIFY.

ENDMODULE.                 " GT_ZSAP_PRODUCTS_MODIFY  INPUT

*&---------------------------------------------------------------------**&      Form  GT_ZSAP_PRODUCTS_MODIFY*&---------------------------------------------------------------------**      Identify changes                                               **---------------------------------------------------------------------*FORM gt_zsap_products_modify.

  MODIFY gt_zsap_products INDEX gv_zsap_products_linact.  IF      sy-subrc <> 0  AND NOT gt_zsap_products  IS INITIAL.    gt_zsap_products-client  = sy-mandt.    gt_zsap_products-partner = but000-partner.    INSERT gt_zsap_products INDEX gv_zsap_products_linact.  ENDIF.

ENDFORM.                    " GT_ZSAP_PRODUCTS_MODIFY

Page 80: CRM BUPA SAP

*&---------------------------------------------------------------------**&      Module  GT_ZSAP_PRODUCTS_LINACT_DETERM  INPUT*&---------------------------------------------------------------------**      Set new index**----------------------------------------------------------------------*MODULE GT_ZSAP_PRODS_LINACT_DETERM INPUT.

  PERFORM GT_ZSAP_PRODUCTS_LINACT_DETERM.

ENDMODULE.                 " GT_ZSAP_PRODUCTS_LINACT_DETERM  INPUT

*&---------------------------------------------------------------------**&      Form  GT_ZSAP_PRODUCTS_LINACT_DETERM*&---------------------------------------------------------------------**      SAP Products: Set new index                                     **----------------------------------------------------------------------*FORM gt_zsap_products_linact_determ.

  gv_zsap_products_linact = tctrl_zsap_products-top_line.

ENDFORM.                    " GT_ZSAP_PRODUCTS_LINACT_DETERM

Page 81: CRM BUPA SAP

ABAP Coding for the PBO Flow LogicUseThe screen event PBO is used to format the data to be displayed before each call.

Because only CHAR fields can be used in the screens for displaying data in the BDT, format-ting of typed data is required (for example, fields with date entries, currency fields..). Format-ting for the BDT display can happen for this event.

For this purpose the BDT offers the possibility of calling view-specific PBO function modules. This occurs independently of the normal PBO routines that are executed by the screen. Al-ways use the PBO function module and not the standard PBO routines in the screen.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions The function group must have been created (Creating a new BDT Function Group).

The screen must have been created (Creating a BDT Screen).

ProcedureCreate a function module using the following naming convention:

Z_<Application>_<BDT Application Object>_PBO_<View>In this case the BDT application object is ’BUPA ’. Example name: Z_ZCUS_BUPA_PBO_ZOE20

This process is described in „Procedure for Creating a Function Module“

Example (Business Partner New Field BUT000)

The following coding is suitable for the example (Business Partner New Field But000):

In this example the use of form routines that are called by the function modules is clearer than placing the functional logic within the function module directly. If you want to structure your functional logic in this way too, then:

FUNCTION Z_ZOE1_BUPA_PBO_ZOE10 .*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Read domain value text  ----------------------------------------  PERFORM ZOE1_FIRST_PBO.

*------ Possibility to read data from other tables*  PERFORM ZOE1ID_PBO.

Page 82: CRM BUPA SAP

ENDFUNCTION.

*&---------------------------------------------------------------------**&      Form  ZOE1_FIRST_PBO*&---------------------------------------------------------------------**      Data for initial display                                        **----------------------------------------------------------------------*FORM zoe1_first_pbo.

  CALL FUNCTION 'BUS_DOMVALUES_PBO'       EXPORTING            i_domname = 'ZZSAP_CUSTOMER'            i_value   = but000-zzsapcustmr       IMPORTING            e_text    = gv_text.

ENDFORM.                    " ZOE1_FIRST_PBO

Example (Business Partner New Field BUT020)FUNCTION Z_ZOE3_BUPA_PBO_ZOE30.

*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

* Get the address number for the address being processed currently CALL FUNCTION 'BUA_BUPA_BUT020_GET' IMPORTING E_ADDRNUMBER = GV_ADDRNUMBER.

READ TABLE GT_BUT020 INTO GS_BUT020 WITH KEY ADDRNUMBER = GV_ADDRNUMBER.

IF SY-SUBRC = 0. GV_ZZADRKIND = GS_BUT020-ZZADRKIND. ELSE.* This check prevents deletion in the event of an incorrect entry and * termination message(PAI Module will not then run). IF GV_PAI_CHECK IS INITIAL. CLEAR GV_ZZADRKIND. GV_PAI_CHECK = gc_true. ENDIF. ENDIF.

ENDFUNCTION.

Page 83: CRM BUPA SAP

ABAP Coding for the PAI ProcessUseIn screen event PAI the data entered is checked for consistency. This can either be carried out in a check table or with the assistance of a semantic rule.

For this event too the BDT offers the possibility of calling view-dependent PAI function mod-ules. Use only modules called by the BDT for carrying out your consistency checks. You should in any case avoid checks within the screen flow logic, otherwise the decoupling of check and interface does not occur.

Ensure also that you issue error messages via the BDT Message Handler only. This collects and issues messages with the assistance of the function module BUS_MESSAGE_STORE.

Preconditions The function group must have been created (Creating a new BDT Function Group).

The screen must have been created (Creating a BDT Screen).

ProcedureCreate a Function Module using the following naming convention:

Z_<Application>_<BDT Application Object>_PAI_<View>In this case the BDT application object is ’BUPA’. Example name: Z_ZCUS_BUPA_PAI_ZOE20

This process is described in „Procedure for Creating a Function Module“

Example (Business Partner New Field BUT000)

FUNCTION Z_ZOE1_BUPA_PAI_ZOE10 .*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

*------ Read domain value text  ----------------------------------------  PERFORM ZOE1_FIRST_PAI.

  PERFORM ZOE1ID_PAI.

ENDFUNCTION.

FORM zoe1_first_pai.*------ Test date of the first contact ---------------------------------*------ ... BDT-FM to the test Calls -----------------------------------  DATA: lc_zsapcustmr LIKE dd07l-domname VALUE 'ZSAP_CUSTOMER',        lv_zsapcustmr LIKE but000-zzsapcustmr.  MOVE but000-zzsapcustmr TO lv_zsapcustmr.

Page 84: CRM BUPA SAP

  CALL FUNCTION 'BUS_DOMVALUES_PAI'       EXPORTING            i_domname     = lc_zsapcustmr*            NAME          = GV_DOMNAME            i_value       = lv_zsapcustmr       EXCEPTIONS            value_not_found = 1.

*------ ... Issue incorrect entry: mistake message ---------------------  IF sy-subrc <> 0.    PERFORM exception_message_send USING sy-msgty                                         'BUT000-ZZSAPCUSTMR'.  ENDIF.

ENDFORM.                    " ZOE1_FIRST_PAI

FORM zoe1id_pai.*------ local data declaration -----------------------------------------  DATA: lv_status LIKE bus000flds-char1.

*------ don't check ----------------------------------------------------*------ ... if field not enterable  ------------------------------------  CALL FUNCTION 'BUS_FMOD_STATUS_GET'       EXPORTING            i_fldgr  = '703'  " <==== hard-coding?       IMPORTING            e_status = lv_status.  CHECK lv_status <> gc_fstat_suppressed    AND lv_status <> gc_fstat_display.

*------ ... if field is empty ------------------------------------------  CHECK NOT but000-zzsapcustmr IS INITIAL.

ENDFORM.      

*&---------------------------------------------------------------**&      Form  EXCEPTION_MESSAGE_SEND                             **&---------------------------------------------------------------**       Exception message issue over Message Handler             **----------------------------------------------------------------**      --> I_MSGTY        Message type                           **      --> I_TBFLD_STRG   Cursorfield And/or. fields highlighted **----------------------------------------------------------------*FORM EXCEPTION_MESSAGE_SEND USING I_MSGTY                                  I_TBFLD_STRG.  CALL FUNCTION 'BUS_MESSAGE_STORE'       EXPORTING            ARBGB      = SY-MSGID            MSGTY      = I_MSGTY            TXTNR      = SY-MSGNO            MSGV1      = SY-MSGV1            MSGV2      = SY-MSGV2            MSGV3      = SY-MSGV3            MSGV4      = SY-MSGV4            TBFLD_STRG = I_TBFLD_STRG.ENDFORM.

Page 85: CRM BUPA SAP

Example (Business Partner New Field BUT020)FUNCTION Z_ZOE3_BUPA_PAI_ZOE30.

*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

DATA: LV_INDX LIKE SY-TABIX.

*------ Get current address -------------------------------------- IF GV_ADDRNUMBER IS INITIAL. CALL FUNCTION 'BUA_BUPA_BUT020_GET' IMPORTING E_ADDRNUMBER = GV_ADDRNUMBER. ENDIF.

CHECK NOT GV_ZZADRKIND IS INITIAL. CLEAR GV_PAI_CHECK. CLEAR GS_BUT020.

*------ Include data in the gt_but020 ---------------------------READ TABLE GT_BUT020 INTO GS_BUT020 WITH KEY ADDRNUMBER = GV_ADDRNUMBER. IF SY-SUBRC = 0. LV_INDX = SY-TABIX. GS_BUT020-ZZADRKIND = GV_ZZADRKIND. MODIFY GT_BUT020 FROM GS_BUT020 INDEX LV_INDX. ELSE. GS_BUT020-ADDRNUMBER = GV_ADDRNUMBER. GS_BUT020-ZZADRKIND = GV_ZZADRKIND. APPEND GS_BUT020 TO GT_BUT020. ENDIF.

ENDFUNCTION.

Example (Business Partner New Table)You can define your check logic here. The example will run without this check too.

Page 86: CRM BUPA SAP

ABAP Coding for the PBC ProcessUseIn the screen event PBC the data to be added is formatted before the initial call.

Programming this event is only necessary when creating new tables, not when appending new fields to existing tables.

Preconditions The function group must have been created (Creating a new BDT Function Group).

The screen must have been created (Creating a BDT Screen).

ProcedureCreate a function module using the following naming convention:

Z_<Application>_<BDT Application Object>_PBC_<View>In this case the BDT application object is ’BUPA’. Example name: Z_ZCUS_BUPA_PBC_ZOE20

This process is described in „Procedure for Creating a Function Module“

Example (Business Partner New Table)

FUNCTION Z_ZOE2_BUPA_PBC_ZOE20 .*"----------------------------------------------------------------------*"*"Local interface:*"  IMPORTING*"     REFERENCE(I_ACTION) LIKE  BUS000FLDS-CHAR1*"----------------------------------------------------------------------

*------ Do not carry out actions following entries into screen ---------  CHECK I_ACTION = '1'     OR I_ACTION = '2'.

*------ Sort product entries ---------------------------------------------  SORT GT_ZSAP_PRODUCTS BY PARTNER SAP_PRODUCTS.

*------ Display begins with the first entry ----------------------------  GV_ZSAP_PRODUCTS_LINACT = 1.

ENDFUNCTION.

Page 87: CRM BUPA SAP

Creating New BDT Field GroupsUseIn a field group, fields are grouped together whose common ready-for-input status should be controlled. A field group may only contain fields for one application. A customer should neither change nor extend the definitions of field groups delivered by SAP because this represents a modification. Instead the customer should define his or her own field groups and assign them to his or her own views.

ProcedureYou can access the interfaces for maintaining BDT control tables by entering /NBUPT in the SAP-GUI command field. Alternatively you can call maintenance transactions by their transac-tion codes.

1. Choose menu option Business Partner->Control->Screen layout->Field Groups (transaction BUS2).

2. In the maintenance interface click on the button „New entries“. Make the following entries in the Detail screen:Field Group: The number range 600-500 is reserved for customers. Description: Enter the description for the field group here.Further entries in this Detail screen for the field group are optional– you can read their de-scription in the [Developer’s Manual BDT].

3. Return to the overview screen for the field groups, select your new field group and choose “Field Group->Field assignment“ from the left-hand side of the navigation tree by double-clicking.

4. Enter table and field names. Normally you should select the checkfield „Input field“.

5. Save your data.

Example (Business Partner New Field BUT000)Create a field group and assign it to table BUT000, Field ZZSAPCUSTMR.

Example (Business Partner New Field BUT020)Create a field group and assign it to table BUT020, Field ZZADRKIND.

Example (Business Partner New Table)Create a field group and assign it to table ZSAP_PRODUCTS, Field SAP_PRODUCTS.

Page 88: CRM BUPA SAP

Creating a New View in the BDTUse

One or more field groups make up a view. All attributes that are displayed and checked to-gether are grouped in one view. The fields of a view cannot be separated in screen layout since they are located on the same subscreen.

A view may only contain fields from one application. A downstream application may not ex-tend a view; instead, it should create its own views for its attributes and assign its own sub-screens to these views. The same applies to customers, as extending a view amounts to a modification.

Preconditions Create an application as necessary

A subscreen must have been created as a screen (Creating a BDT Screen).

Registering the Created Subscreen as a BDT View 1. To log on to the subscreen you created as a BDT view, choose menu option Business Part-

ner->Control->Screen layout->Views (transaction BUS3).

2. Click on the pushbutton „New entries“. This takes you to the detail entry template for BDT views.

3. Enter a name that starts with Z and contains your application name.

4. Enter a Description for the view.

5. In the field Application enter either your newly created application, or application BUP for data, or BUA for addresses as default.

6. You should use ’0’ as default differentiation type.

7. Generally you can enter BUP010 (central data) or BUA010 (addresses) in Data set. If you have created a new data set, enter it here.

8. You should select Entry view and Dialog view.

9. Enter the program name and number of your screen in Subscreen.

10. Enter the function module names for the following events:

Before screen callup (PBC): Function module that runs only once before screen callup

Prior to output (PBO): Function module that runs prior to each output of the view.

Following entry (PAI): Function module that runs following each entry in the view.

11. Leave the fields in Text object empty and choose Data screen as screen configuration.

12. Save your data.

Page 89: CRM BUPA SAP

Assigning Field Groups to a View1. Double-clicking on „View->Field group assignment“ on the left-hand side of the navi-

gation tree takes you to the assignment maintenance interface.

2. Click on the button „New entries“ and enter the field groups you want (F4 assistance possible).

3. Save your data.

Example (Business Partner New Field BUT000)Create a view with the name ZOE10 and enter the following values:

Application = “BUP”

Differentiation type = “0”

Data set = “BUP010”

Select Entry view and Dialog view

Program name = “SAPLZCRM_BP_OBJECTEXTENSION_FG” (name of your function group)

Screen number = “0001”

Prior to output = “Z_ZOE1_BUPA_PBO_ZOE10”

Following entry = “Z_ZOE1_BUPA_PAI_ZOE10”

Select Data screen

Example (Business Partner New Field BUT020)Create a view with the name ZOE30 and enter the following values:

Application = “BUA”

Differentiation type = “0”

Data set = “BUA010”

Select Entry view and Dialog view

Program name = “SAPLZCRM_BP_OBJEXTENSION_FG3” (Name of your function group)

Screen number = “0001”

Prior to output = “Z_ZOE3_BUPA_PBO_ZOE30”

Following entry = “Z_ZOE3_BUPA_PAI_ZOE30”

Select Data screen

Example (Business Partner New Table)Create a view with the name ZOE20 and enter the following values:

Page 90: CRM BUPA SAP

Application = “BUP”

Differentiation type = “0”

Data set = “BUP010”

Select Entry view and Dialog view

Program name = “ SAPLZCRM_BP_OBJEXTENSION_FG2” (Name of your function group)

Screen number = “ 0020”

Prior to output = Z_ZOE2_BUPA_PBC_ZOE20

Select Data screen

Assign the field groups you created earlier (e.g. 703) to your views.

Page 91: CRM BUPA SAP

Creating a BDT SectionUseOne or more views are grouped together to form a section. The BDT automatically puts a frame around each section. The only exception to this rule is the first section of a screen in which the header data appears. According to SAP ergonomic guidelines a frame should not be put around this data. In addition to the description, you also define a language-dependent title for the section, which is displayed in a dialog in the upper left-hand corner of the frame.

Depending on data character it may be necessary to create a new section or use an old one. In the next stage you must extend newly created or existing sections.

PreconditionsA new view must have been created (Creating a New View in the BDT).

ProcedureIf views should only be assigned to existing sections without creating new sections, omit steps 2 – 6.

1. To create a new section, choose menu option Business Partner->Control->Screen layout->Sections (transaction BUS4).

2. Click on the pushbutton „New entries“.

3. Enter the technical name of the new section under Sections. This should be in the customer namespace, i.e. start with ’Z’.

4. Enter a Description and a Title to serve as a frame header in the dialog.

5. Save your data.

6. Return to the maintenance transaction main screen

7. Select the section you changed or added and by double-clicking on the menu option „Assign section -> Views“ goto the maintenance screen.

8. Click on the pushbutton „New entries“.

9. You should enter a 6-figure item number under Item. If you assign new views to existing sections you should pay attention to the customer names-pace. The last two figures in the item are reserved for the customer.

10. Enter the name of the view.

11. Repeat the last two steps for all views to be specified.

12. Save your data.

Example (Business Partner New Field BUT000)Create a section ZOE1_1 as described above and assign view ZOE10 to it.

Page 92: CRM BUPA SAP

Example (Business Partner New Field BUT020)Create a section ZOE3_1 as described above and assign view ZOE30 to it.

Example (Business Partner New Table)Create a section ZOE2_2 as described above and assign view ZOE20 to it.

Page 93: CRM BUPA SAP

Creating a BDT ScreenUseThe screen represents the largest unit in screen layout. One or more sections are grouped to-gether as a screen. In addition to screens created with the BDT, you can integrate screens that were not created with the BDT by using the External screens selection.

Creating a BDT Screen1. To create a new screen choose the menu option Business Partner->Control->Display layout-

>Screens (transaction BUS5).

2. Click on the pushbutton „New entries“.

3. Enter the technical name of the new section under Sections. This should be in the customer namespace, i.e. start with ’Z’.

4. Enter a Description and a Title that will be visible in the Business Partner dialog.

5. You can normally leave the remaining settings in their default state.

6. Save your data.

Assigning Sections to a Screen1. Return from the maintenance transaction (BUS5) to the main screen.

2. Select the newly created screen.

3. Double-clicking on „ Assign screen->Sections “ on the left-hand side of the navigation tree takes you to the assignment maintenance interface. Click on the button „New entries“.

4. You should enter a 6-figure item number under Item. If you assign new sections to existing screens you should pay attention to the customer namespace. The last two figures in the item are reserved for the customer.

5. Enter the name of the section.Note: You must insert the section BUP009 or EMPTY in New screens before your newly cre-ated section!

6. Repeat the last two steps for all sections to be specified.

7. Save your data.

Assigning New Screens to a Screen SequenceIf you have created a new screen you must now assign it to a screen sequence.

1. To define screen sequences choose the menu option Business Partner->Control->Screen se-quence (transaction BUS6).

2. Choose a screen sequence (normally BUP001).

3. Double-clicking on „Assign screen sequence->Screens“ on the left-hand side of the naviga-tion tree takes you to the assignment maintenance interface. Click on the button „New en-tries“.

Page 94: CRM BUPA SAP

4. You must specify the item number under Item. Insert your screen between other screens. Pay attention to the customer namespace. The last two figures in the item are reserved for the customer.

5. Enter the name of your screen in the column Screen.

6. Save your data.

Example (Business Partner New Field BUT000)Create a screen ZOE1_1 as described above with the title „SAP Customer?“.

Assign the screen to section ZOE1_1 and screen sequence BUP1 and BUP001.

Example (Business Partner New Field BUT020)The visualization of append structure data can only take place in the address detail screen BUA130 because extension of the table control for the address overview cannot be achieved without modification. Assign your section ZOE3_1 to screen BUA130. Because you are using an already existing screen you do not need to assign it to a screen sequence.

Example (Business Partner New Table)Create a screen ZOE2_2 as described above with the title „Used SAP Products“.

Assign the screen to section ZOE2_2 and screen sequence BUP1 and BUP001.

Page 95: CRM BUPA SAP

Registering BDT Event FunctionsUseSo that your newly created event function module can be called by the BDT you must register it in BDT Customizing. This applies only to general event function modules in the application. View-dependent function modules determined for PBO or PAI are not registered here.

PrerequisiteYou have created all necessary function modules for the BDT Events.

ProcedureYou can access the interfaces for maintaining BDT control tables by entering /NBUPT in the SAP-GUI command field. Alternatively you can call maintenance transactions by their transac-tion codes.

Execute the steps below for each function module.

1. To register a function module choose the menu option Business Partner->Control->Events->Business Data Toolset (transaction BUS7).

2. Select the event you want and goto menu option „Assign event -> Function Module“ in the maintenance screen by double-clicking on it.

3. Click on the pushbutton „New entries“.

4. You should enter a 6-figure item number under Item. If you assign new sections to existing screens you should pay attention to the customer namespace. The last two figures in the item are reserved for the customer.

5. Specify the name of your function module.

6. Enter an ’X’ in the field Call.

7. Enter your application in the field Application. If you have not created a new application, use the application BUP for central data and application BUA for addresses.

8. Save your data.

Example (Business Partner All Scenarios)Register all the event modules you created as described above.

Page 96: CRM BUPA SAP

Structures for Data ExchangeUseThe Message BDocs in the CRM Middleware transport their contents in complex (encapsu-lated) ABAP Dictionary structures.

To do this the Business Partner BDoc BUPA_MAIN uses the structure BUS_EI_EXTERN. At the lowest level it contains the BAPI structures of the Business Partners and the BAPI struc-tures for CRM-specific data in the APPEND of the CRM. Customers can extend the complex structure per APPEND. However, in this case the existing BAPI structures in the lowest level may not be extended, but new structures must be assigned to a higher level per APPEND.

You can assign your new table to the complex structure according to its business affiliation – but not at the lowest level.

The creation and extension of structures is described in more detail in: Extending and Creat-ing Business Partner Tables

In addition you require BAPIMTCS containers in which the BDoc is mapped for transport to the R/3 OLTP system.

Example (Business Partner New Field for BUT000)

Process the data type BUS_EI_EXTERN in the ABAP Dictionary in change mode. Then dou-ble-click on the component CENTRAL_DATA, after that on the component COMMON, and fi-nally on DATA. You are now in the substructure BUS_EI_BUPA_CENTRAL_DATA; where you can create a new append structure.

Choose the name ZABUT000TEST2 with component ZZSAPCUSTMR and component type ZSAPCUSTOMER.

Example (Business Partner New Field for BUT020)

Process the data type BUS_EI_EXTERN in the ABAP Dictionary in change mode. Then dou-ble-click on the component CENTRAL_DATA, after that on the component ADDRESS, then on ADDRESSES, after that on row type BUS_EI_BUPA_ADDRESS, then on the component DATA and finally on POSTAL. You are now in the substructure BUS_EI_BUPA_POSTAL_AD-DRESS, where you can create a new append structure.

Choose the name ZABUS_EI_BUPA_POSTAL_ADDRESS with component ZZADRKIND and component type ZADR_KIND.

Example (Business Partner New Table)First, create structure ZBUS_EI_STRUC_SAPPROD_X:

Component Component Type

SELLER BAPIUPDATE

CONTRACT_DATE BAPIUPDATE

Page 97: CRM BUPA SAP

Then create structure ZBUS_EI_BUPA_SAPPROD:

Component Component Type

TASK BUS_EI_OBJECT_TASK

DATA_KEY ZSAPPRODUCT

DATA ZBUS_EI_STRUC_SAPPROD

DATAX ZBUS_EI_STRUC_SAPPROD_X

After that, create table type ZBUS_EI_BUPA_SAPPROD_T that uses ZBUS_EI_BUPA_SAP-PROD as a row type.

Then create structure ZBUS_EI_SAPPROD:

Component Component Type

CURRENT_STATE BUS_EI_CURRENT_STATE

SAPPRODUCTS ZBUS_EI_BUPA_SAPPROD_T

Then extend complex structure BUS_EI_EXTERN per Append:

Process the data type BUS_EI_EXTERN in the ABAP Dictionary in change mode. Then dou-ble-click on the component CENTRAL_DATA. You are now in the substructure BUS_EI_CEN-TRAL_DATA; where you can create a new append structure.

Choose the name ZABUZSAPPRODUCTS with component ZZSAPPRODUCTS and compo-nent type ZBUS_EI_SAPPROD.

Create two structures as a BAPIMTCS container for the data exchange:

1. ZSPRD_R3A1 contains the field CURSTAT with the data element XFIELD. This indicator should notify the CRM system whether „Current State“, that is, the complete data record is sent.

2. ZSPRD_R3A2 contains the following fields:

Fields Data Element Short Description

TASK CHAR1 I, C, D for Insert, Change or Delete

DATA_KEY ZSAPPRODUCT Character field, length 10

SELLER CHAR40 Character, 40-figure

CTR_DATE DATS Field, type DATS

SELLERX CHAR1 X-Flag

CTR_DATEX CHAR1 X-Flag

This structure transports data from the table ZSAP_PRODUCS to the R/3 system. If the Cur-rent State flag has not been set, the task field gives instructions what should be done with the data record in the R/3 (Insert, Change, Delete). In the event of a change only the fields flagged with an X are overwritten.

Page 98: CRM BUPA SAP

CRM Business Partner: OutboundUseThe CRM Business Partner writes in the Outbound – before it updates the data in the data-base – the data to be sent in the complex structure of the BDoc BUPA_MAIN.

This means the data for the BDoc must not be read from the database, but must be got per callback from the application function group (BDT) or from the BAPI.

If the Business Partner of a customer is extended by additional data, then this data (analogous to the standard) must be mapped in to the resulting extended complex Bdoc structure.

For this purpose the CRM-Outbound recognizes various Events where mapping function modules with fixed interfaces are called.

Event Description

CRMOU CRM Business Partner Outbound

CRMIN CRM Business Partner Inbound

APADO Simplified Outbound for addresses (BUT020)

APCEO Simplified Outbound for central data (BUT000)

There is a special logic for APPENDS to BUT000 or BUT020. In the mapper that executes the mapping from database tables to the complex structure for BUT000 or BUT020 an event is called in which a customer can map his or her own data in the complex Bdoc structure without this having to be read per callback.

Registering Function Modules1. Start transaction SM30 (Menu path System Services Table maintenance Extended

table maintenance.

2. Enter Table/View CRMC_BUT_CALL_FU.

3. Click on the Maintain button.

4. Choose New entries for the process interface you want or change existing entries as follows:

Parameter Value

Event Event name (e.g. CRMOU)

Object BUPA or Business Partner

Item Enter a 6-figure item number greater than existing entries. Starting with 9 might be a good choice.

Function name Your function module, e.g. z_apceo_append_but000

Call Tick here, must be active to be called.

5. Click on the Save button and leave the transaction.

Page 99: CRM BUPA SAP

Example (Business Partner New Field for BUT000)Create the following objects in your function group for the BUT000 extension (see Creating a new BDT Function Group):

FUNCTION z_apceo_append_but000 .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(IS_BUT000) TYPE BUT000*" CHANGING*" REFERENCE(COMMON_DATA) TYPE BUS_EI_BUPA_CENTRAL*"----------------------------------------------------------------------

* register this function in CRMC_BUT_CALL_FU, event APCEO for BUPA

MOVE-CORRESPONDING is_but000 TO common_data-data-zzsapcustmr.

ENDFUNCTION.

Register this module as described above in the table CRMC_BUT_CALL_FU.

Example (Business Partner New Field for BUT020)Create the following objects in your function group for the BUT020 extension (see Creating a new BDT Function Group):

FUNCTION z_apado_append_but020 .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(IS_BUT020) TYPE BUT020*" CHANGING*" REFERENCE(COMMON_DATA) TYPE BUS_EI_BUPA_POSTAL_ADDRESS*"----------------------------------------------------------------------

MOVE-CORRESPONDING is_but020 TO common_data-zzadrkind.ENDFUNCTION.

Register this module as described above in the table CRMC_BUT_CALL_FU.

Example (Business Partner New Table)Create the following objects in your function group for the new table (see Creating a new BDT Function Group):

FUNCTION z_crmout_new_tables .*"----------------------------------------------------------------------*"*"Local interface:

Page 100: CRM BUPA SAP

*" IMPORTING*" REFERENCE(IV_MODE) TYPE CHAR1 OPTIONAL*" TABLES*" TI_BAPIIDLIST STRUCTURE BAPIIDLIST OPTIONAL*" CHANGING*" REFERENCE(C_BP_STRUCT) TYPE BUS_EI_MAIN*"----------------------------------------------------------------------

* register this function in CRMC_BUT_CALL_FU, event CRMOUT for BUPA

DATA bpartner TYPE bu_partner. DATA lt_zsap_products_kz TYPE TABLE OF zsap_products_kz. DATA ls_zsap_products_kz TYPE zsap_products_kz. DATA zzsapproducts TYPE zbus_ei_sapprod. DATA ls_sapproducts TYPE zbus_ei_bupa_sapprod.

FIELD-SYMBOLS: <fs_bpext> TYPE bus_ei_extern.

* Loop over all Business Partners in the list LOOP AT c_bp_struct-partners ASSIGNING <fs_bpext>. REFRESH lt_zsap_products_kz. CLEAR zzsapproducts. bpartner = <fs_bpext>-header-object_instance-bpartner.

* Process Function Group Callback in none-extract mode IF iv_mode IS INITIAL. CALL FUNCTION 'Z_ZOE2_ZSAPPROD_CALLBACK' EXPORTING partner_number = bpartner TABLES t_zsapprod = lt_zsap_products_kz.

* Extract from database in extract-mode ELSEIF iv_mode = 'E'. SELECT * FROM zsap_products INTO CORRESPONDING FIELDS OF TABLE lt_zsap_products_kz WHERE partner = bpartner.

* Exit mode is unknown ELSE. EXIT. ENDIF.

* Map data to BDoc structure LOOP AT lt_zsap_products_kz INTO ls_zsap_products_kz. CLEAR ls_sapproducts. ls_sapproducts-task = ls_zsap_products_kz-kz. ls_sapproducts-data_key = ls_zsap_products_kz-sap_products. MOVE-CORRESPONDING ls_zsap_products_kz TO ls_sapproducts-data. ls_sapproducts-datax-seller = 'X'. ls_sapproducts-datax-contract_date = 'X'. APPEND ls_sapproducts TO zzsapproducts-sapproducts. ENDLOOP. IF sy-subrc = 0. IF iv_mode = 'E'. zzsapproducts-current_state = 'X'. ELSE. zzsapproducts-current_state = ''. ENDIF.

Page 101: CRM BUPA SAP

<fs_bpext>-central_data-zzsapproducts = zzsapproducts. ENDIF.

ENDLOOP.

ENDFUNCTION.

Register this module as described above in the table CRMC_BUT_CALL_FU.

FUNCTION z_zoe2_zsapprod_callback .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" REFERENCE(PARTNER_NUMBER) TYPE BU_PARTNER OPTIONAL*" TABLES*" T_ZSAPPROD STRUCTURE ZSAP_PRODUCTS_KZ*"----------------------------------------------------------------------

REFRESH: t_zsapprod.

* Read from BDT global memory LOOP AT mem_zsap_products. IF partner_number IS INITIAL OR mem_zsap_products-partner = partner_number. APPEND mem_zsap_products TO t_zsapprod. ENDIF. ENDLOOP.

LOOP AT mem_zsap_products_old WHERE kz = 'D'. IF partner_number IS INITIAL OR mem_zsap_products_old-partner = partner_number. APPEND mem_zsap_products_old TO t_zsapprod. ENDIF. ENDLOOP.

* Read from "BAPI" global memory

IF t_zsapprod[] IS INITIAL. LOOP AT gt_zsapprod. IF partner_number IS INITIAL OR gt_zsapprod-partner = partner_number. APPEND gt_zsapprod TO t_zsapprod. ENDIF. ENDLOOP.

LOOP AT gt_zsapprod_old WHERE kz = 'D'. IF partner_number IS INITIAL OR gt_zsapprod_old-partner = partner_number. APPEND gt_zsapprod_old TO t_zsapprod. ENDIF. ENDLOOP. ENDIF.

ENDFUNCTION.

Page 102: CRM BUPA SAP

Note: This Callback module enables you to create applications and data exchange in various function groups. This was not done in this example, but it is better in any case to use this Call-back module.

Page 103: CRM BUPA SAP

CRM Business Partner InboundUseThe CRM Business Partner Inbound is called by the Middleware. It is responsible for validat-ing data that should be imported into the CRM and making the relevant changes per BAPI.

Additional information to be completed by the customer must also be checked and updated. To do this, event CRMIN must be implemented. The function module contains the complex Bdoc structure, checks the data and saves it with a BAPI-like function module. Errors that may have occurred are returned via BAPIRETURN parameters and are taken into account in the CRM Service during error handling.

The Business Partner offers a special service for extending tables BUT000 or BUT020 per APPEND. You can write this directly to the memory of the Business Partner after checking with the assistance of modules BUP_MEMORY_BUT000_FILL and BUP_MEMORY_BUT020_FILL, where it is updated together with the rest of table BUT000 or BUT020.

Example: Business Partner New Field for BUT000 and BUT020Create the following objects in your function group for the BUT000 extension (see Creating a new BDT Function Group):

FUNCTION z_crmin_append_fields .*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" REFERENCE(STATUS) TYPE SMWVALSTAT*" CHANGING*" REFERENCE(C_BP_STRUCT) TYPE BUS_EI_EXTERN*" REFERENCE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*"----------------------------------------------------------------------

* register this function in CRMC_BUT_CALL_FU, event CRMIN for BUPA

DATA: lv_partnerguid TYPE but000-partner_guid, lv_partner TYPE bu_partner, lv_partnerext TYPE bu_bpext, ls_bus1006ce TYPE bapibus1006_central, ls_bus1006ceo TYPE bapibus1006_central, ls_bus000 TYPE bus000___i, lt_bus020 TYPE TABLE OF bus020___i, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2.

FIELD-SYMBOLS: <fs_bupa_addr> TYPE bus_ei_bupa_address, <fs_bus020i> TYPE bus020___i.

status = 'S'. lv_partnerguid = c_bp_struct-header-object_instance-bpartnerguid. lv_partnerext =

Page 104: CRM BUPA SAP

c_bp_struct-central_data-common-data-bp_centraldata-partnerexternal.

CALL FUNCTION 'BUPA_NUMBERS_GET' EXPORTING iv_partner_guid = lv_partnerguid iv_partner_external = lv_partnerext IMPORTING ev_partner = lv_partner.

CHECK NOT lv_partner IS INITIAL. " or add error message

* -------- Business Partner - New Fields in BUT000

* Get BUT000 table from global memory CALL FUNCTION 'BUP_MEMORY_BUT000_GET' EXPORTING iv_partner = lv_partner IMPORTING es_but000 = ls_bus000 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0.

* Workaround for initial BUT000 memory CALL FUNCTION 'BAPI_BUPA_CENTRAL_GETDETAIL' EXPORTING businesspartner = lv_partner IMPORTING centraldata = ls_bus1006ceo TABLES return = lt_return. LOOP AT lt_return TRANSPORTING NO FIELDS WHERE type CA 'AEX'. status = 'A'. ENDLOOP.

IF status <> 'A'. ls_bus1006ce = ls_bus1006ceo. ls_bus1006ce-searchterm1 = 'EEWDUMMY'. CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE' EXPORTING businesspartner = lv_partner centraldata = ls_bus1006ce. CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE' EXPORTING businesspartner = lv_partner centraldata = ls_bus1006ceo. CALL FUNCTION 'BUP_MEMORY_BUT000_GET' EXPORTING iv_partner = lv_partner IMPORTING es_but000 = ls_bus000 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. status = 'A'. ENDIF. ENDIF. ELSE.* Move BDoc data to table

Page 105: CRM BUPA SAP

MOVE-CORRESPONDING c_bp_struct-central_data-common-data-zzsapcustmr TO ls_bus000.

* Put table back to global memory CALL FUNCTION 'BUP_MEMORY_BUT000_FILL' EXPORTING is_but000 = ls_bus000 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. status = 'A'. RETURN. ENDIF. ENDIF.

* -------- Business Partner - New Fields in BUT020

IF status <> 'A'.* Get BUT020 table from global memory CALL FUNCTION 'BUP_MEMORY_BUT020_GET' EXPORTING iv_partner = lv_partner TABLES et_but020 = lt_bus020 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. EXIT. ENDIF. ENDIF.

IF status <> 'A'.* Move BDoc data to table LOOP AT lt_bus020 ASSIGNING <fs_bus020i>. LOOP AT c_bp_struct-central_data-address-addresses ASSIGNING <fs_bupa_addr> WHERE data-postal-data-standardaddress = 'X'. MOVE-CORRESPONDING <fs_bupa_addr>-data-postal-zzadrkind TO <fs_bus020i>.* Set Update flag if necessary IF <fs_bus020i>-aktyp IS INITIAL. <fs_bus020i>-aktyp = '02'. ENDIF. EXIT. ENDLOOP. ENDLOOP.

* Put tables back to global memory CALL FUNCTION 'BUP_MEMORY_BUT020_FILL' TABLES it_but020 = lt_bus020 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. status = 'A'. ENDIF. ENDIF.

* ------ General: Error Handling

IF status = 'A'.

Page 106: CRM BUPA SAP

ls_return-type = sy-msgty. ls_return-id = sy-msgid. ls_return-number = sy-msgno. ls_return-message_v1 = sy-msgv1. ls_return-message_v2 = sy-msgv2. ls_return-message_v3 = sy-msgv3. ls_return-message_v4 = sy-msgv4. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO ls_return-message.

CALL FUNCTION 'BUPA_MWX_BDOC_BUILD_ERR_MESS' EXPORTING iv_obj_id = c_bp_struct-header-object_instance-bpartnerguid is_bapiret2 = ls_return IMPORTING et_err_msg = error_segments. ENDIF.

ENDFUNCTION.

Register this module in the table CRMC_BUT_CALL_FU (described in CRM Business Partner: Outbound).

Example (Business Partner New Table)Create the following objects in your function group for the new table (see Creating a new BDT Function Group):

FUNCTION Z_CRMIN_NEW_TABLES .*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" REFERENCE(STATUS) TYPE SMWVALSTAT*" CHANGING*" REFERENCE(C_BP_STRUCT) TYPE BUS_EI_EXTERN*" REFERENCE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*"----------------------------------------------------------------------

* register this function in CRMC_BUT_CALL_FU, event CRMIN for BUPA

DATA lt_return TYPE TABLE OF bapiret2. DATA ls_return TYPE bapiret2.

DATA bpartnerguid TYPE bu_partner_guid. DATA partnerexternal TYPE bu_bpext.

DATA bp_task TYPE bus_ei_object_task.

status = 'S'.

bpartnerguid = c_bp_struct-header-object_instance-bpartnerguid. bp_task = c_bp_struct-header-object_task. partnerexternal =

Page 107: CRM BUPA SAP

c_bp_struct-central_data-common-data-bp_centraldata-partnerexternal. IF NOT bpartnerguid IS INITIAL. CLEAR partnerexternal. ENDIF.

IF ( NOT c_bp_struct-central_data-zzsapproducts IS INITIAL ) OR bp_task = 'D' OR bp_task = 'C'.

CALL FUNCTION 'Z_ZOE2_ZSAPPROD_PERSIST' EXPORTING iv_bpartnerguid = bpartnerguid iv_partner_external = partnerexternal iv_bptask = bp_task iv_current_state = c_bp_struct-central_data-zzsapproducts-current_state it_sapproducts = c_bp_struct-central_data-zzsapproducts-sapproducts TABLES et_return = lt_return.

ENDIF.

* File Error LOOP AT lt_return INTO ls_return. CALL FUNCTION 'BUPA_MWX_BDOC_BUILD_ERR_MESS' EXPORTING iv_obj_id = c_bp_struct-header-object_instance-bpartnerguid is_bapiret2 = ls_return IMPORTING et_err_msg = error_segments. IF ls_return-type CA 'XEA'. status = 'A'. ENDIF. ENDLOOP.ENDFUNCTION.

Register this module in the table CRMC_BUT_CALL_FU (described in CRM Business Partner: Outbound).

The following module fulfills part of the BAPI norm and calls the update task after the COM-MIT.

FUNCTION z_zoe2_zsapprod_persist .*"----------------------------------------------------------------------*"*"Lokale Schnittstelle:*" IMPORTING*" REFERENCE(IV_BPARTNERGUID) TYPE BU_PARTNER_GUID OPTIONAL*" REFERENCE(IV_PARTNER_EXTERNAL) TYPE BU_BPEXT OPTIONAL*" REFERENCE(IV_BPTASK) TYPE BUS_EI_OBJECT_TASK OPTIONAL*" REFERENCE(IV_CURRENT_STATE) TYPE BUS_EI_CURRENT_STATE OPTIONAL*" REFERENCE(IT_SAPPRODUCTS) TYPE ZBUS_EI_BUPA_SAPPROD_T*" TABLES*" ET_RETURN STRUCTURE BAPIRET2*"----------------------------------------------------------------------* Pseudo-BAPI to write ZSAPCUSTOMER to database

CONSTANTS: lc_table_products LIKE cdpos-tabname VALUE 'ZSAP_PRODUCTS'.

DATA lv_bpartner TYPE bu_partner.

Page 108: CRM BUPA SAP

DATA lt_zsapprod TYPE TABLE OF zsap_products_kz. DATA lt_zsapprod_old TYPE TABLE OF zsap_products_kz. DATA ls_zsapprod TYPE zsap_products_kz. DATA ls_zsapprod2 TYPE zsap_products_kz. DATA ls_sapproducts TYPE zbus_ei_bupa_sapprod. DATA lv_tabix LIKE sy-tabix. DATA lf_kz TYPE char1.

* Get Number, because of internal number assignment CALL FUNCTION 'BUPA_NUMBERS_GET' EXPORTING iv_partner_guid = iv_bpartnerguid iv_partner_external = iv_partner_external IMPORTING ev_partner = lv_bpartner TABLES et_return = et_return.

IF lv_bpartner IS INITIAL.* TODO: You might add error handling here EXIT. ENDIF.

* Read old status if necessary LOOP AT gt_zsapprod_old WHERE partner = lv_bpartner. APPEND gt_zsapprod_old TO lt_zsapprod_old. ENDLOOP. IF sy-subrc <> 0. SELECT * FROM zsap_products INTO CORRESPONDING FIELDS OF TABLE lt_zsapprod_old WHERE partner = lv_bpartner. CLEAR ls_zsapprod. MODIFY lt_zsapprod_old FROM ls_zsapprod TRANSPORTING client WHERE NOT client IS INITIAL. ELSE. LOOP AT gt_zsapprod WHERE partner = lv_bpartner. APPEND gt_zsapprod TO lt_zsapprod. ENDLOOP. ENDIF.

* Add old status to new if no deletion or current state required IF iv_bptask <> 'D' AND iv_bptask <> 'C' AND iv_current_state IS INITIAL. lt_zsapprod[] = lt_zsapprod_old[]. ENDIF.

IF iv_bptask = 'D'.* Leave new status empty to delete everything,* because BuPa was deleted.

ELSE.* Create new status regarding current state, task flags* and x-flags

* Map BDoc data to local table LOOP AT it_sapproducts INTO ls_sapproducts.

Page 109: CRM BUPA SAP

CLEAR ls_zsapprod. MOVE-CORRESPONDING ls_sapproducts-data TO ls_zsapprod. ls_zsapprod-sap_products = ls_sapproducts-data_key. ls_zsapprod-partner = lv_bpartner. CLEAR ls_zsapprod-client. lf_kz = ls_sapproducts-task.

* Add data to new status if current state is given IF ( iv_bptask = 'C' OR NOT iv_current_state IS INITIAL ) AND lf_kz <> 'D'. APPEND ls_zsapprod TO lt_zsapprod. ELSE.* Otherwise: Read existing data with same key CLEAR: ls_zsapprod2, lv_tabix. READ TABLE lt_zsapprod INTO ls_zsapprod2 WITH KEY sap_products = ls_zsapprod-sap_products. IF sy-subrc = 0. lv_tabix = sy-tabix. ENDIF.

* If fields are not sent, use initial or old value IF ls_sapproducts-datax-seller IS INITIAL. ls_zsapprod-seller = ls_zsapprod2-seller. ENDIF.

IF ls_sapproducts-datax-contract_date IS INITIAL. ls_zsapprod-contract_date = ls_zsapprod2-contract_date. ENDIF.

* If data should be updated or inserted: add/modify to new status IF lf_kz CA 'IUC' OR lf_kz IS INITIAL. IF lv_tabix IS INITIAL. APPEND ls_zsapprod TO lt_zsapprod. ELSE. MODIFY lt_zsapprod FROM ls_zsapprod INDEX lv_tabix. ENDIF.* If data should be deleted: delete from new status ELSEIF lf_kz = 'D'. DELETE lt_zsapprod WHERE sap_products = ls_zsapprod-sap_products. ENDIF.

ENDIF.

ENDLOOP. ENDIF.

SORT lt_zsapprod. SORT lt_zsapprod_old.

CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES' EXPORTING tablename = lc_table_products TABLES table_new = lt_zsapprod

Page 110: CRM BUPA SAP

table_old = lt_zsapprod_old EXCEPTIONS nametab_error = 1 OTHERS = 2. IF sy-subrc <> 0.* TODO: You might add error handling here ENDIF.

* Check data* (you might reuse check-routines of DCHCK-Event)

* Register delete function for rollback or commit CALL FUNCTION 'BUFFER_SUBSCRIBE_FOR_REFRESH' EXPORTING name_of_deletefunc = 'Z_ZOE2_ZSAPPROD_INIT'.

* Map local data to global BAPI data DELETE gt_zsapprod_old WHERE partner = lv_bpartner. DELETE gt_zsapprod WHERE partner = lv_bpartner. APPEND LINES OF lt_zsapprod_old TO gt_zsapprod_old. APPEND LINES OF lt_zsapprod TO gt_zsapprod.

* Save data PERFORM data_save ON COMMIT.

* Call BADI for Modifications CALL FUNCTION 'BUPA_BADI_CALL'.

ENDFUNCTION.

FUNCTION Z_ZOE2_ZSAPPROD_INIT .*"----------------------------------------------------------------------*"*"Local interface:*"----------------------------------------------------------------------

clear: gt_zsapprod, gt_zsapprod_old.

refresh: gt_zsapprod, gt_zsapprod_old.

ENDFUNCTION.

FORM data_save .

*------ ... Asynchronous (with COMMIT) --------------------------------- IF gv_xupdtask = gc_x. CALL FUNCTION 'Z_ZOE2_BUPA_UPDATE' IN UPDATE TASK TABLES t_zsap_products = gt_zsapprod t_zsap_products_old = gt_zsapprod_old.

*------ ... Synchronous (without COMMIT) --------------------------------- ELSE. CALL FUNCTION 'Z_ZOE2_BUPA_UPDATE'

Page 111: CRM BUPA SAP

TABLES t_zsap_products = gt_zsapprod t_zsap_products_old = gt_zsapprod_old. ENDIF.

ENDFORM. " DATA_SAVE

Page 112: CRM BUPA SAP

Programming CRM Middleware ExitsUseBecause no CRM Middleware is available in the R/3 OLTP system, Message BDocs cannot be sent directly to the R/3 OLTP system. The content is instead packed in BAPIMTCS contain-ers. These are structures defined in the ABAP Dictionary that are mapped in generic contain-ers (CRMCH4000) and are sent in XML format via qRFC between the R/3 and the CRM along with some administrative information.

Because the SAP standard only maps the BDOC part known to it to the BAPIMTCS container, mapping of customer extensions must be implemented at this stage.

This method is also recommended when fields in the customer master table KNA1 that are not transferred by default should be transferred.

Exceptions are extensions to BUT000 and BUT020: If you have adhered to the naming con-vention shown here and extend the Bdoc structure in the right place, mapping between the BDoc and the BAPIMTCS is executed automatically.

Example (Business Partner New Table)Create a function group for your mapping function module. This is described in Creating a new BDT Function Group.

* Macro MOVE_CASTING *************************************FIELD-SYMBOLS: <unicode_x1> TYPE x, <unicode_x2> TYPE x.DEFINE move_casting. assign &1 to <unicode_x1> casting. assign &2 to <unicode_x2> casting. move <unicode_x1> to <unicode_x2>.END-OF-DEFINITION.

The following modules are required for the Outbound:

FUNCTION z_opfi_smoutil2.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_HEADER) TYPE SMW3_FHD*" VALUE(I_TRANSACTION_HEADER) TYPE SMO8_TMSG*" VALUE(I_TRANSACTION_MESSAGE) TYPE ANY*" VALUE(I_MESSAGE_EXT) TYPE ANY*" VALUE(I_SITE_ID) TYPE SMOG_SITE*" REFERENCE(I_RECIPIENTS) TYPE SMW_RECTA2*" TABLES*" T_BAPIMTCS STRUCTURE BAPIMTCS*" T_BAPICRMSFK STRUCTURE BAPICRMSFK*" T_BAPIPAREX STRUCTURE BAPIPAREX*" CHANGING*" REFERENCE(E_STATUS) TYPE SMW3_RECST*" REFERENCE(E_SUCCESS_BEHAVIOUR) TYPE SMOFSUCBEF

Page 113: CRM BUPA SAP

*" REFERENCE(E_NO_STANDARD_UPLOAD) TYPE XFIELD*" REFERENCE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*" REFERENCE(E_BAPICRMUH1) TYPE BAPICRMUH1*"----------------------------------------------------------------------

CASE i_header-bdoc_type.

* Extension for Business Transaction WHEN 'SALESDOCUMENT'.

* Extension for Business Partner WHEN 'BUPA_MAIN'. CALL FUNCTION 'Z_MAP_BUPA_TO_MW' EXPORTING i_header = i_header i_transaction_header = i_transaction_header i_transaction_message = i_transaction_message i_message_ext = i_message_ext i_site_id = i_site_id i_recipients = i_recipients TABLES t_bapimtcs = t_bapimtcs t_bapicrmsfk = t_bapicrmsfk t_bapiparex = t_bapiparex CHANGING e_status = e_status e_success_behaviour = e_success_behaviour e_no_standard_upload = e_no_standard_upload error_segments = error_segments e_bapicrmuh1 = e_bapicrmuh1.

ENDCASE.

ENDFUNCTION.

FUNCTION Z_MAP_BUPA_TO_MW .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_HEADER) TYPE SMW3_FHD*" VALUE(I_TRANSACTION_HEADER) TYPE SMO8_TMSG*" VALUE(I_TRANSACTION_MESSAGE) TYPE ANY*" VALUE(I_MESSAGE_EXT) TYPE ANY*" VALUE(I_SITE_ID) TYPE SMOG_SITE*" REFERENCE(I_RECIPIENTS) TYPE SMW_RECTA2*" TABLES*" T_BAPIMTCS STRUCTURE BAPIMTCS*" T_BAPICRMSFK STRUCTURE BAPICRMSFK*" T_BAPIPAREX STRUCTURE BAPIPAREX*" CHANGING*" REFERENCE(E_STATUS) TYPE SMW3_RECST*" REFERENCE(E_SUCCESS_BEHAVIOUR) TYPE SMOFSUCBEF*" REFERENCE(E_NO_STANDARD_UPLOAD) TYPE XFIELD*" REFERENCE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*" REFERENCE(E_BAPICRMUH1) TYPE BAPICRMUH1*"----------------------------------------------------------------------

DATA:

Page 114: CRM BUPA SAP

ls_bapimtcs TYPE bapimtcs, lv_partner_guid TYPE bu_partner_guid_32, ls_zsapprod TYPE zbus_ei_bupa_sapprod, next_free_currdno TYPE currdno VALUE 1, ls_zsprd_r3a1 TYPE zsprd_r3a1, ls_zsprd_r3a2 TYPE zsprd_r3a2.

FIELD-SYMBOLS: <fs_msg_bupa> TYPE bus_ei_main, <fs_msg_bpext> TYPE bus_ei_extern. DATA lr_cast_illegal TYPE REF TO cx_sy_assign_cast_illegal_cast. DATA lr_cast_unknown TYPE REF TO cx_sy_assign_cast_unknown_type. DATA err_text TYPE string.

CHECK i_header-bdoc_type = 'BUPA_MAIN'.

* Determine next free CURRDNO LOOP AT t_bapimtcs. IF t_bapimtcs-currdno > next_free_currdno. next_free_currdno = t_bapimtcs-currdno + 1. ENDIF. ENDLOOP.

ASSIGN i_message_ext TO <fs_msg_bupa>. IF sy-subrc <> 0. EXIT.* TODO: Error Handling ENDIF.

LOOP AT <fs_msg_bupa>-partners ASSIGNING <fs_msg_bpext>.

lv_partner_guid = <fs_msg_bpext>-header-object_instance-bpartnerguid.

CHECK NOT <fs_msg_bpext>-central_data-zzsapproducts IS INITIAL.

* pack current state flag of ZSAP_PRODUCTS CLEAR: ls_bapimtcs, ls_zsprd_r3a1. ls_bapimtcs-tabname = 'ZSPRD_R3A1'. ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid. ls_bapimtcs-relkey = lv_partner_guid. next_free_currdno = next_free_currdno + 1. ls_zsprd_r3a1-curstat = <fs_msg_bpext>-central_data-zzsapproducts-current_state. move_casting ls_zsprd_r3a1 ls_bapimtcs-data. APPEND ls_bapimtcs TO t_bapimtcs.

LOOP AT <fs_msg_bpext>-central_data-zzsapproducts-sapproducts INTO ls_zsapprod.* pack data of ZSAP_PRODUCTS CLEAR: ls_bapimtcs, ls_zsprd_r3a2. ls_bapimtcs-tabname = 'ZSPRD_R3A2'. ls_bapimtcs-segtype = 'DA'. ls_bapimtcs-currdno = next_free_currdno. ls_bapimtcs-objkey = lv_partner_guid.

Page 115: CRM BUPA SAP

ls_bapimtcs-relkey = lv_partner_guid. next_free_currdno = next_free_currdno + 1. ls_zsprd_r3a2-task = ls_zsapprod-task. ls_zsprd_r3a2-data_key = ls_zsapprod-data_key. ls_zsprd_r3a2-seller = ls_zsapprod-data-seller. ls_zsprd_r3a2-ctr_date = ls_zsapprod-data-contract_date. ls_zsprd_r3a2-sellerx = ls_zsapprod-datax-seller. ls_zsprd_r3a2-ctr_datex = ls_zsapprod-datax-contract_date. move_casting ls_zsprd_r3a2 ls_bapimtcs-data. APPEND ls_bapimtcs TO t_bapimtcs. ENDLOOP.

ENDLOOP.

ENDFUNCTION.

The following modules are required for the Inbound:

FUNCTION z_opfi_smoutil3.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_OBJNAME) TYPE SMO_OBJNAM*" VALUE(I_OBJCLASS) TYPE SMO_OBJCLA*" VALUE(I_SENDER_TYPE) TYPE SMW1STID*" VALUE(I_SENDER_SITE_ID) TYPE SMO_SITEID*" VALUE(I_TARGET_SITE_ID) TYPE SMO_SITEID*" EXPORTING*" REFERENCE(E_DO_NOT_CALL_FLOW) TYPE XFIELD*" TABLES*" TI_BAPIMTCS STRUCTURE BAPIMTCS*" T_MESSAGES STRUCTURE BAPICRMMSG*" TI_KEY_INFO STRUCTURE BAPICRMKEY*" TI_OTHER_INFO STRUCTURE BAPIEXTC*" TI_BAPIIDLIST STRUCTURE BAPIIDLIST*" CHANGING*" REFERENCE(HEADER) TYPE SMW3_FHD*" VALUE(MESSAGE)*" VALUE(MESSAGE_EXT) OPTIONAL*" VALUE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*" VALUE(OBJECT_LINKS) TYPE TRL_BORID*" VALUE(E_BAPICRMDH2) TYPE BAPICRMDH2*"----------------------------------------------------------------------

* Check whether Exit was called during Download CHECK ( e_bapicrmdh2-ref_id IS INITIAL ) AND ( e_bapicrmdh2-dwnloadtyp = 'D' ).

CASE i_objname.

* Extension for Business Transaction WHEN 'SALESDOCUMENT'.

* Extension for Business Partner WHEN 'BUPA_MAIN' or 'CUSTOMER_MAIN'. CALL FUNCTION 'Z_MAP_MW_TO_BUPA'

Page 116: CRM BUPA SAP

EXPORTING i_objname = i_objname i_objclass = i_objclass i_sender_type = i_sender_type i_sender_site_id = i_sender_site_id i_target_site_id = i_target_site_id IMPORTING e_do_not_call_flow = e_do_not_call_flow TABLES ti_bapimtcs = ti_bapimtcs t_messages = t_messages ti_key_info = ti_key_info ti_other_info = ti_other_info ti_bapiidlist = ti_bapiidlist CHANGING header = header MESSAGE = message message_ext = message_ext error_segments = error_segments object_links = object_links e_bapicrmdh2 = e_bapicrmdh2.

ENDCASE.

ENDFUNCTION.

FUNCTION z_map_mw_to_bupa .*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_OBJNAME) TYPE SMO_OBJNAM*" VALUE(I_OBJCLASS) TYPE SMO_OBJCLA*" VALUE(I_SENDER_TYPE) TYPE SMW1STID*" VALUE(I_SENDER_SITE_ID) TYPE SMO_SITEID*" VALUE(I_TARGET_SITE_ID) TYPE SMO_SITEID*" EXPORTING*" REFERENCE(E_DO_NOT_CALL_FLOW) TYPE XFIELD*" TABLES*" TI_BAPIMTCS STRUCTURE BAPIMTCS*" T_MESSAGES STRUCTURE BAPICRMMSG*" TI_KEY_INFO STRUCTURE BAPICRMKEY*" TI_OTHER_INFO STRUCTURE BAPIEXTC*" TI_BAPIIDLIST STRUCTURE BAPIIDLIST*" CHANGING*" REFERENCE(HEADER) TYPE SMW3_FHD*" VALUE(MESSAGE)*" VALUE(MESSAGE_EXT) OPTIONAL*" VALUE(ERROR_SEGMENTS) TYPE SMW_ERRTAB*" VALUE(OBJECT_LINKS) TYPE TRL_BORID*" VALUE(E_BAPICRMDH2) TYPE BAPICRMDH2*"----------------------------------------------------------------------

DATA: ls_bapimtcs TYPE bapimtcs, bus_ei_extern TYPE bus_ei_extern,

* -------- Business Partner - New Tables

Page 117: CRM BUPA SAP

ls_zsapprod TYPE zbus_ei_bupa_sapprod, ls_zsprd_r3a1 TYPE zsprd_r3a1, ls_zsprd_r3a2 TYPE zsprd_r3a2.

FIELD-SYMBOLS: <fs_msg_bupa> TYPE bus_ei_main, <fs_msg_bpext> TYPE bus_ei_extern.

CHECK header-bdoc_type = 'BUPA_MAIN'.

ASSIGN message_ext TO <fs_msg_bupa>. IF sy-subrc <> 0. EXIT.* TODO: Error Handling ENDIF.

* -------- Business Partner - New Tables LOOP AT ti_bapimtcs WHERE tabname = 'ZSPRD_R3A1' OR tabname = 'ZSPRD_R3A2'.

LOOP AT <fs_msg_bupa>-partners ASSIGNING <fs_msg_bpext> WHERE header-object_instance-bpartnerguid = ti_bapimtcs-objkey.

CLEAR: ls_zsprd_r3a1, ls_zsprd_r3a2.

IF ti_bapimtcs-tabname = 'ZSPRD_R3A1'. move_casting ti_bapimtcs-data ls_zsprd_r3a1. <fs_msg_bpext>-central_data-zzsapproducts-current_state = ls_zsprd_r3a1-curstat.

ELSEIF ti_bapimtcs-tabname = 'ZSPRD_R3A2'. move_casting ti_bapimtcs-data ls_zsprd_r3a2. CLEAR ls_zsapprod. ls_zsapprod-task = ls_zsprd_r3a2-task. ls_zsapprod-data_key = ls_zsprd_r3a2-data_key. ls_zsapprod-data-seller = ls_zsprd_r3a2-seller. ls_zsapprod-data-contract_date = ls_zsprd_r3a2-ctr_date. ls_zsapprod-datax-seller = ls_zsprd_r3a2-sellerx. ls_zsapprod-datax-contract_date = ls_zsprd_r3a2-ctr_datex.

APPEND ls_zsapprod TO <fs_msg_bpext>-central_data-zzsapproducts-sapproducts. ENDIF.

EXIT.

ENDLOOP.

ENDLOOP.

ENDFUNCTION.