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

How to Insert Max. Rate

former_member381412
Participant
0 Likes
4,015

Hello SAP Guru,

I have developed a ZREPORT in material price list. my report is working fine..!!

i want to show only max. Rate per kg. in my report

Like that: i have enter a input parameter material code, invoice date 01.04.2014 to 21.08.2014 And sales organization then shows only one highest rate per kg. How to do .

Please check my code and give me idea or correct my code..!! Please find a attached screenshot and code also..!!

Thanks in Advance

Richa

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,983

Hi,

FORM DISPLAY_DATA .

    SORT ITAB BY MATNR KBETR DESCENDING.  " You may add other columns if required like

                                                                               customer sales organisation etc.

     DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR.


   SORT ITAB BY VBELN MATNR.
   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       I_CALLBACK_PROGRAM      = REPNAME
       I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
       IS_LAYOUT               = LAYOUT
       IT_FIELDCAT             = FIELDTAB[]
       I_SAVE                  = G_SAVE
       IS_VARIANT              = G_VARIANT
       IT_EVENTS               = EVENTS[]
       IS_PRINT                = ALV_PRINT
     TABLES
       T_OUTTAB                = ITAB
     EXCEPTIONS
       PROGRAM_ERROR           = 1
       OTHERS                  = 2.


Regards

17 REPLIES 17
Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
3,983

Hello Richa,

Sort internal table by materal and rate per kg.

delete adjacent duplicates


FORM DISPLAY_DATA .

*sort itab by material
  sort itab by matnr kbetr descending.
  delete adjacent duplicates from itab comparing matnr .

*
  SORT ITAB BY VBELN MATNR.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      = REPNAME
      I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
      IS_LAYOUT              = LAYOUT
      IT_FIELDCAT            = FIELDTAB[]
      I_SAVE                  = G_SAVE
      IS_VARIANT              = G_VARIANT
      IT_EVENTS              = EVENTS[]
      IS_PRINT                = ALV_PRINT
    TABLES
      T_OUTTAB                = ITAB
    EXCEPTIONS
      PROGRAM_ERROR          = 1
      OTHERS                  = 2.

*  loop at itab.
*    select SINGLE name1 into itab-name1
*            from kna1
*            WHERE kunnr = itab-kunag.
*
*    write:/ itab-vbeln, itab-kunag, itab-name1, itab-fkdat, itab-fkart,  itab-kbetr,itab-kwert, ITAB-ZJEXP,itab-ZJECS,itab-ZJHSC,
*            itab-mwsbk, itab-netwr.
*  endloop.
ENDFORM.     

Thanks 

Read only

0 Likes
3,983

Dear Learner,

Thanks for the reply.!!

Please Correct my code and reply if its' possible..!!

Because i wil try max. time but i am not success..!

Read only

Former Member
0 Likes
3,983

Hi,

If yo are fetching rate from table you can use MAX statement in your query or els you can manage inside loop.

Please provide some more details and let us know where exactly you need help.

Regards,

Lingaraj


Read only

0 Likes
3,983

Dear Lingaraj,

Thank for the reply..!!

I have already attached a code and screen shot .!!

As per my requirement i want to show only Max. Rate per kg.in Billing Level.

EXP.

DATE                            Material                Rate

15.07.2014                     12345                   155

19.08,2014                     12345                   160

19.08.2014                     12345                   135

20.08.2014                     12345                   150

I want to output  only

19.08,2014                     12345                   160

Thanks in Advance

Richa

Read only

former_member202771
Contributor
0 Likes
3,983

Hi Richa,

SORT output_table DESCENDING BY rate.

Read output_table index 1.

Thanks,

Anil

Read only

0 Likes
3,983

Dear Anil,

Thanks for the Reply..!!

Please check my code and give me correct code if it's possible..!!

Richa

Read only

0 Likes
3,983

Hi Richa,

DATA : Itab1 type table of ITAB,

           lwa_tab type itab.

SORT itab DESCENDING BY netwr.


Read itab into lwa_tab index 1.


append lwa_tab to itab1.


In CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' ,

Instead of ITAB, pass ITAB1.


Thanks,

Anil

Read only

0 Likes
3,983

Hi Richa,

Just sorting the internal table and deleting the adjacent duplicates will solve your problem. You need to do this just before you display your ALV.

But, the reply suggested by Anil will fetch you only one entry.For multiple material selection, it will not work.

Refer to the code given by Always Learner in his reply. That will give you the required solution.

Read only

Former Member
0 Likes
3,983


Hi Richa,

Since you are summing up the rate values for some other calculation, fetching data using MAX function in the SELECT statement may not get you the desired results.

The best way is to sort and delete the adjacent duplicates.

SORT itab BY matnr ASCENDING kbetr DESCENDING.

DELETE ADJACENT DUPLICATES FROM itab COMPARING matnr.

Read only

VenkatRamesh_V
Active Contributor
0 Likes
3,983

Hi Richa,

Try,

Sort itab by vbeln posnr  kbetr descending.

Delete Adjacent duplicates from itab comparing vbeln posnr  kbetr.

Regards,

Venkat.

Read only

Former Member
0 Likes
3,984

Hi,

FORM DISPLAY_DATA .

    SORT ITAB BY MATNR KBETR DESCENDING.  " You may add other columns if required like

                                                                               customer sales organisation etc.

     DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR.


   SORT ITAB BY VBELN MATNR.
   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       I_CALLBACK_PROGRAM      = REPNAME
       I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
       IS_LAYOUT               = LAYOUT
       IT_FIELDCAT             = FIELDTAB[]
       I_SAVE                  = G_SAVE
       IS_VARIANT              = G_VARIANT
       IT_EVENTS               = EVENTS[]
       IS_PRINT                = ALV_PRINT
     TABLES
       T_OUTTAB                = ITAB
     EXCEPTIONS
       PROGRAM_ERROR           = 1
       OTHERS                  = 2.


Regards

Read only

0 Likes
3,983

Hi,

Sort ITAB by matnr kbetr DESCENDING.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR.

Rgds,

Vaikunt

Read only

0 Likes
3,983

Dear Somendra,

This condition is working fine.!

If i am try to Material Number Low to Material Number High then Price condition is not working

Exp.

Material no. Low                   Material no. High

Read only

0 Likes
3,983

Hi,

     ????

     In abap code where you are giving these low and high values,Not getting correctly,

     Although price is getting by knumv and kposnr.

Read only

0 Likes
3,983

Dear  Somendra

Enter a input parameter

Material Number           12345 to   12347

date                          19.08.2014 to 21.08.2014

then i want to show 12345 Max. Rate and 12347 Max Rate

Now Enter this input showing all material Max. Rate

Read only

0 Likes
3,983

Hi,

     If I Understand then you want only the values for material-low and material-high and skip all the values for material lies in between low and high.

So Add a clause no interval in selection screen

SELECTION-SCREEN BEGIN OF BLOCK DOCDATA WITH FRAME TITLE TEXT-DOC.
SELECT-OPTIONSMATNR FOR VBRP-MATNR  no INTERVALS,


Regards

Read only

0 Likes
3,983

Dear Somendra,

As per my requirement i want to insert one other field and insert Current Bill Rate

Please check my screen shot..!!

Rate per KG. is Max. Rate but As per my requirement Current Rate is Latest Bill Rate

Richa