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

ALV - field count

Former Member
0 Likes
845

Hi experts,

I am having one requiment i am creating one alv report whre i am displyaing ALV grid. So i hav some fields such as org. unit, personal no, position and job id.

so my requiment is i am haivng no of organiztional units i which there are no of peronnal nos and thir postion and job id.

so after completing of each org. i need to count the no of personal no.( here peronal no shows no of persons in that org. unit) so i need to count and display the no of persons in that org unit before staring of the next org. unit. and also i need to show the job id. job id is comman for all in that org. unit.

i hv to show one row at the end of each org unti showing cout of no of person and the job id.

just look at the format i needed.

Org Unit Personnel No.POSITION Job ID

5000001 1 6000001 700001

5000001 2 6000001 700001

<b>............ 2..........................700001</b>

5000002 3 6000002 700002

5000002 44 6000002 700002

5000002 42 6000002 700002

5000002 40 6000002 700002

<b>............ 4..........................700002</b>

note: i need to show the count of persons only . I dont need the sum of perons.

Here 500001, and 500002 are org units. and after completing one org unit. in the same filed personnal no it is showing count of that field and also job id (700001).

How to do in ALv grid display?

<REMOVED BY MODERATOR>

regards,

sunil kairam

Edited by: sunil kairam on Feb 19, 2008 10:50 AM

Edited by: Alvaro Tejada Galindo on Mar 4, 2008 4:05 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
750

sort the table organization id

loop itab.

counter = counter + 1.

at end of <organization id>

write : count.

count = 0.

endat.

endloop

sort the table organization id

loop itab.

counter = counter + 1.

at end of <organization id>

write : count.

count = 0.

endat.

endloop

3 REPLIES 3
Read only

Former Member
0 Likes
751

sort the table organization id

loop itab.

counter = counter + 1.

at end of <organization id>

write : count.

count = 0.

endat.

endloop

Read only

Former Member
0 Likes
750

Sunil,

Follow the below code.

'Personnel No'--For there columns give your table field name.


DATA : w_fieldcat TYPE slis_fieldcat_alv,
       i_fieldcat TYPE slis_t_fieldcat_alv,
       gs_layout   TYPE slis_layout_alv,
       wa_sort1 TYPE slis_t_sortinfo_alv,
       wa_sort2 TYPE slis_sortinfo_alv.

  wa_sort2-spos = '01'.
  wa_sort2-up = 'X'.
  wa_sort2-fieldname = 'Org Unit'.--column name from 

  APPEND wa_sort2 TO wa_sort1.
  CLEAR wa_sort2.

  wa_sort2-spos = '02'.
  wa_sort2-up = 'X'.
  wa_sort2-subtot = 'X'.
  wa_sort2-fieldname = 'Personnel No'.

  APPEND wa_sort2 TO wa_sort1.
  CLEAR wa_sort2.

 wa_sort2-spos = '03'.
  wa_sort2-up = 'X'.
  wa_sort2-fieldname = 'POSITION Job ID'. 
  APPEND wa_sort2 TO wa_sort1.
  CLEAR wa_sort2.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
         EXPORTING
              i_callback_program       = ws_repid
              i_callback_pf_status_set = 'GUI_STAT1'
              i_callback_user_command  = 'STAT'
              is_layout                = gs_layout
              it_fieldcat              = i_fieldcat[]
              it_sort                  = wa_sort1
         TABLES
              t_outtab                 = i_zaw_pol_plan.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Mar 4, 2008 4:07 PM

Read only

Former Member
0 Likes
750

Hi check the below code

REPORT zmr_cpw NO STANDARD PAGE HEADING

LINE-SIZE 165

LINE-COUNT 65(2)

MESSAGE-ID zmm.

----


----


  • TABLE DECLARATION

**----


*tables

TABLES: aufk, "Order master data

afvc, "Operations within an order

ekko, "purchasing docs

resb, "reservation/dep requirements

bapiret2. "Return parameter

----


  • SELECT-OPTIONS *

----


----


  • PARAMETERS *

----


*selection parameters

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP.

PARAMETERS: p_werks LIKE resb-werks OBLIGATORY. "plant

SELECT-OPTIONS: s_matnr FOR resb-matnr, "material

s_lifnr FOR afvc-lifnr, "vendor

s_erdat FOR aufk-erdat. "start date

SELECTION-SCREEN SKIP.

SELECT-OPTIONS: s_reswk FOR ekko-reswk NO-DISPLAY

DEFAULT '1301' OPTION EQ SIGN I. "whse

SELECTION-SCREEN END OF BLOCK b01.

SELECTION-SCREEN SKIP.

*plant report selections

SELECTION-SCREEN ULINE /10(55).

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 12(17) text-s00

FOR FIELD p_obplt.

PARAMETERS: p_obplt RADIOBUTTON GROUP rept.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 20(17) text-s01

FOR FIELD p_ptven.

PARAMETERS: p_ptven AS CHECKBOX.

SELECTION-SCREEN COMMENT 44(17) text-s02

FOR FIELD p_ptplt.

PARAMETERS: p_ptplt AS CHECKBOX.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

*vendor report selection

SELECTION-SCREEN ULINE /10(55).

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 12(17) text-s03

FOR FIELD p_obven.

PARAMETERS: p_obven RADIOBUTTON GROUP rept.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

*ALV data

TYPE-POOLS slis. "ALV list viewer

DATA: gs_sett TYPE lvc_s_glay,

gs_title TYPE lvc_title,

gx_vari TYPE disvariant,

g_vari TYPE disvariant,

d_extfg(1) TYPE c.

DATA: p_fieldcat TYPE slis_t_fieldcat_alv, "list

t_fieldcat TYPE slis_t_fieldcat_alv, "popup

s_fieldcat TYPE slis_fieldcat_alv,

t_extab TYPE slis_t_extab, "funct exclude

t_extab_x TYPE slis_t_extab,

s_extab TYPE slis_extab,

p_programname LIKE sy-repid.

*----- Processing options -


SELECTION-SCREEN BEGIN OF BLOCK b02 WITH FRAME TITLE text-002.

SELECTION-SCREEN SKIP.

PARAMETERS:

p_varia LIKE gx_vari-variant . "Layout

SELECTION-SCREEN END OF BLOCK b02.

DATA: count(2) TYPE n,

header2 TYPE char100,

header3 TYPE char100,

header4 TYPE char100,

datch TYPE char10, "date character

datfr TYPE char10, "reformat date

datto TYPE char10, "reformat date

qfield TYPE char14,

afield TYPE char14,

qtfld TYPE char3 VALUE 'qty',

amfld TYPE char3 VALUE 'dmb',

name1 LIKE lfa1-lifnr.

*internal tables

*BAPI messages

DATA: BEGIN OF t_bapiret2 OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA: END OF t_bapiret2.

*-report data

DATA: BEGIN OF t_coredata OCCURS 0.

INCLUDE STRUCTURE zms_coredata.

DATA: flagd.

DATA: ebeln LIKE ekkn-ebeln.

DATA: END OF t_coredata.

DATA: t_coredata_x LIKE t_coredata OCCURS 0 WITH HEADER LINE.

*EKKO

DATA: BEGIN OF t_ekko OCCURS 0,

ebeln LIKE ekko-ebeln,

loekz LIKE ekko-loekz,

zzref LIKE ekko-zzref,

zzref_n LIKE ekko-ebeln,

flagd,

END OF t_ekko.

*-EKKN

DATA: BEGIN OF t_ekkn OCCURS 0,

ebeln LIKE ekkn-ebeln,

aufnr LIKE ekkn-aufnr,

END OF t_ekkn.

*-AUFK

DATA: BEGIN OF t_aufk OCCURS 0,

aufnr LIKE aufk-aufnr,

auart LIKE aufk-auart,

END OF t_aufk.

*descriptions

*-report

DATA: BEGIN OF t_report OCCURS 0,

codet LIKE dd03p-scrtext_m,

lifnr LIKE afvc-lifnr,

namel LIKE lfa1-name1,

aufnr LIKE mseg-aufnr,

auart LIKE aufk-auart,

aufnr_m LIKE mseg-aufnr,

auart_m LIKE aufk-auart,

erdat LIKE aufk-erdat,

matnr LIKE mseg-matnr,

maktx LIKE makt-maktx,

iloan LIKE zms_coredata-iloan,

tplnr LIKE zms_coredata-tplnr,

equnr LIKE zms_coredata-equnr,

eqktx LIKE zms_coredata-eqktx,

quans LIKE zms_coredata-quans,

sernr LIKE zms_coredata-sernr,

count TYPE i,

END OF t_report.

*-detail table

DATA: BEGIN OF t_detail_01 OCCURS 0,

aufnr LIKE mseg-aufnr,

aufnr_m LIKE mseg-aufnr,

ebeln LIKE ekko-ebeln,

matnr LIKE mseg-matnr,

END OF t_detail_01.

----


  • CONSTANTS DECLARATION *

----


CONSTANTS: c_yes TYPE char1 VALUE 'X',

c_nodesc TYPE name1 VALUE '**NO DESCRIPTION**',

c_pov LIKE zms_coredata-ocode VALUE 'POV',"Plant owes vendor

c_pop LIKE zms_coredata-ocode VALUE 'POP',"Plant owes plant

c_vop LIKE zms_coredata-ocode VALUE 'VOP',"Vendor owes plant

c_ub LIKE aufk-auart VALUE 'UB'.

----


  • HEADER *

----


TOP-OF-PAGE.

PERFORM top_of_page.

----


  • FOOTER *

----


  • INCLUDE zfooter.

----


  • END-OF-PAGE *

----


*END-OF-PAGE.

*PERFORM display_footer.

AT SELECTION-SCREEN.

*message if no reporting option is chosen for Owed by Plant

IF NOT p_obplt IS INITIAL.

IF p_ptven IS INITIAL

AND p_ptplt IS INITIAL.

MESSAGE e000(zmm) WITH text-m02.

ENDIF.

ENDIF.

----


----- At selection screen on value request for "Layout" -


----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varia.

PERFORM select_layout.

----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

*retrieve CORE data using BAPI

PERFORM get_core_data.

*build report table

PERFORM report_table.

END-OF-SELECTION.

----


  • LIST PROCESSING *

----


*write report

*-heading data

PERFORM heading_data.

PERFORM alv_list_viewer.

----


  • SUBROUTINES *

----


*forms

&----


*& Form get_CORE_DATA

&----


FORM get_core_data.

CALL FUNCTION 'ZMM_BAPI_GET_CORE_OWEAGE'

EXPORTING

bapi_plant = p_werks

TABLES

bapi_rangesmatnr = s_matnr

bapi_rangeslifnr = s_lifnr

bapi_rangesbldat = s_erdat

bapi_rangesreswk = s_reswk

coredata = t_coredata

return = t_bapiret2.

*Vendor owes Plant

IF NOT p_obven IS INITIAL.

DELETE t_coredata WHERE NOT ocode = c_vop.

EXIT.

ENDIF.

*Plant owes

IF NOT p_obplt IS INITIAL.

DELETE t_coredata WHERE ocode = c_vop.

ENDIF.

*Plant owes vendor

IF NOT p_ptven IS INITIAL.

t_coredata-flagd = c_yes.

MODIFY t_coredata TRANSPORTING flagd WHERE ocode = c_pov. "keep

ENDIF.

*Plant owes plant

IF NOT p_ptplt IS INITIAL.

t_coredata-flagd = c_yes.

MODIFY t_coredata TRANSPORTING flagd WHERE ocode = c_pop. "keep

ENDIF.

DELETE t_coredata WHERE flagd IS INITIAL.

*-get additional data

t_coredata_x[] = t_coredata[].

DELETE t_coredata_x WHERE NOT auart = c_ub. "STO

CHECK NOT t_coredata_x[] IS INITIAL.

LOOP AT t_coredata_x.

t_coredata_x-ebeln = t_coredata_x-aufnr.

MODIFY t_coredata_x TRANSPORTING ebeln.

ENDLOOP.

*-get CORE Stock Transport Orders for display

SELECT ebeln loekz zzref

INTO TABLE t_ekko

FROM ekko

WHERE reswk = p_werks.

DELETE t_ekko WHERE NOT loekz IS INITIAL.

DELETE t_ekko WHERE zzref IS INITIAL. "not create w/ref to STO

*reformat field

LOOP AT t_ekko.

t_ekko-zzref_n = t_ekko-zzref(10).

MODIFY t_ekko TRANSPORTING zzref_n.

ENDLOOP.

SORT t_ekko BY zzref_n.

*--Mine Maintenance Order

SELECT ebeln aufnr

INTO TABLE t_ekkn

FROM ekkn

FOR ALL ENTRIES IN t_coredata_x

WHERE ebeln = t_coredata_x-ebeln.

DELETE t_ekkn WHERE aufnr IS INITIAL.

CHECK NOT t_ekkn[] IS INITIAL.

*--Mine Maintenance Order Type

SELECT aufnr auart

INTO TABLE t_aufk

FROM aufk

FOR ALL ENTRIES IN t_ekkn

WHERE aufnr = t_ekkn-aufnr.

ENDFORM. " get_CORE_DATA

*

&----


*& Form report_table

&----


FORM report_table.

*create report table

SORT t_ekkn BY ebeln.

SORT t_aufk BY aufnr.

LOOP AT t_coredata.

CLEAR t_report.

MOVE-CORRESPONDING t_coredata TO t_report.

*Mine maint order

IF t_report-auart = c_ub.

READ TABLE t_ekkn WITH KEY ebeln = t_report-aufnr BINARY SEARCH.

IF sy-subrc = 0.

t_report-aufnr_m = t_ekkn-aufnr.

READ TABLE t_aufk WITH KEY aufnr = t_ekkn-aufnr BINARY SEARCH.

IF sy-subrc = 0.

t_report-auart_m = t_aufk-auart.

ENDIF.

ENDIF.

ENDIF.

CASE t_coredata-ocode.

WHEN c_pop.

t_report-codet = text-s02.

WHEN c_pov.

t_report-codet = text-s01.

WHEN c_vop.

t_report-codet = text-s03.

ENDCASE.

  • Add 1 to the count column to use with totaling

t_report-count = '1'.

APPEND t_report.

ENDLOOP.

ENDFORM. " report_table

&----


*& Form ALV_list_viewer

&----


FORM alv_list_viewer.

IF t_report[] IS INITIAL.

WRITE: text-m01.

ENDIF.

CHECK NOT t_report[] IS INITIAL.

SORT t_report BY lifnr matnr aufnr sernr.

PERFORM function_exclude. "this is for the popup view

  • Call ABAP List Viewer (ALV)

p_programname = sy-repid.

gx_vari-report = sy-repid.

gx_vari-username = sy-uname.

gx_vari-variant = p_varia.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = p_programname

i_internal_tabname = 'T_REPORT'

i_inclname = p_programname

CHANGING

ct_fieldcat = p_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

PERFORM field_catalog TABLES p_fieldcat.

gs_sett-top_p_only = 'X'.

CONCATENATE header3 header4 INTO gs_title SEPARATED BY space.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gx_vari-report

i_callback_top_of_page = 'TOP_OF_PAGE'

i_callback_user_command = 'USER_COMMAND'

i_grid_settings = gs_sett

i_structure_name = 'T_REPORT'

i_grid_title = gs_title

is_variant = gx_vari

i_save = 'A'

it_fieldcat = p_fieldcat[]

TABLES

t_outtab = t_report.

ENDFORM. " ALV_list_viewer

&----


*& Form field_catalog

&----


FORM field_catalog TABLES p_fieldcat TYPE slis_t_fieldcat_alv.

LOOP AT p_fieldcat INTO s_fieldcat.

CASE s_fieldcat-fieldname.

WHEN 'CODET'.

s_fieldcat-seltext_s = 'Oweage'.

s_fieldcat-seltext_m = 'Oweage'.

s_fieldcat-seltext_l = 'Oweage'.

s_fieldcat-reptext_ddic = 'Oweage'.

WHEN 'NAMEL'.

s_fieldcat-seltext_s = 'Name'.

s_fieldcat-seltext_m = 'Name'.

s_fieldcat-seltext_l = 'Name'.

s_fieldcat-reptext_ddic = 'Name'.

WHEN 'AUFNR_M'.

s_fieldcat-seltext_s = 'MineOrd'.

s_fieldcat-seltext_m = 'Mine Order'.

s_fieldcat-seltext_l = 'Mine Maint Order'.

s_fieldcat-reptext_ddic = 'Mine Order'.

WHEN 'AUART_M'.

s_fieldcat-seltext_s = 'MineOrdTyp'.

s_fieldcat-seltext_m = 'Mine Order Type'.

s_fieldcat-seltext_l = 'Mine Maint Order Type'.

s_fieldcat-reptext_ddic = 'Mine Order Type'.

WHEN 'EBELN'.

s_fieldcat-seltext_s = 'CORE STO'.

s_fieldcat-seltext_m = 'CORE STO'.

s_fieldcat-seltext_l = 'CORE Stock Transport Order'.

s_fieldcat-reptext_ddic = 'CORE STO'.

s_fieldcat-key = ' '.

WHEN 'COUNT'.

s_fieldcat-seltext_s = 'COUNT'.

s_fieldcat-seltext_m = 'COUNT'.

s_fieldcat-seltext_l = 'COUNT'.

s_fieldcat-reptext_ddic = 'COUNT'.

s_fieldcat-key = ' '.

ENDCASE.

MODIFY p_fieldcat FROM s_fieldcat.

ENDLOOP.

ENDFORM. " field_catalog

&----


*& Form heading_data

&----


FORM heading_data.

*-heading data

header2 = text-h01.

*-format date range

IF s_erdat[] IS INITIAL.

SORT t_report BY erdat.

READ TABLE t_report INDEX 1.

s_erdat-low = t_report-erdat.

SORT t_report BY erdat DESCENDING.

READ TABLE t_report INDEX 1.

s_erdat-high = t_report-erdat.

APPEND s_erdat.

ENDIF.

READ TABLE s_erdat INDEX 1.

WRITE s_erdat-low TO datfr.

WRITE s_erdat-high TO datto.

CONCATENATE datfr 'to' datto

INTO header3 SEPARATED BY space.

*plant

READ TABLE t_coredata INDEX 1.

CONCATENATE p_werks t_coredata-namew

INTO header4 SEPARATED BY space.

ENDFORM. " heading_data

&----


*& Form top_of_page

&----


FORM top_of_page.

CALL FUNCTION 'Z_REPORT_HEADER'

EXPORTING

header2 = header2

header3 = header3

header4 = header4.

ENDFORM. " top_of_page

&----


*& Form user_command

&----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

*F2

CHECK r_ucomm = '&IC1'.

*field deterimines further action

CASE rs_selfield-sel_tab_field.

WHEN 'T_REPORT-AUFNR'. "if STO - display CORE STO

READ TABLE t_report INDEX rs_selfield-tabindex.

CHECK t_report-auart = c_ub."only if order is STO

REFRESH t_detail_01.

LOOP AT t_ekko

WHERE zzref_n = t_report-aufnr.

t_detail_01-aufnr = t_report-aufnr.

t_detail_01-aufnr_m = t_report-aufnr_m.

t_detail_01-ebeln = t_ekko-ebeln.

t_detail_01-matnr = t_report-matnr.

APPEND t_detail_01.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = p_programname

i_internal_tabname = 'T_DETAIL_01'

i_inclname = p_programname

CHANGING

ct_fieldcat = t_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

PERFORM field_catalog TABLES t_fieldcat.

t_extab_x[] = t_extab[].

*these are the FCodes to keep on the popup screen

DELETE t_extab_x WHERE fcode = '&AC1'. "cancel

DELETE t_extab_x WHERE fcode = '%SC'. "find

DELETE t_extab_x WHERE fcode = '%SC+'. "repeat find

DELETE t_extab_x WHERE fcode = '&OUP'. "sort asc

DELETE t_extab_x WHERE fcode = '&ODN'. "sort desc

SORT t_detail_01 BY ebeln.

CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

EXPORTING

i_title = text-h02

i_tabname = 'T_DETAIL_01'

it_fieldcat = t_fieldcat[]

it_excluding = t_extab_x

TABLES

t_outtab = t_detail_01.

ENDCASE.

ENDFORM. " user_command

&----


*& Form function_exclude

&----


FORM function_exclude.

*this form excludes all functions on popup screen

*delete entries that should appear on the popup from this table prior to

*REUSE_ALV_POPUP_TO_SELECT

s_extab-fcode = '&ONT'. "copy/enter

APPEND s_extab TO t_extab.

s_extab-fcode = '&ETA'. "detail

APPEND s_extab TO t_extab.

s_extab-fcode = '%SC'. "find

APPEND s_extab TO t_extab.

s_extab-fcode = '%SC+'. "find next

APPEND s_extab TO t_extab.

s_extab-fcode = '&OUP'. "sort asc

APPEND s_extab TO t_extab.

s_extab-fcode = '&ODN'. "sort desc

APPEND s_extab TO t_extab.

s_extab-fcode = '&ILT'. "filter

APPEND s_extab TO t_extab.

s_extab-fcode = '&OL0'. "display variant

APPEND s_extab TO t_extab.

s_extab-fcode = '&CRB'. "H scroll-1st

APPEND s_extab TO t_extab.

s_extab-fcode = '&CRL'. "H scroll-prev

APPEND s_extab TO t_extab.

s_extab-fcode = '&CRR'. "H scroll-next

APPEND s_extab TO t_extab.

s_extab-fcode = '&CRE'. "H scroll-last

APPEND s_extab TO t_extab.

s_extab-fcode = '&AC1'. "Cancel

APPEND s_extab TO t_extab.

s_extab-fcode = '&ALL'. "select all

APPEND s_extab TO t_extab.

s_extab-fcode = '&SAL'. "deselect all

APPEND s_extab TO t_extab.

ENDFORM. " function_exclude