cancel
Showing results for 
Search instead for 
Did you mean: 

AMDP Duplicate Entries

0 Kudos
2,531

Hello,

I am Trying to create simple AMDP class for MARA and MARC Table..

i am getting duplicate entries in it.

below is my code:

AMDP Class

CLASS zcl_material_list DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
  PUBLIC SECTION.
  INTERFACES if_amdp_marker_hdb.
  TYPES:BEGIN OF ty_s_mara,
        mandt type mandt,
        matnr TYPE matnr,
        MTART type MTART,
        MATKL type MATKL,
        MEINS type MEINS,
        werks TYPE werks_d,
        END OF ty_S_mara.
types: tt_mara TYPE STANDARD TABLE OF ty_s_mara.
  methods material_list
    importing
      VALUE(ip_werks) TYPE werks_d
      value(ip_mandt) type mandt
      VALUE(ip_filters) TYPE string " PARAMETER for the SELECT OPTION String
    exporting
       value(et_material) type tt_mara.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
CLASS zcl_material_list IMPLEMENTATION.
METHOD material_list BY DATABASE PROCEDURE
                     FOR HDB
                     LANGUAGE SQLSCRIPT
                     options READ-ONLY
                     using mara marc.
et_material = select mara.mandt,
                     mara.matnr,
                     mara.mtart,
                     mara.matkl,
                     mara.meins,
                     marc.werks
                FROM mara as mara
                inner join marc as marc
                    on mara.matnr = marc.matnr
                    WHERE marc.werks = ip_werks
                      and mara.mandt = ip_mandt;
*               where mara.matnr = ip_matnr;
 et_material = APPLY_FILTER(:et_material, :ip_filters );
ENDMETHOD.
ENDCLASS.

Report To call AMDP Class

REPORT zr_amdp_select_option.
TABLES: mara.
PARAMETERS:p_werks TYPE werks_d.
SELECT-OPTIONS:s_matnr FOR mara-matnr.
**In line declaration for AMDP CLass instance
DATA(it_data) = NEW zCl_material_list( ).
DATA : LR_ALV TYPE REF TO CL_SALV_TABLE.
*********Data fetching*******************
* Build where clause for data fetching
* Class-Method to convert the select options to a dynamic where clause which
* will be passed to the AMDP for data filteration after data selection


data(lv_where) = cl_shdb_seltab=>combine_seltabs(
it_named_seltabs = VALUE #(
( name = 'MATNR' dref = REF #( s_matnr[] ) )
) ).
********Atlernate method******************

*cl_shdb_seltab=>combine_seltabs(
*EXPORTING
*  it_named_seltabs = VALUE #(
*  ( name = 'MATNR' dref = REF #( S_MATNR[] ) )
*  )
*  RECEIVING
*rv_where = DATA(lv_where) ).

******Calling AMDP Method to get data***********
call METHOD it_data->material_list
EXPORTING
  ip_filters = lv_where
  ip_werks = p_werks
  ip_mandt = sy-mandt
IMPORTING
  et_material = data(it_matnr).
*  TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY "get SALV factory instance
*    EXPORTING
*      LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*      R_CONTAINER    =
*      CONTAINER_NAME =
IMPORTING
  R_SALV_TABLE = LR_ALV
CHANGING
  T_TABLE      = it_matnr.
*   CATCH CX_SALV_MSG .
*  ENDTRY.
LR_ALV->display( ).


OutPut
client matnr           Mattyp  mat grp  uom     plant   
120	100006287	ZPKG	320	NOS	MF01
120	100006287	ZPKG	320	NOS	MF01
120	100006289	ZPKG	320	NOS	MF01
120	100006289	ZPKG	320	NOS	MF01


Entries are repeating...

Regards,

Aditya Vora

View Entire Topic
pfefferf
Active Contributor
0 Kudos

In case you have different clients and data for that different clients, the reason can be the mission comparison for the client in the join condition.

...
on mara.mandt = marc.mand
and mara.matnr = marc.matnr
...

Regards,
Florian

Hi Florian Pfeffer

Thanks a lot!! it worked.

Regards,

Aditya vora