I love ALE. It is super-powerful and, once you get the hang of it, is a snap to configure. Recently, I was setting up an HRMD_A interface for my client. Everything was going smoothly until I ran into a requirement to filter out the social security number (PERID), birthdate (GBDAT), and gender (GESCH) for privacy reasons. All of these fields are in segment E1P0002. Initially, I thought that this requirement was easy enough to accomplish. I just created a IDOC reduction in transaction BD53 and filtered out the three fields. I soon found out that while entire segments were getting reduced from the IDOC as configured, the individually reduced fields were still showing up in the IDOC. What’s going on?!?
Well, after some digging, I found OSS Note 381766. This note’s cause section states:
The reduction at segment level (see also Note 301223) was facilitated in order to be able to copy message type HRMD_A. This involved setting the reduction at field level, which was not taken into account in the code because it is not possible to centrally determine which fields are mandatory and which are dependent for all country versions. In addition, for one info type there may several records for different periods of time, which may also cause a problem when you are reducing fields.
So, in essence, field-level reduction isn’t supported for HRMD_A. The solution supplied in the OSS note suggests creating user-exit code to filter out the unwanted fields. I already have implemented BADI HRALE00OUTBOUND_IDOC to add some other processing logic (if you’re lucky I’ll cover that logic in this blog, too), so I have a module in which I can place the code. And while the code to loop through an IDOC and clear out all instances of E1P0002-PERID, E1P0002-GBDAT, and E1P0002-GESCH is very easy, I can’t help but think I can make the code more useful. You see, I hate unitasking code. I can see it now. If I take the shortcut path and wrote the unitasking code to clear those 3 fields, the code won’t be in production for more than a month before the requirements change and now there is another field that needs to be filtered out as well. With unitasking code, I would have to crack open the code, create a transport, unit test, transport to Q, integration test, wait for a transport window, blah, blah, blah. Ugh! What a waste of time for a minor change. We can do better.
I decided to create a multi-tasking module that will work for HRMD_A message types. The fields to be cleared will be stored in TVARV in the format <SEGMENT>-<FIELD> (e.g. E1P0002-PERID). That way, whenever the HR functional team wanted to filter out a new field, all they had to do was to update a TVARV variable.
To implement the solution, I created a new method called CLEAR_IDOC_FIELDS in my class implementation for BADI HRALE00OUTBOUND_IDOC. CLEAR_IDOC_FIELDS has the same method signature as IF_EX_HRALE00OUTBOUND_IDOC~IDOC_DATA_FOR_RECEIVER_MODIFY:
The code is pretty straight forward. To allow multiple interfaces to coexist in method CLEAR_IDOC_FIELDS, the TVARV variable that stores the fields to clear is in the format ‘ZHR_CLR_’ concatenated with the IDOC message type.
METHOD CLEAR_IDOC_FIELDS . *----------------------------------------------------------------------* * Class: ZCL_IM_HRALE00OUTBOUNDIDOC * * Method: CLEAR_IDOC_FIELDS * * Author: Craig Stasila * *----------------------------------------------------------------------* TYPES: BEGIN OF TY_FILTER, TABNAME TYPE DFIES-TABNAME, FIELDNAME TYPE DFIES-FIELDNAME, POSITION TYPE DFIES-POSITION, OFFSET TYPE DFIES-OFFSET, LENG TYPE DFIES-LENG, END OF TY_FILTER. DATA: WA_FILTER TYPE TY_FILTER, LT_FILTER TYPE TABLE OF TY_FILTER, LS_TABNAME TYPE DDOBJNAME, LS_SAV_TABNAME TYPE DDOBJNAME. DATA: LS_NAME TYPE TVARV-NAME, LT_TVARVC TYPE TABLE OF TVARVC, WA_TVARVC TYPE TVARVC. DATA: LT_DFIES TYPE TABLE OF DFIES, WA_DFIES TYPE DFIES. DATA: LR_SEGNAM TYPE RANGE OF EDIDD-SEGNAM, WR_SEGNAM LIKE LINE OF LR_SEGNAM. FIELD-SYMBOLS: <FS> TYPE LINE OF EDIDD_TT. * Fields to clear are in variable CONCATENATE 'ZHR_CLR_' MESTYP INTO LS_NAME. * Get list of fields to clear from TVARV SELECT * FROM TVARVC INTO TABLE LT_TVARVC WHERE NAME = LS_NAME AND TYPE = 'S'. CHECK SY-SUBRC = 0. * Build list of fields to clear LOOP AT LT_TVARVC INTO WA_TVARVC. CLEAR WA_FILTER. SPLIT WA_TVARVC-LOW AT '-' INTO WA_FILTER-TABNAME WA_FILTER-FIELDNAME. CHECK SY-SUBRC = 0. COLLECT WA_FILTER INTO LT_FILTER. ENDLOOP. SORT LT_FILTER BY TABNAME. CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD. * Get field offsets LOOP AT LT_FILTER INTO WA_FILTER. LS_TABNAME = WA_FILTER-TABNAME. IF LS_TABNAME NE LS_SAV_TABNAME. CALL FUNCTION 'DDIF_NAMETAB_GET' EXPORTING TABNAME = LS_TABNAME TABLES DFIES_TAB = LT_DFIES EXCEPTIONS NOT_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. CONTINUE. ENDIF. SORT LT_DFIES BY TABNAME FIELDNAME. ENDIF. LS_SAV_TABNAME = LS_TABNAME. READ TABLE LT_DFIES INTO WA_DFIES WITH KEY TABNAME = WA_FILTER-TABNAME FIELDNAME = WA_FILTER-FIELDNAME BINARY SEARCH. CHECK SY-SUBRC = 0. WA_FILTER-POSITION = WA_DFIES-POSITION. WA_FILTER-OFFSET = WA_DFIES-OFFSET / CL_ABAP_CHAR_UTILITIES=>CHARSIZE. WA_FILTER-LENG = WA_DFIES-LENG. MODIFY LT_FILTER FROM WA_FILTER. * Build segment name range IF SY-SUBRC = 0. WR_SEGNAM-SIGN = 'I'. WR_SEGNAM-OPTION = 'EQ'. WR_SEGNAM-LOW = WA_FILTER-TABNAME. COLLECT WR_SEGNAM INTO LR_SEGNAM. ENDIF. ENDLOOP. * Loop at IDOC to clear fields LOOP AT IDOC_DATA ASSIGNING <FS>. IF <FS>-SEGNAM IN LR_SEGNAM. LOOP AT LT_FILTER INTO WA_FILTER WHERE TABNAME = <FS>-SEGNAM. CLEAR <FS>-SDATA+WA_FILTER-OFFSET(WA_FILTER-LENG). ENDLOOP. ENDIF. ENDLOOP. ENDMETHOD.
I also added the following code to IF_EX_HRALE00OUTBOUND_IDOC~IDOC_DATA_FOR_RECEIVER_MODIFY:
* Clear IDOC fields CALL METHOD ME->CLEAR_IDOC_FIELDS EXPORTING IDOC_CONTROL = IDOC_CONTROL RECEIVER = RECEIVER MESTYP = IDOC_CONTROL-MESTYP CHANGING IDOC_DATA = IDOC_DATA.
Finally, I maintained the following TVARV variable:
That’s all it takes! Now individual field values can be easily be filtered from outbound HRMD_A IDOCs!.
UPDATE: My colleague informed me that instead of using TVARV, I should continue to use BD53 to manage the IDOC reduction and change my code to look up the field reductions in TBD24. This would be a great idea, but my full HRMD_A solution uses custom filter objects and a custom IDOC formatting function module. And BD53 does not play well with these customizations.