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: 

Display count of records in an ALV

Former Member
0 Kudos

I am very much new to ABAP, kindly help me in the following issue -

I want to display the count of records of values selected from selection screen in an ALV.

EX : I want to use select options to get CARRID from SFLIGHT table and display the count of values obtained for that CARRID in an ALV

CARRID : AA

No.of Records : 50

Please help me with the code in OOPS concepts...

Moderator Message: Unmarked as question due to its basic nature. Please try to search in SCN before posting.

Message was edited by: Kesavadas Thekkillath

8 REPLIES 8

FredericGirod
Active Contributor
0 Kudos

Hi,

one of the most common question

so, put a column "count" with "1" at each line

sum the line

and make a intermediate sum in the column CARRID

Fred

0 Kudos

Kindly help me with a sample code....with the exact fields. Please post the code snippet and which works......also the ALV display in OOPS concepts....

Former Member
0 Kudos

Hi,

Hope you have completed the rest of the report correctly. In the fieldcatalog of carrid add the following line.

ls_fieldcat-do_sum       = 'X'.

When you will add this parameter it show automatically show you the sum at the end.

If you face any issues, do let us know.

Regards

Purnand

0 Kudos

hi,

I have actually did all the select statements and got the records.....What i require is the count of the records.

From SFLIGHT table i want to fetch CARRID's in selection screen using SELECT-OPTIONS.

Then for these CARRID's i have obtained.......I want to display the no:of records available for each CARRID in an ALV.

ex : CARRID : AA,AZ,LH                                 *This in selection screen

    

AA - 30     * These should be shown in an ALV

AZ - 40

LH - 36

Kindly send me a code Snippet which works for this requirement.

Regards,

Hari

Former Member
0 Kudos

Hi Hari,

Are you asking the total number of records after fetching from the table.

This is what i understood from your question.If yes, you can use the "Describe table" statement to achieve the same.

Thanks.

0 Kudos

From SFLIGHT table i want to fetch CARRID's in selection screen using SELECT-OPTIONS.

Then for these CARRID's i have obtained.......I want to display the no:of records available for each CARRID in an ALV.

ex : CARRID : AA,AZ,LH                                 *This in selection screen

    

AA - 30     * These should be shown in an ALV

AZ - 40

LH - 36

Kindly send me a code Snippet which works for this requirement.

Regards,

Hari

0 Kudos

Hi hari,

After fetching all the records into an internal table, sort the internal table by "Carrid".

Loop at the internal table and by using if or while statement you can put some logic to count the records.

For example, if the records are in internal table IT, then loop at this and count the number of records according to carrid.

sort it by carrid.
   loop at it into wa.
     if wa-carrid = 'AA'.
       cnt_aa = cnt_aa + 1.
     elseif wa-carrid = 'AZ'.
      cnt_az = cnt_az + 1.
    endif.
   endloop.

The variables cnt_aa will hold the total number of records for carrid "AA" and variable cnt_az will hold for carrid "AZ.

This logic should work.

Hope this helps.

Thanks.

gurunathkumar_dadamu
Active Contributor
0 Kudos

Hi,

create the container and try the below code.

tables:mara.

data: g_alv1  TYPE REF TO cl_gui_alv_grid,
        c_cont1 TYPE REF TO cl_gui_custom_container.

data: it_fieldcat TYPE lvc_t_fcat ,
         ty_fieldcat TYPE lvc_s_fcat ,

         it_mara type table of mara,

        wa_mara like line of it_mara.

select-options:s_matnr for mara-matnr.

start-of-selection.

select * from mara into it_mara

                 where matnr in s_matnr.

CALL SCREEN 100.

*&---------------------------------------------------------------------*

*& Module pbo_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo_100 OUTPUT.
*set pf-status 'XXX'.
*set titlebar 'XXX'.
ENDMODULE. " PBO_100 OUTPUT

*&---------------------------------------------------------------------*
*& Module alv_100 OUTPUT
*&---------------------------------------------------------------------*

MODULE alv_100 OUTPUT.
*Check if there is no custom container in screen 100
  IF c_cont1 IS INITIAL.
*Creating object of container
    CREATE OBJECT c_cont1
     EXPORTING
       container_name = 'CCONT'.

*Creating object of alv
    CREATE OBJECT g_alv1
       EXPORTING
        i_parent = c_cont1.
  
    ENDIF.

data:lv_count type i.

*- count the total no of records going to display

describe the it_mara lines into lv_count.

*Displaying the ALV grid
    CALL METHOD c_alv1->set_table_for_first_display
      EXPORTING
        is_layout       = ty_lay1
      CHANGING
        it_outtab       = it_mara
        structure       = mara.

for more help check this linke http://scn.sap.com/thread/144338.

Regards,

Gurunath kumar D