Question

I select data from transparent tables and cluster tables and put the result into an internal table. As cluster tables can't be joined, I used two select single for retrieving data from the cluster tables.

The problem is that, in the loop, each output line is assigned the same information of the first line in the internal table (D at each line). Maybe it's because the field of the where condition retrieves 3 lines with the same value from the BELNR column.

First, here is the code:

FORM select_data1 CHANGING lt_data LIKE gt_map1.   
  FIELD-SYMBOLS: <fs_main> TYPE zimposto_consumo.

  SELECT 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 bsis AS c ON c~belnr = a~belnr )
      INNER JOIN vbrk AS d ON d~xblnr = c~belnr )
      WHERE a~belnr IN belnr.


  LOOP AT lt_data ASSIGNING <fs_main>.
      SELECT SINGLE kbetr fwste hwste FROM bset
        INTO (<fs_main>-kbetr, <fs_main>-fwste, <fs_main>-hwste)
        WHERE belnr = <fs_main>-belnr.

      SELECT SINGLE koart FROM bseg
        INTO (<fs_main>-koart)
        WHERE buzei = 1
        AND belnr = <fs_main>-belnr.


    IF <fs_main>-koart = 'D'.    
          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 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).
                  write: <fs_main>-koart. 
    ELSE.   
                  write: 'Não há dados a mostrar.'. 
    ENDIF.   
  ENDLOOP.

ENDFORM.                    "select_data1

The result is this one:

runtime result

The 'D' at the right of the output table shouldn't be D for the 3 lines. Only the first one should be D and the other two should be S.

What is wrong?

Was it helpful?

Solution

Your WRITE <fs_main>-koart. is inside the block IF <fs_main>-koart = 'D'..

So you always get the D. I think that's a problem of the code copy.

You use

      SELECT SINGLE koart FROM bseg
        INTO (<fs_main>-koart)
        WHERE buzei = 1
        AND belnr = <fs_main>-belnr.

and you don't check SY-SUBRC. If no entry is found, the old value of <fs_main>-koart keeps in the variable.

I would recommend:

      clear <fs_main>-koart.
      "<fs_main>-koart = '?'.    "Alternative
      SELECT SINGLE koart FROM bseg
        INTO (<fs_main>-koart)
        WHERE buzei = 1
        AND belnr = <fs_main>-belnr.

or

      SELECT SINGLE koart FROM bseg
        INTO (<fs_main>-koart)
        WHERE buzei = 1
        AND belnr = <fs_main>-belnr.
      IF SY-SUBRC NE 0.
        clear <fs_main>-koart.
        "<fs_main>-koart = '?'.    "Alternative
        " or you may skip the output with NEXT
      ENDIF.

OTHER TIPS

You have line item (BUZEI) hard coded in your select. I suspect that is the cause of the repeated data.

Just a comment, I find it really weird you are not filtering by company and year. remember the same BELNR for a document this year won't be the same document next year. The same with companies.

Please be sure that is what you want your program to show. Because it may become a problem when the fiscal year change or new companies are added to the system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top