SAP Knowledge Base Article - Public

3764878 - Journal Entry Substitution BADI FIN_ACDOC_SUBSTITUTION and Summarization

Symptom

BADI IN_ACDOC_SUBSTITUTION is utilized to Substitute accounting document items of the complete journal entry with the possibility to access data from other items.

This BAdI is based on the entry view, which might be compressed if entry view summarization is active (Configuration activity Activate Entry View Summarization SSCUI 106716). 

See Entry View Summarization



From release 2608, 2 new parameters are added:

ParameterNameDescription 
ImportingITEM_MAPPINGIf summarization is active the item mapping table contains references to all the corresponding uncompresseditems for each accounting document item. For each entry in accountingdocitem there can be multiple uncompresseditems items. 
ChangingUPDATED_FIELDSThis allows to keep the record of the actually updated fields and to not overwrite fields not changed. The fields which are impacted are the Item Text and Custom fields as these fields can be substituted in addition to summarization.

If this parameter is set only those columns listed in this table are taken into consideration by the subsequent posting process.  This is necessary so as to avoid overwriting fields which are meant to be left unchanged.  For example Document Item Text/Custom fields.

"Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental."  

Environment

SAP S/4HANA Public Cloud Edition 

Resolution

Importing ParametersDescription 
ACCOUNTINGDOCHEADERAccounting Document Header Input
ACCOUNTINGDOCITEMSAccounting Document Items Input 
UNCOMPRESSEDITEMSContains the data sent to the accounting interface in the form it was before summarization. 
ITEM_MAPPINGContains the mapping between summarized and the uncompressed items.

Changing ParametersDescription
ACCOUNTINGDOCITEMSOUTAccounting Document Items Text, Assignment and Custom fields Output
SUBSTITUTIONDONESubstitution Done? TRUE (='X') and FALSE (=' ')
UPDATED_FIELDS Names of updated fields (optional, if unchanged behaviour stays as before upgrade)



To keep record of the actually updated fields, to not overwrite fields not changed the following coding is needed:

insert conv #(  'NAME OF FIELD YOU SUBSTITUTE ' ) into TABLE   updated_fields. 


Important Points to Note:


1. For FIN_ACDOC_SUBSTITUTION - Journal Entry Substitution the following fields can be substituted

Name Description 
DOCUMENTITEMTEXTItem Text
REFERENCE1IDBYBUSINESSPARTNERBusiness Partner Reference Key 1
REFERENCE2IDBYBUSINESSPARTNERBusiness Partner Reference Key 2
REFERENCE3IDBYBUSINESSPARTNERReference Key for Line Item
ASSIGNMENTREFERENCEAssignment Number
FINANCIALTRANSACTIONTYPETransaction Type
YY1_CustomFieldsCustom Fields



2. Keep in mind that the items in ACCOUNTINGDOCITEMS could be initial due to summarization.  See full list of fields in  Entry View Summarization

In this case the mapping expressed in the parameter ITEM_MAPPING can be used to retrieve the uncompressed entries. 


Examples with summarization active and substitution:

Configuration activity: Activate Entry View Summarization (ID 106716 )




Example 1: 

In App Custom Logic (App ID F6957) FIN_ACDOC_SUBSTITUTION - Journal Entry Substitution created to substitute ASSIGNMENTREFERENCE with value of account for S accounts. 

" ----------------------------------------------------------------------------------------------
    " BAdI usage:
    " Substitute accounting document items of the complete journal entry with the possibility
    " to access data from other items.
    " Note that this BAdI is based on the entry view, which might be compressed if entry view
    " summarization is active (SSCUI 106716). Summarization is active by default for new tenants.
    " See https://help.sap.com/docs/SAP_S4HANA_CLOUD/0fa84c9d9c634132b7c4abb9ffdd8f06/3a295f45d9354aa09418530288fc166c.html
    " In that case, UNCOMPRESSEDITEMS contains the data sent to the accounting interface
    " in the form it was before summarization. The parameter ITEM_MAPPING contains the apping between
    "  summarized and the uncompressed items.
    "  if you want to access the summarized accounting item for each item in UNCOMPRESSEDITEMS, the following loop could be used
*          LOOP at UNCOMPRESSEDITEMS into data(ls_uncompressed).
*           data(lv_index) =  sy-tabix.
*           data(ls_accitem) = accountingdocitems[ ITEM_MAPPING[ key k2 COMPONENTS
*              uncompresseditems_index = lv_index ]-accountingdocitems_index ].
*         ENDLOOP.
    "
    " SUBSTITUTIONDONE:
    " -- Please always set this flag when updating any item
    " -- Substitutions take effect only when true (‘X’) is set.
    " ACCOUNTINGDOCITEMSOUT:
    " -- Please always copy values from input to output and keep rowindex
    " -- Existing values might be cleared or wrong items changed otherwise.
    " ----------------------------------------------------------------------------------------------
    DATA ls_itemout TYPE fins_acdoc_out.

    CLEAR accountingdocitemsout.

    " Use Case 1 : Document type 'RE' and GLACCOUNT = '0061003000' involved in positng:
    " substitute ASSIGNMENTREFERENCE with account  0061003000 if found in G/L account items (type S)

    " --------------------------------------------------------------------------------------------
    IF accountingdocheader-AccountingDocumentType = 'RE' AND uncompresseditems IS NOT INITIAL.
      DATA lv_GLACCOUNT TYPE hkont.
      LOOP AT accountingdocitems REFERENCE INTO DATA(lr_item) WHERE FinancialAccountType = 'S' AND GLACCOUNT = '0061003000'.
        lv_GLACCOUNT = lr_item->GLACCOUNT.
        EXIT.
      ENDLOOP.
      IF lv_GLACCOUNT IS NOT INITIAL.
        LOOP AT accountingdocitems REFERENCE INTO lr_item WHERE FinancialAccountType = 'S'.
          " Notes:
          " 1. Please always copy the values from input to output first before any substitutions,
          "    otherwise, the initial values from the output will be used for substitutions!
          " 2. Always keep 'rowindex' unchanged, otherwise, another item will be substituted accidently!
          MOVE-CORRESPONDING lr_item->* TO ls_itemout.
          ls_itemout-ASSIGNMENTREFERENCE = lv_GLACCOUNT.

           " keep record of the actually updated fields, to not overwrite fields not changed
          insert conv #( 'ASSIGNMENTREFERENCE' ) into TABLE   updated_fields.
          APPEND ls_itemout TO accountingdocitemsout.
          substitutiondone = abap_true.

        ENDLOOP.
      ENDIF.
    ENDIF.




In App Create Supplier Invoice Advanced (MIRO) Item Text is manually entered. 





Post 

Select Accounting Document 


Entry View shows substitution correctly for assignment reference,  the fields Cost Center, Item Text and Profit center are cleared on the Entry View as summarization is active.   



Ledger View shows update of summarized fields including item text in addition to substituted values for assignment reference. 






Example 2: Incorrect Custom Logic and results:


Here the line  insert conv #( 'ASSIGNMENTREFERENCE' ) into TABLE   updated_fields. is commented out, therefore it is not used in coding.



New posting with same data as prior posting





Entry View shows substitution correctly for assignment reference, the fields Cost Center, Item Text and Profit center are cleared on the Entry View as summarization is active.    




Ledger View shows update of substituted field, the Cost center and Profit Center are updated, however the item text is missing even though it was manually entered in the supplier invoice during creation as in example 1. 






The item text (likewise custom fields) is in addition to a value that can be substituted also a summarization field. To ensure that value is transferred it is necessary to add coding  insert conv #( 'ASSIGNMENTREFERENCE' ) into TABLE in substitution, this keep the record of the actually updated fields, in this case the assignment reference, and does not allow overwriting fields not changed in this case the item text. 

See example 1 with correct coding logic. 



Point to note: Where the entry view is Suppressed in accordance with Entry View Summarization - Suppress If Possible, this BADI cannot be used as there is no entry view. Workaround use Manage Substitution/Validation Rules (App ID F4406) e.g. Journal Entry Item business context/ alternative BADI e.g. FIN_ACDOC_ITEM_SUBSTITUTION - Journal Entry Item Substitution 



See Also

3060075 Journal Entries without Entry View

3620938 Assign an attribute of one journal entry item to another journal entry item - SAP S/4HANA Cloud Public Edition

2802958 How to substitute custom fields on cloud systems

Business Add-Ins for Substitution for Journal Entries

Keywords

 (BSTAT) = 'U', , KBA , FI-SL-VSR-2CL , Validation, Substitution and Rules (Public Cloud) , How To

Product

SAP S/4HANA Cloud Public Edition all versions

Attachments

Pasted image.png