Domanda

I've been making a report and now it's in the quality server. The thing is, when it was in development it was working fine, but now it repeats some of the invoice numbers, not all of them and it repeats two times for one invoice and four for another one. I don't know if it is code problem or or something else. here's the code:

IF kunnr[] IS INITIAL
    AND belnr[] IS INITIAL
    AND spart IS NOT INITIAL
    AND gjahr[] IS NOT INITIAL
    AND bukrs[] IS NOT INITIAL
    AND allgstid IS INITIAL
    AND augdt[] IS NOT INITIAL
    AND budat[] IS INITIAL
    AND kbetr IS INITIAL
    AND vkorg IS INITIAL.
    SELECT c~kunnr a~belnr d~spart a~bldat a~waers c~wrbtr a~hwaer c~dmbtr
      INTO CORRESPONDING FIELDS OF TABLE lt_data
        FROM ( ( bkpf AS a
      INNER JOIN bsad AS c ON c~belnr = a~belnr )
      INNER JOIN vbrk AS d ON d~xblnr = c~belnr )
      WHERE a~gjahr IN gjahr
        AND a~bukrs IN bukrs
        AND d~spart = spart
        AND c~augdt IN augdt.
    IF sy-subrc <> 0.
      MESSAGE i425.
    ENDIF.

  ENDIF.



  LOOP AT lt_data ASSIGNING <fs_main>.


    CLEAR <fs_main>-kbetr.
    CLEAR <fs_main>-fwste.
    CLEAR <fs_main>-hwste.
    IF kbetr IS INITIAL.
      SELECT SINGLE kbetr fwste hwste
        FROM bset
        INTO (<fs_main>-kbetr, <fs_main>-fwste, <fs_main>-hwste)
        WHERE belnr = <fs_main>-belnr
        AND bukrs IN bukrs
        AND gjahr IN gjahr
        AND mwskz BETWEEN 'L0' AND 'L2'.
    ELSE.
      SELECT SINGLE kbetr fwste hwste
        FROM bset
        INTO (<fs_main>-kbetr, <fs_main>-fwste, <fs_main>-hwste)
        WHERE belnr = <fs_main>-belnr
        AND bukrs IN bukrs
        AND gjahr IN gjahr
        AND mwskz BETWEEN 'L0' AND 'L2'
        AND kbetr = kbetr.
    ENDIF.

    AT NEW kunnr.

      SELECT SINGLE name1 FROM kna1
          INTO (wa_bseg-name1)
          WHERE kunnr = <fs_main>-kunnr.


      IF sy-subrc = 0.
        FORMAT COLOR COL_TOTAL INTENSIFIED ON.

        WRITE:/ sy-uline(137), / sy-vline NO-GAP,
                        2 'Entidade: ', <fs_main>-kunnr, wa_bseg-name1,
                        137 sy-vline NO-GAP, / sy-uline(137).

      ENDIF.
    ENDAT.

    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    WRITE:/
            sy-vline NO-GAP,
            (16) <fs_main>-belnr NO-GAP,
            sy-vline NO-GAP,
            (16) <fs_main>-spart CENTERED NO-GAP,
            sy-vline NO-GAP,
            (10) <fs_main>-bldat NO-GAP,
            sy-vline NO-GAP.
    perc = <fs_main>-kbetr / 10.
    WRITE: (10) perc NO-GAP,
            sy-vline NO-GAP,
            (5) <fs_main>-waers NO-GAP,
            sy-vline NO-GAP,
            (16) <fs_main>-wrbtr NO-GAP,
            sy-vline NO-GAP,
            (16) <fs_main>-fwste NO-GAP,
            sy-vline NO-GAP,
            (5) <fs_main>-hwaer NO-GAP,
            sy-vline NO-GAP,
            (16) <fs_main>-dmbtr NO-GAP,
            sy-vline NO-GAP,
            (16) <fs_main>-hwste NO-GAP,
            sy-vline NO-GAP.
    WRITE:/ sy-uline(137).
È stato utile?

Soluzione 2

The problem is solved. I was using the wrong field of vbrk table. It should be vbeln, not xblnr. Thank you anyway.

Altri suggerimenti

You're doing INNER JOIN bsad, but table bsad has a primary key which includes BUZEI, the number of the line item within the accounting document. So if the invoice has more than one line item, you will get more than one line for it... if you only want one line per document then don't join to bsad. If you need information from bsad you could pull that in a separate select in the loop (e.g. you could select the sum of wrbtr for each document, I think).

I've actually run into this type of thing before, as inevitably in development all the test documents I create only ever have one line item (because it's quicker..).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top