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 count rows

Former Member
0 Likes
2,015

Hi,

I want to count records against each project no, below is my code

*&---------------------------------------------------------------------*
*& Report  /BWN0/PS_TABLE_ALLOC_DTL_RPT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  /BWN0/PS_TABLE_ALLOC_DTL_RPT.



*provide tables
**TABLES: MARA, MAKT, MARD.
*provide type-pools
TABLES:      ekpo, EKKO, proj, AFKO,PRPS.

TYPE-POOLS: SLIS.

*provide select-options
*SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
SELECT-OPTIONS: vPROJN FOR PRPS-PSPHI.
*PARAMETER: CURRDATE TYPE paedt.
*SELECT-OPTIONS: DOCNUM FOR ekpo-EBELN.
TYPES: BEGIN OF p_proj,
   PSPHI TYPE PRPS-PSPHI,
*  pspnr TYPE proj-pspnr,
   BEDID TYPE KBED-BEDID,
   POST1 TYPE PROJ-POST1,
   AZMAX TYPE KAKO-AZMAX,
   POSTU TYPE PROJ-POSTU,
*  KAPAR TYPE KAKO-KAPAR,
   END OF p_proj.

   DATA : vCount type int4. "for counting number of lines


   DATA: IT_PROJ TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
         WA_PROJ TYPE p_proj,
         VSNO TYPE INT4.
*provide data objects
DATA: V_REPID TYPE SY-REPID,
       WA_EKKO_FIELD TYPE SLIS_FIELDCAT_ALV,       "it is for field catalog
       WA_EKPO_FIELD TYPE SLIS_FIELDCAT_ALV,
       WA_PROJ_FIELD TYPE SLIS_FIELDCAT_ALV,
       WA_PRPS_FIELD TYPE SLIS_FIELDCAT_ALV,
*      WA_MARD_FIELD TYPE SLIS_FIELDCAT_ALV,

       WA_EKPO TYPE EKPO,
       WA_ekko TYPE ekko,
       WA_KAKO TYPE KAKO,
       WA_PRPS TYPE PRPS,
*      WA_MARD TYPE MARD,

       IT_ekpo_FIELD TYPE SLIS_T_FIELDCAT_ALV,
       IT_ekko_FIELD TYPE SLIS_T_FIELDCAT_ALV,
       IT_PROJ_FIELD TYPE SLIS_T_FIELDCAT_ALV,
       IT_PRPS_FIELD TYPE SLIS_T_FIELDCAT_ALV,
*      IT_MARD_FIELD TYPE SLIS_T_FIELDCAT_ALV,

       IT_ekpo TYPE TABLE OF ekpo,
       IT_ekko TYPE TABLE OF ekko,
       IT_KAKO TYPE TABLE OF KAKO,
       IT_PRPS TYPE TABLE OF PRPS,
*      IT_MARD TYPE TABLE OF MARD,

       V_LAYOUT TYPE SLIS_LAYOUT_ALV,

       IT_EVENTS TYPE SLIS_T_EVENT,            "it is for events
       IT_EVENTS1 TYPE SLIS_T_EVENT,            "it is for events
       WA_EVENTS TYPE SLIS_ALV_EVENT.

       V_REPID = SY-REPID.


*provide field catalog perform
PERFORM FIELD_CAT.
*call the initial function module
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
   EXPORTING
     I_CALLBACK_PROGRAM             = V_REPID
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =
           .
*provide perform for select the data
PERFORM SELECT_DATA.
*call mara append list

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
   EXPORTING
     IS_LAYOUT                        = V_LAYOUT
     IT_FIELDCAT                      = IT_PROJ_FIELD[]
     I_TABNAME                        = 'PROJ'
     IT_EVENTS                        = IT_EVENTS[]
*   IT_SORT                          =
*   I_TEXT                           = ' '
   TABLES
     T_OUTTAB                         = IT_PROJ
  EXCEPTIONS
    PROGRAM_ERROR                    = 1
    MAXIMUM_OF_APPENDS_REACHED       = 2
    OTHERS                           = 3.
*call makt append list
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
   EXPORTING
     IS_LAYOUT                        = V_LAYOUT
     IT_FIELDCAT                      = IT_EKPO_FIELD
     I_TABNAME                        = 'EKPO'
     IT_EVENTS                        = IT_EVENTS1[]
*   IT_SORT                          =
*   I_TEXT                           = ' '
   TABLES
     T_OUTTAB                         = IT_EKPO
  EXCEPTIONS
    PROGRAM_ERROR                    = 1
    MAXIMUM_OF_APPENDS_REACHED       = 2
    OTHERS                           = 3.
**call mard append list
*CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
*  EXPORTING
*    IS_LAYOUT                        = V_LAYOUT
*    IT_FIELDCAT                      = IT_MARD_FIELD
*    I_TABNAME                        = 'MARD'
*    IT_EVENTS                        = IT_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
*  TABLES
*    T_OUTTAB                         = IT_MARD
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3.
**display the data
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* EXCEPTIONS
*   PROGRAM_ERROR                 = 1
*   OTHERS                        = 2.
.

*&--------------------------------------------------------------------*
*&      Form  TOP_PAGE
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM TOP_PAGE.
WRITE:/ 'DOCUMENT HEADER INFORMATION' COLOR 6.
ENDFORM.                    "TOP_PAGE

FORM TOP_PAGE1.
WRITE:/ 'DETAIL INFORMATION' COLOR 5.
ENDFORM.                    "TOP_PAGE

FORM FIELD_CAT .

WA_PROJ_FIELD-COL_POS = 1.
WA_PROJ_FIELD-FIELDNAME = 'PSPHI'.
WA_PROJ_FIELD-REF_TABNAME = 'PRPS'.
APPEND WA_PROJ_FIELD TO IT_PROJ_FIELD.
CLEAR WA_PROJ_FIELD.

WA_PROJ_FIELD-COL_POS = 2.
WA_PROJ_FIELD-FIELDNAME = 'BEDID'.
WA_PROJ_FIELD-REF_TABNAME = 'KBED'.
APPEND WA_PROJ_FIELD TO IT_PROJ_FIELD.
CLEAR WA_PROJ_FIELD.


WA_PROJ_FIELD-COL_POS = 3.
WA_PROJ_FIELD-FIELDNAME = 'vCount'.
WA_PROJ_FIELD-seltext_m = 'Table'.
WA_PROJ_FIELD-REF_TABNAME = 'PROJ'.
APPEND WA_PROJ_FIELD TO IT_PROJ_FIELD.
CLEAR WA_PROJ_FIELD.

WA_PROJ_FIELD-COL_POS = 4.
WA_PROJ_FIELD-FIELDNAME = 'AZMAX'.
WA_PROJ_FIELD-REF_TABNAME = 'KAKO'.
APPEND WA_PROJ_FIELD TO IT_PROJ_FIELD.
CLEAR WA_PROJ_FIELD.

WA_PROJ_FIELD-COL_POS = 5.
WA_PROJ_FIELD-FIELDNAME = 'POSTU'.
WA_PROJ_FIELD-REF_TABNAME = 'PROJ'.
APPEND WA_PROJ_FIELD TO IT_PROJ_FIELD.
CLEAR WA_PROJ_FIELD.

WA_EKPO_FIELD-COL_POS = '1'.
WA_EKPO_FIELD-FIELDNAME = 'MATNR'.
WA_EKPO_FIELD-REF_TABNAME = 'EKPO'.
APPEND WA_EKPO_FIELD TO IT_EKPO_FIELD.
CLEAR WA_EKPO_FIELD.

WA_EKPO_FIELD-COL_POS = 2.
WA_EKPO_FIELD-FIELDNAME = 'MENGE'.
WA_EKPO_FIELD-REF_TABNAME = 'EKPO'.
APPEND WA_EKPO_FIELD TO IT_EKPO_FIELD.
CLEAR WA_EKPO_FIELD.

WA_EKPO_FIELD-COL_POS = 3.
WA_EKPO_FIELD-FIELDNAME = 'MEINS'.
WA_EKPO_FIELD-REF_TABNAME = 'EKPO'.
APPEND WA_EKPO_FIELD TO IT_EKPO_FIELD.
CLEAR WA_EKPO_FIELD.


WA_EVENTS-FORM = 'TOP_PAGE'.
WA_EVENTS-NAME = 'TOP_OF_PAGE'.
APPEND WA_EVENTS TO IT_EVENTS.
CLEAR WA_EVENTS.

WA_EVENTS-FORM = 'TOP_PAGE1'.
WA_EVENTS-NAME = 'TOP_OF_PAGE'.
APPEND WA_EVENTS TO IT_EVENTS1.

ENDFORM.                    " FIELD_CAT


*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SELECT_DATA .



SELECT *
   INTO CORRESPONDING FIELDS OF TABLE IT_PROJ
   FROM PROJ
   INNER JOIN PRPS ON PROJ~PSPNR = PRPS~PSPNR
   INNER JOIN AFPO ON AFPO~PROJN = PRPS~PSPNR
   INNER JOIN AFKO ON AFKO~AUFNR = AFPO~AUFNR
   INNER JOIN KBED ON KBED~BEDID = AFKO~BEDID
   INNER JOIN KAKO ON KAKO~KAPID = KBED~KAPID
   WHERE PRPS~PSPHI IN vPROJN.
* * AND KAKO-KAPAR = '001'.

select count(*) into vCount
  from proj.
*  WHERE
*  PRPS~PSPHI IN vPROJN.

ENDFORM.                    " SELECT_DATA

Moderator message : Not enough re-search before posting, discussion locked.

Message was edited by: Vinod Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,729

User abap statement  : Describe.


describe table <itab> lines <variable>.

here you get total number of lines into <variable>.


User abap statement  : Describe.


describe table <itab> lines <variable>.

here you get total number of lines into <variable>.


6 REPLIES 6
Read only

former_member193464
Contributor
0 Likes
1,729

use loop events to calculate the number of records for each proj. no . .something like

sort it_proj by  psphi.
loop at it_proj into wa_proj.

increase count by 1

at end of psphi.

total no. of records for psphi = count.
clear the count variable for next psphi.
endat
Endloop.

you can search scn for loop events explaination to learn in more detail..

Read only

0 Likes
1,729

hi,

thanks for your reply can you please guide me using my code how can i get record counts of a perticalar project no

Read only

0 Likes
1,729

i think if you search in community you will get it easily...
still,
if you want to do it for just one proj. no.
then  in your internal table...

sort it_proj by psphi.
Loop at it_proj onto wa_proj where psphi = ýour hardcoded project no.'.

count = count + 1.

Endloop.

after the loop you will get the number of records in count variable...
but if you want to calculate it for all...
define a table with two fields , proj no. and second field as no. of records...
and use 

loop at it_proj into wa_proj.

count = count + 1.

wa_new-psphi = wa_proj-psphi.

at end of psphi.

wa_new-count = count.append wa_new to gt_new.

append wa_new to gt_new.

clear: wa_new,count.

endat.
Endloop.

now your new table gt_new have all the project no. and their corresponding records.

if you are not clear on loop events , pls go through loop events there are many posts for loop events in community.

Read only

Former Member
0 Likes
1,730

User abap statement  : Describe.


describe table <itab> lines <variable>.

here you get total number of lines into <variable>.


Read only

0 Likes
1,729

Can you please give code solution using my code, it will be helpful for me

Regards

Read only

0 Likes
1,729

i am very much interested to help you.

here code sample. where you can incorporate into your code by applying simple logic.

1) take 1 integer variable for example cnt.

2) IT_PROJ is your internal table.

3) put a statement in (PAI)

    DESCRIBE TABLE IT_PROJ LINES cnt.

now you have total number of internal table line count into cnt variable.

_____________________________________________________________________

logic count for each project...

Data begin of projcnt occurs 0,

    projno like prps-pspnr,

        counter type i,

    end of projcnt.

loop at IT_PROJ.

at new it_proj-pspnr.

   projcnt-projno = it_proj-pspnr.

   clear cnt.

   append projcnt.

endat.

   cnt = cnt + 1.

   modify cnt.

endloop.

just understand the logic and apply by your own.

hope this helps.

Avirat

Message was edited by: Avirat Patel