Skip to Content
0
Former Member
Nov 07, 2012 at 11:14 AM

Amount is repeating in a zreport

28 Views

I have written a report for stockdetails .In this report the amount field is repeating .It is displaying the first value for all.

*&---------------------------------------------------------------------*
*& Report YSTOCK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT YSTOCK.
TABLES:MARD,MARC,MAKT.
TYPE-POOLS:SLIS.

DATA : FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
* WA_FIELDCAT TYPE slis_fieldcat_alv .

DATA: 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.


TYPES: BEGIN OF TY_MARD,
MATNR LIKE MARD-MATNR,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
VERPR TYPE MBEW-VERPR,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARD.

TYPES: BEGIN OF TY_MBEW,
MATNR LIKE MBEW-MATNR,
VERPR LIKE MBEW-VERPR,
END OF TY_MBEW.

TYPES:BEGIN OF TY_MAKT,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF TY_MAKT.

DATA:WA_FINAL TYPE TY_MARD,
IT_FINAL TYPE TABLE OF TY_MARD.

DATA:WA_MBEW TYPE TY_MBEW,
IT_MBEW TYPE TABLE OF TY_MBEW.

DATA:WA_MAKT TYPE TY_MAKT,
IT_MAKT TYPE TABLE OF TY_MAKT.

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS S_MATNR FOR MARD-MATNR.
SELECT-OPTIONS S_PLANT FOR MARD-WERKS.
SELECT-OPTIONS S_LGORT FOR MARD-LGORT.
SELECTION-SCREEN END OF BLOCK BLK1.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.
PERFORM DATA_RETRIEVAL1.
PERFORM DATA_RETRIEVAL2.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.
PERFORM BUILD_EVENTS.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL .
SELECT MATNR WERKS LGORT LABST
FROM MARD INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
WHERE MATNR IN S_MATNR
AND WERKS IN S_PLANT
AND LGORT IN S_LGORT.
ENDFORM. " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL1 .
IF NOT IT_FINAL IS INITIAL.
SELECT MATNR VERPR FROM MBEW
INTO CORRESPONDING FIELDS OF TABLE IT_MBEW
FOR ALL ENTRIES IN IT_FINAL
WHERE MATNR = IT_FINAL-MATNR.
ENDIF.

LOOP AT IT_FINAL INTO WA_FINAL.
READ TABLE IT_MBEW INTO WA_MBEW WITH KEY MATNR = WA_FINAL-MATNR.
IF SY-SUBRC EQ 0.
WA_FINAL-VERPR = WA_MBEW-VERPR.

MODIFY IT_FINAL FROM WA_FINAL.
ENDIF.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL1
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL2 .

ENDFORM. " DATA_RETRIEVAL2
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .

FIELDCATALOG-FIELDNAME = 'MATNR'. " field Name
FIELDCATALOG-SELTEXT_M = 'MATERIAL NO'. " Field heading
FIELDCATALOG-COL_POS = 0. " col position
FIELDCATALOG-OUTPUTLEN = 10. " output Lenght
FIELDCATALOG-EMPHASIZE = 'X'. " Emphasize (highlight columns in color)
*fieldcatalog-key = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.



FIELDCATALOG-FIELDNAME = 'WERKS'. " field Name
FIELDCATALOG-SELTEXT_M = 'PLANT'. " Field heading
FIELDCATALOG-COL_POS = 1. " col position
FIELDCATALOG-OUTPUTLEN = 10. " output Lenght
*fieldcatalog-emphasize = 'X'. " Emphasize (highlight columns in color)
*fieldcatalog-key = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.



FIELDCATALOG-FIELDNAME = 'LGORT'. " field Name
FIELDCATALOG-SELTEXT_M = 'STORAGE LOC'. " Field heading
FIELDCATALOG-COL_POS = 2. " col position
FIELDCATALOG-OUTPUTLEN = 25. " output Lenght
*fieldcatalog-emphasize = 'X'. " Emphasize (highlight columns in color)
*fieldcatalog-key = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.


FIELDCATALOG-FIELDNAME = 'LABST'. " field Name
FIELDCATALOG-SELTEXT_M = 'CLOSING STCK'. " Field heading
FIELDCATALOG-COL_POS = 3. " col position
FIELDCATALOG-OUTPUTLEN = 10. " output Lenght
FIELDCATALOG-EMPHASIZE = 'X'. " Emphasize (highlight columns in color)
*fieldcatalog-key = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.



FIELDCATALOG-FIELDNAME = 'VERPR'. " field Name
FIELDCATALOG-SELTEXT_M = 'AMOUNT'. " Field heading
FIELDCATALOG-COL_POS = 4. " col position
FIELDCATALOG-OUTPUTLEN = 10. " output Lenght
*fieldcatalog-emphasize = 'X'. " Emphasize (highlight columns in color)
*fieldcatalog-key = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.




ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
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-ZEBRA = 'X'.
* gd_layout-group_change_edit = 'X'.
ENDFORM. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form BUILD_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
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_USER_COMMAND
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE SLIS_EV_USER_COMMAND TO LS_EVENT-FORM.
APPEND LS_EVENT TO GT_EVENTS.
ENDIF.
READ TABLE GT_EVENTS
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE SLIS_EV_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO GT_EVENTS.
ENDIF.
ENDFORM. " BUILD_EVENTS
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
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 = 'A'
I_DEFAULT = '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 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 = 'STOCK DETAILS'.

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.


DESCRIBE TABLE IT_FINAL LINES LD_LINES.


* describe table wa_eban 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 = 'ZSHIV_LOGO'."'ZSHIV_LOGO'.




ENDFORM. " DISPLAY_ALV_REPORT