Register Login

CIF error Open SQL-Array-Insert leads to duplicate records.

Updated Jul 05, 2019

This error is caused by the CIF transfer of material versions. For material versions to be transferred correctly from the R/3 into an APO system, the R/3 table MATERIALID must be mapped in APO tables MATMAP and MATKEY. This usually takes place in function /SAPAPO/DM_PRODUCTS_MAINTAIN.

However, if user exit '001' is used (maybe necessary for various reasons) in function /SAPAPO/CIF_PROD_INBOUND and table LT_CIF_MATMAP is filled or interface variable EF_MAP_USE is set to X, the mapping of the material versions must also simultaneously take place into table LT_CIF_MATMAP in this user exit.
The following sample code is the instructions for carrying this out:
*--------------------------------------------------------------------*
*   INCLUDE ZXCIFUSERU08 *--------------------------------------------------------------------*
*"*"Lokale Schnittstelle:
*"       EXPORTING
*"             VALUE(EF_MAP_USE) TYPE  XFELD
*"             VALUE(EF_DUP_CHECK) TYPE  XFELD
*"       TABLES
*"              IT_MATKEY STRUCTURE  /SAPAPO/CIF_MATKEY
*"              IT_MATKEYX STRUCTURE  /SAPAPO/CIF_MATKEYX
*"              IT_MATTXT STRUCTURE  /SAPAPO/CIF_MATTXT
*"              IT_MATTXTX STRUCTURE  /SAPAPO/CIF_MATTXTX
*"              IT_MARM STRUCTURE  /SAPAPO/CIF_MARM
*"              IT_MARMX STRUCTURE  /SAPAPO/CIF_MARMX
*"              IT_MATLOC STRUCTURE  /SAPAPO/CIF_MATLOC
*"              IT_MATLOCX STRUCTURE  /SAPAPO/CIF_MATLOCX
*"              IT_MATCLASS STRUCTURE  /SAPAPO/CIF_MATCLASS
*"              IT_EXTENSIONIN STRUCTURE  /SAPAPO/CIFBPAREX
*"              ET_RETURN STRUCTURE  BAPIRET2CIF_MATTXT
*"              ET_MATMAP STRUCTURE  /SAPAPO/CIF_MATMAP
*"       CHANGING
*"             VALUE(CS_CONTROLS) TYPE  /SAPAPO/CIF_CTRLPARAM
*"             VALUE(CF_DST_BSG) TYPE  /SAPAPO/LOGQS
*"       EXCEPTIONS
*"              USEREXIT_ERROR
*"---------------------------------------------------------*
DATA lt_cif_matmap TYPE TABLE OF /sapapo/cif_matmap WITH HEADER LINE.

DATA lv_srcsys LIKE cs_controls-logsrcsys VALUE ''.     "Quellsystem
CONCATENATE
   cs_controls-logsrcsys(3) cs_controls-logsrcsys+7(3) INTO lv_srcsys.
LOOP AT it_matkey.
  READ TABLE it_matkeyx INDEX sy-tabix.
  IF it_matkeyx-matnrlong IS INITIAL.
*   X-Flag not set: standard case, no long material numbers
    MOVE IT_MATKEY-EXT_MATNR TO ET_MATMAP-EXT_MATNR.
    CONCATENATE IT_MATKEY-EXT_MATNR '@' LV_SRCSYS INTO ET_MATMAP-MATNR.
    COLLECT ET_MATMAP.
  ELSE.
*   X-Flag set: R/3-system can have long material numbers
    MOVE it_matkey-ext_matnr TO lt_cif_matmap-ext_matnr.
    IF it_matkey-matnrlong IS INITIAL.
*     long material number not used for this material
      MOVE it_matkey-ext_matnr TO et_matmap-matnr.
    ELSE.
*     long material number used for this material
      MOVE it_matkey-matnrlong TO lt_cif_matmap-matnr.
*     material version may also come along with long material number
      IF NOT it_matkeyx-matvers IS INITIAL.
*       try direct
        MOVE it_matkey-matvers TO lt_cif_matmap-matvers.  "may be
      ENDIF.
      IF lt_cif_matmap-matvers IS INITIAL.
        IF NOT it_matvers[] IS INITIAL.
*         try IT_MATVERS
          READ TABLE it_matverx
             WITH KEY ext_matnr = it_matkey-ext_matnr
                      ext_locno = space.
          IF sy-subrc = 0.
            IF NOT it_matverx-matvers IS INITIAL.  "check X-field
              READ TABLE it_matvers INDEX sy-tabix. "may be same index
              IF sy-subrc <> 0 OR
                 it_matvers-ext_matnr <> it_matkey-ext_matnr OR
                 it_matvers-ext_locno <> space.
                READ TABLE it_matvers              "correct read
                  WITH KEY ext_matnr = it_matkey-ext_matnr
                           ext_locno = space.
              ENDIF.
              IF sy-subrc = 0.
                MOVE it_matvers-matvers TO lt_cif_matmap-matvers.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
    COLLECT lt_cif_matmap.                 "store separatly
  ENDIF.
ENDLOOP.

IF NOT lt_cif_matmap[] IS INITIAL.
  APPEND LINES OF lt_cif_matmap TO et_matmap.
ENDIF.

IF NOT et_matmap[] IS INITIAL.
  ef_map_use   = 'X'.
  ef_dup_check = 'A'.
ENDIF.

 


×