Monday 24 June 2019

Custom Data from FI-CA to RAR (Part II – Development Procedures)

Introduction


The purpose of this two part blog is to describe a solution that allows custom values to be populated on the provider contract and then transferred to SAP Revenue Accounting.  The custom values can be populated using both the provider contract create transaction and the standard creation BAPI.  The standard provider contract transactions are enhanced using the Business Data Toolset (BDT).  Using event 8205, the custom values are transferred to Revenue Accounting as both main and condition items.


Part I provides an overview of the solution’s components.

Part II describes the technical steps required to build the solution.

5. Populating the Custom Values with Functions


5.1 Create the Custom Data Element for “Total Cost to Fulfill”

1. Go to transaction SE11
2. Create data element ZCTF_TOTAL
3. Enter the Short Description: “Total Cost to Fulfill”
4. Use Domain: WRTV7
5. Enter the following information for Field Label

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6. Save and activate the data element.

5.2 Create the Custom Data Element for “Total Cost to Obtain”

1. Go to transaction SE11
2. Create data element ZCTO_TOTAL
3. Enter the Short Description: “Total Cost to Obtain”
4. Use Domain: WRTV7
5. Enter the following information for Field Label

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6. Save and activate the data element.

5.3 Add the Custom Fields to a New Structure

i .Go to transaction SE11
ii. Create a new structure name “ZPRC_ITEM_CUSTOM”
iii. Enter “Provider Contract: Custom fields added to item” as the description

1. Add the two fields to the structure

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

2. Set the “Reference table” and “Reference field” for the two fields

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

3. Save and activate the structure.

5.4 Add the New Structure to the Provider Contract Table

This allows the custom fields to be saved with a provider contract

1. Go to transaction SE11
2. Enter table “DFKK_VT_I” and click display
3. Scroll to the bottom of the table on double-click on the customizing include named “CI_DFKK_VT_I”
4. Answer “Yes” when the system asks if you want to create the include
5. Give the include a description, for example, “Append Structure for DFKK_VT_I (Items of Provider Contract)”
6. Put the cursor in the first line of the table and the using the top menu select Edit -> Include -> Insert
7. Enter “ZPRC_ITEM_CUSTOM” in the include field and click continue
8. Save and activate the customizing include.

5.5 Append the New Structure to the BAPI Extension Structure

This allows the custom fields to be passed in the EXTENSIONIN Table of the standard BAPI

1. Go to transaction SE11
2. Enter structure “BAPI_TE_VT_I” and click display
3. From the top menu select Goto-> Append Structure
4. Enter a name for the new append structure, for example “ZBAPI_TE_VT_I”
5. Enter a description for the new append structure, for example “Append Structure for BAPI_TE_VT_I”
6. Put the cursor in the first line of the append structure and the using the top menu select Edit -> Include -> Insert
7. Enter “ZPRC_ITEM_CUSTOM” in the include field and click continue
8. Save and activate the append structure.

5.6 Add the New Fields to the Provider Contract Data Structure

This allows the custom fields to flow from the standard BAPI into the database.  The fields cannot be added an include structure, because the fields must have a character data type.

1. Go to transaction SE11
2. Enter structure “FKK_VT_I_DI” and click display
3. Scroll to the bottom of the table on double-click on the customizing include named “CI_FKK_VT_I_DI”
4. Answer “Yes” when the system asks if you want to create the include
5. Give the include a description, for example, “Append Structure for CI_FKK_VT_I_DI”
6. Add the two fields using the “Built-in Type” button
7. Give the fields the following attributes

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

8. Save and activate the structure.

5.7 Create a New Structure for the Custom Function

This new structure will be used in the interface of the custom function, which will be created in the next few steps.  This structure allows the custom fields to be passed with the contract line items

1. Go to transaction SE11
2. Enter structure “ZBAPI_BILLCONTR_I_CREATE” and click create
3. Enter a description for the structure, for example “BAPI Structure for Contract Item Data (Attachment)”
4. Put the cursor in the first line of the structure and the using the top menu select Edit -> Include -> Insert
5. Enter “BAPI_BILLCONTR_I_CREATE” in the include field and click continue
6. Put the cursor in the second line of the structure and the using the top menu select Edit -> Include -> Insert
7. Enter “ZPRC_ITEM_CUSTOM” in the include field and click continue
8. Save and activate the structure.

5.8 Create a Function Group for the Custom Function

1. Go to transaction SE80
2. In the Repository Browser, select “Function Group” from the selection
3. Enter the function group name “ZVKK_VT_BAPI” and hit the Enter key.
4. Answer “Yes” when asked if you want to create the function group
5. Enter a description for the function group, for example “CT: Create Provider Contract”
6. Save and activate the function group.

5.9 Create the Custom Function to Call the Standard BAPI

1. Go to transaction SE37
2. In the Function Module field enter “Z_API_CTRACBILLCONTRACT_CREATE” and click Create
3. Give the function module a description, for example “CT: Create Provider Contract”
4. Using “BAPI_CTRACBILLCONTRACT_CREATE” as a reference, set the following Import parameters

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

5. Set the following Export parameters

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6. Set the following Table parameters

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

7. Add the following source code

"*****************************************************
" NAME:   z_api_ctracbillcontract_create
" DESCR:  Simplified and enhanced version of BAPI_CTRABILLCONTRACT_CREATE
" AUTHOR: James Koefelda - SAP America, inc
" DATE:   5/21/2019
"*****************************************************
FUNCTION z_api_ctracbillcontract_create .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(CONTRACTDATA) TYPE  BAPI_BILLCONTR_H_CREATE
*"     VALUE(TESTRUN) TYPE  BAPI_BILLCONTR_CONTROL-TESTRUN DEFAULT
*"       SPACE
*"     VALUE(WRITECHANGEDOCUMENTS) TYPE
*"        BAPI_BILLCONTR_CONTROL-WRITECHANGEDOCUMENTS DEFAULT 'X'
*"  EXPORTING
*"     VALUE(CONTRACT) TYPE  BAPI_BILLCONTR_H_CREATE-CONTRACT
*"  TABLES
*"      ZCONTRACTITEMDATA STRUCTURE  ZBAPI_BILLCONTR_I_CREATE
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------

  TYPES: BEGIN OF t_uuid,
           contractitemid TYPE vtpid_c_kk,
           uuid           TYPE sysuuid_x16,
         END OF t_uuid.

  DATA: lv_timestamp TYPE tzntstmps,
        lv_uuid      TYPE sysuuid_x16.

  DATA: ls_contractdatax     TYPE bapi_billcontr_h_createx,
        lt_contractitemdata  TYPE TABLE OF bapi_billcontr_i_create,
        lt_contractitemdatax TYPE TABLE OF bapi_billcontr_i_createx,
        lt_extensionin       TYPE TABLE OF bapiparex,
        lt_uuid              TYPE TABLE OF t_uuid.

  "*********************************************************
  " Generate Timestamp for the Extension Table
  "*********************************************************
  PERFORM f_get_timestamp CHANGING lv_timestamp.

  "***********************************************************
  " Fill the CONTRACTDATAX Structure for all populated values in the contract header
  "***********************************************************
  PERFORM f_set_contractdatax USING contractdata CHANGING ls_contractdatax.

  "***********************************************************
  " Process Contract line items
  "************************************************************
  LOOP AT zcontractitemdata ASSIGNING FIELD-SYMBOL(<lfs_zcontractitemdata>).

    "Get and set UUID for contractitemparent
    IF <lfs_zcontractitemdata>-contractitemparentid IS NOT INITIAL.
      READ TABLE lt_uuid ASSIGNING FIELD-SYMBOL(<lfs_uuid>)
        WITH KEY contractitemid = <lfs_zcontractitemdata>-contractitemparentid.
      IF sy-subrc = 0.
        <lfs_zcontractitemdata>-contractitemparentid =  <lfs_uuid>-uuid.
      ENDIF.
    ENDIF.

    "Get UUID
    PERFORM f_get_uuid CHANGING lv_uuid.

    "Save UUID in lt_uiid
    APPEND INITIAL LINE TO lt_uuid ASSIGNING <lfs_uuid>.
    <lfs_uuid>-contractitemid = <lfs_zcontractitemdata>-contractitemid.
    <lfs_uuid>-uuid = lv_uuid.

    "set UUID for contractitem
    <lfs_zcontractitemdata>-contractitemid = lv_uuid.

    " Fill EXTENSIONIN table for custom fields of each contract item
    APPEND INITIAL LINE TO lt_extensionin ASSIGNING FIELD-SYMBOL(<lfs_extensionin>).
    PERFORM f_set_extensionin USING <lfs_zcontractitemdata> lv_timestamp CHANGING <lfs_extensionin>.

    "'Remove' custom fields from contract item data
    APPEND INITIAL LINE TO lt_contractitemdata ASSIGNING FIELD-SYMBOL(<lfs_contractitemdata>).
    MOVE-CORRESPONDING <lfs_zcontractitemdata> TO <lfs_contractitemdata>.

    " Fill the CONTRACTITEMDATAX table for all populated values of each contract item
    " excludes custom fields
    APPEND INITIAL LINE TO lt_contractitemdatax ASSIGNING FIELD-SYMBOL(<lfs_contractitemdatax>).
    PERFORM f_set_contractitemdatax USING <lfs_contractitemdata> CHANGING <lfs_contractitemdatax>.

  ENDLOOP.

  "******************************************************
  " Call the BAPI to create the provider contract
  "*******************************************************
  CALL FUNCTION 'BAPI_CTRACBILLCONTRACT_CREATE'
    EXPORTING
      contractdata         = contractdata
      contractdatax        = ls_contractdatax
      testrun              = testrun
      writechangedocuments = writechangedocuments
    IMPORTING
      contract             = contract
    TABLES
      contractitemdata     = lt_contractitemdata
      contractitemdatax    = lt_contractitemdatax
      return               = return
      extensionin          = lt_extensionin.

  IF contract IS NOT INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  ENDIF.

ENDFUNCTION.

​8. Save the code
9. In the code, find the statement “PERFORM f_get_timestamp CHANGING lv_timestamp.”
10. Double-click on “f_get_timestamp”
11. Answer “Yes” when asked if you want to create the routine
12. Select a name for a new to include to contain the code
13. Enter the following code into the new include

*----------------------------------------------------------------------*
***INCLUDE LZVKK_VT_BAPIF01.
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  F_DYNAMIC_FILL_X
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_PI_NAME_V  text
*      -->P_PI_NAME_X  text
*      -->P_PI_STRUC_V  text
*      <--P_PC_STRUC_X  text
*----------------------------------------------------------------------*
FORM f_dynamic_fill_x  USING    pi_name_v
                                pi_name_x
                                pi_struc_v
                       CHANGING pc_struc_x.

  CONSTANTS: lc_typ_tab(1) TYPE c VALUE 'h',
             lc_typ_str(1) TYPE c VALUE 'v'.

  DATA: lo_structdescr_v TYPE REF TO cl_abap_structdescr,
        ls_component_v   TYPE abap_compdescr.

  lo_structdescr_v ?= cl_abap_typedescr=>describe_by_name( pi_name_v ).

  LOOP AT lo_structdescr_v->components INTO ls_component_v.

    ASSIGN COMPONENT ls_component_v-name OF STRUCTURE pi_struc_v TO FIELD-SYMBOL(<lfs_field_v>).
    DESCRIBE FIELD <lfs_field_v> TYPE DATA(lv_type_v).

    CASE lv_type_v.
      WHEN lc_typ_tab.
      WHEN lc_typ_str.
      WHEN OTHERS.
        IF <lfs_field_v> IS NOT INITIAL.
          ASSIGN COMPONENT ls_component_v-name OF STRUCTURE pc_struc_x TO FIELD-SYMBOL(<lfs_field_x>).
          IF sy-subrc = 0 AND <lfs_field_x> IS ASSIGNED.
            <lfs_field_x> = abap_true.
          ENDIF.

        ENDIF.
    ENDCASE.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_SET_CONTRACTDATAX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CONTRACTDATA  text
*      <--P_CONTRACTDATAX  text
*----------------------------------------------------------------------*
FORM f_set_contractdatax  USING    pi_contractdata TYPE bapi_billcontr_h_create
                          CHANGING pc_contractdatax TYPE bapi_billcontr_h_createx.

  PERFORM f_dynamic_fill_x USING    'BAPI_BILLCONTR_H_CREATE'
                                    'BAPI_BILLCONTR_H_CREATEX'
                                    pi_contractdata
                           CHANGING pc_contractdatax.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_SET_CONTRACTITEMDATAX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CONTRACTITEMDATA  text
*      <--P_CONTRACTITEMDATAX  text
*----------------------------------------------------------------------*
FORM f_set_contractitemdatax  USING    pi_contractitemdata  TYPE bapi_billcontr_i_create
                              CHANGING pc_contractitemdatax TYPE bapi_billcontr_i_createx.

  PERFORM f_dynamic_fill_x USING    'BAPI_BILLCONTR_I_CREATE'
                                    'BAPI_BILLCONTR_I_CREATEX'
                                    pi_contractitemdata
                           CHANGING pc_contractitemdatax.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_GET_TIMESTAMP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_TIMESTAMP  text
*----------------------------------------------------------------------*
FORM f_get_timestamp  CHANGING pc_timestamp TYPE tzntstmps.

  DATA: lv_timezone TYPE timezone.

  CALL FUNCTION 'GET_SYSTEM_TIMEZONE'
    IMPORTING
      timezone = lv_timezone.

  CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
    EXPORTING
      i_datlo     = sy-datum
      i_timlo     = sy-uzeit
      i_tzone     = lv_timezone
    IMPORTING
      e_timestamp = pc_timestamp.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_SET_EXTENSIONIN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_<LFS_CONTRACTITEMDATA>  text
*      -->P_LV_TIMESTAMP  text
*      <--P_<LFS_EXTENSIONIN>  text
*----------------------------------------------------------------------*
FORM f_set_extensionin  USING    pi_contractitemdata TYPE zbapi_billcontr_i_create
                                 pi_timestamp TYPE tzntstmps
                        CHANGING pc_extensionin TYPE bapiparex.


  CONSTANTS: lc_ext_structure TYPE te_struc VALUE 'BAPI_TE_VT_I'.

  DATA: ls_bapi_te_vt_i TYPE bapi_te_vt_i,
        ls_extensionin  TYPE bapiparex.

  ls_bapi_te_vt_i-contractitemid = pi_contractitemdata-contractitemid.
  ls_bapi_te_vt_i-valid_timestamp = pi_timestamp.
  ls_bapi_te_vt_i-zzctf_total = pi_contractitemdata-zzctf_total.
  ls_bapi_te_vt_i-zzcto_total = pi_contractitemdata-zzcto_total.

  ls_extensionin-structure = lc_ext_structure.

  cl_abap_container_utilities=>fill_container_c(
    EXPORTING
      im_value               = ls_bapi_te_vt_i " structure of type ls_bapi_te_vt_i
    IMPORTING
      ex_container           = ls_extensionin+30 " values 1-4
    EXCEPTIONS
      illegal_parameter_type = 1
      OTHERS                 = 2 ).

  pc_extensionin = ls_extensionin.


ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  F_GET_GUID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_GUID  text
*----------------------------------------------------------------------*
FORM f_get_uuid  CHANGING p_uuid TYPE sysuuid_x16.

  TRY.
      CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_x16
        RECEIVING
          uuid = p_uuid.
    CATCH cx_uuid_error.
  ENDTRY.

ENDFORM.
14. Save and activate the function module

5.10 Create the Report to Call the Custom Function

1. Go to transaction SE38
2. Create a program named “ZPRC_UPLOAD” with the following attributes

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

3. Add the following source code

*&---------------------------------------------------------------------*
*& Report  ZPRC_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zprc_upload.

“*******************************************************
“*******************************************************
“ Global Data declarations
“*******************************************************
“*******************************************************
TYPE-POOLS: truxs.

TYPES: BEGIN OF t_datatab,
         contract_hdr            TYPE vtkey_kk,
         contract_ext            TYPE vtalt_kk,
         partner                 TYPE gpart_kk,
         contract_description    TYPE vtbez_kk,
         contract_start          TYPE tstmp_c_kk,
         contract_end            TYPE tstmp_c_kk,
         authoritygroup          TYPE begru,
         comp_code               TYPE bukrs,
         time_zone               TYPE tizon_kk,
         contract_category       TYPE vtcat_kk,
         contract_characteristic TYPE vtchr_kk,
         contract_status         TYPE status_vt_kk.
        INCLUDE STRUCTURE zbapi_billcontr_i_create.
TYPES: END OF t_datatab.

TYPES: BEGIN OF t_uuid,
         contract       TYPE vtkey_kk,
         contractitemid TYPE vtpid_c_kk,
     “    uuid           TYPE sysuuid_x16,
       END OF t_uuid.

DATA: lv_contract    TYPE bapi_billcontr_h_create-contract,
      lv_uuid        TYPE sysuuid_x16,
      lv_parent_uuid TYPE sysuuid_x16.

DATA: ls_hdr  TYPE bapi_billcontr_h_create,
      lt_itm  TYPE ztt_bapi_billcontr_i_create,
      ls_item  TYPE zbapi_billcontr_i_create,
      lt_ret  TYPE TABLE OF bapiret2,
      lt_uuid TYPE TABLE OF t_uuid.

DATA: lt_datatab TYPE STANDARD TABLE OF t_datatab,
      ls_datatab TYPE t_datatab,
      lt_raw     TYPE truxs_t_text_data.


“******************************************************
“******************************************************
“ Selection Screen
“*****************************************************
“*****************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file TYPE  rlgrap-filename.
PARAMETERS: p_head TYPE char01 DEFAULT ‘X’.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: p_test TYPE  testrun.
PARAMETERS: p_chgdoc TYPE writecd_kk DEFAULT ‘X’.
SELECTION-SCREEN END OF BLOCK b2.

“******************************************************
“******************************************************
“ At Selection Screen
“******************************************************
“******************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION ‘F4_FILENAME’
    EXPORTING
      field_name = ‘P_FILE’
    IMPORTING
      file_name  = p_file.


  “*****************************************************
  “*****************************************************
  “ Start of Selection
  “*****************************************************
  “*****************************************************
START-OF-SELECTION.

  “ Convert Excel Data to SAP internal Table Data
  CALL FUNCTION ‘TEXT_CONVERT_XLS_TO_SAP’
    EXPORTING
*     I_FIELD_SEPERATOR    =
      i_line_header        = p_head
      i_tab_raw_data       = lt_raw       “ WORK TABLE
      i_filename           = p_file
    TABLES
      i_tab_converted_data = lt_datatab[]  “ACTUAL DATA
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  “********************************************************
  “********************************************************
* END-OF-SELECTION.
  “********************************************************
  “********************************************************

END-OF-SELECTION.


  “********************************************************
* Process Excel Data and Create Provider Contracts
  “********************************************************
  LOOP AT lt_datatab ASSIGNING FIELD-SYMBOL(<lfs_exdata>).

    “***************************************
    “Fill Contract Header
    “***************************************
    IF <lfs_exdata>-contract_hdr IS NOT INITIAL.

      “***************************************
      “Create Provier Contract
      “***************************************
      IF ls_hdr IS NOT INITIAL AND lt_itm[] IS NOT INITIAL.
        PERFORM f_create_contract USING ls_hdr p_test p_chgdoc lt_itm.
      ENDIF.

      “***************************************
      “Start New Contract – Fill Header
      “***************************************
      CLEAR: ls_hdr, ls_item.
      REFRESH: lt_itm.

      MOVE-CORRESPONDING <lfs_exdata> TO ls_hdr.
      ls_hdr-contract = <lfs_exdata>-contract_hdr.
    ENDIF.

    “***************************************
    “Fill Contract Item
    “***************************************
    CLEAR: ls_item.
    MOVE-CORRESPONDING <lfs_exdata> TO ls_item.

    “Validate Item & Header contract numbers match
    IF ls_item-contract <> ls_hdr-contract.
      SKIP 1.
      WRITE: / text-001 && ` ` && text-011 && ` ` && ls_item-contract && ` <> ` && ls_hdr-contract.
      WRITE: / text-002.
      CLEAR: ls_hdr.
      EXIT.
    ENDIF.

    “Validate and set parent uuid.
    IF ls_item-contractitemparentid IS NOT INITIAL.
      READ TABLE lt_uuid ASSIGNING FIELD-SYMBOL(<lfs_uuid>)
        WITH KEY contract = ls_hdr-contract
                 contractitemid = ls_item-contractitemparentid.
      IF sy-subrc <> 0.
        SKIP 1.
        WRITE: / text-001 && ` ` && text-012 && ` ` && ls_item-contractitemparentid.
        WRITE: / text-002.
        CLEAR: ls_hdr.
        EXIT.
      ENDIF.

    “  ls_item-contractitemparentid = <lfs_uuid>-uuid.
    ENDIF.

    “Set uuid and save in lt_uuid.
    “PERFORM f_get_uuid CHANGING lv_uuid.

    APPEND INITIAL LINE TO lt_uuid ASSIGNING <lfs_uuid>.
    <lfs_uuid>-contract = ls_hdr-contract.
    <lfs_uuid>-contractitemid = ls_item-contractitemid.
    “<lfs_uuid>-uuid = lv_uuid.

    “Add contract item to LT_ITM
    CLEAR: ls_item-contract.
    “ls_item-contractitemid = lv_uuid.
    APPEND ls_item TO lt_itm.

  ENDLOOP.


  “***************************************
  “Create Provier Contract
  "***************************************
  IF ls_hdr IS NOT INITIAL AND lt_itm[] IS NOT INITIAL.
    PERFORM f_create_contract USING ls_hdr p_test p_chgdoc lt_itm.
  ENDIF.

  "******************************************************
  "******************************************************
  " Includes
  "******************************************************
  "******************************************************
  INCLUDE zprc_upload_f01.
4. Save the code
5. Double-click on the include name in the last line of the code
6. Answer “Yes” when asked if you want to create the include
7. Add the following code to the new include

*----------------------------------------------------------------------*
***INCLUDE ZPRC_UPLOAD_F.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  F_GET_GUID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_GUID  text
*----------------------------------------------------------------------*
FORM f_get_uuid  CHANGING p_uuid TYPE sysuuid_x16.

  TRY.
      CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_x16
        RECEIVING
          uuid = p_uuid.
    CATCH cx_uuid_error.
  ENDTRY.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_CREATE_CONTRACT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LS_CONTRACTDATA  text
*      -->P_P_TEST  text
*      -->P_P_CHGDOC  text
*      -->P_LT_CONTRACTITEMDATA  text
*----------------------------------------------------------------------*
FORM f_create_contract  USING    pi_hdr type bapi_billcontr_h_create
                                 pi_test type testrun
                                 pi_chgdoc type writecd_kk
                                 pi_itm type ZTT_BAPI_BILLCONTR_I_CREATE.

  DATA: lv_contract TYPE bapi_billcontr_h_create-contract,
        lt_ret      TYPE TABLE OF bapiret2.

  clear: pi_hdr-contract.

  CALL FUNCTION 'Z_API_CTRACBILLCONTRACT_CREATE'
    EXPORTING
      contractdata         = pi_hdr
      testrun              = pi_test
      writechangedocuments = pi_chgdoc
    IMPORTING
      contract             = lv_contract
    TABLES
      zcontractitemdata    = pi_itm
      return               = lt_ret.

  "***************************************
  " List processing
  "***************************************
  WRITE: / 'Contract = ', lv_contract.
  SKIP 1.
  LOOP AT lt_ret ASSIGNING FIELD-SYMBOL(<fs_ret>).
    WRITE: / <fs_ret>-message.
  ENDLOOP.
  ULINE.

ENDFORM.
8. Save the code
9. From the top menu select Goto -> Text Elements -> Selection Texts
10. Enter the following selection texts

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

11. Click on the Text Symbols tab
12. Enter the following Text Symbols

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

13. Save the texts and activate the report

5.11 Test the Custom Function

1. Modify the attached Excel spreadsheet with the required data
2. Go to transaction SE38
3. Enter program ZPRC_UPLOAD and click the Execute Button
4. Click on the drop-down for the “File Name” field
5. Select the locally saved Excel spreadsheet
6. Click the Execute button
7. Confirm the data using table DFKK_VT_I

6. Populating the Custom Values with Transactions.


You can refer to the BDT Developer Manual, in the reference section of this document, for the following steps.

6.1 Create the Function Group

This function group will hold the subscreen, PBO/PAI modules, and the PAI/PBO functions required to enhance the transaction

1. Go to transaction SE80
2. In the Repository Browser, select “Function Group” from the selection
3. Enter the function group name “ZVKK_BDT_PRC” and hit the Enter key.
4. Answer “Yes” when asked if you want to create the function group
5. Enter a description for the function group, for example “BDT enhancements to Provider Contracts
6. Save and activate the function group.

6.2 Create the Subscreen

This subscreen will hold the custom fields and will be added to the provider contract transactions.

1. Go to transaction SE80
2. In the Repository Browser, select “Function Group” from the selection
3. Enter the function group name “ZVKK_BDT_PRC” and hit the Enter key.
4. Right-click on the screens folder and select “Create”
5. Enter a screen number such as “1000”
6. Enter a description such as “CtrItm: Costs”
7. Select “Subscreen” for the screen type and click continue
8. Open the screen layout, Select Dictionary /Program Fields and add the custom fields to the screen.

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

9. Save the screen
10. Click on the “Flow Logic” tab
11. Create one PBO module and one PAI module.

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

12. In PBO module, call function module ‘BUS_PBO’. No other logic should be placed in the PBO module. Data extraction, field checks should be carried out in a separate function.

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

13. In the PAI module call function module ‘BUS_PAI’. No other logic should be placed in the PAI module. Data extraction, field checks should be carried out in a separate function.

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

14. Save and activate everything

6.3 Create the PBO Function

This PBO function will get the data for the currently selected contract item.  It then takes the values for the custom fields and pushes them into the screen fields of the custom subscreen.

1. Go to transaction SE80
2. In the Repository Browser, select “Function Group” from the selection
3. Enter the function group name “ZVKK_BDT_PRC” and hit the Enter key.
4. Expand the “Includes” folder
5. Open the “Top” include and enter the following tables statement

FUNCTION-POOL ZVKK_BDT_PRC.                 "MESSAGE-ID ..

* INCLUDE LZVKK_BDT_PRCD...                  " Local class definition

  TABLES: dfkk_vt_i.
6. Save the include
7. Right click on the “Function Modules” folder and select “Create”
8. Create a function, such as “Z_VKK_CAVT_PBO_ZVKK1000”
9. Enter a description, such as “PBO 1000 Provider Contract – Costs”
10. Enter the following code

FUNCTION z_vkk_cavt_pbo_zvkk1000.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------
  DATA: ls_vt_i TYPE dfkk_vt_i.

  CALL FUNCTION 'VKK_CAVT_DFKK_VT_I_GET'
    IMPORTING
      es_vt_i = ls_vt_i.

  dfkk_vt_i-zzctf_total = ls_vt_i-zzctf_total.
  dfkk_vt_i-zzcto_total = ls_vt_i-zzcto_total.

ENDFUNCTION.
11. Save and activate everything

6.4  Create the PAI Function

This PAI function will get the data for the currently selected contract item.  It then takes the values that were entered on the screen and saves it back to the contract items in memory.

1. Go to transaction SE80
2. In the Repository Browser, select “Function Group” from the selection
3. Enter the function group name “ZVKK_BDT_PRC” and hit the Enter key.
4. Right-click on the Function Modules folder and select “Create”
5. Create a function, such as “Z_VKK_CAVT_PAI_ZVKK1000”
6. Enter a description, such as “PAI 1000 Provider Contract – Costs”
7. Enter the following code

FUNCTION z_vkk_cavt_pai_zvkk1000.
*"--------------------------------------------------------------------
*"*"Local Interface:
*"--------------------------------------------------------------------
  DATA: ls_vt_i TYPE dfkk_vt_i.

  CALL FUNCTION 'VKK_CAVT_DFKK_VT_I_GET'
    IMPORTING
      es_vt_i = ls_vt_i.

  ls_vt_i-zzctf_total = dfkk_vt_i-zzctf_total.
  ls_vt_i-zzcto_total = dfkk_vt_i-zzcto_total.

  CALL FUNCTION 'VKK_CAVT_DFKK_VT_I_COLLECT'
    EXPORTING
      i_subname = 'CI_DFKK_VT_I'
      i_vt_i    = ls_vt_i.


ENDFUNCTION.
8. Save and activate everything

6.5 Configure BDT: Create a Field Group

The BDT configuration will allow the subscreen to be added to the standard provider contract transactions.  You will add the subscreen to the “Contract Items: Overview II” tab.

1. Go to transaction SE43
2. Enter “BUPT” for the “Area Menu” and then click the display button
3. Expand the “BDT General” node
4. Expand the “Utilities” node
5. Execute BDT Analyzer
6. Enter “CAVT” for the “Application Object”
7. Enter “VKK” for the “Application”
8. Click the “Execute” button
9. Expand the following nodes to reach the Field Group named “0150 – Header Data: Provider Contract”

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

10. The custom fields will not actually be added to the “VLL150 – Contract Specification” section. However, access to an existing field group is required to create a new one. Select the “0150 – Header Data: Provider Contract” Field Group.
11. Click the “New Entries” button
12. Field groups within 700 – 799 are reserved for customers. So, enter the number 700 for the field group
13. Enter a Description for the field group, such as “CtrItm: Total Costs”
14. Enter “VKK_CAVT_EVENT_FMOD_ITEM” in the “FM for fld grouping” field. This is the standard function module used by all the field groups of this application

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

15. Save the field group
16. Continue to click the “Back” button to reach the main screen of the BDT Analyzer

6.6 Configure BDT: Create a View

1. Under “Views” node, select the “VKK150 – Header Data: Provider Contract” View

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

2. Click the “New Entries” button
3. Enter a name for the view, such as ZVKK01
4. Enter a description for the view, such as “CtrItm: Costs”
5. Enter “VKK” for the Application
6. Enter “0” for the Differentiation Type
7. Enter “VKK500” for the Data Set. This is critical.  The view will not be displayed if it is not assigned to an existing Data Set.
8. Select “Entry View”
9. Select “Dialog View”
10. In the “Program Name” field, under Subscreen, enter the main program of the function group that was created in step 2.2.1 (e.g. SAPLZVKK_BDT_PRC)
11. Enter the screen number that was created in step 2.2.2 (e.g. 1000)
12. Under Function Module, in the “Before Output” field, enter the name of the PBO function that was created in step 2.2.3 (e.g. Z_VKK_CAVT_PBO_ZVKK1000)
13. Under Function Module, in the “After Entry” field, enter the name of the PAI function that was created in step 2.2.4 (e.g. Z_VKK_CAVT_PAI_ZVKK1000)
14. Under “Screen Configuration”, select “Data Screen”
15. Check the entries against the following:

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

16. Save the view
17. Select the view that was just created and then on the left-hand side, under “Dialog Structure”, select “View -> Field Groups”
18. Click the “New Entries” Button
19. Enter the Field Group (e.g. 700)
20. Save the view
21. Continue to click the “Back” button to reach the main screen of the BDT Analyzer

6.7  Configure BDT: Create a Section

1. Under “Sections” node, select the “VKK150 – Contract Specification” section
2. Click the “New Entries” button
3. Enter a name for the section, such as ZCVKK1
4. Enter a description for the section, such as “CtrItm: Costs”
5. Enter a Title for the section, such as “Cost”. This will be displayed in the transaction.
6. Save the section
7. Select the section that was just created and then on the left-hand side, under “Dialog Structure”, select “Section -> Views”
8. Click the “New Entries” Button
9. Enter “999991” for the Item
10. Enter the view that was just created (e.g. ZVKK01)
11. The view is now assigned to the section
12. Click Save
13. Continue to click the “Back” button to reach the main screen of the BDT Analyzer

6.8  Configure BDT: Assign the Section to an Existing Screen

1. Under “Screens” node, select the “VKK500 – Contract Items: Overview II” screen

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

2. On the left-hand side, select “Screen -> Sections”
3. Click the “New Entries” button
4. Enter an item number (e.g. 20001). The item number will determine where the subscreen is placed on the parent screen.
5. Enter the section name (e.g. ZCVKK1)

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6. Click Save
7. Continue to click the “Back” button to reach the main screen of the BDT Analyzer

6.9 Configure BDT: Confirm the Configuration

1. Continue to click the “Back” button to reach the selection screen of the BDT Analyzer
2. Execute the Analyzer with the same selections

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

3. Expand the nodes underneath the “VKK500 – Contract Items: Overview II” screen
4. The section, view, field group, and fields should now be shown in the hierarchy

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6.10 Configure BDT: Generate Subscreen Containers

1. Go to transaction SE43
2. Enter “BUPT” for the “Area Menu” and then click the display button
3. Expand the “BDT General” node
4. Expand the “Utilities” node
5. Execute “Generate Subscreen Container”
6. Enter the following selections and click the Execute button

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

6.11 Test the Screen Enhancement

1. Go to transactions FP_VT1, FP_VT2, and FP_VT3
2. Confirm that the Fields are visible under “Contract Items: Overview II”

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

3. Confirm that the values of the custom fields can be changed
4. Save a changed provider contract and confirm that the values are updated in table DFKK_VT_I

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

7. Transferring the Custom Values into Revenue Accounting.


7.1 Append the Custom Fields to the Revenue Accounting – Main Item

To have access to the custom fields in event 8205, the fields must be appended to the Main Item in Revenue Accounting.

1. Go to transaction SE11
2. Enter table “DFKKRA_RAI_MI” and click “Display”
3. Scroll to the bottom of the table on double-click on the customizing include named “CI_FKKRA_RAI_MI”
4. Answer “Yes” when the system asks if you want to create the include
5. Give the include a description, for example, “Customizing Include for DFKKRA_RAI_MI”
6. Put the cursor in the first line of the table and the using the top menu select Edit -> Include -> Insert
7. Enter “ZPRC_ITEM_CUSTOM” in the include field and click continue
8. Save and activate the customizing include.

7.2  Code Event 8205

1. Go to transaction FQEVENT_8205
2. Double-click on the “Installation-Specific Function Module”

SAP ABAP Certifications, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Development

3. Enter the following code

FUNCTION zfkk_sample_8205.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IT_RAI_MI) TYPE  FKKRA_RAI_MI_TAB
*"     REFERENCE(IT_RAI_CO) TYPE  FKKRA_RAI_CO_TAB
*"     REFERENCE(IS_VT_CHANGES) TYPE  FKK_VT_CHANGES OPTIONAL
*"     REFERENCE(IX_SIMULATION) TYPE  XFELD OPTIONAL
*"  EXPORTING
*"     REFERENCE(ET_RAI_MI) TYPE  FKKRA_RAI_MI_TAB
*"     REFERENCE(ET_RAI_CO) TYPE  FKKRA_RAI_CO_TAB
*"----------------------------------------------------------------------

  DATA: lt_rai_co  TYPE fkkra_rai_co_tab,
        lwa_rai_co TYPE dfkkra_rai_co,
        lv_uuid    TYPE sysuuid_x16.

  CALL FUNCTION 'FKK_RA_VT_PREDOC_MERGE_8205'
    EXPORTING
      it_rai_mi     = it_rai_mi
      it_rai_co     = it_rai_co
      is_vt_changes = is_vt_changes
      ix_simulation = ix_simulation
    IMPORTING
      et_rai_mi     = et_rai_mi
      et_rai_co     = et_rai_co.


    LOOP AT et_rai_co ASSIGNING FIELD-SYMBOL(<lfs_rai_co>).

      IF <lfs_rai_co>-condition_type = 'PR00'.

        lwa_rai_co   = <lfs_rai_co>.

  
        "**********************************************************
        " Add Conditions for "Total Cost to Fulfill" & "Total Cost to Obtain"
        "**********************************************************
        READ TABLE et_rai_mi WITH KEY rai_id = <lfs_rai_co>-rai_id ASSIGNING FIELD-SYMBOL(<lfs_rai_mi>).
        IF sy-subrc = 0.

          IF <lfs_rai_mi>-zzctf_total is not INITIAL.        " Total Cost to Fulfill
            PERFORM f_get_uuid CHANGING lv_uuid.
            lwa_rai_co-uuid           = lv_uuid.
            lwa_rai_co-condition_type = 'VPRS'.
lwa_rai_co-chind = 'I'.
"  lwa_rai_co-category =  'C'.
lwa_rai_co-main_cond_type = abap_false.
            lwa_rai_co-betrw = <lfs_rai_mi>-zzctf_total .
            APPEND  lwa_rai_co TO lt_rai_co.
          ENDIF.

          IF <lfs_rai_mi>-zzcto_total is not INITIAL.        " Total Cost to Obtain
            PERFORM f_get_uuid CHANGING lv_uuid.
            lwa_rai_co-uuid           = lv_uuid.
            lwa_rai_co-condition_type = 'COAC'.
lwa_rai_co-chind = 'I'.
"  lwa_rai_co-category =  'C'.
lwa_rai_co-main_cond_type = abap_false.
            lwa_rai_co-betrw = <lfs_rai_mi>-zzcto_total .
            APPEND  lwa_rai_co TO lt_rai_co.
          ENDIF.

        ENDIF.


        CLEAR lwa_rai_co.
      ENDIF.

    ENDLOOP.

    IF <lfs_rai_co> IS ASSIGNED.
      UNASSIGN <lfs_rai_co>.
    ENDIF.

    IF lt_rai_co[] IS NOT INITIAL.
      APPEND LINES OF lt_rai_co TO et_rai_co.
    ENDIF.


ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  F_GET_GUID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_GUID  text
*----------------------------------------------------------------------*
FORM f_get_uuid  CHANGING p_uuid TYPE sysuuid_x16.

  TRY.
      CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_x16
        RECEIVING
          uuid = p_uuid.
    CATCH cx_uuid_error.
  ENDTRY.


ENDFORM.​

4. Save and activate the function module

7.3 Test Event 8205

1. Create a Provider Contract using the standard transaction or the report ZPRC_UPLOAD
2. Confirm that the custom fields are populated in the main item using table DFKKRA_RAI_MI
3. Confirm that conditions are created for each of the custom fields using table DFKKRA_RAI_CO

No comments:

Post a Comment