Downtime Announcement: Please note the SAP Community Wiki will be unavailable due to a system upgrade on Thursday, September 24th between 6 and 7 AM CEST
Skip to end of metadata
Go to start of metadata

This Document describes how to include Customer Master Record (Tax Groupings) in customer ale (outbound and inbound)  using standard message type DEBMAS . As per the SAP Note 577502 Maintenance of Individual customer master fields without modifications into standard-dialog of the customer master record can be integrated with the help the Business Add-In (BAdI) technology which provide interfaces and where custom fields can be maintained in the Standard.  In the customer master record dialog the fields are admitted via customer-specific subscreens into the maintenance of the customer master. The Standard is informed about these subscreens via interfaces.

In the standard batch input of the customer master there are available interfaces so you can also integrate the maintenance of the fields via batch input into batch input program RFBIDE00 which is delivered by the standard.

The ALE-outbound of the customer master provides interfaces which integrates the filling of the segments of the customer master IDoc that do not belong to the standard into the standard procedure.

The ALE-inbound of the customer master provides interfaces that allow to integrate the data contained in the customer master IDoc from the non-standard-segments into the table of the batch input data calculated by the standard-program.

However the processing of the table KNAT do not lie within the module pool of SAPMF02D.  Hence in the customer ALE, an outbound customer idoc gets created in the source system without Customer Master Record (Tax Groupings) information i.e KNAT .

The idea here is to create a custom segment for CustomerMaster Record (Tax Groupings) and  include this information in the customer master ALE and distribute along with the standard segments.

Assumption: ALE distribution Model for Customer has been set up.

1. Create a segment ZE1KNAT1 with all specific fields of KNAT

2.  Create a Custom Idoc type (Copy of DEBMAS06) ZDEBMAS06 and add the custom segment as a child to the standard segment  E1KNA1M.

Include Customer Master Record (Tax Groupings) information in customer outbound Idoc creation

1. Create a project ZCUST through CMOD and assign the enhancement VSV00001 to the project.

2. Now populate the Customer Outbound Idoc through the User Exit ZXVSVU01  of EXIT_SAPLVV01_001

TABLES: ZE1KNAT1.
CHECK SEGMENT_NAME = 'E1KNA1M'.
*Update the idoc data with Tax Categories data (KNAT)
  data: g_kunnr type kna1-kunnr,
        tb_knat type standard table of knat with header line.
  g_kunnr = idoc_data-sdata+3(10).
  select * from knat into table tb_knat where kunnr = g_kunnr.
  loop at tb_knat.
    move-corresponding tb_knat to ZE1KNAT1.
    IDOC_DATA-SEGNAM = 'ZE1KNAT1'.
    IDOC_DATA-SDATA = ZE1KNAT1.
    APPEND IDOC_DATA.
    CLEAR IDOC_DATA.
  endloop.

Process Customer Master Record (Tax Groupings) information in customer Inbound Idoc

1. Implement the BADI Definition CUSTOMER_ADD_DATA_BI .   

2. Create a table type ZE1KNAT1_T  with the line type as  ZE1KNAT1 (Structure of custom defined segment ZE1KNAT1 ) . Define the attribute TB_KNAT type table type  in the implemented BADI to store the values of Tax Categories
3.  Implement the below code in the method PASS_NON_STANDARD_SEGMENT.
    This code basically populates the values of non standard segment
     IF I_SEGMENT_NAME = 'ZE1KNAT1'.
      APPEND I_SEGMENT_DATA TO TB_KNAT.

    ENDIF.

4  Implement the below Code in the method FILL_FT_TABLE_USING_DATA_ROWS . Read the KNAT data in this method  and export to abap memory to read again in the  customer Save User Exit
 TYPES:BEGIN OF TY_KNAT_EXT,
        KUNNR TYPE STRING,
        TAXGR TYPE STRING,
        SBJDF TYPE STRING,
        SBJDT TYPE STRING,
        EXNR TYPE STRING,
        EXRT TYPE STRING,
        EXDF TYPE STRING,
        EXDT TYPE STRING,
      END OF TY_KNAT_EXT.
  DATA: L_LINE1  TYPE TY_KNAT_EXT,
        TB_KNAT_EXP TYPE STANDARD TABLE OF TY_KNAT_EXT,
        TB_KNAT2 LIKE TB_KNAT_EXP,
        TB_KNAT1 LIKE TB_KNAT_EXP,
        WA_KNAT_EXT TYPE ZE1KNAT1.
CLEAR:WA_KNAT_EXT,

        L_LINE.
  LOOP AT TB_KNAT INTO WA_KNAT_EXT WHERE KUNNR = I_BKN00-KUNNR.
    L_LINE1-KUNNR = WA_KNAT_EXT-KUNNR.
    L_LINE1-TAXGR = WA_KNAT_EXT-TAXGR.
    L_LINE1-SBJDF = WA_KNAT_EXT-SBJDF.
    L_LINE1-SBJDT = WA_KNAT_EXT-SBJDT.
    L_LINE1-EXNR = WA_KNAT_EXT-EXNR.
    L_LINE1-EXRT = WA_KNAT_EXT-EXRT.
    L_LINE1-EXDF = WA_KNAT_EXT-EXDF.
    L_LINE1-EXDT = WA_KNAT_EXT-EXDT.
    APPEND L_LINE1 TO TB_KNAT1.
  ENDLOOP.
  DATA: MEM_ID_KNAT TYPE C LENGTH 7 VALUE 'TB_KNAT'.
  IF NOT TB_KNAT1[] IS INITIAL.
    FREE MEMORY ID MEM_ID_KNAT.
    EXPORT TB_KNAT2 = TB_KNAT1 TO MEMORY ID MEM_ID_KNAT.

  ENDIF.

Having implemented the code to export KNAT data in the custom Badi, now import the data in customer Save user exit.  Create a project ZCUSTMAS in cmod and assign the enhcnacement  SAPMF02D to enable the save user exit ZXF04U01 of EXIT_SAPMF02D_001 of the customer

5.Implement below Code in the save user exit ZXF04U01 of EXIT_SAPMF02D_001.
TYPES:BEGIN OF TY_KNAT_EXT,
      KUNNR TYPE STRING,
      TAXGR TYPE STRING,
      SBJDF TYPE STRING,
      SBJDT TYPE STRING,
      EXNR TYPE STRING,
      EXRT TYPE STRING,
      EXDF TYPE STRING,
      EXDT TYPE STRING,
      KZ   TYPE STRING,
    END OF TY_KNAT_EXT.
 DATA: TB_KNAT_EXP TYPE STANDARD TABLE OF TY_KNAT_EXT,
      MEM_ID_KNAT TYPE C LENGTH 7 VALUE 'TB_KNAT',
      TB_KNAT2 LIKE TB_KNAT_EXP,
      TB_KNAT1 LIKE TB_KNAT_EXP,
      WA_KNAT_EXT TYPE TY_KNAT_EXT,
      IT_KNAT TYPE STANDARD TABLE OF FKNAT WITH HEADER LINE,
      WA_KNAT_EXT1 TYPE TY_KNAT_EXT,
      WA_KNAT TYPE FKNAT,
      L_INDEX1 TYPE SY-TABIX,
      L_SUBRC TYPE SY-SUBRC,
      L_INDEX TYPE SY-TABIX,
      I_KNAT LIKE FKNAT OCCURS 0.
 FIELD-SYMBOLS: <N_KNAT> LIKE I_KNAT.
SELECT * FROM KNAT INTO CORRESPONDING FIELDS OF TABLE IT_KNAT WHERE
  KUNNR = I_KNA1-KUNNR.
 IMPORT TB_KNAT2 = TB_KNAT1 FROM MEMORY ID MEM_ID_KNAT.
FREE MEMORY ID MEM_ID_KNAT.

DATA: MEM_TAX TYPE C LENGTH 7 VALUE 'MEM_TAX'.
SELECT * FROM KNAT INTO CORRESPONDING FIELDS OF   TABLE IT_KNAT WHERE KUNNR = I_KNA1-KUNNR.
IMPORT TB_KNAT2 = TB_KNAT1 FROM MEMORY ID MEM_ID_KNAT.
FREE MEMORY ID MEM_ID_KNAT.
* Process the knat table only when it is being ale'd.
IF NOT TB_KNAT1[] IS INITIAL.
  LOOP AT TB_KNAT1 INTO WA_KNAT_EXT.
    L_INDEX1 = SY-TABIX.
    L_SUBRC = 4.
    READ TABLE IT_KNAT WITH KEY  KUNNR = WA_KNAT_EXT-KUNNR
                       TAXGR = WA_KNAT_EXT-TAXGR.
    IF SY-SUBRC = 0.
      L_INDEX = SY-TABIX.
      CLEAR WA_KNAT_EXT1.
      MOVE-CORRESPONDING IT_KNAT TO WA_KNAT_EXT1.
      L_SUBRC = 0.
    ENDIF.
    IF L_SUBRC = 0.
* If data is not changed, don't process the record
      IF
      WA_KNAT_EXT-SBJDF = WA_KNAT_EXT1-SBJDF AND
      WA_KNAT_EXT-SBJDT = WA_KNAT_EXT1-SBJDT AND
      WA_KNAT_EXT-EXNR  = WA_KNAT_EXT1-EXNR  AND
      WA_KNAT_EXT-EXRT  = WA_KNAT_EXT1-EXRT  AND
      WA_KNAT_EXT-EXDF  = WA_KNAT_EXT1-EXDF AND
      WA_KNAT_EXT-EXDT  = WA_KNAT_EXT1-EXDT .
        DELETE TB_KNAT1 INDEX L_INDEX1.
        DELETE IT_KNAT INDEX L_INDEX.
      ELSE.
        WA_KNAT_EXT-KZ = 'U'.
        MODIFY TB_KNAT1 FROM WA_KNAT_EXT.
        IT_KNAT-KZ = 'U'.
        MODIFY IT_KNAT INDEX L_INDEX.
      ENDIF.
    ELSE.
      WA_KNAT_EXT-KZ = 'I'.
      MODIFY TB_KNAT1 FROM WA_KNAT_EXT.
    ENDIF.
  ENDLOOP.

* The tables J_1AXKNAT  & J_1AYKNAT  are being fed to the FM J_1A_COMPARE_KNAT_MF02D for onward updation of *KNAT table entries which is done in an update task  IF NOT TB_KNAT1[] IS INITIAL.
    ASSIGN ('(SAPMF02D)J_1AXKNAT[]') TO <N_KNAT>.
    IF SY-SUBRC = 0.
* Modify the KNAT value which in turn will update
* the database table KNVA
      LOOP AT TB_KNAT1 INTO WA_KNAT_EXT.
        MOVE-CORRESPONDING WA_KNAT_EXT TO WA_KNAT.
        APPEND WA_KNAT TO <N_KNAT>  .
        CLEAR WA_KNAT.
      ENDLOOP.
      UNASSIGN <N_KNAT>.
    ENDIF.
  ENDIF.
  IF NOT IT_KNAT[] IS INITIAL.
    ASSIGN ('(SAPMF02D)J_1AYKNAT[]') TO <N_KNAT>.
    IF SY-SUBRC = 0.
      CLEAR: WA_KNAT.
      LOOP AT IT_KNAT.
        MOVE-CORRESPONDING IT_KNAT TO WA_KNAT.
        APPEND WA_KNAT TO <N_KNAT> .
        CLEAR IT_KNAT.
      ENDLOOP.
      UNASSIGN <N_KNAT>.
    ENDIF.
  ENDIF.
ENDIF.