Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

highest value in output

Former Member
0 Likes
481

hi all,

in the report i need to fetch the data based on BELNR BUKRS HKONT and ZUONR

For eg:

for a particular belnr

BELNR BUKRS GJAHR HKONT ZUONR DMBTR

5004 0005 2008 3421 TM0000 54

5004 0005 2008 3421 TM3421 60

5004 0005 2008 3421 TM3426 20

The output should display as only one line item with highest ZUONR and sum of the DMBTR as

BELNR BUKRS GJAHR HKONT ZUONR DMBTR

5004 0005 2008 3421 TM3426 134

please help me how to WRITE CODE get the highest ZUONR field in output and sum of the DMBTR FIELD.

MY code is , all the data is in gt_bseg.

LOOP AT GT_BSEG.

MOVE GT_BSEG-BUKRS TO GT_FINAL-BUKRS.

MOVE GT_BSEG-BELNR TO GT_FINAL-BELNR.

MOVE GT_BSEG-GJAHR TO GT_FINAL-GJAHR.

MOVE GT_BSEG-DMBTR TO GT_FINAL-DMBTR.

MOVE GT_BSEG-WRBTR TO GT_FINAL-WRBTR.

MOVE GT_BSEG-HKONT TO GT_FINAL-HKONT.

MOVE GT_BSEG-ZUONR TO GT_FINAL-ZUONR.

MOVE GT_BSEG-PSWSL TO GT_FINAL-PSWSL.

READ TABLE GT_BKPF WITH KEY BUKRS = GT_BSEG-BUKRS

BELNR = GT_BSEG-BELNR

GJAHR = GT_BSEG-GJAHR

BINARY SEARCH.

IF SY-SUBRC = 0.

MOVE GT_BKPF-BUDAT TO GT_FINAL-BUDAT.

MOVE GT_BKPF-BLART TO GT_FINAL-BLART.

MOVE GT_BKPF-BLDAT TO GT_FINAL-BLDAT.

ENDIF.

APPEND GT_FINAL.

CLEAR GT_FINAL.

ENDLOOP.

please help

3 REPLIES 3
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
463

LOOP AT GT_BSEG.

MOVE GT_BSEG-BUKRS TO GT_FINAL-BUKRS.

MOVE GT_BSEG-BELNR TO GT_FINAL-BELNR.

MOVE GT_BSEG-GJAHR TO GT_FINAL-GJAHR.

  • MOVE GT_BSEG-DMBTR TO GT_FINAL-DMBTR.

GT_FINAL-DMBTR = GT_BSEG-DMBTR + GT_FINAL-DMBTR.

MOVE GT_BSEG-WRBTR TO GT_FINAL-WRBTR.

MOVE GT_BSEG-HKONT TO GT_FINAL-HKONT.

MOVE GT_BSEG-ZUONR TO GT_FINAL-ZUONR.

MOVE GT_BSEG-PSWSL TO GT_FINAL-PSWSL.

READ TABLE GT_BKPF WITH KEY BUKRS = GT_BSEG-BUKRS

BELNR = GT_BSEG-BELNR

GJAHR = GT_BSEG-GJAHR

BINARY SEARCH.

IF SY-SUBRC = 0.

MOVE GT_BKPF-BUDAT TO GT_FINAL-BUDAT.

MOVE GT_BKPF-BLART TO GT_FINAL-BLART.

MOVE GT_BKPF-BLDAT TO GT_FINAL-BLDAT.

ENDIF.

APPEND GT_FINAL.

CLEAR GT_FINAL.

ENDLOOP.

Sort gt_final by ZUONR descending dmbtr descenfing .

In the first line you will get the highest ZUONR.

Read only

Former Member
0 Likes
463

Try these codes:

SORT GT_BSEG BY ZUONR DESCENDING.

LOOP AT GT_BSEG.
IF Sy-tabix = 1.
MOVE GT_BSEG to GT_FINAL.                      " First Row in the table will have Highest ZUONR
ENDIF.
GT_FINAL-DMBTR = GT_FINAL-DMBTR + GT_BSEG-DMBTR.      " Sum of all DMBTR.
ENDLOOP.

APPEND GT_FINAL.       " Update ROW

This will work.

Regards,

Gurpreet

Read only

Former Member
0 Likes
463

Hi,

Try this code..

SORT gt_bseg BY belnr bukrs gjahr hkont zuonr DESCENDING.
LOOP AT gt_bseg.
  AT NEW hkont.
    MOVE gt_bseg-bukrs TO gt_final-bukrs.
    MOVE gt_bseg-belnr TO gt_final-belnr.
    MOVE gt_bseg-gjahr TO gt_final-gjahr.
    MOVE gt_bseg-wrbtr TO gt_final-wrbtr.
    MOVE gt_bseg-hkont TO gt_final-hkont.
    MOVE gt_bseg-zuonr TO gt_final-zuonr.
    MOVE gt_bseg-pswsl TO gt_final-pswsl.
  ENDIF.

  gt_final-dmbtr = gt_final-dmbtr + gt_bseg-dmbtr.

  AT END OF  hkont.
    READ TABLE gt_bkpf WITH KEY bukrs = gt_bseg-bukrs
              belnr = gt_bseg-belnr
              gjahr = gt_bseg-gjahr
              BINARY SEARCH.
    IF sy-subrc = 0.
      MOVE gt_bkpf-budat TO gt_final-budat.
      MOVE gt_bkpf-blart TO gt_final-blart.
      MOVE gt_bkpf-bldat TO gt_final-bldat.
    ENDIF.
    APPEND gt_final.
    CLEAR gt_final.
  ENDIF.
ENDLOOP.