0% found this document useful (0 votes)
14 views3 pages

ABAP Code for Cost Center Mapping

This document contains the code for two ABAP methods: GLOBAL_END and GLOBAL_START. GLOBAL_END loops through a result table and concatenates fields to generate a new field. GLOBAL_START selects data from a mapping table, loops through a source table, checks for prefix matches, and generates a new cost center field by concatenating values from the mapping and source tables.

Uploaded by

klasskovskaya.n
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

ABAP Code for Cost Center Mapping

This document contains the code for two ABAP methods: GLOBAL_END and GLOBAL_START. GLOBAL_END loops through a result table and concatenates fields to generate a new field. GLOBAL_START selects data from a mapping table, loops through a source table, checks for prefix matches, and generates a new cost center field by concatenating values from the mapping and source tables.

Uploaded by

klasskovskaya.n
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

METHOD GLOBAL_END.

FIELD-SYMBOLS:
<RESULT_FIELDS> TYPE _ty_s_TG_1.

DATA: MONITOR_REC TYPE rstmonitor.

* Note the _M class are not considered for DTP execution.


* ABAP Breakpoints must be set in the generated program instead

* ABAP Breakpoints within an ABAP End-Routine must be set


* in the _A class if the transformation runtime is set to SAP HANA!

**** begin of routine - insert your code only below this line ****

LOOP AT result_package ASSIGNING <result_fields>.

<result_fields>-calmonth2 = <result_fields>-fiscper3+1(2).
CONCATENATE <result_fields>-calyear <result_fields>-calmonth2 INTO
<result_fields>-calmonth.

ENDLOOP.

**** end of routine - insert your code only before this line ****
ENDMETHOD.

METHOD GLOBAL_START.

FIELD-SYMBOLS:
<SOURCE_FIELDS> TYPE _ty_s_SC_1.

DATA: MONITOR_REC TYPE rstmonitor.

* Note the _M class are not considered for DTP execution.


* ABAP Breakpoints must be set in the generated program instead

**** begin of routine - insert your code only below this line ****

... "insert your code here

DATA: IT_SOURCE_PACKAGE TYPE STANDARD TABLE OF _TY_S_SC_1,


WA_SOURCE_PACKAGE TYPE _TY_S_SC_1.

**Defining the structure******

TYPES: BEGIN OF PREFIX,


COMP_CODE(4) TYPE C,
SF_CC_PREFIX_A(10) TYPE C,
SF_CC_PREFIX_B(10) TYPE C,
B4_CC_PREFIX(10) TYPE C,
END OF PREFIX.

**Defining internal table and Work area**************

DATA: LT_PREFIX TYPE STANDARD TABLE OF PREFIX,


LS_PREFIX TYPE PREFIX.
***********************************************************

CLEAR : WA_SOURCE_PACKAGE, LT_PREFIX, LS_PREFIX.


REFRESH : IT_SOURCE_PACKAGE.

**Select the data and put into internal table ***************

SELECT COMP_CODE SF_CC_PREFIX_A SF_CC_PREFIX_B B4_CC_PREFIX FROM /BIC/APAMSPDP012


INTO corresponding fields of TABLE LT_PREFIX
FOR ALL ENTRIES IN SOURCE_PACKAGE WHERE comp_code = source_package-company_code.

***********************************************************************
DATA: len_prefix_a type i,
len_prefix_b type i,
len_sf_cc type i,
b4_cc(15) type c,
source_cc_prefix(15) type c.

SORT source_package BY company_code.

LOOP AT SOURCE_PACKAGE INTO WA_SOURCE_PACKAGE.


READ TABLE LT_PREFIX INTO LS_PREFIX
WITH KEY comp_code = WA_SOURCE_PACKAGE-company_code
BINARY SEARCH.

**** Checking if the mapping ADSO PAMSPDP01 contains such a 0comp_code,


**** and b4_cc_perfix is filled there and either sf_cc_prefix_a or sf_cc_prefix_b
is filled.

IF ( SY-SUBRC = 0 and LS_PREFIX-b4_cc_prefix <> 'n/a' ).


SHIFT WA_SOURCE_PACKAGE-cost_center LEFT DELETING LEADING '0'.
len_prefix_a = strlen( LS_PREFIX-sf_cc_prefix_a ).
len_prefix_b = strlen( LS_PREFIX-sf_cc_prefix_b ).

**** Checking if the cost centers from the source ADSO PEHSADU01
**** have a prefix from the mapping ADSO PAMSPDP01 - sf_cc_prefix_a or
sf_cc_prefix_b.

IF LS_PREFIX-sf_cc_prefix_a <> 'n/a' and len_prefix_a <=


strlen( WA_SOURCE_PACKAGE-cost_center ).
IF len_prefix_a = 0.
source_cc_prefix = ''.
ELSE.
source_cc_prefix = WA_SOURCE_PACKAGE-cost_center(len_prefix_a).
ENDIF.
IF source_cc_prefix = LS_PREFIX-sf_cc_prefix_a and len_prefix_a <
strlen( WA_SOURCE_PACKAGE-cost_center ).
len_sf_cc = strlen( WA_SOURCE_PACKAGE-cost_center ) - len_prefix_a.

IF len_prefix_a > 0.
b4_cc = LS_PREFIX-b4_cc_prefix &&
WA_SOURCE_PACKAGE-cost_center+len_prefix_a(len_sf_cc).
ELSE.
b4_cc = LS_PREFIX-b4_cc_prefix && WA_SOURCE_PACKAGE-
cost_center.
ENDIF.
replace all occurrences of '-' in b4_cc with ''.
WA_SOURCE_PACKAGE-cost_center = b4_cc.
APPEND WA_SOURCE_PACKAGE TO IT_SOURCE_PACKAGE.
ELSE.
IF ( len_prefix_b < strlen( WA_SOURCE_PACKAGE-cost_center ) and
LS_PREFIX-sf_cc_prefix_b <> 'n/a' ).
IF len_prefix_b = 0.
source_cc_prefix = ''.
ELSE.
source_cc_prefix = WA_SOURCE_PACKAGE-
cost_center(len_prefix_b).
ENDIF.
IF source_cc_prefix = LS_PREFIX-sf_cc_prefix_b.
len_sf_cc = strlen( WA_SOURCE_PACKAGE-cost_center ) -
len_prefix_b.

IF len_prefix_b > 0.
b4_cc = LS_PREFIX-b4_cc_prefix &&
WA_SOURCE_PACKAGE-
cost_center+len_prefix_b(len_sf_cc).
ELSE.
b4_cc = LS_PREFIX-b4_cc_prefix && WA_SOURCE_PACKAGE-
cost_center.
ENDIF.
replace all occurrences of '-' in b4_cc with ''.
WA_SOURCE_PACKAGE-cost_center = b4_cc.
APPEND WA_SOURCE_PACKAGE TO IT_SOURCE_PACKAGE.
ELSE.
DELETE SOURCE_PACKAGE.
ENDIF.
ELSE.
DELETE SOURCE_PACKAGE.
ENDIF.
ENDIF.

ELSE.
DELETE SOURCE_PACKAGE.
ENDIF.
ELSE.
DELETE SOURCE_PACKAGE.
ENDIF.

ENDLOOP.

REFRESH SOURCE_PACKAGE.
SOURCE_PACKAGE = IT_SOURCE_PACKAGE.

**** end of routine - insert your code only before this line ****
ENDMETHOD.

Common questions

Powered by AI

Data transformation is handled by selecting data from the specified table /BIC/APAMSPDP012 into an internal table LT_PREFIX using a structured table that includes component fields like COMP_CODE and prefixes. The routine reads entries using binary search and manipulates cost centers by aligning them with mapped prefixes. The process involves stripping leading zeros, concatenating with relevant prefixes, and ensuring the transformed cost center fits criteria from existing mappings, ultimately achieving a transformed and harmonized dataset as required.

Table sorting is crucial for the effectiveness of the binary search algorithm used in the routine. Binary search can only be applied to sorted data, as it relies on the ability to discard half of the remaining elements during each iteration. By ensuring data is sorted, the routine efficiently performs searches and retrieves mapping data accurately and rapidly, significantly optimizing runtime performance.

CONCATENATE is used to combine fields such as 'calyear' and 'calmonth2' into a composite 'calmonth', which is essential for creating a unified identifier from separate data fragments. SHIFT operation is employed to remove leading zeros from cost center fields, facilitating the matching and transformation processes. Both operations are significant as they directly influence the accuracy of data transformation and subsequent analyses, ensuring proper formatting and usability.

ABAP Breakpoints must be set in the generated program and within an ABAP End-Routine in the _A class when the transformation runtime is set to SAP HANA. This setup is crucial because it helps in debugging and ensures that the expected logic runs correctly within the SAP HANA environment, particularly when embedded SQL or other transformations need to be validated in real-time.

The routine employs deletion of entries from the SOURCE_PACKAGE as a way to handle unmapped or unmatched data. If conditions are not met (such as no matching prefix found), the routine removes the offending entries. While effective at filtering out invalid data, this strategy could lead to data loss if not managed properly, necessitating careful validation and checks during routine execution.

The deletion strategy could inadvertently lead to data loss if incorrect entries are removed without verification, potentially excluding valid data due to mismatches in expected vs. actual data structures. Mitigating this requires implementing comprehensive validation checks prior to deletion and maintaining logs of deletions for post-processing review, allowing for accurate error diagnosis and recovery if needed.

The routine assumes that the ADSO PAMSPDP01 contains a valid '0comp_code' entry and that either the sf_cc_prefix_a or sf_cc_prefix_b fields are filled along with the b4_cc_prefix not being 'n/a'. These assumptions are critical for the routine to correctly map cost centers to the desired prefixes and perform transformations. If these conditions are not met, the data is discarded from further processing.

The use of binary search in the routine is effective for efficient data retrieval, especially in sorted datasets. Binary search drastically reduces the time complexity compared to a linear search, making it suitable for handling large datasets commonly involved in enterprise environments like SAP. This method ensures that the program can swiftly locate mapping configurations corresponding to specific company codes, enhancing performance.

The program ensures relevance by applying conditional checks on each data entry. It verifies that components like b4_cc_prefix are not 'n/a', and at least one of the sf_cc_prefix fields is filled before proceeding with transformations. Data failing these checks is deleted from the SOURCE_PACKAGE. This filtering mechanism ensures that only data meeting predefined criteria contributes to the final output, maintaining data quality and relevance.

The routine computes string lengths of prefixes and adjusts the length of the cost center string dynamically. This manipulation determines how prefixes are concatenated and ensures the new length fits processing criteria. The calculation of string lengths is vital for preserving data integrity and ensuring that each cost center fits methodically within its mapped prefix framework, preventing errors in subsequent data operations.

You might also like