cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between custom report and fbl3n data results

BRILIANTO
Newcomer
0 Kudos
304

left (ALV custom report result) right (fbl3n tcode result)

when matched there are hkont (GL/Account) & belnr (DcoumentNo) fields that do not appear in the ALV custom report, even though the query has pulled the others, what do you think is the reason? here is my code :

FORM fetch_data.

  " show data based on PERIOD or POSTING DATE
  IF p_period 'X'"Jika p_period is true

    SELECT bukrs belnr gjahr budat monat waers hwaer blart bldat
     INTO TABLE i_bkpf
     FROM bkpf AS a
     WHERE a~gjahr s_fiscyr " fiscal year
         AND bukrs '1000' " company code
         AND monat IN s_perio" period

  ELSE" Posting Date

    SELECT bukrs belnr gjahr budat monat waers hwaer blart bldat
      INTO TABLE i_bkpf
      FROM bkpf AS a
      WHERE a~gjahr s_fiscyr " fiscal year
          AND bukrs '1000' " company code
          AND budat BETWEEN s_date-low AND s_date-high" Posting date
  ENDIF.

  IF i_bkpf IS NOT INITIAL.

          " GET DATA FROM BSEG TABLE
      SELECT hkont bukrs belnr gjahr bschl lifnr ebeln wrbtr prctr aufnr
      INTO TABLE i_bseg
      FROM bseg
      FOR ALL ENTRIES IN i_bkpf
        WHERE gjahr i_bkpf-gjahr
          AND bukrs i_bkpf-bukrs
          AND belnr i_bkpf-belnr " Document Number
          AND hkont IN s_hkont.

    " GET VENDOR DATA
    IF i_bseg IS NOT INITIAL.

      SELECT lifnr name1 stras ort01 pstlz
      INTO TABLE i_lfnr
      FROM lfa1
      FOR ALL ENTRIES IN i_bseg
        WHERE lifnr i_bseg-lifnr.
    ENDIF.

    IF i_bseg IS NOT INITIAL.

      SELECT e~ebeln e~bedat e~lifnr f~matnr f~menge f~netpr
        INTO TABLE i_ekkp
         FROM ekko AS e
         LEFT JOIN ekpo AS f
         ON e~ebeln f~ebeln " Purchasing Document
      FOR ALL ENTRIES IN i_bseg
        WHERE lifnr i_bseg-lifnr
        AND e~ebeln i_bseg-ebeln.

    ENDIF.

    IF i_bseg IS NOT INITIAL.

      LOOP AT i_bkpf INTO ls_bkpf.
        LOOP AT i_bseg INTO ls_bseg WHERE bukrs ls_bkpf-bukrs AND gjahr ls_bkpf-gjahr AND belnr ls_bkpf-belnr.
          CLEAR ls_result.

          IF ls_bseg-wrbtr IS NOT INITIAL.

            ls_bseg-wrbtr ls_bseg-wrbtr * 100.

          ENDIF.

          IF ls_bseg-lifnr IS NOT INITIAL.
            READ TABLE i_lfnr INTO ls_lfnr WITH KEY lifnr ls_bseg-lifnr BINARY SEARCH.
            MOVE-CORRESPONDING ls_lfnr TO ls_result.
          ENDIF.

          IF ls_bseg-ebeln IS NOT INITIAL.
            READ TABLE i_ekkp INTO ls_ekkp WITH KEY ebeln ls_bseg-ebeln BINARY SEARCH.
            MOVE-CORRESPONDING ls_ekkp TO ls_result.
          ENDIF.

          IF sy-subrc EQ 0.
            MOVE-CORRESPONDING ls_bkpf TO ls_result.
            MOVE-CORRESPONDING ls_bseg TO ls_result.
            APPEND ls_result TO lt_result.
          ENDIF.

        ENDLOOP.
      ENDLOOP.
    ENDIF.

    IF p_sum_gl 'X'.
      PERFORM display_sum_gl.
    ENDIF.

    IF p_sum_vn 'X'.
      PERFORM display_sum_vn.
    ENDIF.

  ENDIF.

ENDFORM.                    "fetch_data
 


Accepted Solutions (0)

Answers (1)

Answers (1)

RaymondGiuseppi
Active Contributor
0 Kudos

Remove the check for sy-subrc before appending record

  • Better use i_bseg in an external loop, and replace the i_bkpf loop with a single READ TABLE

Also

  • Add buzei in the BSEG select to prevent FOR ALL ENTRIES to remove duplicate results
  • Remove the (ugly) wrbtr * 100, but add currency code bkpf-waers in displayed table, insure in field catalog to link code field with amount field
  • Define internal tables with a sorted type, so remove the explicit binary search