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: 

subtotal in alv

Former Member
0 Kudos

<b>hi experts

i want to subtotal according MATERIAL NO,and i need to display the below</b>

matnr LIKE mara-matnr, " MATERIAL NUMBER

mbrsh LIKE mara-mbrsh, " INDUSTRY SECTOR

mtart LIKE mara-mtart, " Material type

meins LIKE mara-meins, " BASE UNIT OF MEASURE

matkl LIKE mara-matkl, " MATERIAL GROUP

werks LIKE marc-werks, " PLANT

mmsta LIKE marc-mmsta, " PLANT-SPECIFIC MATERIAL STATUS

awsls LIKE marc-awsls, " VARIANCE KEY

prctr LIKE marc-prctr, " PROFIT CENTER

losgr LIKE marc-losgr, " LOT SIZE OF PRODUCT COSTING

disgr LIKE marc-disgr, " MRP GROUP

maabc LIKE marc-maabc, " ABC ANALYSIS

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

maktx LIKE makt-maktx, " MATERIAL DESCRIPTION

lgort LIKE mard-lgort, " STORAGE LOCATION

labst LIKE mard-labst, " STOCK QUANTITY

vkorg LIKE mvke-vkorg, " SALES ORGANISATION

<b>I hava written a code for this ,no syntex errors r displaying but it is not executeing also,the code is below,if any changes made pls make it in bold</b>

TYPE-POOLS: SLIS. " ALL THE DEFINATIONS INTERNAL TABLES STRUCTURES AND

" CONSTANTS ARE DECLARED IN TYPE-POOL CALLED SLIS

DATA: VT_FIELDCATLOG1 TYPE SLIS_T_FIELDCAT_ALV. " THIS INTERNAL TABLE

" CONTAINS THE FIELD

" ATTRIBUTES

DATA:X TYPE I,Y TYPE I,a type i,b type i.

&----


  • TABLE DECLARATION

&----


TABLES: marc, " PLANT DATA

mara, " GENERAL MATERIAL DATA

mbew, " MATERIAL VALUATION

mard, " CURRENT INVENTORY

makt, " MATERIAL DESCRIPTION

mvke. " SALES DATA FOR MATERIAL

&----


  • INTERNAL TABLE DECLARATION

&----


DATA: BEGIN OF i_marc OCCURS 0, " PLANT DATA

matnr LIKE marc-matnr, " MATERIAL NUMBER

werks LIKE marc-werks, " PLANT

disgr LIKE marc-disgr, " MRP GROUP

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

END OF i_marc.

DATA: BEGIN OF i_output OCCURS 0,

matnr LIKE mara-matnr, " MATERIAL NUMBER

mbrsh LIKE mara-mbrsh, " INDUSTRY SECTOR

mtart LIKE mara-mtart, " Material type

meins LIKE mara-meins, " BASE UNIT OF MEASURE

matkl LIKE mara-matkl, " MATERIAL GROUP

werks LIKE marc-werks, " PLANT

mmsta LIKE marc-mmsta, " PLANT-SPECIFIC MATERIAL STATUS

awsls LIKE marc-awsls, " VARIANCE KEY

prctr LIKE marc-prctr, " PROFIT CENTER

losgr LIKE marc-losgr, " LOT SIZE OF PRODUCT COSTING

disgr LIKE marc-disgr, " MRP GROUP

maabc LIKE marc-maabc, " ABC ANALYSIS

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

maktx LIKE makt-maktx, " MATERIAL DESCRIPTION

lgort LIKE mard-lgort, " STORAGE LOCATION

labst LIKE mard-labst, " STOCK QUANTITY

vkorg LIKE mvke-vkorg, " SALES ORGANISATION

Y TYPE I,

END OF i_output.

DATA: BEGIN OF i_mard OCCURS 0,

matnr LIKE mard-matnr, "MATERIAL NUMBER

lgort LIKE mard-lgort, "STORAGE LOCATION

labst LIKE mard-labst, "STOCK QUANTITY

END OF i_mard.

DATA: BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr, "MATERIAL NUMBER

vkorg LIKE mvke-vkorg, "SALES ORGANIZATION

END OF i_mvke.

&----


  • START OF SELECTION

&----


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

SELECT-OPTIONS: s_matnr FOR marc-matnr.

PARAMETER : p_werks LIKE marc-werks OBLIGATORY.

SELECT-OPTIONS: s_lgort FOR mard-lgort,

s_dispo FOR marc-dispo.

SELECTION-SCREEN END OF BLOCK b1.

&----


  • INITIALIZATION.

&----


INITIALIZATION.

p_werks = '1200'.

s_matnr-sign = 'I'.

s_matnr-option = 'EQ'.

s_matnr-low = 'M-14'.

s_matnr-high = 'M-18'.

s_lgort-sign = 'I'.

s_lgort-option = 'BT'.

s_lgort-low = '0001'.

s_lgort-high = '0007'.

s_dispo-sign = 'I'.

s_dispo-option = 'EQ'.

s_dispo-low = '001'.

s_dispo-high = '005'.

APPEND s_matnr.

APPEND s_lgort.

APPEND s_dispo.

CLEAR s_matnr.

CLEAR s_lgort.

CLEAR s_dispo.

&----


  • START OF SELECTION

&----


START-OF-SELECTION.

SELECT matnr werks disgr dismm dispo

FROM marc

INTO CORRESPONDING FIELDS OF TABLE i_marc

WHERE matnr IN s_matnr

AND dispo IN s_dispo

AND werks = p_werks.

IF i_marc[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARC'.

EXIT.

ENDIF.

SELECT matnr lgort labst FROM mard INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks = p_werks.

IF i_mard[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARD'.

EXIT.

ENDIF.

SELECT matnr vkorg

FROM mvke

INTO table i_mvke for all entries in I_marc

WHERE matnr = i_marc-matnr.

LOOP AT i_marc.

MOVE-CORRESPONDING i_marc TO i_output.

CLEAR marc.

SELECT SINGLE matnr mbrsh mtart meins matkl

FROM mara

INTO CORRESPONDING FIELDS OF mara

WHERE matnr = i_output-matnr.

IF sy-subrc = 0.

MOVE-CORRESPONDING mara TO i_output.

ELSE.

CONTINUE.

ENDIF.

SELECT SINGLE matnr maktx

FROM makt

INTO CORRESPONDING FIELDS OF makt

WHERE matnr = i_output-matnr

AND spras = SY-LANGU.

IF sy-subrc = 0.

MOVE-CORRESPONDING makt TO i_output.

ENDIF.

LOOP AT i_mvke WHERE matnr = i_marc-matnr.

MOVE i_mvke-vkorg TO i_output-vkorg.

APPEND i_output.

ENDLOOP.

LOOP AT i_mard WHERE matnr = i_marc-matnr.

MOVE: i_mard-labst TO i_output-labst,

i_mard-lgort TO i_output-lgort.

APPEND i_output.

ENDLOOP.

CLEAR i_output.

X = i_output-MATNR .

ADD X TO Y.

ENDLOOP.

DATA: T_SORT TYPE slis_t_sortinfo_alv.

DATA: S_SORT like line of t_sort.

DATA: wa_sortinfo TYPE slis_sortinfo_alv,

i_sortcat TYPE slis_t_sortinfo_alv.

DATA: v_fieldcatlog TYPE SLIS_FIELDCAT_ALV,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

perform build_fieldcatalog.

perform build_layout.

PERFORM sortcat_init CHANGING i_sortcat.

FORM build_fieldcatalog.

v_fieldcatlog-col_pos = '1'.

v_fieldcatlog-fieldname = 'MATNR'.

v_fieldcatlog-seltext_m = 'MATERIAL NUMBER '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATNR'.

v_fieldcatlog-ref_tabname = 'MARC'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '2'.

v_fieldcatlog-fieldname = 'WERKS'.

v_fieldcatlog-seltext_m = 'PLANT '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'WERKS'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '3'.

v_fieldcatlog-fieldname = 'DISPO'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'DISPO'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '4'.

v_fieldcatlog-fieldname = 'MBRSH'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MBRSH'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '5'.

v_fieldcatlog-fieldname = 'MEINS'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MEINS'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '6'.

v_fieldcatlog-fieldname = 'MATKL'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATKL'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '7'.

v_fieldcatlog-fieldname = 'VKORG'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'VKORG'.

v_fieldcatlog-ref_tabname = 'MVKE'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '8'.

v_fieldcatlog-fieldname = 'VTWEG'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'VTWEG'.

v_fieldcatlog-ref_tabname = 'MVKE'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '9'.

v_fieldcatlog-fieldname = 'MAKTX'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MAKTX'.

v_fieldcatlog-ref_tabname = 'MAKT'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '11'.

v_fieldcatlog-fieldname = 'LGORT'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LGORT'.

v_fieldcatlog-ref_tabname = 'MARD'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '10'.

v_fieldcatlog-fieldname = 'LABST'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LABST'.

v_fieldcatlog-ref_tabname = 'MARD'.

v_fieldcatlog-hotspot = 'X'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

ENDFORM.

FORM build_layout.

gd_layout-NO_INPUT = 'X'.

gd_layout-colwidth_optimize = 'X'.

GD_LAYOUT-TOTALS_TEXT = 'TOTALS'(201).

ENDFORM.

&----


  • ALV PROCESS

&----


*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

  • EXPORTING

  • i_program_name = sy-repid

  • i_internal_tabname = 'I_OUTPUT'

  • i_client_never_display = 'X'

  • i_inclname = sy-repid

  • CHANGING

  • ct_fieldcat = vt_fieldcat.

  • .

  • IF sy-subrc <> 0.

  • ENDIF.

form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

is_layout = gd_layout

it_fieldcat = vt_fieldcatlog1[]

it_sort = i_sortcat

i_save = 'X'

tables

t_outtab = I_OUTPUT

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

endif.

endform. " DISPLAY_ALV_REPORT

FORM sortcat_init CHANGING i_sortcat TYPE slis_t_sortinfo_alv.

CLEAR wa_sortinfo.

wa_sortinfo-fieldname = 'MANTNR'.

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 1. " First sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

CLEAR wa_sortinfo.

wa_sortinfo-fieldname = 'LABST'.

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 2. " Sec sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

ENDFORM. " sortcat_init

&----


*& ALV Form top-of-page

&----


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.

call function 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header

i_logo = 'ENJOYSAP_LOGO'.

endform. " top-of-page

&----


*& END-OF-SELECTION.

&----


END-OF-SELECTION.

END-OF-PAGE.

ULINE .

WRITE : SY-PAGNO.

<b>Thanks and regard

satya</b>

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You have given the material number MATNR in the declaration..But in the sort internal table you have give MANTNR

wa_sortinfo-fieldname = '<b>MATNR</b>'.

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 1. " First sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

Thanks,

Naren

15 REPLIES 15

Former Member
0 Kudos

Hi,

You have given the material number MATNR in the declaration..But in the sort internal table you have give MANTNR

wa_sortinfo-fieldname = '<b>MATNR</b>'.

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 1. " First sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

Thanks,

Naren

0 Kudos

hi narendra

i have changed in to MATNR eventhough i did not get output

thanks and regard

satya

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Where is the rest of it? You haven't called the ALV Function module.

Regards,

Rich Heilman

0 Kudos

hi rich

i have used 'REUSE_ALV_GRID_DISPLAY'

thanks and regard

satya

Former Member
0 Kudos

Hello,

Check mz post in this thread>

Vasanth

Former Member
0 Kudos

Hi,

As mentioned by rich you didn't call the subroutine display_alv_report to display the report..Call after the sortcat_int..

perform build_layout.

PERFORM sortcat_init CHANGING i_sortcat.

<b>perform display_alv_report.</b>

Thanks,

Naren

0 Kudos

hi Naren

i have used perform display_alv_report, it is going to runtime error

thanks and regard

satya

0 Kudos

hi naren

pls execute code where u had made modifications ,the output is getting two subtotals for every single material ,i need single subtotal ,pls help me if u can .

thanks and regard

satya

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is the corrected code. First you need to call the form "display_alv_report." Also, there was a typo when buidling the sort cat, and you don't need the entry for LABST in the sort cat.



report zrich_0001 .

type-pools: slis. " ALL THE DEFINATIONS INTERNAL TABLES STRUCTURES AND
" CONSTANTS ARE DECLARED IN TYPE-POOL CALLED SLIS


data: vt_fieldcatlog1 type slis_t_fieldcat_alv. " THIS INTERNAL TABLE
" CONTAINS THE FIELD
" ATTRIBUTES
data:x type i,y type i,a type i,b type i.


*&---------------------------------------------------------------------*
* TABLE DECLARATION
*&---------------------------------------------------------------------*

tables: marc, " PLANT DATA
mara, " GENERAL MATERIAL DATA
mbew, " MATERIAL VALUATION
mard, " CURRENT INVENTORY
makt, " MATERIAL DESCRIPTION
mvke. " SALES DATA FOR MATERIAL



*&---------------------------------------------------------------------*
* INTERNAL TABLE DECLARATION
*&---------------------------------------------------------------------*


data: begin of i_marc occurs 0, " PLANT DATA
matnr like marc-matnr, " MATERIAL NUMBER
werks like marc-werks, " PLANT
disgr like marc-disgr, " MRP GROUP
dismm like marc-dismm, " MRP TYPE
dispo like marc-dispo, " MRP CONTROLLER
end of i_marc.


data: begin of i_output occurs 0,
matnr like mara-matnr, " MATERIAL NUMBER
mbrsh like mara-mbrsh, " INDUSTRY SECTOR
mtart like mara-mtart, " Material type
meins like mara-meins, " BASE UNIT OF MEASURE
matkl like mara-matkl, " MATERIAL GROUP
werks like marc-werks, " PLANT
mmsta like marc-mmsta, " PLANT-SPECIFIC MATERIAL STATUS
awsls like marc-awsls, " VARIANCE KEY
prctr like marc-prctr, " PROFIT CENTER
losgr like marc-losgr, " LOT SIZE OF PRODUCT COSTING
disgr like marc-disgr, " MRP GROUP
maabc like marc-maabc, " ABC ANALYSIS
dismm like marc-dismm, " MRP TYPE
dispo like marc-dispo, " MRP CONTROLLER
maktx like makt-maktx, " MATERIAL DESCRIPTION
lgort like mard-lgort, " STORAGE LOCATION
labst like mard-labst, " STOCK QUANTITY
vkorg like mvke-vkorg, " SALES ORGANISATION
y type i,
end of i_output.


data: begin of i_mard occurs 0,
matnr like mard-matnr, "MATERIAL NUMBER
lgort like mard-lgort, "STORAGE LOCATION
labst like mard-labst, "STOCK QUANTITY
end of i_mard.

data: begin of i_mvke occurs 0,
matnr like mvke-matnr, "MATERIAL NUMBER
vkorg like mvke-vkorg, "SALES ORGANIZATION
end of i_mvke.

*&--------------------------------------------------------------------*
* START OF SELECTION
*&--------------------------------------------------------------------*



selection-screen begin of block b1 with frame title text-001.

select-options: s_matnr for marc-matnr.
parameter : p_werks like marc-werks obligatory.

select-options: s_lgort for mard-lgort,
s_dispo for marc-dispo.

selection-screen end of block b1.

*&--------------------------------------------------------------------*
* INITIALIZATION.
*&--------------------------------------------------------------------*

initialization.

  p_werks = '1200'.
  s_matnr-sign = 'I'.
  s_matnr-option = 'EQ'.
  s_matnr-low = 'M-14'.
  s_matnr-high = 'M-18'.
  s_lgort-sign = 'I'.
  s_lgort-option = 'BT'.
  s_lgort-low = '0001'.
  s_lgort-high = '0007'.
  s_dispo-sign = 'I'.
  s_dispo-option = 'EQ'.
  s_dispo-low = '001'.
  s_dispo-high = '005'.

  append s_matnr.
  append s_lgort.
  append s_dispo.
  clear s_matnr.
  clear s_lgort.
  clear s_dispo.

*&--------------------------------------------------------------------*
* START OF SELECTION
*&--------------------------------------------------------------------*



start-of-selection.

  select matnr werks disgr dismm dispo
  from marc
  into corresponding fields of table i_marc
  where matnr in s_matnr
  and dispo in s_dispo
  and werks = p_werks.


  if i_marc[] is initial.
    write:/ 'NO DATA IS SELECTED FOR DISPLAY from MARC'.
    exit.
  endif.

  select matnr lgort labst from mard into table i_mard
  for all entries in i_marc
  where matnr = i_marc-matnr
  and werks = p_werks.


  if i_mard[] is initial.
    write:/ 'NO DATA IS SELECTED FOR DISPLAY from MARD'.
    exit.
  endif.

  select matnr vkorg
  from mvke
  into table i_mvke for all entries in i_marc
  where matnr = i_marc-matnr.


  loop at i_marc.
    move-corresponding i_marc to i_output.
    clear marc.


    select single matnr mbrsh mtart meins matkl
    from mara
    into corresponding fields of mara
    where matnr = i_output-matnr.

    if sy-subrc = 0.
      move-corresponding mara to i_output.
    else.
      continue.
    endif.

    select single matnr maktx
    from makt
    into corresponding fields of makt
    where matnr = i_output-matnr
    and spras = sy-langu.


    if sy-subrc = 0.
      move-corresponding makt to i_output.
    endif.


    loop at i_mvke where matnr = i_marc-matnr.
      move i_mvke-vkorg to i_output-vkorg.
      append i_output.
    endloop.



    loop at i_mard where matnr = i_marc-matnr.

      move: i_mard-labst to i_output-labst,
      i_mard-lgort to i_output-lgort.


      append i_output.
    endloop.
    clear i_output.

    x = i_output-matnr .
    add x to y.

  endloop.

  data: t_sort type slis_t_sortinfo_alv.
  data: s_sort like line of t_sort.


  data: wa_sortinfo type slis_sortinfo_alv,
  i_sortcat type slis_t_sortinfo_alv.

  data: v_fieldcatlog type slis_fieldcat_alv,
  gd_tab_group type slis_t_sp_group_alv,
  gd_layout type slis_layout_alv,
  gd_repid like sy-repid.


  perform build_fieldcatalog.
  perform build_layout.
  perform sortcat_init changing i_sortcat.
  perform display_alv_report.


*---------------------------------------------------------------------*
*       FORM build_fieldcatalog                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form build_fieldcatalog.

  v_fieldcatlog-col_pos = '1'.
  v_fieldcatlog-fieldname = 'MATNR'.
  v_fieldcatlog-seltext_m = 'MATERIAL NUMBER '.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'MATNR'.
  v_fieldcatlog-ref_tabname = 'MARC'.
  v_fieldcatlog-do_sum = 'X'.

  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '2'.
  v_fieldcatlog-fieldname = 'WERKS'.
  v_fieldcatlog-seltext_m = 'PLANT '.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'WERKS'.
  v_fieldcatlog-ref_tabname = 'MARC'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '3'.
  v_fieldcatlog-fieldname = 'DISPO'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'DISPO'.
  v_fieldcatlog-ref_tabname = 'MARC'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '4'.
  v_fieldcatlog-fieldname = 'MBRSH'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'MBRSH'.
  v_fieldcatlog-ref_tabname = 'MARA'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '5'.
  v_fieldcatlog-fieldname = 'MEINS'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'MEINS'.
  v_fieldcatlog-ref_tabname = 'MARA'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.

  v_fieldcatlog-col_pos = '6'.
  v_fieldcatlog-fieldname = 'MATKL'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'MATKL'.
  v_fieldcatlog-ref_tabname = 'MARA'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '7'.
  v_fieldcatlog-fieldname = 'VKORG'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'VKORG'.
  v_fieldcatlog-ref_tabname = 'MVKE'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


*  v_fieldcatlog-col_pos = '8'.
*  v_fieldcatlog-fieldname = 'VTWEG'.
**  v_fieldcatlog-tabname = 'I_OUT'.
*  v_fieldcatlog-ref_fieldname = 'VTWEG'.
*  v_fieldcatlog-ref_tabname = 'MVKE'.
*  append v_fieldcatlog to vt_fieldcatlog1.
*  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '9'.
  v_fieldcatlog-fieldname = 'MAKTX'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'MAKTX'.
  v_fieldcatlog-ref_tabname = 'MAKT'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '11'.
  v_fieldcatlog-fieldname = 'LGORT'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'LGORT'.
  v_fieldcatlog-ref_tabname = 'MARD'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.


  v_fieldcatlog-col_pos = '10'.
  v_fieldcatlog-fieldname = 'LABST'.
  v_fieldcatlog-tabname = 'I_OUTPUT'.
  v_fieldcatlog-ref_fieldname = 'LABST'.
  v_fieldcatlog-ref_tabname = 'MARD'.
  v_fieldcatlog-hotspot = 'X'.

  v_fieldcatlog-do_sum = 'X'.
  append v_fieldcatlog to vt_fieldcatlog1.
  clear v_fieldcatlog.
endform.

*---------------------------------------------------------------------*
*       FORM build_layout                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text = 'TOTALS'(201).
endform.




*&---------------------------------------------------------------------*
* ALV PROCESS
*&---------------------------------------------------------------------*

*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
* EXPORTING
* i_program_name = sy-repid
* i_internal_tabname = 'I_OUTPUT'
* i_client_never_display = 'X'
* i_inclname = sy-repid
* CHANGING
* ct_fieldcat = vt_fieldcat.
* .
* IF sy-subrc <> 0.
* ENDIF.

form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program = gd_repid
            is_layout          = gd_layout
            it_fieldcat        = vt_fieldcatlog1[]
            it_sort            = i_sortcat
            i_save             = 'X'
       tables
            t_outtab           = i_output
       exceptions
            program_error      = 1
            others             = 2.

  if sy-subrc <> 0.
  endif.
endform. " DISPLAY_ALV_REPORT




*---------------------------------------------------------------------*
*       FORM sortcat_init                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  I_SORTCAT                                                     *
*---------------------------------------------------------------------*
form sortcat_init changing i_sortcat type slis_t_sortinfo_alv.

  clear wa_sortinfo.
  wa_sortinfo-fieldname = 'MATNR'.
  wa_sortinfo-tabname = 'I_OUTPUT'.
  wa_sortinfo-spos = 1. " First sort by this field.
  wa_sortinfo-up = 'X'. " Ascending
  wa_sortinfo-subtot = 'X'. " Subtotal at Name1
  append wa_sortinfo to i_sortcat.

*  clear wa_sortinfo.
*  wa_sortinfo-fieldname = 'LABST'.
*  wa_sortinfo-tabname = 'I_OUTPUT'.
*  wa_sortinfo-spos = 2. " Sec sort by this field.
*  wa_sortinfo-up = 'X'. " Ascending
*  wa_sortinfo-subtot = 'X'. " Subtotal at Name1
*  append wa_sortinfo to i_sortcat.

endform. " sortcat_init

*&--------------------------------------------------------------------*
*& ALV Form top-of-page
*&--------------------------------------------------------------------*

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.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header
            i_logo             = 'ENJOYSAP_LOGO'.

endform. " top-of-page

*&--------------------------------------------------------------------*
*& END-OF-SELECTION.
*&--------------------------------------------------------------------*


end-of-selection.

end-of-page.
  uline .
  write : sy-pagno.

Regards,

Rich Heilman

0 Kudos

Also, since VTWEG is not in your internal table, I also commented the part where you are adding this field to the field catalog.

Regards,

Rich Heilman

0 Kudos

hi rich

i have tried code after modifications u have suggested,i am getting out put,but i am getting two subtotals for every material,what we can do any suggestions.

thanks and regard

satya

Former Member
0 Kudos

Hi,

Check this modified code..THis works fine for me...Changes are marked in bold..

TYPE-POOLS: SLIS. " ALL THE DEFINATIONS INTERNAL TABLES STRUCTURES AND

" CONSTANTS ARE DECLARED IN TYPE-POOL CALLED SLIS

DATA: VT_FIELDCATLOG1 TYPE SLIS_T_FIELDCAT_ALV. " THIS INTERNAL TABLE

" CONTAINS THE FIELD

" ATTRIBUTES

DATA:X TYPE I,Y TYPE I,a type i,b type i.

&----


  • TABLE DECLARATION

&----


TABLES: marc, " PLANT DATA

mara, " GENERAL MATERIAL DATA

mbew, " MATERIAL VALUATION

mard, " CURRENT INVENTORY

makt, " MATERIAL DESCRIPTION

mvke. " SALES DATA FOR MATERIAL

&----


  • INTERNAL TABLE DECLARATION

&----


DATA: BEGIN OF i_marc OCCURS 0, " PLANT DATA

matnr LIKE marc-matnr, " MATERIAL NUMBER

werks LIKE marc-werks, " PLANT

disgr LIKE marc-disgr, " MRP GROUP

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

END OF i_marc.

DATA: BEGIN OF i_output OCCURS 0,

matnr LIKE mara-matnr, " MATERIAL NUMBER

mbrsh LIKE mara-mbrsh, " INDUSTRY SECTOR

mtart LIKE mara-mtart, " Material type

meins LIKE mara-meins, " BASE UNIT OF MEASURE

matkl LIKE mara-matkl, " MATERIAL GROUP

werks LIKE marc-werks, " PLANT

mmsta LIKE marc-mmsta, " PLANT-SPECIFIC MATERIAL STATUS

awsls LIKE marc-awsls, " VARIANCE KEY

prctr LIKE marc-prctr, " PROFIT CENTER

losgr LIKE marc-losgr, " LOT SIZE OF PRODUCT COSTING

disgr LIKE marc-disgr, " MRP GROUP

maabc LIKE marc-maabc, " ABC ANALYSIS

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

maktx LIKE makt-maktx, " MATERIAL DESCRIPTION

lgort LIKE mard-lgort, " STORAGE LOCATION

labst LIKE mard-labst, " STOCK QUANTITY

vkorg LIKE mvke-vkorg, " SALES ORGANISATION

Y TYPE I,

END OF i_output.

DATA: BEGIN OF i_mard OCCURS 0,

matnr LIKE mard-matnr, "MATERIAL NUMBER

lgort LIKE mard-lgort, "STORAGE LOCATION

labst LIKE mard-labst, "STOCK QUANTITY

END OF i_mard.

DATA: BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr, "MATERIAL NUMBER

vkorg LIKE mvke-vkorg, "SALES ORGANIZATION

END OF i_mvke.

&----


  • START OF SELECTION

&----


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

SELECT-OPTIONS: s_matnr FOR marc-matnr.

PARAMETER : p_werks LIKE marc-werks OBLIGATORY.

SELECT-OPTIONS: s_lgort FOR mard-lgort,

s_dispo FOR marc-dispo.

SELECTION-SCREEN END OF BLOCK b1.

&----


  • INITIALIZATION.

&----


INITIALIZATION.

p_werks = '1200'.

s_matnr-sign = 'I'.

s_matnr-option = 'EQ'.

s_matnr-low = 'M-14'.

s_matnr-high = 'M-18'.

s_lgort-sign = 'I'.

s_lgort-option = 'BT'.

s_lgort-low = '0001'.

s_lgort-high = '0007'.

s_dispo-sign = 'I'.

s_dispo-option = 'EQ'.

s_dispo-low = '001'.

s_dispo-high = '005'.

APPEND s_matnr.

APPEND s_lgort.

APPEND s_dispo.

CLEAR s_matnr.

CLEAR s_lgort.

CLEAR s_dispo.

&----


  • START OF SELECTION

&----


START-OF-SELECTION.

SELECT matnr werks disgr dismm dispo

FROM marc

INTO CORRESPONDING FIELDS OF TABLE i_marc

WHERE matnr IN s_matnr

AND dispo IN s_dispo

AND werks = p_werks.

IF i_marc[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARC'.

EXIT.

ENDIF.

SELECT matnr lgort labst FROM mard INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks = p_werks.

IF i_mard[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARD'.

EXIT.

ENDIF.

SELECT matnr vkorg

FROM mvke

INTO table i_mvke for all entries in I_marc

WHERE matnr = i_marc-matnr.

LOOP AT i_marc.

MOVE-CORRESPONDING i_marc TO i_output.

CLEAR marc.

SELECT SINGLE matnr mbrsh mtart meins matkl

FROM mara

INTO CORRESPONDING FIELDS OF mara

WHERE matnr = i_output-matnr.

IF sy-subrc = 0.

MOVE-CORRESPONDING mara TO i_output.

ELSE.

CONTINUE.

ENDIF.

SELECT SINGLE matnr maktx

FROM makt

INTO CORRESPONDING FIELDS OF makt

WHERE matnr = i_output-matnr

AND spras = SY-LANGU.

IF sy-subrc = 0.

MOVE-CORRESPONDING makt TO i_output.

ENDIF.

LOOP AT i_mvke WHERE matnr = i_marc-matnr.

MOVE i_mvke-vkorg TO i_output-vkorg.

APPEND i_output.

ENDLOOP.

LOOP AT i_mard WHERE matnr = i_marc-matnr.

MOVE: i_mard-labst TO i_output-labst,

i_mard-lgort TO i_output-lgort.

APPEND i_output.

ENDLOOP.

CLEAR i_output.

X = i_output-MATNR .

ADD X TO Y.

ENDLOOP.

DATA: T_SORT TYPE slis_t_sortinfo_alv.

DATA: S_SORT like line of t_sort.

DATA: wa_sortinfo TYPE slis_sortinfo_alv,

i_sortcat TYPE slis_t_sortinfo_alv.

DATA: v_fieldcatlog TYPE SLIS_FIELDCAT_ALV,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

perform build_fieldcatalog.

perform build_layout.

PERFORM sortcat_init CHANGING i_sortcat.

<b>perform display_alv_report.</b>

FORM build_fieldcatalog.

v_fieldcatlog-col_pos = '1'.

v_fieldcatlog-fieldname = 'MATNR'.

v_fieldcatlog-seltext_m = 'MATERIAL NUMBER '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATNR'.

v_fieldcatlog-ref_tabname = 'MARC'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '2'.

v_fieldcatlog-fieldname = 'WERKS'.

v_fieldcatlog-seltext_m = 'PLANT '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'WERKS'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '3'.

v_fieldcatlog-fieldname = 'DISPO'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'DISPO'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '4'.

v_fieldcatlog-fieldname = 'MBRSH'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MBRSH'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '5'.

v_fieldcatlog-fieldname = 'MEINS'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MEINS'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '6'.

v_fieldcatlog-fieldname = 'MATKL'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATKL'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '7'.

v_fieldcatlog-fieldname = 'VKORG'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'VKORG'.

v_fieldcatlog-ref_tabname = 'MVKE'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

<b>*v_fieldcatlog-col_pos = '8'.

*v_fieldcatlog-fieldname = 'VTWEG'.

*v_fieldcatlog-tabname = 'I_OUT'.

*v_fieldcatlog-ref_fieldname = 'VTWEG'.

*v_fieldcatlog-ref_tabname = 'MVKE'.

*APPEND v_fieldcatlog TO vt_fieldcatlog1.

*CLEAR v_fieldcatlog.</b>

v_fieldcatlog-col_pos = '9'.

v_fieldcatlog-fieldname = 'MAKTX'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MAKTX'.

v_fieldcatlog-ref_tabname = 'MAKT'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '11'.

v_fieldcatlog-fieldname = 'LGORT'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LGORT'.

v_fieldcatlog-ref_tabname = 'MARD'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '10'.

v_fieldcatlog-fieldname = 'LABST'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LABST'.

v_fieldcatlog-ref_tabname = 'MARD'.

v_fieldcatlog-hotspot = 'X'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

ENDFORM.

FORM build_layout.

gd_layout-NO_INPUT = 'X'.

gd_layout-colwidth_optimize = 'X'.

GD_LAYOUT-TOTALS_TEXT = 'TOTALS'(201).

ENDFORM.

&----


  • ALV PROCESS

&----


*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

  • EXPORTING

  • i_program_name = sy-repid

  • i_internal_tabname = 'I_OUTPUT'

  • i_client_never_display = 'X'

  • i_inclname = sy-repid

  • CHANGING

  • ct_fieldcat = vt_fieldcat.

  • .

  • IF sy-subrc <> 0.

  • ENDIF.

form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

is_layout = gd_layout

it_fieldcat = vt_fieldcatlog1[]

it_sort = i_sortcat

i_save = 'X'

tables

t_outtab = I_OUTPUT

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

endif.

endform. " DISPLAY_ALV_REPORT

FORM sortcat_init CHANGING i_sortcat TYPE slis_t_sortinfo_alv.

CLEAR wa_sortinfo.

<b>wa_sortinfo-fieldname = 'MATNR'.</b>

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 1. " First sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

ENDFORM. " sortcat_init

&----


*& ALV Form top-of-page

&----


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.

call function 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header

i_logo = 'ENJOYSAP_LOGO'.

endform. " top-of-page

&----


*& END-OF-SELECTION.

&----


END-OF-SELECTION.

END-OF-PAGE.

ULINE .

WRITE : SY-PAGNO.

Thanks,

Naren

0 Kudos

hi naren

i have tried code after modifications u have suggested,i am getting out put,but i am getting two subtotals for every material,i need single subtotal for every material,what we can do any suggestions.

thanks and regard

satya

Former Member
0 Kudos

Hi,

Try this code..I removed the APPEND statement within the LOOP AT i_mvke

TYPE-POOLS: SLIS. " ALL THE DEFINATIONS INTERNAL TABLES STRUCTURES AND

" CONSTANTS ARE DECLARED IN TYPE-POOL CALLED SLIS

DATA: VT_FIELDCATLOG1 TYPE SLIS_T_FIELDCAT_ALV. " THIS INTERNAL TABLE

" CONTAINS THE FIELD

" ATTRIBUTES

DATA:X TYPE I,Y TYPE I,a type i,b type i.

&----


  • TABLE DECLARATION

&----


TABLES: marc, " PLANT DATA

mara, " GENERAL MATERIAL DATA

mbew, " MATERIAL VALUATION

mard, " CURRENT INVENTORY

makt, " MATERIAL DESCRIPTION

mvke. " SALES DATA FOR MATERIAL

&----


  • INTERNAL TABLE DECLARATION

&----


DATA: BEGIN OF i_marc OCCURS 0, " PLANT DATA

matnr LIKE marc-matnr, " MATERIAL NUMBER

werks LIKE marc-werks, " PLANT

disgr LIKE marc-disgr, " MRP GROUP

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

END OF i_marc.

DATA: BEGIN OF i_output OCCURS 0,

matnr LIKE mara-matnr, " MATERIAL NUMBER

mbrsh LIKE mara-mbrsh, " INDUSTRY SECTOR

mtart LIKE mara-mtart, " Material type

meins LIKE mara-meins, " BASE UNIT OF MEASURE

matkl LIKE mara-matkl, " MATERIAL GROUP

werks LIKE marc-werks, " PLANT

mmsta LIKE marc-mmsta, " PLANT-SPECIFIC MATERIAL STATUS

awsls LIKE marc-awsls, " VARIANCE KEY

prctr LIKE marc-prctr, " PROFIT CENTER

losgr LIKE marc-losgr, " LOT SIZE OF PRODUCT COSTING

disgr LIKE marc-disgr, " MRP GROUP

maabc LIKE marc-maabc, " ABC ANALYSIS

dismm LIKE marc-dismm, " MRP TYPE

dispo LIKE marc-dispo, " MRP CONTROLLER

maktx LIKE makt-maktx, " MATERIAL DESCRIPTION

lgort LIKE mard-lgort, " STORAGE LOCATION

labst LIKE mard-labst, " STOCK QUANTITY

vkorg LIKE mvke-vkorg, " SALES ORGANISATION

Y TYPE I,

END OF i_output.

DATA: BEGIN OF i_mard OCCURS 0,

matnr LIKE mard-matnr, "MATERIAL NUMBER

lgort LIKE mard-lgort, "STORAGE LOCATION

labst LIKE mard-labst, "STOCK QUANTITY

END OF i_mard.

DATA: BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr, "MATERIAL NUMBER

vkorg LIKE mvke-vkorg, "SALES ORGANIZATION

END OF i_mvke.

&----


  • START OF SELECTION

&----


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

SELECT-OPTIONS: s_matnr FOR marc-matnr.

PARAMETER : p_werks LIKE marc-werks OBLIGATORY.

SELECT-OPTIONS: s_lgort FOR mard-lgort,

s_dispo FOR marc-dispo.

SELECTION-SCREEN END OF BLOCK b1.

&----


  • INITIALIZATION.

&----


INITIALIZATION.

p_werks = '1200'.

s_matnr-sign = 'I'.

s_matnr-option = 'EQ'.

s_matnr-low = 'M-14'.

s_matnr-high = 'M-18'.

s_lgort-sign = 'I'.

s_lgort-option = 'BT'.

s_lgort-low = '0001'.

s_lgort-high = '0007'.

s_dispo-sign = 'I'.

s_dispo-option = 'EQ'.

s_dispo-low = '001'.

s_dispo-high = '005'.

APPEND s_matnr.

APPEND s_lgort.

APPEND s_dispo.

CLEAR s_matnr.

CLEAR s_lgort.

CLEAR s_dispo.

&----


  • START OF SELECTION

&----


START-OF-SELECTION.

SELECT matnr werks disgr dismm dispo

FROM marc

INTO CORRESPONDING FIELDS OF TABLE i_marc

WHERE matnr IN s_matnr

AND dispo IN s_dispo

AND werks = p_werks.

IF i_marc[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARC'.

EXIT.

ENDIF.

SELECT matnr lgort labst FROM mard INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks = p_werks.

IF i_mard[] IS INITIAL.

WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARD'.

EXIT.

ENDIF.

SELECT matnr vkorg

FROM mvke

INTO table i_mvke for all entries in I_marc

WHERE matnr = i_marc-matnr.

LOOP AT i_marc.

MOVE-CORRESPONDING i_marc TO i_output.

CLEAR marc.

SELECT SINGLE matnr mbrsh mtart meins matkl

FROM mara

INTO CORRESPONDING FIELDS OF mara

WHERE matnr = i_output-matnr.

IF sy-subrc = 0.

MOVE-CORRESPONDING mara TO i_output.

ELSE.

CONTINUE.

ENDIF.

SELECT SINGLE matnr maktx

FROM makt

INTO CORRESPONDING FIELDS OF makt

WHERE matnr = i_output-matnr

AND spras = SY-LANGU.

IF sy-subrc = 0.

MOVE-CORRESPONDING makt TO i_output.

ENDIF.

LOOP AT i_mvke WHERE matnr = i_marc-matnr.

MOVE i_mvke-vkorg TO i_output-vkorg.

ENDLOOP.

LOOP AT i_mard WHERE matnr = i_marc-matnr.

MOVE: i_mard-labst TO i_output-labst,

i_mard-lgort TO i_output-lgort.

APPEND i_output.

ENDLOOP.

CLEAR i_output.

X = i_output-MATNR .

ADD X TO Y.

ENDLOOP.

DATA: T_SORT TYPE slis_t_sortinfo_alv.

DATA: S_SORT like line of t_sort.

DATA: wa_sortinfo TYPE slis_sortinfo_alv,

i_sortcat TYPE slis_t_sortinfo_alv.

DATA: v_fieldcatlog TYPE SLIS_FIELDCAT_ALV,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

perform build_fieldcatalog.

perform build_layout.

PERFORM sortcat_init CHANGING i_sortcat.

perform display_alv_report.

FORM build_fieldcatalog.

v_fieldcatlog-col_pos = '1'.

v_fieldcatlog-fieldname = 'MATNR'.

v_fieldcatlog-seltext_m = 'MATERIAL NUMBER '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATNR'.

v_fieldcatlog-ref_tabname = 'MARC'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '2'.

v_fieldcatlog-fieldname = 'WERKS'.

v_fieldcatlog-seltext_m = 'PLANT '.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'WERKS'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '3'.

v_fieldcatlog-fieldname = 'DISPO'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'DISPO'.

v_fieldcatlog-ref_tabname = 'MARC'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '4'.

v_fieldcatlog-fieldname = 'MBRSH'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MBRSH'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '5'.

v_fieldcatlog-fieldname = 'MEINS'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MEINS'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '6'.

v_fieldcatlog-fieldname = 'MATKL'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MATKL'.

v_fieldcatlog-ref_tabname = 'MARA'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '7'.

v_fieldcatlog-fieldname = 'VKORG'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'VKORG'.

v_fieldcatlog-ref_tabname = 'MVKE'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

*v_fieldcatlog-col_pos = '8'.

*v_fieldcatlog-fieldname = 'VTWEG'.

*v_fieldcatlog-tabname = 'I_OUT'.

*v_fieldcatlog-ref_fieldname = 'VTWEG'.

*v_fieldcatlog-ref_tabname = 'MVKE'.

*APPEND v_fieldcatlog TO vt_fieldcatlog1.

*CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '9'.

v_fieldcatlog-fieldname = 'MAKTX'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'MAKTX'.

v_fieldcatlog-ref_tabname = 'MAKT'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '11'.

v_fieldcatlog-fieldname = 'LGORT'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LGORT'.

v_fieldcatlog-ref_tabname = 'MARD'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

v_fieldcatlog-col_pos = '10'.

v_fieldcatlog-fieldname = 'LABST'.

v_fieldcatlog-tabname = 'I_OUT'.

v_fieldcatlog-ref_fieldname = 'LABST'.

v_fieldcatlog-ref_tabname = 'MARD'.

v_fieldcatlog-hotspot = 'X'.

v_FIELDCATLOG-DO_SUM = 'X'.

APPEND v_fieldcatlog TO vt_fieldcatlog1.

CLEAR v_fieldcatlog.

ENDFORM.

FORM build_layout.

gd_layout-NO_INPUT = 'X'.

gd_layout-colwidth_optimize = 'X'.

GD_LAYOUT-TOTALS_TEXT = 'TOTALS'(201).

ENDFORM.

&----


  • ALV PROCESS

&----


*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

  • EXPORTING

  • i_program_name = sy-repid

  • i_internal_tabname = 'I_OUTPUT'

  • i_client_never_display = 'X'

  • i_inclname = sy-repid

  • CHANGING

  • ct_fieldcat = vt_fieldcat.

  • .

  • IF sy-subrc <> 0.

  • ENDIF.

form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

is_layout = gd_layout

it_fieldcat = vt_fieldcatlog1[]

it_sort = i_sortcat

i_save = 'X'

tables

t_outtab = I_OUTPUT

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

endif.

endform. " DISPLAY_ALV_REPORT

FORM sortcat_init CHANGING i_sortcat TYPE slis_t_sortinfo_alv.

CLEAR wa_sortinfo.

wa_sortinfo-fieldname = 'MATNR'.

wa_sortinfo-tabname = 'I_OUTPUT'.

wa_sortinfo-spos = 1. " First sort by this field.

wa_sortinfo-up = 'X'. " Ascending

wa_sortinfo-subtot = 'X'. " Subtotal at Name1

APPEND wa_sortinfo TO i_sortcat.

ENDFORM. " sortcat_init

&----


*& ALV Form top-of-page

&----


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.

call function 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header

i_logo = 'ENJOYSAP_LOGO'.

endform. " top-of-page

&----


*& END-OF-SELECTION.

&----


END-OF-SELECTION.

END-OF-PAGE.

ULINE .

WRITE : SY-PAGNO.

Thanks,

Naren

0 Kudos

hi naren

thank u ,atlast i got it.

thanks and regard

satya