Application Development 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: 

ALV-report

Former Member
0 Kudos
142

Hi

I am doing ALV grid Display, Some of my columns are hiding. I want to display all the columns in the layout when i execute the report

suggestions Please

Regards

4 REPLIES 4

Former Member
0 Kudos
88

Former Member
0 Kudos
88

hi,

REPORT ZTUFI091 .

&----


*& Report ZDEMO_ALVGRID *

*& *

&----


*& *

*& Example of a simple ALV Grid Report *

*& ................................... *

*& *

*& The basic requirement for this demo is to display a number of *

*& fields from the EKKO table. *

&----


*REPORT zdemo_alvgrid .

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

statu TYPE ekpo-statu,

aedat TYPE ekpo-aedat,

matnr TYPE ekpo-matnr,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko.

*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.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform build_events.

perform build_print_params.

perform display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

  • There are a number of ways to create a fieldcat.

  • For the purpose of this example i will build the fieldcatalog manualy

  • by populating the internal table fields individually and then

  • appending the rows. This method can be the most time consuming but can

  • also allow you more control of the final product.

  • Beware though, you need to ensure that all fields required are

  • populated. When using some of functionality available via ALV, such as

  • total. You may need to provide more information than if you were

  • simply displaying the result

  • I.e. Field type may be required in-order for

  • the 'TOTAL' function to work.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'STATU'.

fieldcatalog-seltext_m = 'Status'.

fieldcatalog-col_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.

fieldcatalog-seltext_m = 'Item change date'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.

fieldcatalog-seltext_m = 'PO quantity'.

fieldcatalog-col_pos = 5.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-seltext_m = 'Order Unit'.

fieldcatalog-col_pos = 6.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-seltext_m = 'Price Unit'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

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_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_ekko

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 DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh

up to 10 rows

from ekpo

into table it_ekko.

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 = 'EKKO Table 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_ekko 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.

----


  • FORM USER_COMMAND *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

  • Check function code

CASE r_ucomm.

WHEN '&IC1'.

  • Check field clicked on within ALVgrid report

IF rs_selfield-fieldname = 'EBELN'.

  • Read data table, using index of row user clicked on

READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.

  • Set parameter ID for transaction screen field

SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.

  • Sxecute transaction ME23N, and skip initial data entry screen

CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDFORM.

&----


*& 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.

&----


*& 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.

Former Member
0 Kudos
88

Hi,

are you changed the field catalog once created or added fields(which are hiding) later once created ?

rgds

Deepak

kesavadas_thekkillath
Active Contributor
0 Kudos
88

hi before printing to alv kindly verify whether all the columns are assigned to fields catalog.

im giving u a sample prg which i did when i was a beginner........in this i have used macro for assigning field catalog.....try this it reduces large amount of LOC......

This prg may be well not optimised....but u r alv doubt could be solved.

REPORT zpp468_unitwise_quality_report

MESSAGE-ID zpp

NO STANDARD PAGE HEADING.

======================TABLES=============================

TABLES: marc, "Plant Data for Material

t001w, "Plants/Branches

mseg, "Posted Qty & Costcenter

mkpf, "Posting Document

makt, "Material Description

qmel. "RT & CostCenter

===================VARIABLE DECLARATIONS==================

DATA: mt(2) TYPE c,

mnt(15) TYPE c,

dat_of_mon(10) TYPE c,

f_dt_mon TYPE sy-datum,

l_dat_mon TYPE sy-datum,

wk_dispo LIKE marc-dispo,

sw_werks LIKE marc-werks.

====================ALV DECLARATIONS=====================

TYPE-POOLS : slis.

DATA: alvfld TYPE slis_fieldcat_alv,

fieldcat TYPE slis_t_fieldcat_alv,

alvfld1 TYPE slis_fieldcat_alv,

fieldcat1 TYPE slis_t_fieldcat_alv,

v_events TYPE slis_t_event WITH HEADER LINE,

wk_events LIKE LINE OF v_events,

it_list_comments TYPE slis_t_listheader,

wk_list_comments LIKE LINE OF it_list_comments.

CONSTANTS: c_formname_top_of_page TYPE slis_formname

VALUE 'F_TOP_OF_PAGE'.

================INTERNAL TABLES DEFINITIONS===============

DATA:BEGIN OF it_desc OCCURS 0,

dispo LIKE marc-dispo,

matnr LIKE marc-matnr,

maktx LIKE makt-maktx,

fevor LIKE marc-fevor,

prd_qty TYPE i VALUE 0,

msn TYPE i VALUE 0,

psn TYPE i VALUE 0,

mgeig type p decimals 0,

psn_rt_ppm TYPE i VALUE 0,

psn_rt_msn_ppm TYPE i VALUE 0,

END OF it_desc.

DATA: BEGIN OF it_qmel OCCURS 0,

matnr LIKE qmel-matnr,

mgeig type p,

END OF it_qmel.

DATA:BEGIN OF it_prdqty OCCURS 0,

matnr LIKE marc-matnr,

prd_qty TYPE i VALUE 0,

msn TYPE i VALUE 0,

psn TYPE i VALUE 0,

mgeig type p,

psn_rt_ppm TYPE i VALUE 0,

psn_rt_msn_ppm TYPE i VALUE 0,

END OF it_prdqty.

DATA:BEGIN OF itabmkpf OCCURS 0,

mblnr LIKE mkpf-mblnr,

END OF itabmkpf.

DATA:BEGIN OF it_rt OCCURS 0,

matnr LIKE qmel-matnr,

mgeig type p,

END OF it_rt.

DATA: BEGIN OF itabmseg OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

erfmg LIKE mseg-erfmg,

bwart LIKE mseg-bwart,

kostl like mseg-kostl,

END OF itabmseg.

DATA:BEGIN OF it_consolidated OCCURS 0,

dispo LIKE marc-dispo,

prd_qty TYPE i VALUE 0,

msn TYPE i VALUE 0,

psn TYPE i VALUE 0,

mgeig type p decimals 0,

psn_rt_ppm TYPE i VALUE 0,

psn_rt_msn_ppm TYPE i VALUE 0,

END OF it_consolidated.

DATA:BEGIN OF it_alv OCCURS 0,

matnr LIKE marc-matnr,

maktx LIKE makt-maktx,

fevor LIKE marc-fevor,

prd_qty TYPE i VALUE 0,

kostl LIKE qmfe-kostl,

msn TYPE i VALUE 0,

psn TYPE i VALUE 0,

mgeig type p decimals 0,

psn_rt_ppm TYPE i VALUE 0,

psn_rt_msn_ppm TYPE i VALUE 0,

END OF it_alv.

data: begin of it_mseg_cst occurs 0,

matnr like mseg-matnr,

erfmg like mseg-erfmg,

kostl like mseg-kostl,

end of it_mseg_cst.

========================RANGES======================================

RANGES: r_dat FOR mkpf-budat, "Month date ranges

r_mrpc FOR marc-dispo, "MRP Controllers

r_mat FOR marc-matnr. "Material No's

r_mrpc-option = 'EQ'.

r_mrpc-sign = 'I'.

r_mat-option = 'EQ'.

r_mat-sign = 'I'.

r_dat-option = 'BT'.

r_dat-sign = 'I'.

  • ===================ALV MACRO DEFINITIONS BEGINS HERE==============*

DEFINE alv_macro_fill. "For List 1 Consolidated View

alvfld-fieldname = &1.

alvfld-seltext_m = &2.

alvfld-fix_column = &3.

alvfld-outputlen = &4.

if &1 = 'DISPO'.

alvfld-emphasize = 'C711'.

alvfld-hotspot = 'X'.

endif.

if ( &1 = 'MSN' or &1 = 'PSN' or &1 = 'PRD_QTY' or &1 = 'RTSEG' ).

alvfld-do_sum = 'X'.

endif.

if &1 = 'PSN_RT_MSN_PPM' or &1 = 'PSN_RT_PPM'.

alvfld-emphasize = 'C100'.

endif.

append alvfld to fieldcat.

clear alvfld.

END-OF-DEFINITION.

DEFINE alv_macro_fill1. "For List 2 Descriptive view

alvfld1-fieldname = &1.

alvfld1-seltext_m = &2.

alvfld1-fix_column = &3.

alvfld1-outputlen = &4.

if ( &1 = 'MSN' or &1 = 'PSN' or &1 = 'PRD_QTY' or &1 = 'RTSEG' ).

alvfld1-do_sum = 'X'.

endif.

if &1 = 'PSN_RT_MSN_PPM' or &1 = 'PSN_RT_PPM'.

alvfld1-emphasize = 'C100'.

endif.

append alvfld1 to fieldcat1.

clear alvfld1.

END-OF-DEFINITION.

  • ===================ALV MACRO DEFINITIONS ENDS HERE==============*

================SELECTION-SCREEN LAYOUT============================

SELECTION-SCREEN BEGIN OF BLOCK entry WITH FRAME TITLE text-007.

PARAMETERS: choose RADIOBUTTON GROUP a USER-COMMAND c1 DEFAULT 'X',

choose2 RADIOBUTTON GROUP a.

selection-screen skip 1.

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

PARAMETERS:so_werks TYPE marc-werks MODIF ID shw.

SELECTION-SCREEN COMMENT 40(75) text-004.

select-options: sp_werks for marc-werks no intervals.

PARAMETERS:s_budat TYPE mkpf-budat MODIF ID dat.

PARAMETERS: month(2) TYPE n MODIF ID mth.

PARAMETERS: yr(4) TYPE n MODIF ID yr.

SELECTION-SCREEN END OF BLOCK entry1.

SELECTION-SCREEN END OF BLOCK entry.

=============AT SELECTION SCREEN EVENTS================

AT SELECTION-SCREEN OUTPUT.

IF choose = 'X'. "For Daily Report

LOOP AT SCREEN.

IF screen-group1 = 'MTH'.

screen-active = '0'.

MODIFY SCREEN.

ELSEIF screen-group1 = 'YR'.

screen-active = '0'.

MODIFY SCREEN.

ELSE.

ENDIF.

ENDLOOP.

ELSEIF choose2 = 'X'. "For Monthly Report

LOOP AT SCREEN.

IF screen-group1 = 'DAT'.

screen-active = '0'.

MODIFY SCREEN.

ELSE.

ENDIF.

ENDLOOP.

ENDIF.

*******************

START-OF-SELECTION.

*******************

PERFORM validations.

IF choose2 = 'X'.

PERFORM date_month_yr_assign.

ENDIF.

PERFORM getdata.

PERFORM fill_columns.

clear it_consolidated.

SORT it_consolidated BY dispo .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_background_id = 'ALV_BACKGROUND'

it_fieldcat = fieldcat[]

it_events = v_events[]

TABLES

t_outtab = it_consolidated

EXCEPTIONS

program_error = 1

OTHERS = 2.

END-OF-SELECTION.

&----


*& Form getdata

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM getdata .

if so_werks <> ' '.

IF so_werks = 'HOS1'.

sw_werks = 'HOS'.

r_mrpc-low = '1MS'. APPEND r_mrpc.r_mrpc-low = '1WS'.APPEND r_mrpc.

r_mrpc-low = '1PA'. APPEND r_mrpc.r_mrpc-low = '1SC'.APPEND r_mrpc.

r_mrpc-low = '1PR'. APPEND r_mrpc.

ELSEIF so_werks = 'HOS2'.

sw_werks = 'HOS'.

r_mrpc-low = '2MS'. APPEND r_mrpc.r_mrpc-low = '2WS'.APPEND r_mrpc.

r_mrpc-low = '2PA'. APPEND r_mrpc.r_mrpc-low = '2PR'.APPEND r_mrpc.

r_mrpc-low = '2SC'. APPEND r_mrpc.

ELSEIF so_werks = 'HOS3'.

sw_werks = 'HOS'.

r_mrpc-low = '3MS'. APPEND r_mrpc. r_mrpc-low = '3GH'.APPEND r_mrpc.

r_mrpc-low = '3HT'. APPEND r_mrpc. r_mrpc-low = '3PL'.APPEND r_mrpc.

r_mrpc-low = '3GS'. APPEND r_mrpc. r_mrpc-low = '3SC'.APPEND r_mrpc.

endif.

elseif sp_werks <> ' '.

loop at sp_werks.

if sp_werks-low = 'HOS'.

r_mrpc-low = '1MS'. APPEND r_mrpc. r_mrpc-low = '1WS'.APPEND r_mrpc.

r_mrpc-low = '1PA'. APPEND r_mrpc. r_mrpc-low = '1SC'.APPEND r_mrpc.

r_mrpc-low = '1PR'. APPEND r_mrpc. r_mrpc-low = '2MS'.APPEND r_mrpc.

r_mrpc-low = '2WS'. APPEND r_mrpc. r_mrpc-low = '2PA'.APPEND r_mrpc.

r_mrpc-low = '2PR'. APPEND r_mrpc. r_mrpc-low = '2SC'.APPEND r_mrpc.

r_mrpc-low = '3MS'. APPEND r_mrpc. r_mrpc-low = '3GH'.APPEND r_mrpc.

r_mrpc-low = '3HT'. APPEND r_mrpc. r_mrpc-low = '3PL'.APPEND r_mrpc.

r_mrpc-low = '3GS'. APPEND r_mrpc. r_mrpc-low = '3SC'.APPEND r_mrpc.

elseif sp_werks-low = 'MYSR'.

r_mrpc-low = '4MS'. APPEND r_mrpc. r_mrpc-low = '4PA'.APPEND r_mrpc.

r_mrpc-low = '4SC'. APPEND r_mrpc. r_mrpc-low = '4WS'.APPEND r_mrpc.

r_mrpc-low = '6GH'. APPEND r_mrpc. r_mrpc-low = '6GS'.APPEND r_mrpc.

r_mrpc-low = '6HT'. APPEND r_mrpc.

elseif sp_werks-low = 'HP'.

r_mrpc-low = '7PA'. APPEND r_mrpc. r_mrpc-low = '7SC'.APPEND r_mrpc.

r_mrpc-low = '7WS'. APPEND r_mrpc.

elseif sp_werks-low = '1001'.

r_mrpc-low = 'AEA'. APPEND r_mrpc.r_mrpc-low = 'AMS'.APPEND r_mrpc.

r_mrpc-low = 'APA'. APPEND r_mrpc.r_mrpc-low = 'APL'.APPEND r_mrpc.

r_mrpc-low = 'APR'. APPEND r_mrpc.r_mrpc-low = 'ASP'.APPEND r_mrpc.

r_mrpc-low = 'AVA'. APPEND r_mrpc.r_mrpc-low = 'AWS'.APPEND r_mrpc.

r_mrpc-low = 'ASC'. APPEND r_mrpc.

endif.

endloop.

CLEAR r_mrpc.

DELETE ADJACENT DUPLICATES FROM r_mrpc.

ENDIF.

if so_werks = ' '.

SELECT marc~dispo marc~matnr makt~maktx marc~fevor

APPENDING TABLE it_desc

FROM marc INNER JOIN makt

ON marc~matnr = makt~matnr

where marc~werks in sp_werks

and dispo in r_mrpc.

endif.

if sp_werks = ' '.

SELECT marc~dispo marc~matnr makt~maktx marc~fevor

APPENDING TABLE it_desc

FROM marc INNER JOIN makt

ON marc~matnr = makt~matnr

WHERE marc~dispo in r_mrpc

AND marc~werks = sw_werks.

endif.

LOOP AT it_desc.

at new matnr.

move it_desc-matnr to r_mat-low.

APPEND r_mat.

endat.

ENDLOOP.

CLEAR: r_mat.

SORT R_MAT ASCENDING.

DELETE ADJACENT DUPLICATES FROM R_MAT.

IF choose = 'X'.

SELECT mblnr APPENDING TABLE itabmkpf FROM mkpf CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND budat EQ s_budat.

ELSEIF choose2 = 'X'.

SELECT mblnr APPENDING TABLE itabmkpf FROM mkpf CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND budat IN r_dat.

ENDIF.

if sp_werks = ' '.

SELECT mblnr matnr erfmg bwart kostl APPENDING TABLE itabmseg FROM

mseg CLIENT SPECIFIED FOR ALL ENTRIES IN itabmkpf

WHERE mandt = sy-mandt

AND mblnr = itabmkpf-mblnr

AND werks = sw_werks AND

( bwart = '131' OR bwart = '132' OR bwart = '551' OR bwart =

'555' ) and matnr in r_mat.

endif.

if so_werks = ' '.

SELECT mblnr matnr erfmg bwart kostl APPENDING TABLE itabmseg

FROM mseg CLIENT SPECIFIED FOR ALL ENTRIES IN itabmkpf

WHERE mandt = sy-mandt

AND mblnr = itabmkpf-mblnr

AND werks in sp_werks AND

( bwart = '131' OR bwart = '132' OR bwart = '551' OR bwart =

'555' ) and matnr in r_mat.

endif.

LOOP AT itabmseg WHERE bwart = '132'.

itabmseg-erfmg = itabmseg-erfmg * -1.

MODIFY itabmseg.

ENDLOOP.

LOOP AT itabmseg.

CASE itabmseg-bwart.

WHEN '132' OR '131' .

MOVE: itabmseg-matnr TO it_prdqty-matnr,

itabmseg-erfmg TO it_prdqty-prd_qty.

COLLECT it_prdqty.

CLEAR: it_prdqty, itabmseg.

WHEN '551'.

MOVE: itabmseg-matnr TO it_prdqty-matnr,

itabmseg-erfmg TO it_prdqty-msn.

COLLECT it_prdqty.

CLEAR: it_prdqty, itabmseg.

WHEN '555'.

MOVE: itabmseg-matnr TO it_mseg_cst-matnr,

itabmseg-erfmg TO it_mseg_cst-erfmg,

itabmseg-kostl to it_mseg_cst-kostl.

append it_mseg_cst.

clear it_mseg_cst.

MOVE: itabmseg-matnr TO it_prdqty-matnr,

itabmseg-erfmg TO it_prdqty-psn.

COLLECT it_prdqty.

CLEAR: it_prdqty, itabmseg.

ENDCASE.

ENDLOOP.

CLEAR: it_prdqty, itabmseg, it_mseg_cst.

sort it_mseg_cst by matnr erfmg descending.

delete adjacent duplicates from it_mseg_cst.

IF choose = 'X'.

if sp_werks = ' '.

SELECT matnr sum( mgeig )

APPENDING TABLE it_qmel FROM qmel

CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND erdat = s_budat

AND matnr IN r_mat

AND mawerk = sw_werks

AND ( qmart = 'F4' OR qmart = 'F9' )

group by matnr.

endif.

if so_werks = ' '.

SELECT matnr sum( mgeig )

APPENDING TABLE it_qmel FROM qmel

CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND erdat = s_budat

AND matnr IN r_mat

AND mawerk in sp_werks

AND ( qmart = 'F4' OR qmart = 'F9' )

group by matnr.

endif.

ELSEIF choose2 = 'X'.

if sp_werks = ' '.

SELECT matnr sum( mgeig )

APPENDING TABLE it_qmel FROM qmel

CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND erdat IN r_dat

AND matnr IN r_mat

AND mawerk = sw_werks

AND ( qmart = 'F4' OR qmart = 'F9' )

group by matnr.

endif.

if so_werks = ' '.

SELECT matnr sum( mgeig )

APPENDING TABLE it_qmel FROM qmel

CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND erdat IN r_dat

AND matnr IN r_mat

AND mawerk IN sp_werks

AND ( qmart = 'F4' OR qmart = 'F9' )

group by matnr.

endif.

ENDIF.

describe table it_qmel.

if sy-tfill <> 0.

loop at it_desc.

read table it_qmel with key matnr = it_desc-matnr.

if sy-subrc = 0.

move: it_qmel-mgeig to it_desc-mgeig.

modify it_desc.

endif.

endloop.

endif.

LOOP AT it_desc.

READ TABLE it_prdqty WITH KEY matnr = it_desc-matnr.

IF sy-subrc = 0.

MOVE: it_prdqty-prd_qty TO it_desc-prd_qty,

it_prdqty-msn TO it_desc-msn,

it_prdqty-psn TO it_desc-psn.

MODIFY it_desc.

ENDIF.

ENDLOOP.

LOOP AT it_desc.

MOVE: it_desc-dispo TO it_consolidated-dispo,

it_desc-prd_qty TO it_consolidated-prd_qty,

it_desc-psn TO it_consolidated-psn,

it_desc-mgeig TO it_consolidated-mgeig,

it_desc-msn TO it_consolidated-msn.

COLLECT it_consolidated.

CLEAR it_consolidated.

ENDLOOP.

LOOP AT it_consolidated.

IF it_consolidated-prd_qty > 0.

it_consolidated-psn_rt_ppm = ( ( it_consolidated-psn +

it_consolidated-mgeig ) / it_consolidated-prd_qty ) * ( 10 ** 6 )

.

it_consolidated-psn_rt_msn_ppm = ( ( it_consolidated-psn +

it_consolidated-mgeig + it_consolidated-msn ) /

it_consolidated-prd_qty ) * ( 10 ** 6 ).

MODIFY it_consolidated.

ENDIF.

CLEAR it_consolidated.

ENDLOOP.

delete it_consolidated where PRD_QTY = 0 and PSN = 0 and mgeig = 0 and

MSN = 0.

ENDFORM. " getdata

&----


*& Form validations

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM validations ..

CONDENSE: so_werks.

if sp_werks is not initial and so_werks <> ' '.

MESSAGE i000(38) WITH 'Choose one Entry option for plant'.

STOP.

endif.

IF choose = 'X'.

IF s_budat IS INITIAL.

MESSAGE i000(38) WITH 'Enter date'.

STOP.

ENDIF.

ELSEIF choose2 = 'X'.

IF month IS INITIAL.

MESSAGE i935.

STOP.

ENDIF.

IF yr IS INITIAL .

MESSAGE i000(38) WITH 'Enter Year'.

STOP.

ENDIF.

ENDIF.

IF so_werks = ' ' and sp_werks = ' '.

MESSAGE i000(38) WITH 'Enter plant'.

STOP.

endif.

if so_werks <> ' '.

IF so_werks <> 'HOS1' AND so_werks <> 'HOS2' AND so_werks <>

'HOS3' .

MESSAGE i000(38) WITH 'Invalid Plant'.

STOP.

ENDIF.

endif.

if sp_werks is not initial.

if sp_werks-low <> 'HOS' and sp_werks-low <> 'MYSR' and sp_werks-low

<> 'HP' and sp_werks-low <> '1001'.

MESSAGE i000(38) WITH 'Invalid Plant'.

STOP.

endif.

endif.

ENDFORM. " validations

&----


*& Form date_Month_yr_assign

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM date_month_yr_assign .

CONDENSE: month, yr.

CASE month.

WHEN '1' OR '01'.

move : '01' to mt,

'JANUARY' to mnt.

WHEN '2' OR '02'.

move: '02' to mt,

'FEBRUARY' to mnt.

WHEN '3' OR '03'.

move: '03' to mt,

'MARCH' to mnt.

WHEN '4' OR '04'.

move: '04' to mt,

'APRIL' to mnt.

WHEN '5' OR '05'.

move: '05' to mt,

'MAY' to mnt.

WHEN '6' OR '06'.

move: '06' to mt,

'JUNE' to mnt.

WHEN '7' OR '07'.

move: '07' to mt,

'JULY' to mnt.

WHEN '8' OR '08'.

move: '08' to mt,

'AUGUST' to mnt.

WHEN '9' OR '09'.

move: '09' to mt,

'SEPTEMBER' to mnt.

WHEN '10'.

move: '10' to mt,

'OCTOBER' to mnt.

WHEN '11'.

move: '11' to mt,

'NOVEMBER' to mnt.

WHEN '12'.

move: '12' to mt,

'DECEMBER' to mnt.

ENDCASE.

CONCATENATE '01' '.' mt '.' yr INTO dat_of_mon .

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = dat_of_mon

IMPORTING

date_internal = f_dt_mon

EXCEPTIONS

date_external_is_invalid = 1

OTHERS = 2.

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'

EXPORTING

day_in = f_dt_mon

IMPORTING

last_day_of_month = l_dat_mon

EXCEPTIONS

day_in_no_date = 1

OTHERS = 2.

r_dat-low = f_dt_mon.

r_dat-high = l_dat_mon.

APPEND r_dat.

ENDFORM. " date_Month_yr_assign

&----


*& Form f_event_build

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_event_build .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = v_events[].

READ TABLE v_events WITH KEY name = slis_ev_top_of_page

INTO wk_events.

IF sy-subrc = 0.

MOVE c_formname_top_of_page TO wk_events-form.

MODIFY v_events FROM wk_events INDEX sy-tabix.

ENDIF.

ENDFORM. " f_event_build

&----


*& Form F_TOP_OF_PAGE

&----


  • text

----


FORM f_top_of_page.

DATA: wk_fmdate TYPE zservice_date,

wk_datum TYPE zservice_date,

hold_day LIKE dtresr-weekday,

wk_todate TYPE zservice_date.

CLEAR: it_list_comments[].

wk_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action

wk_list_comments-key = ''.

wk_list_comments-info = 'UNITWISE QUALITY REPORT'.

APPEND wk_list_comments TO it_list_comments.

CLEAR wk_list_comments.

wk_list_comments-typ = 'S'. " H = Header, S = Selection, A = Action

wk_list_comments-key = ''.

IF choose = 'X'.

WRITE s_budat TO wk_datum.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = s_budat

IMPORTING

weekday = hold_day.

CONCATENATE 'DATE: ' wk_datum ':' hold_day INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

wk_list_comments-typ = 'S'. " H = Header, S = Selection, A = Action

wk_list_comments-key = ''.

wk_list_comments-info = ' '.

APPEND wk_list_comments TO it_list_comments.

if wk_dispo = ' '.

if so_werks = ' '.

wk_list_comments-info = 'PLANT :'.

APPEND wk_list_comments TO it_list_comments.

loop at sp_werks.

wk_list_comments-info = sp_werks-low..

APPEND wk_list_comments TO it_list_comments.

endloop.

else.

CONCATENATE 'PLANT : ' so_werks INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

endif.

ENDIF.

endif.

IF choose2 = 'X'.

CONCATENATE 'MONTH :' mnt INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

CONCATENATE 'YEAR :' yr INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

if wk_dispo = ' '.

if so_werks = ' '.

wk_list_comments-info = 'PLANT :'.

APPEND wk_list_comments TO it_list_comments.

loop at sp_werks.

concatenate space space sp_werks-low INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

endloop.

else.

CONCATENATE 'PLANT : ' so_werks INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

endif.

endif.

ENDIF.

if wk_dispo <> ' '.

CONCATENATE 'MRP : ' wk_dispo INTO

wk_list_comments-info SEPARATED BY space.

APPEND wk_list_comments TO it_list_comments.

CLEAR wk_list_comments.

clear wk_dispo.

endif.

CLEAR wk_list_comments.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = it_list_comments.

ENDFORM. "F_TOP_OF_PAGE

&----


*& Form FILL_COLUMNS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_columns .

REFRESH fieldcat.

REFRESH fieldcat1.

PERFORM f_event_build.

                                                  • LIST 1 **************************************

alv_macro_fill 'DISPO' 'MRP' 'X' ' '.

alv_macro_fill 'PRD_QTY' 'PRD(OK+REJ)' ' ' '15'.

alv_macro_fill 'PSN' 'PSN' ' ' ' '.

alv_macro_fill 'MGEIG' 'RT(QJO+RTSEG)' ' ' '15'.

alv_macro_fill 'PSN_RT_PPM' 'PPM(PSN+RT)' ' ' '12'.

alv_macro_fill 'MSN' 'MSN' ' ' ' '.

alv_macro_fill 'PSN_RT_MSN_PPM' 'TOT_PPM(PSNRTMSN)' ' ' '25'.

                                                • LIST 2 ****************************************

alv_macro_fill1 'MATNR' 'PARTNO' 'X' ' '.

alv_macro_fill1 'MAKTX' 'DESCRIPTION' 'X' '15'.

alv_macro_fill1 'FEVOR' 'CELL' ' ' ' '.

alv_macro_fill1 'PRD_QTY' 'PRD(OK+REJ)' ' ' '15'.

alv_macro_fill1 'PSN' 'PSN' ' ' ' '.

alv_macro_fill1 'KOSTL' 'CST CNTR' ' ' '9'.

alv_macro_fill1 'MGEIG' 'RT(QJO+RTSEG)' ' ' '15'.

alv_macro_fill1 'PSN_RT_PPM' 'PPM(PSN+RT)' ' ' '15'.

alv_macro_fill1 'MSN' 'MSN' ' ' ' '.

alv_macro_fill1 'PSN_RT_MSN_PPM' 'TOT_PPM(PSNRTMSN)' ' ' '24'.

v_events-name = 'USER_COMMAND'.

v_events-form = 'VAL'.

APPEND v_events.

ENDFORM. " FILL_COLUMNS

&----


*& Form VAL

&----


  • text

----


  • -->USER_COMMANtext

  • -->CURSOR text

----


FORM val USING user_command LIKE sy-ucomm cursor TYPE slis_selfield.

DATA: wk_kostl LIKE qmfe-kostl,

wk_len TYPE i.

REFRESH it_alv.

IF cursor-fieldname = 'DISPO'.

LOOP AT it_consolidated.

READ TABLE it_consolidated INDEX cursor-tabindex.

wk_dispo = it_consolidated-dispo.

ENDLOOP.

LOOP AT it_desc WHERE dispo = wk_dispo.

MOVE-CORRESPONDING it_desc TO it_alv.

IF it_alv-prd_qty > 0.

it_alv-psn_rt_ppm = ( ( it_alv-psn + it_alv-mgeig )

/ it_alv-prd_qty ) * ( 10 ** 6 ).

it_alv-psn_rt_msn_ppm = ( ( it_alv-psn + it_alv-mgeig +

it_alv-msn )

/ it_alv-prd_qty ) * ( 10 ** 6 ).

ENDIF.

APPEND it_alv.

CLEAR it_alv.

ENDLOOP.

loop at it_alv.

read table it_mseg_cst with key matnr = it_alv-matnr.

if sy-subrc = 0.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = it_mseg_cst-kostl

IMPORTING

OUTPUT = it_mseg_cst-kostl

.

it_alv-kostl = it_mseg_cst-kostl.

modify it_alv.

endif.

endloop.

clear it_alv.

delete it_alv where PRD_QTY = 0 and PSN = 0 and mgeig = 0

and MSN = 0.

SORT it_alv BY matnr fevor.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_background_id = 'ALV_BACKGROUND'

i_structure_name = 'IT_ALV'

it_fieldcat = fieldcat1

i_save = 'A'

it_events = v_events[]

TABLES

t_outtab = it_alv.

ENDIF.

ENDFORM. "val