Aller au contenu

Compter les lignes

Source :

https://www.sapforbeginners.com/blog/how-to-count-entries-of-a-particular-group-in-an-internal-table/

Ça marche nickel code que je connaissais pas

MON CODE modifié :

*---------------------------------------------------------------------*
* Report Z_PAVAN_TEST
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*

TYPES:
BEGIN OFty_material,
matnrTYPE char40,
maktxTYPE char40,
matklTYPE char9,
END OFty_material.
DATA:lt_materialsTYPE STANDARD TABLE OFty_material.

DATAit_213TYPE TABLE OF/bic/b0000213000.

SELECT*INTOTABLEit_213FROM/bic/b0000213000.

* Simply get the unique material groups, use WITHOUT MEMBERS*

LOOP AT it_213INTODATA(s_213) 
    GROUPBY  (matnr=s_213-matnrsize=GROUPSIZE) 
    ASCENDING 
    WITHOUTMEMBERS REFERENCE INTODATA(s213_group).

    WRITE:/s213_group->matnr,s213_group->size.

ENDLOOP.

Le code original il crée les données de la table interne à la main

*---------------------------------------------------------------------*
* Report Z_PAVAN_TEST
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*

REPORT z_pavan_test.

TYPES:
BEGIN OF ty_material,
        matnr TYPE char40,
        maktx     TYPE char40,
        matkl     TYPE char9,
END   OF ty_material.

DATA: lt_materials TYPE STANDARD TABLE OF ty_material.

lt_materials = VALUE #(
( matnr = '000000000051000298' maktx = 'Description 1' matkl = 'A' )
( matnr = '000000000051003780' maktx = 'Description 2'      matkl = 'A'  )
( matnr = '000000000051008389' maktx = 'Description 3' matkl =  'B')
( matnr = '000000000051008390' maktx = 'Description 4' matkl = 'C'  )
( matnr = '000000000051008394' maktx = 'Description 5' matkl = 'B' ) ).

* Simply get the unique material groups, use WITHOUT MEMBERS
LOOP AT lt_materials INTO DATA(ls_materials)

GROUP BY  ( matkl = ls_materials-matkl size = GROUP SIZE )

ASCENDING

WITHOUT MEMBERS

REFERENCE INTO DATA(matkl_group).

WRITE: / matkl_group->matkl, matkl_group->size.

ENDLOOP.