Skip to Content
0
Former Member
Mar 11, 2013 at 07:10 AM

Problem in ALV Report

54 Views

Dear All,

I had Create One AlV Report Which is related to Daily Production Report with Serial NO. IN THis Report Serial no. are not coming correctly.

because in Table OBJK and SER03 reference field is MBLNR are Duplicate. and in MSEG Table MBLNR are not DUplicate. Code are Below Shown. pl resove my Issue. Thanks in Advance.

*&---------------------------------------------------------------------*
*& Report ZDAILY_PRD_RPT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDAILY_PRD_RPT.

TABLES: mseg,mkpf,objk,mara.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES : BEGIN OF ty_mseg,
MBLNR TYPE mseg-MBLNR,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
lgort TYPE mseg-lgort,
bwart TYPE mseg-bwart,
zeile TYPE mseg-zeile,
erfmg TYPE mseg-erfmg,
aufnr TYPE mseg-aufnr,
EQUNR TYPE mseg-EQUNR,

END OF ty_mseg.
TYPES : BEGIN OF ty_mkpf,
MBLNR TYPE mkpf-MBLNR,
CPUDT TYPE mkpf-CPUDT,
END OF ty_mkpf.
TYPES : BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.
TYPES : BEGIN OF ty_objk,
matnr TYPE objk-matnr,
sernr TYPE objk-sernr,
obknr TYPE objk-obknr,
END OF ty_objk.
TYPES : BEGIN OF ty_mara,
matnr TYPE mara-matnr,
matkl TYPE mara-matkl,
END OF ty_mara.
TYPES : BEGIN OF ty_sernr,
datum TYPE ser03-datum,
mblnr TYPE mblnr,
mjahr TYPE mjahr,
zeile TYPE MSEG-zeile,
werk TYPE ser03-werk,
lagerort TYPE ser03-lagerort,
bwart TYPE bwart,
sernr TYPE sernr,
matnr TYPE matnr,
* werks TYPE werks,
* lgort TYPE lgort,
* bwart TYPE bwart,
* erfmg TYPE erfmg,
* aufnr TYPE aufnr,
END OF ty_sernr.

TYPES : BEGIN OF ty_ser03,
MBLNR TYPE ser03-MBLNR,
datum TYPE ser03-datum,
obknr TYPE ser03-obknr,
END OF ty_ser03.


TYPES : BEGIN OF ty_final,
datum TYPE ser03-datum,
MBLNR TYPE mseg-MBLNR,
matnr TYPE mseg-matnr,
maktx TYPE makt-maktx,
matkl TYPE mara-matkl,
sernr TYPE objk-sernr,
bwart TYPE mseg-bwart,
CPUDT TYPE mkpf-CPUDT,
LAGERORT TYPE ser03-LAGERORT,
werk TYPE ser03-werk,
zeile TYPE mseg-zeile,
erfmg TYPE mseg-erfmg,
""aufnr TYPE mseg-aufnr,
END OF ty_final.

TYPES : BEGIN OF ty_join,
mblnr TYPE ser03-mblnr,
mjahr TYPE ser03-mjahr,
datum TYPE ser03-datum,
zeile TYPE ser03-zeile,
werk TYPE ser03-werk,
lagerort TYPE ser03-lagerort,
matnr TYPE mseg-matnr,
bwart TYPE mseg-bwart,
erfmg TYPE mseg-erfmg,
aufnr TYPE mseg-aufnr,
sernr TYPE objk-sernr,
obknr TYPE objk-obknr,
maktx TYPE makt-maktx,
matkl TYPE mara-matkl,
END OF ty_join.

DATA : it_join TYPE STANDARD TABLE OF ty_join,
wa_join TYPE ty_join.




data : it_mseg TYPE STANDARD TABLE OF ty_MSEG,
wa_MSEG TYPE ty_mseg,
it_mkpf TYPE STANDARD TABLE OF ty_mkpf,
wa_mkpf TYPE ty_mkpf,
it_makt TYPE STANDARD TABLE OF ty_makt,
wa_makt TYPE ty_makt,
it_objk TYPE STANDARD TABLE OF ty_objk,
wa_objk TYPE ty_objk,
it_mara TYPE STANDARD TABLE OF ty_mara,
wa_mara TYPE ty_mara,
it_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final,
it_sernr TYPE TABLE OF ty_sernr,
wa_sernr TYPE ty_sernr,
it_ser03 TYPE STANDARD TABLE OF ty_ser03,
wa_ser03 TYPE ty_ser03.
*
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv,
wa_event TYPE slis_alv_event.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

BREAK 10115.
perform data_retrieval.
* if it_final[] IS INITIAL.
* MESSAGE 'Data is not found' TYPE 'I'.
* LEAVE LIST-PROCESSING.
* ENDIF.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.

*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001 .
* SELECT-OPTIONS s_purch for ekbe-ebeln. ""Purchase Document
SELECT-OPTIONS S_DAT FOR mkpf-CPUDT OBLIGATORY. "Posting Date
SELECT-OPTIONS s_mat for mseg-matnr. "Material
SELECT-OPTIONS s_mgrp FOR mara-matkl.
SELECT-OPTIONS s_code for mseg-werks DEFAULT 'TA02'. ""Plant
* SELECT-OPTIONS s_date for ekko-bedat. "Document Date
* SELECT-OPTIONS s_vndr for ekko-lifnr. "Vendor
* SELECT-OPTIONS s_mtnr for ekpo-matkl. "Material Group
SELECT-OPTIONS s_strg for mseg-werks DEFAULT '2F37'.

SELECTION-SCREEN END OF BLOCK a1.




*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

DATA : RS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
fieldcatalog-fieldname = 'MBLNR'.
fieldcatalog-seltext_m = 'Material Doc.'.
fieldcatalog-col_pos = 1.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material'.
fieldcatalog-col_pos = 2.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MAKTX'.
fieldcatalog-seltext_m = 'Material Desc.'.
fieldcatalog-col_pos = 3.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MATKL'.
fieldcatalog-seltext_m = 'Material Group'.
fieldcatalog-col_pos = 4.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'SERNR'.
fieldcatalog-seltext_m = 'Serial No.'.
fieldcatalog-col_pos = 5.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'BWART'.
fieldcatalog-seltext_m = 'Mvt Type'.
fieldcatalog-col_pos = 6.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'DATUM'.
fieldcatalog-seltext_m = 'Posting Date'.
fieldcatalog-col_pos = 7.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'LAGERORT'.
fieldcatalog-seltext_m = 'Storage Location'.
fieldcatalog-col_pos = 8.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'WERK'.
fieldcatalog-seltext_m = 'PLANT'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'ZEILE'.
fieldcatalog-seltext_m = 'ITEM'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'ERFMG'.
fieldcatalog-seltext_m = 'QTY'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.



endform. " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
wa_event-name = slis_ev_top_of_page.
wa_event-form = 'TOP_OF_PAGE'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
wa_event-name = slis_ev_user_command.
wa_event-form = 'USER_COMMAND'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
gd_layout-colwidth_optimize = 'X'.
gd_layout-zebra = 'X'.
endform. " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
* i_callback_pf_status_set = 'SET_PF_STATUS'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_final
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*----------------------------------------------------------*
* FORM SET_PF_STATUS *
*----------------------------------------------------------*
*FORM set_pf_status USING rt_extab TYPE slis_t_extab.
* SET PF-STATUS 'SAVE'.
* "Copy of 'STANDARD' pf_status from fgroup SALV
*ENDFORM.

*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
if s_dat IS INITIAL.
MESSAGE 'Please Enter Posting Data' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
BREAK 10115.

select a~datum a~mblnr a~mjahr a~zeile a~werk a~lagerort a~bwart
b~sernr b~matnr
into table it_sernr
from ser03 as a inner join objk as b
on a~obknr = b~obknr
* for all entries in it_mseg
* where a~mblnr = it_mseg-mblnr
WHERE a~datum in s_dat
AND a~bwart = '101'
AND a~werk in s_code
AND a~lagerort IN S_strg
AND b~matnr in s_mat.

SELECT mblnr
matnr
werks
lgort
bwart
zeile
erfmg
aufnr
FROM mseg
INTO TABLE it_mseg
FOR ALL ENTRIES IN it_sernr
WHERE matnr = it_sernr-matnr
AND mblnr = it_sernr-mblnr
and werks in s_code
AND lgort IN S_strg
AND matnr in s_mat
AND BWART = '101'.
* AND cpudt in s_dat.



DELETE ADJACENT DUPLICATES FROM it_sernr COMPARING mblnr.

SELECT maktx
FROM makt
INTO TABLE it_makt""-maktx
FOR ALL ENTRIES IN it_mseg
WHERE matnr = it_mseg-matnr.

SELECT matkl
FROM mara
INTO TABLE it_mara
* INTO wa_mara-matkl
FOR ALL ENTRIES IN it_mseg
WHERE matnr = it_mseg-matnr
and matkl in s_mgrp.









BREAK 10115.
* LOOP AT it_mseg INTO wa_mseg.
LOOP AT it_sernr INTO wa_sernr.
wa_final-sernr = wa_sernr-sernr.
wa_final-datum = wa_sernr-datum.
wa_final-mblnr = wa_sernr-mblnr.
wa_final-matnr = wa_sernr-matnr.
wa_final-werk = wa_sernr-werk.
wa_final-lagerort = wa_sernr-lagerort.
wa_final-bwart = wa_sernr-bwart.
wa_final-zeile = wa_sernr-zeile.
* wa_final-erfmg = wa_sernr-erfmg.
READ TABLE it_mseg INTO wa_mseg INDEX sy-tabix.
wa_final-erfmg = wa_mseg-erfmg.
* wa_final-aufnr = wa_final-aufnr.
READ TABLE it_mara INTO wa_mara INDEX sy-tabix.
wa_final-matkl = wa_mara-matkl.
* READ TABLE it_mkpf INTO wa_mkpf INDEX sy-tabix.
* wa_final-CPUDT = wa_mkpf-CPUDT.
READ TABLE it_makt INTO wa_makt INDEX sy-tabix."" INDEX sy-tabix.
wa_final-maktx = wa_makt-maktx.
* READ TABLE it_objk INTO wa_objk WITH key matnr = wa_final-matnr.""INDEX sy-tabix.
* wa_final-sernr = wa_objk-sernr.
APPEND wa_final to it_final.
ENDLOOP.


*
*
*BREAK 10115.
*LOOP AT it_objk INTO wa_objk.
* wa_final-sernr = wa_objk-sernr.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING sernr.
** APPEND wa_final to it_final.
* ENDLOOP.



endform. " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.

* Title
wa_header-typ = 'H'.

wa_header-info = 'Daily Production Report'.
append wa_header to t_header.
clear wa_header.

* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.

* Total No. of Records Selected
describe table it_final lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.

call function 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform. "top-of-page


*------------------------------------------------------------------*
* FORM USER_COMMAND *
*------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*------------------------------------------------------------------*
*************************Double click Event**************************
*********************************************************************
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'AWKEY'.
BREAK 10115.
data: r_belnr type range of awkey,
r_belnr_l like line of r_belnr.
*now in the code replace1 your loop by this:
*loop at it_final into wa_final.
* r_belnr_l-sign = 'I'.
* r_belnr_l-OPTION = 'EQ'.
* r_belnr_l-LOW = wa_final-awkey.
* r_belnr_l-high = ' '.
* append r_belnr_l to r_belnr.
*endloop.
*SUBMIT RM08RELEASE VIA SELECTION-SCREEN WITH SO_BELNR IN r_belnr AND RETURN.
* LOOP AT it_final INTO wa_final.
ENDIF.
ENDCASE.
ENDFORM.
** Check field clicked on within ALVgrid report
* IF rs_selfield-fieldname = 'AWKEY'.
** Read data table, using index of row user clicked on
* READ TABLE it_final INTO wa_final INDEX rs_selfield-tabindex.
* BREAK 10115.
** Set parameter ID for transaction screen field
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
** Sxecute transaction MRBR, and skip initial data entry screen
* CALL TRANSACTION 'MRBR' AND SKIP FIRST SCREEN.
* ENDIF.
"user_command


*&---------------------------------------------------------------------*
*& Form BUILD_EVENTS
*&---------------------------------------------------------------------*
* Build events table
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.

read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS


*&---------------------------------------------------------------------*
*& Form BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
* Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*& Form END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.

write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_PAGE

*&---------------------------------------------------------------------*
*& Form END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.

skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_LIST*&---------------------------------------------------------------------*

Redards,

Rakesh Pampaniya