Application Development 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: 

how to show detail report in alv

Former Member
0 Kudos

Hi all,

i need to do a alv report i have a huge data.

for example:-

ccode-ven_no-ctry-CUR-amt--

0001--123---USEUR-100--

0001--124---useur- 50--

0001--124---us-us-200--

0001--124---us-us-500--

0002--125---eur-aud---100--

0002--125---eur-cad----50--

0002--126---eur-cad---100--

0002--126---eurus- 50--

0002--126---eurcad-250-

0002--127---eurgbp-150-

0002--127---eurgbp- 50--

i have data like that but i want a alv report with above columns but not all the records to be displayed but only total amt and different vendor details according to company code and vendor details.

for example i want the above data to be displayed in this way.

ccode-ven_no-ctry-CUR-amt--

0001--123---useur-100--

-


124-----useur- 50--

-


124-----us-us-700--

0002--125---eur-aud---100--

-


125-----eurus-150--

-


126-----eur-cad---350--

-


127-----eurgbp-200-

kindly help me regarding this if possible with example.

thanks in advance,

regards,

venu.

1 ACCEPTED SOLUTION

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You can achieve this by COLLECT as Andreas suggested.

Here is the sample code.

types: BEGIN OF ty,

NAME(20),

SALES TYPE I,

END OF ty.

data : itab type standard table of ty,

itab1 type standard table of ty,

wa type ty,

wa1 type ty.

wa-NAME = 'Duck'. wa-SALES = 10.

append wa to itab.

wa-NAME = 'Tiger'. wa-SALES = 20.

append wa to itab.

wa-NAME = 'Duck'. wa-SALES = 30.

append wa to itab.

loop at itab into wa.

wa1 = wa.

collect wa1 into itab1.

endloop.

loop at itab1 into wa1.

write : / wa1-name , wa1-sales.

endloop.

For more details about collect,check this link.

http://www.geocities.com/SiliconValley/Campus/6345/collect.htm

If it is useful,reward points.Otherwise,get back.

8 REPLIES 8

andreas_mann3
Active Contributor
0 Kudos

Hi,

keyword is collect

-> you've to collect your itab:

pls make sure that your amount field has the correct sign and you can collect your itab

regards Andreas

Former Member
0 Kudos

Hi,

Maybe you could post your code here, as you need to be more specific so we can help. The use of collect will affect your coding if you are using numeric fields in your data as it will add the numeric fields together that belong to the same key. so that might not solve your problem.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You can achieve this by COLLECT as Andreas suggested.

Here is the sample code.

types: BEGIN OF ty,

NAME(20),

SALES TYPE I,

END OF ty.

data : itab type standard table of ty,

itab1 type standard table of ty,

wa type ty,

wa1 type ty.

wa-NAME = 'Duck'. wa-SALES = 10.

append wa to itab.

wa-NAME = 'Tiger'. wa-SALES = 20.

append wa to itab.

wa-NAME = 'Duck'. wa-SALES = 30.

append wa to itab.

loop at itab into wa.

wa1 = wa.

collect wa1 into itab1.

endloop.

loop at itab1 into wa1.

write : / wa1-name , wa1-sales.

endloop.

For more details about collect,check this link.

http://www.geocities.com/SiliconValley/Campus/6345/collect.htm

If it is useful,reward points.Otherwise,get back.

0 Kudos

hi jayanthi,

i want my report to be displayed like this

ccode-ven_no-ctry-CUR-amttot_ven-pay_by_vendor----


tot_pay

0001--123---useur---100--


1

0001--124---us-eur--- 50--


1

0001--124---us--us---700


2
2
--


4

0002--125---eur-aud-----100


1--


0002--125---eurcad


50
1
--


0002--126---eur--us


50--


1

0002--126---eurcad---350--


2

0002--127---eurgbp---200


2--


7

i hope u will understand wht is my requirement....

in simple words i want total no of payments made to each vendor with total amt and total payments made under each company code

here is my code......


report Y_TR_PAY9.

type-pools slis.
tables: lfa1,
         bsak,
         tcurr.




data: fieldcat type slis_t_fieldcat_alv.
data: sort     type slis_t_sortinfo_alv.

data : begin of wa occurs 0,
        bukrs type bsak-bukrs,
        lifnr type bsak-lifnr,
        land1 type lfa1-land1,
        name1 like lfa1-name1,
        augdt like bsak-augdt,
        waers like bsak-waers,
        dmbtr like bsak-dmbtr,
        ukurs like tcurr-ukurs,
        total type p decimals 2,
        vbund like bsak-vbund,
        augbl like bsak-augbl,
        belnr like bsak-belnr,
        blart like bsak-blart,
        bschl like bsak-bschl,
        tot_pay type i value 0,
        tot_invnr type i value 0,
        counter type i,
        count type i value 0,
        tot_vend  type i,
        vend type i.
data :end of wa.

*data : itab like table of wa.
*data: counter type i value 0.
data: count type i.
data :   temp_count type i value 0.
data :   temp_count1 type i value 0.
data :   temp_count2 type i value 0.
data :   temp_count3 type i value 0.
data :   temp_count4 type i value 0.

data : itab like table of wa.


SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME.

SELECT-OPTIONS : s_bukrs for wa-bukrs default '0002',
                 s_lifnr for wa-lifnr,
                 s_land  for wa-land1,
                 s_augdt for wa-augdt,
                 s_vbund for wa-vbund,
                 s_waers for wa-waers,
                 s_dmbtr for wa-dmbtr,
                 s_blart for wa-blart default 'KZ',
                 s_bschl for wa-bschl default '25'.

SELECTION-SCREEN END OF BLOCK A.


Start-of-selection.


*  perform get_data.
*    perform get_data1.


************************************************************************
***Get_Data
************************************************************************
*form get_data.

  select distinct bukrs lifnr waers from bsak into corresponding
fields
 of wa
          where bukrs in s_bukrs
          and   lifnr in s_lifnr
          and   augdt in s_augdt
          and   vbund in s_vbund
          and   blart in s_blart
          and   bschl in s_bschl.

    select single * from tcurr
                  where fcurr = 'EUR'
                  and   tcurr = wa-waers.

    wa-UKURS = tcurr-UKURS.

  select single * into corresponding fields of wa from lfa1
where lifnr eq wa-lifnr.



*perform total.


*form total.
*loop at itab into wa.
 CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
   EXPORTING
*    CLIENT                  = 001
    DATE                    = sy-datum
     FOREIGN_CURRENCY        = wa-WAERS
     LOCAL_CURRENCY          = TCURR-FCURR
     FOREIGN_AMOUNT          = wa-DMBTR
*    RATE                    = tcurr-ukurs
    TYPE_OF_RATE            = 'M'
*    READ_TCURR              = 'X'
  IMPORTING
    EXCHANGE_RATE           = tcurr-UKURS
*    FOREIGN_FACTOR          =
    LOCAL_AMOUNT            = wa-TOTAL
*    LOCAL_FACTOR            =
*    EXCHANGE_RATEX          =
*    FIXED_RATE              =
*    DERIVED_RATE_TYPE       =
*  EXCEPTIONS
*    NO_RATE_FOUND           = 1
*    OVERFLOW                = 2
*    NO_FACTORS_FOUND        = 3
*    NO_SPREAD_FOUND         = 4
*    DERIVED_2_TIMES         = 5
*    OTHERS                  = 6
           .
 IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

append wa to itab.
 endselect.


  loop at itab into wa.


    temp_count = temp_count + 1.

    at end of lifnr.
      wa-count = temp_count.
      modify itab from wa transporting count.
      clear temp_count.
    endat.

   temp_count4 = temp_count4 + 1.

    at end of augbl.
      wa-tot_pay = temp_count4.
      modify itab from wa transporting tot_pay.
      clear temp_count4.
    endat.



    at new lifnr.
      temp_count1 = temp_count1 + 1.
      wa-counter = temp_count1.
      MODIFY itab from wa transporting counter.
    endat.


    temp_count2 = temp_count2 + 1.

    at END OF bukrs.
      wa-tot_vend = temp_count2.
      modify itab from wa transporting  tot_vend.
      clear temp_count2.
    endat.



   at end of lifnr.
     temp_count3 = temp_count3 + 1.
     at end of bukrs.
     wa-vend = temp_count3.
     modify itab from wa transporting vend.
     clear temp_count3.
     endat.

    endat.



  endloop.



 perform write_report.

*endform.
ENDSELECT.

************************************************************************
*WRITE_REPORT
************************************************************************
form write_report.
  perform build_field_catalog.
  perform build_sort.
* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            it_fieldcat = fieldcat
            it_sort     = sort
       TABLES
            t_outtab    = itab.

endform.

************************************************************************
*BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat.
  refresh: fieldcat.
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'COMPANY CODE'.
  fc_tmp-fieldname  = 'BUKRS'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'VENDOR NUMBER'.
  fc_tmp-fieldname  = 'LIFNR'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'COUNTRY'.
  fc_tmp-fieldname  = 'LAND1'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'VENDOR NAME'.
  fc_tmp-fieldname  = 'NAME1'.
  fc_tmp-tabname   = 'itab'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'CLEARING DATE'.
  fc_tmp-fieldname  = 'AUGDT'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'CURRENCY'.
  fc_tmp-fieldname  = 'WAERS'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'TOTAL AMT'.
  fc_tmp-fieldname  = 'DMBTR'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'EXCHANGE RATE'.
  fc_tmp-fieldname  = 'UKURS'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'PAID IN EUROS'.
  fc_tmp-fieldname  = 'TOTAL'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-col_pos    = 2.
*fc_tmp-do_sum = 'X'.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'TRADING PARTNER'.
  fc_tmp-fieldname  = 'VBUND'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'CLEARING DOCU'.
  fc_tmp-fieldname  = 'AUGBL'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'INVOICE'.
  fc_tmp-fieldname  = 'BELNR'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'DOCUMENT TYPE'.
  fc_tmp-fieldname  = 'BLART'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'POSTINK KEY'.
  fc_tmp-fieldname  = 'BSCHL'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.



  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'INVOICES CLEARED FOR EACH PAYMENT'.
  fc_tmp-fieldname  = 'TOT_PAY'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
*fc_tmp-col_pos = 3.
*fc_tmp-do_sum = 'X'.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'NO OF PAYMENTS'.
  fc_tmp-fieldname  = 'COUNT'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'NO OF VENDORS'.
  fc_tmp-fieldname  = 'COUNTER'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

   clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'TOTAL PAYMENTS'.
  fc_tmp-fieldname  = 'TOT_VEND'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

   clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'VENDORS'.
  fc_tmp-fieldname  = 'VEND'.
  fc_tmp-tabname   = 'ITAB'.
  fc_tmp-outputlen  = '8'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.
ENDFORM.

************************************************************************
*     FORM build_sort
************************************************************************
form build_sort.
*data: tmp_sort type line of slis_t_sortinfo_alv.
*clear: sort. refresh: sort.
*clear tmp_sort.
*tmp_sort-fieldname = 'AUGBL'.
*tmp_sort-tabname   = 'WA'.
*tmp_sort-up        = 'X'.
*tmp_sort-subtot    = 'X'.
*append tmp_sort to sort.
*
**clear: sort. refresh: sort.
*clear tmp_sort.
*tmp_sort-fieldname = 'BLART'.
*tmp_sort-tabname   = 'WA'.
*tmp_sort-up        = 'X'.
*tmp_sort-subtot    = 'X'.
*append tmp_sort to sort.

endform.

kindly help me regarding this.

thanks in advance

regards,

venu.

0 Kudos

The information I gather from your first and last post, this is what you need to do :

a) Sort by company code

b) do_sum = 'x' for fields where you require total

c) subtot = 'x' for subtotal depending upon criteria. If you want subtotal per company code -> while adding the field company code in the sort table, also put subtot = 'X' for the same.

I am not sure about whether subtot works in REUSE_ALV_GRID_DISPLAY. In fact, there is Serdar's good tutorial on ALV, why don't you refer that ?

Here is the link

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an easy reference for alv grid control.pdf

Regards,

Subramanian V.

0 Kudos

hi subramanian,

thanks for replying me can u give me an example.

regards,

venu.

0 Kudos

Here is a sample program which shows how to do sorting.



report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.
data: sort     type slis_t_sortinfo_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      matkl type mara-matkl,
      labor type mara-labor,
      brgew type mara-brgew,
      maktx type makt-maktx,
      end of imara.

* Selection Screen
selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for imara-matnr .
selection-screen end of block b1.

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  select  mara~matnr mara~matkl mara~labor mara~brgew makt~maktx
            into corresponding fields of table imara
              from mara
               inner join makt
                 on mara~matnr = makt~matnr
                    where mara~matnr in s_matnr
                      and makt~spras = sy-langu.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  perform build_field_catalog.

  perform build_sort.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_sort     = sort
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Group'.
  fc_tmp-fieldname  = 'MATKL'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Sort Group'.
  fc_tmp-fieldname  = 'LABOR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Gross Weight'.
  fc_tmp-fieldname  = 'BRGEW'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-do_sum     = 'X'.
  fc_tmp-col_pos    = 4.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Description'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-col_pos    = 5.
  append fc_tmp to fieldcat.

endform.

************************************************************************
*       FORM build_sort                                                *
************************************************************************
form build_sort.

  data: tmp_sort type line of slis_t_sortinfo_alv.

  clear sort. refresh sort.

  clear tmp_sort.
  tmp_sort-fieldname = 'MATKL'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  append tmp_sort to sort.

  clear tmp_sort.
  tmp_sort-fieldname = 'LABOR'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  append tmp_sort to sort.

endform.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

thanks for replying me.

the code which u have given help me in sorting.

but in simple words

i want to display only details but not all the records of the vendor payment details.

i want to display total of all how much and in which currencies and wht amt has paid to these vendors and how many no of payments have made to each vendor.

i hope u have understand my requirement.

kindly help me regarding this.

thanks in advance,

regards,

venu.