Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
derick_r_logan
Discoverer
0 Kudos

Parking a Financial Document using function modules with COPA postings

Applies to:

SAP ECC 6.0.

Summary

This document details the necessary development for creating a parked financial document that will create COPA entries when the financial
document is subsequently posted.

Author(s):    Derick Logan

Company:    GyanSys

Created on:  10 January 2012

Creating a Parked FI document with COPA Characteristics

This solution involves the use of two function modules:
PRELIMINARY_POSTING_FB01 and COPA_PROFITABLITY_SEGMENT. The first function module creates the parked financial document. The second function module is used to determine the Profitability Segment Number.

Calling COPA_PROFITABLITY_SEGMENT

In order to successfully use this function module we need to provide the COPA characteristics used in determining the profitability in table T_COPADATA. In addition we have to fill the I_COBL
import parameter. After a successful call the function module the E_COBL structure will contain the profitability segment number.

Sample Code:

Filling T_COPADATA

  DEFINE f_criteria.

    clear fs_copadata.

    fs_copadata-fnam = &1.

    fs_copadata-fval = &2.

    append fs_copadata to int_copadata.

  END-OF-DEFINITION.

* Fill the characteristics

  CLEAR int_copadata[].

  f_criteria wl_kndnr fs_sheet-customer.

  f_criteria wl_prodh fs_sheet-product_hier.

  f_criteria wl_vkorg fs_sheet-sales_org.

  f_criteria wl_vtweg fs_sheet-dist_channel.

  f_criteria wl_spart fs_sheet-division.

  f_criteria wl_werks fs_sheet-copa_plant.

Filling I_COPA

* Fill COBL

  CLEAR fs_cobl_i.

  fs_cobl_i-glvor = wl_rfbv.

  fs_cobl_i-vorgn = wl_rfbv.

  fs_cobl_i-budat = fs_sheet-post_date.

  fs_cobl_i-bldat = fs_sheet-post_date.

  fs_cobl_i-bukrs = fs_sheet-company_code.

  fs_cobl_i-kokrs = fs_sheet-company_code.

  fs_cobl_i-hkont = fs_sheet-account.

  fs_cobl_i-koart = fs_sheet-koart.

  fs_cobl_i-gjahr = fs_sheet-post_date(4).

  fs_cobl_i-monat = fs_sheet-post_date+4(2).

  fs_cobl_i-buzei = f900_bseg-buzei.

  fs_cobl_i-blart = fs_sheet-blart.

  fs_cobl_i-bschl = f900_bseg-bschl.

  fs_cobl_i-wwert = fs_sheet-value_date.

  fs_cobl_i-waers = fs_sheet-currency.

  fs_cobl_i-dmbtr = f900_bseg-dmbtr.

  fs_cobl_i-shkzg = f900_bseg-shkzg.

  fs_cobl_i-wrbtr = f900_bseg-wrbtr.

Calling the function module

* Determine the COPA object number

  CLEAR fs_cobl_e.

  CALL FUNCTION 'COPA_PROFITABILITY_SEGMENT'

    EXPORTING

      anzeige    = ' '

      dialog     = ' '

      i_cobl     = fs_cobl_i

    IMPORTING

      e_cobl     = fs_cobl_e

    TABLES

      t_copadata = int_copadata

    EXCEPTIONS

      OTHERS     = 1.

Analysing E_COBL

From E_COBL we extract the profit center (PRCTR), profitability segment number (PAOBJNR) and the profitability segment changes (PASUBNR) and transfer that information into the BSEG structure
that will be used as input into function module PRELIMINARY_POSTING_FB01. In addition we set the P&L statement account type flag to ‘X’. Finally we need to clear any fields from BSEG that we use in the COPA determination. If we don’t clear out these fields function module PRELIMINARY_POSTING_FB01 will fail to create the COPA characteristics as it tries to redetermine the characteristics using the partial information provided and fails. In the example below we clear out the customer number (BSEG-KUNNR)

* Update BSEG with COPA object

    f900_bseg-paobjnr = fs_cobl_e-paobjnr.

    f900_bseg-pasubnr = fs_cobl_e-pasubnr.

    f900_bseg-prctr   = fs_cobl_e-prctr.

    f900_bseg-gvtyp   = wl_x.

    CLEAR f900_bseg-kunnr.

Complete code snippet:

FORM f900_determine_copa

  USING f900_bseg TYPE bseg.

  DATA:

    fs_cobl_i           TYPE cobl,

    fs_cobl_e           TYPE cobl,

    int_copadata        TYPE copadata OCCURS 0,

    fs_copadata         TYPE copadata.

  CONSTANTS:

      wl_kndnr(5)       TYPE c VALUE 'KNDNR',

      wl_prodh(5)       TYPE c VALUE 'PRODH',

      wl_vkorg(5)       TYPE c VALUE 'VKORG',

      wl_vtweg(5)       TYPE c VALUE 'VTWEG',

      wl_spart(5)       TYPE c VALUE 'SPART',

      wl_werks(5)       TYPE c VALUE 'WERKS'.

  DEFINE f_criteria.

    clear fs_copadata.

    fs_copadata-fnam = &1.

    fs_copadata-fval =&2.

    append fs_copadata to int_copadata.

  END-OF-DEFINITION.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    EXPORTING

      input  = fs_sheet-customer

    IMPORTING

      output = fs_sheet-customer.

* Fill the characteristics

  CLEAR int_copadata[].

  f_criteria wl_kndnr fs_sheet-customer.

  f_criteria l_prodh fs_sheet-product_hier.

  f_criteria wl_vkorg fs_sheet-sales_org.

  f_criteria wl_vtweg fs_sheet-dist_channel.

  f_criteria wl_spart fs_sheet-division.

  f_criteria wl_werks fs_sheet-copa_plant.

* Fill COBL

  CLEAR fs_cobl_i.

  fs_cobl_i-glvor = wl_rfbv.

  fs_cobl_i-vorgn = wl_rfbv.

  fs_cobl_i-budat = fs_sheet-post_date.

  fs_cobl_i-bldat = fs_sheet-post_date.

  fs_cobl_i-bukrs = fs_sheet-company_code.

  fs_cobl_i-kokrs = fs_sheet-company_code.

  fs_cobl_i-hkont = fs_sheet-account.

  fs_cobl_i-koart = fs_sheet-koart.

  fs_cobl_i-gjahr = fs_sheet-post_date(4).

  fs_cobl_i-monat = fs_sheet-post_date+4(2).

  fs_cobl_i-buzei = f900_bseg-buzei.

  fs_cobl_i-blart = fs_sheet-blart.

  fs_cobl_i-bschl = f900_bseg-bschl.

fs_cobl_i-wwert = fs_sheet-value_date.

  fs_cobl_i-waers = fs_sheet-currency.

  fs_cobl_i-dmbtr = f900_bseg-dmbtr.

  fs_cobl_i-shkzg = f900_bseg-shkzg.

  fs_cobl_i-wrbtr = f900_bseg-wrbtr.

* Determine the COPA object number

  CLEAR fs_cobl_e.

  CALL FUNCTION 'COPA_PROFITABILITY_SEGMENT'

    EXPORTING

      anzeige    = ' '

      dialog     = ' '

      i_cobl     = fs_cobl_i

    IMPORTING

      e_cobl     = fs_cobl_e

    TABLES

      t_copadata = int_copadata

    EXCEPTIONS

      OTHERS     = 1.

  IF syst-subrc = 0.

* Update BSEG with COPA object

    f900_bseg-paobjnr = fs_cobl_e-paobjnr.

    f900_bseg-pasubnr = fs_cobl_e-pasubnr.

    f900_bseg-prctr   = fs_cobl_e-prctr.

    f900_bseg-gvtyp   = wl_x.

    CLEAR f900_bseg-kunnr.

  ENDIF.

ENDFORM.                    "F900_DETERMINE_COPA

Calling PRELIMINARY_POSTING_FB01

In order to successfully call this function module we need to fill tables T_BKPF and T_BSEG. We provide one header record for each debit and credit line item entries. Import parameters I_TCODE
and I_TCODE_INT are set to FV50 (the transaction for parking financial documents).

In our example we are processing entries from an input file. The file contains a grouping of a debit and a credit line. We create one parked document for each set of debit and credit lines. If the line has a reference to a customer we call the form routine to determine the COPA profitability segment number. It is not necessary to determine this information for each line – only where applicable. In our case the credit entries have COPA info, the debit entries do not.

Complete code snippet:

FORM f_process_fv50 .

  DATA:

    int_bkpf            TYPE TABLE OF bkpf,

    wf_line             TYPE i,

    wf_linec(3)         TYPE c,

    fs_bkpf             TYPE bkpf,

    int_bseg            TYPE TABLE OF bseg,

    fs_bseg             TYPE bseg,

    int_bsec            TYPE TABLE OF bsec,

    fs_status           TYPE char200,

    fs_bsec             TYPE bsec,

    int_bset            TYPE TABLE OF bset,

    fs_bset             TYPE bset,

    int_bsez            TYPE TABLE OF bsez,

    wf_ind              TYPE i ,

    fs_bsez             TYPE bsez,

    fs_return           LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

  TABLES : t100.

  CLEAR :  wf_line , wf_ind .

  LOOP AT int_sheet INTO fs_sheet .

    IF wf_ind NE fs_sheet-indicator.

      CLEAR wf_line.

      CLEAR fs_bkpf.

      fs_bkpf-bukrs = fs_sheet-company_code.

      fs_bkpf-gjahr = fs_sheet-post_date(4).

      fs_bkpf-blart = fs_sheet-blart.

      fs_bkpf-bldat = fs_sheet-post_date.

      fs_bkpf-budat = fs_sheet-post_date.

      fs_bkpf-monat = fs_sheet-post_date+4(2).

      fs_bkpf-wwert = fs_sheet-post_date.

      fs_bkpf-cpudt = sy-datum.

      fs_bkpf-bktxt = fs_sheet-header_txt.

      fs_bkpf-cputm = sy-uzeit.

      fs_bkpf-usnam = sy-uname.

      fs_bkpf-tcode = wl_fv50.

      fs_bkpf-xblnr = fs_sheet-reference_doc.

      fs_bkpf-waers = fs_sheet-currency.

      fs_bkpf-hwaer = fs_sheet-currency.

      fs_bkpf-hwae2 = fs_sheet-currency.

      fs_bkpf-basw2 = wl_two.

      fs_bkpf-umrd2 = wl_three.

      fs_bkpf-curt2 = wl_thirty.

      fs_bkpf-kuty2 = wl_m.

      APPEND fs_bkpf TO int_bkpf.

    ENDIF.

    wf_line = wf_line + 1.

    CLEAR fs_bseg.

* Entering BSEG entries

    fs_bseg-bukrs = fs_sheet-company_code..

    fs_bseg-gjahr = fs_sheet-post_date(4).

    fs_bseg-buzei = wf_line.

    fs_bseg-koart = fs_sheet-koart.

    IF fs_sheet-debit_credit EQ wl_dr.

      fs_bseg-bschl = wl_forty.

      fs_bseg-shkzg = wl_s.

    ELSEIF fs_sheet-debit_credit EQ wl_cr.

      fs_bseg-bschl = wl_fifty.

      fs_bseg-shkzg = wl_h.

    ENDIF.

    fs_bseg-wrbtr = fs_sheet-amount.

    fs_bseg-dmbtr = fs_sheet-amount.

    fs_bseg-pswbt = fs_sheet-amount.

    fs_bseg-pswsl = fs_sheet-currency.

    fs_bseg-mwskz = fs_sheet-tax_code.

    fs_bseg-txjcd = fs_sheet-tax_jurisdiction.

    fs_bseg-werks = fs_sheet-plant.

    fs_bseg-vbund = fs_sheet-trading_partner.

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'

      EXPORTING

        input     = fs_sheet-wbs_elem

      IMPORTING

        output    = fs_sheet-wbs_elem

      EXCEPTIONS

        not_found = 1

        OTHERS    = 2.

    IF sy-subrc <> 0.

      CLEAR fs_sheet-wbs_elem.

    ENDIF.

    fs_bseg-projk = fs_sheet-wbs_elem.

    fs_bseg-aufnr = fs_sheet-order.

    fs_bseg-matnr = fs_sheet-material.

    fs_bseg-sgtxt = fs_sheet-sgtxt.

    fs_bseg-kunnr = fs_sheet-customer.

    fs_bseg-vorgn = wl_rfbv.

    fs_bseg-xkres = wl_x.

    fs_bseg-xbilk = wl_x.

    fs_bseg-hkont = fs_sheet-account.

    fs_bseg-kokrs = fs_sheet-company_code.

    fs_bseg-valut = fs_sheet-value_date.

    fs_bseg-kostl = fs_sheet-cost_center.

    fs_bseg-prctr = fs_sheet-profit_center.

    fs_bseg-dmbe2 = fs_sheet-amount.

*Determine COPA characteristics

    IF fs_sheet-customer IS NOT INITIAL.

      PERFORM f900_determine_copa

        USING fs_bseg.

    ENDIF.

    APPEND fs_bseg TO int_bseg.

    AT END OF indicator.

      CALL FUNCTION 'PRELIMINARY_POSTING_FB01'

        EXPORTING

          i_tcode       = wl_fv50

          i_xcmpl       = space

          i_tcode_int   = wl_fv50

        TABLES

          t_bkpf        = int_bkpf

          t_bseg        = int_bseg

          t_bsec        = int_bsec

          t_bset        = int_bset

          t_bsez        = int_bsez

        EXCEPTIONS

          error_message = 1.

      CLEAR fs_status.

      CLEAR wf_linec.

      wf_linec = fs_sheet-indicator.

      t100-sprsl = sy-langu.

      t100-arbgb = sy-msgid.

      t100-msgnr = sy-msgno.

      CLEAR wf_linec.

      wf_linec = fs_sheet-indicator.

* Preparing message

      CALL FUNCTION 'MESSAGE_PREPARE'

        EXPORTING

          language               = t100-sprsl

          msg_id                 = t100-arbgb

          msg_no                 = t100-msgnr

          msg_var1               = syst-msgv1

          msg_var2               = syst-msgv2

          msg_var3               = syst-msgv3

          msg_var4               = syst-msgv4

        IMPORTING

          msg_text               = fs_status

        EXCEPTIONS

          function_not_completed = 1
          message_not_found      = 2

          OTHERS                 = 3.

      IF sy-subrc = 0.

        CONCATENATE text-022

                    wf_linec

                    fs_status

          INTO fs_status

          SEPARATED BY space.

        APPEND fs_status TO int_status.

      ENDIF.

      CLEAR : int_bkpf ,int_bseg.

    ENDAT.

    wf_ind =  fs_sheet-indicator.

  ENDLOOP.

ENDFORM.                    " F_PROCESS_FV50

1 Comment