Search code examples
abapopensql

Duplicate record read to Internal Table


My internal table have double record when show, ex: 10 in billing documents, but 20 in my internal table. MAKTX were display whereby a SPEC-TEST was added to the duplicate value.

SELECT * INTO CORRESPONDING FIELDS OF wa_alv_list
FROM VBRK
INNER JOIN VBRP ON VBRK~VBELN = VBRP~VBELN "BILLING DOCUMENTS (HEADER)
AND VBRK~VKORG = VBRP~VKORG_AUFT
INNER JOIN MAKT ON VBRP~MATNR = MAKT~MATNR
WHERE VBRK~VKORG = VKORG
AND VBRK~BUKRS = BUKRS
AND VBRK~FKDAT IN S_FKDAT
AND VBRP~WERKS IN S_WERKS
ORDER BY VBRK~FKDAT.

Does the above sql caused the error?


Solution

  • You are joining with MAKT (material texts), but there is no restriction for a language. The double quantity of entries can be explained with materials texts in two languages.

    Can you give the definition of wa_alv_list? Or try to add MAKT-LANGU (or MAKT-SPRAS- I'm not sure which one) and a material text to check if you get an entry per language.


    I would recommend to define a parameter:

    PARAMETERS: P_SPRAS like SY-LANGU OBLIGATORY DEFAULT SY-LANGU.
    

    Now you can select the language (e.g. with F4) when you start the report.

    SELECT * INTO CORRESPONDING FIELDS OF wa_alv_list
      FROM VBRK
      INNER JOIN VBRP ON VBRK~VBELN = VBRP~VBELN "BILLING DOCUMENTS (HEADER)
      AND VBRK~VKORG = VBRP~VKORG_AUFT
      INNER JOIN MAKT ON VBRP~MATNR = MAKT~MATNR
      WHERE VBRK~VKORG = VKORG
      AND VBRK~BUKRS = BUKRS
      AND VBRK~FKDAT IN S_FKDAT
      AND VBRP~WERKS IN S_WERKS
      and MAKT~SPRAS = p_SPRAS  "<---Added
      ORDER BY VBRK~FKDAT.
    

    One warning: If the material has no text in the selected language, then no entry is found.