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

Former Member
0 Likes
696

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

5004 0005 2008 3421 WK4537 10

5004 0005 2008 3421 WK7444 30

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

ZUONR = TM0000 TM3421 TM3426

ZUONR = WK4537 WK7444.

Whereas coming to ZUONR TM THE HIGHEST IS TM3426

Whereas coming to ZUONR WK THE HIGHEST IS WK7444

need to compare with first 2 alphabets and add all the dmbtr values

the output should be as

BELNR BUKRS GJAHR HKONT ZUONR DMBTR

5004 0005 2008 3421 TM3426 134

5004 0005 2008 3421 WK7444 40

please help me how to WRITE CODE get the highest ZUONR field in output

please see my code below

if first 2 alphabets are same i am adding the DMBTR, how to get the highest ZUONR

LOOP AT gt_bseg.

gt_output-belnr = gt_bseg-belnr.

gt_output-zuonr+0(2) = gt_bseg-zuonr.

gt_output-dmbtr = gt_bseg-dmbtr.

gt_output-wrbtr = gt_bseg-wrbtr.

COLLECT gt_output.

CLEAR gt_output.

ENDLOOP.

now i am getting as THE followinG Missing the ZUONR value after the alphabets

BELNR BUKRS GJAHR HKONT ZUONR DMBTR

5004 0005 2008 3421 TM------- 134

5004 0005 2008 3421 WK -


40

5 REPLIES 5
Read only

Former Member
0 Likes
676
LOOP AT gt_bseg.

gt_output-belnr = gt_bseg-belnr.
gt_output-zuonr+0(2) = gt_bseg-zuonr.
gt_output-dmbtr = gt_bseg-dmbtr.
gt_output-wrbtr = gt_bseg-wrbtr.



COLLECT gt_output.
CLEAR gt_output.
ENDLOOP.

SORT gt_bseg by belnr zuonr descending.

loop at gt_output into gs_output.

read table gt_bseg into gs_bseg with key belnr = gs_output-belnr .

if sy-subrc = 0.

gs_output-zuonr = gs_bseg-zuonr.
modify gt_output from gs_output transporting zuonr.

endif.

endloop.
Read only

Former Member
0 Likes
676

Add one more field in gt_output to update complete value of ZUONR as DUMMY and another to put only first 2 characters of ZUONR.

Instead of collect do the SUM if ZUONR+0(2) exists in internal table gt_output else APPEND gt_output

LOOP AT gt_bseg.

v_dummy = gt_bseg-zuonr+(2).

read table gt_output with key dummy = v_dummy.

if sy-subrc = 0.

gt_output-dmbtr = gt_output-dmbtr + gt_bseg-dmbtr.

gt_output-wrbtr = gt_bseg-wrbtr.

else

append the required field to gt_output.

append gt_output.

endif.

ENDLOOP.

SORT gt_output on DUMMY DESCENDING.

delete adjacent duplicates from gt_output comparing DUMMY.

See if this works for you.

Edited by: Sunil Sawaikar on Apr 17, 2009 2:19 PM

Read only

Former Member
0 Likes
676

HI,

DATA l_char TYPE bseg-zuonr.
DATA l_index type sy-tabix.

LOOP AT gt_bseg.

gt_output-belnr = gt_bseg-belnr.
gt_output-dmbtr = gt_bseg-dmbtr.
gt_output-wrbtr = gt_bseg-wrbtr.

* gt_output-zuonr = gt_bseg-zuonr.

IF l_char(2) NE  gt_bseg-zuonr(2) AND NOT l_char is initial.
  l_index = sy-tabix.

  READ TABLE gt_ouput INTO l_output index l_index.
  l_output-zuonr = l_char 
  MODIFY gt_ouput from l_output transporting zuonr index l_index 
ENDIF.

COLLECT gt_output.
CLEAR gt_output.
l_char = gt_bseg-zuonr.

ENDLOOP.

Read only

0 Likes
676

hi avinash,

MODIFY gt_ouput from l_output transporting zuonr index l_index .

i am getting an error as No component exists with name INDEX,

COULD you please suggest does it requires any changes.

Read only

0 Likes
676

write as :

MODIFY gt_ouput INDEX l_index from l_output transporting zuonr .