Google Search - Blog...........

ABAP - ALV Heading At Center & At The End Of Page.

report.
TABLES VBAK.
TYPE-POOLS SLIS.

*Data Declaration
TYPES: BEGIN OF T_VBAK,
VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
ERNAM TYPE VBAK-ERNAM,
AUDAT TYPE VBAK-AUDAT,
VBTYP TYPE VBAK-VBTYP,
NETWR TYPE VBAK-NETWR,
VKORG TYPE VBAK-VKORG,
VKGRP TYPE VBAK-VKGRP,
END OF T_VBAK.

DATA IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0.


*ALV Data Declaration
DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
W_FLDCAT TYPE SLIS_FIELDCAT_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID TYPE SY-REPID.

DATA: DATE1(10).

SELECT-OPTIONS: VBELN FOR VBAK-VBELN.

START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BLD_FLDCAT.
PERFORM BLD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.


*Build Field Catalog for ALV Report
FORM BLD_FLDCAT.

W_FLDCAT-FIELDNAME = 'VBELN'.
W_FLDCAT-SELTEXT_M = 'Sales_Document'.
W_FLDCAT-COL_POS = 0.
W_FLDCAT-OUTPUTLEN = 15.
W_FLDCAT-KEY = 'X'.
W_FLDCAT-ICON = 'X'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'ERDAT'.
W_FLDCAT-SELTEXT_L = 'Record_Date_created'.
W_FLDCAT-COL_POS = 1.
W_FLDCAT-KEY = 'X'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'ERNAM'.
W_FLDCAT-SELTEXT_L = 'Cteated_Person_Name'.
W_FLDCAT-COL_POS = 2.
W_FLDCAT-EMPHASIZE = 'C011'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'AUDAT'.
W_FLDCAT-SELTEXT_M = 'Document_Date'.
W_FLDCAT-COL_POS = 3.
W_FLDCAT-EMPHASIZE = 'C110'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'VBTYP'.
W_FLDCAT-SELTEXT_L = 'SDDocument_category'.
W_FLDCAT-COL_POS = 4.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'NETWR'.
W_FLDCAT-SELTEXT_L = 'Net_Value'.
W_FLDCAT-COL_POS = 5.
W_FLDCAT-OUTPUTLEN = 10.
W_FLDCAT-DO_SUM = 'X'.
W_FLDCAT-DATATYPE = 'CURR'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'VKORG'.
W_FLDCAT-SELTEXT_L = 'Sales_Organization'.
W_FLDCAT-COL_POS = 6.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

W_FLDCAT-FIELDNAME = 'VKGRP'.
W_FLDCAT-SELTEXT_M = 'Sales_Group'.
W_FLDCAT-COL_POS = 7.
W_FLDCAT-EMPHASIZE = 'C801'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.

ENDFORM.


*Build Layout for ALV Grid Report

FORM BLD_LAYOUT.
GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-BOX_FIELDNAME = 'VBELN'.
ENDFORM.


*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
IS_LAYOUT = GD_LAYOUT
I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE_SPLIT'
IT_FIELDCAT = FLDCAT[]
I_SAVE = 'X'
TABLES
T_OUTTAB = IT_VBAK
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC ne 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.


*Retrieve data from VBAK table and populate itab IT_VBAK
FORM DATA_RETRIEVAL.
SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG
FROM VBAK
INTO TABLE IT_VBAK
WHERE VBELN IN VBELN.
ENDFORM.

FORM TOP_OF_PAGE_SPLIT USING R_TOP TYPE REF TO CL_DD_DOCUMENT.

DATA: S_TAB TYPE SDYDO_TEXT_TABLE,
C_AREA TYPE REF TO CL_DD_AREA,
TEXT TYPE SDYDO_TEXT_ELEMENT.

TYPES: BEGIN OF TAB_TEXT,
TEXT TYPE SDYDO_TEXT_ELEMENT,
END OF TAB_TEXT.
DATA: I_TEXT TYPE TABLE OF TAB_TEXT.
DATA: W_TEXT TYPE TAB_TEXT.

CALL METHOD R_TOP->INITIALIZE_DOCUMENT.

CALL METHOD R_TOP->VERTICAL_SPLIT
EXPORTING
SPLIT_AREA = R_TOP
SPLIT_WIDTH = '70%'
IMPORTING
RIGHT_AREA = C_AREA.

CONCATENATE SY-DATUM+4(2) ' / ' SY-DATUM+6(2) ' / ' SY-DATUM(4) INTO DATE1.
CONCATENATE 'DATE' DATE1 INTO W_TEXT-TEXT SEPARATED BY ':'.
APPEND W_TEXT TO I_TEXT.

S_TAB[] = I_TEXT[].

CALL METHOD C_AREA->ADD_TEXT
EXPORTING
TEXT_TABLE = S_TAB
FIX_LINES = 'X'
SAP_FONTSIZE = CL_DD_DOCUMENT=>MEDIUM
SAP_EMPHASIS = CL_DD_DOCUMENT=>STRONG.

CALL METHOD R_TOP->ADD_GAP
EXPORTING
WIDTH = 60.

TEXT = 'REPORT HEADING'.
CALL METHOD R_TOP->ADD_TEXT
EXPORTING
TEXT = TEXT
SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->NEW_LINE.

TEXT = 'Report Subheading'.
CALL METHOD R_TOP->ADD_TEXT
EXPORTING
TEXT = TEXT
SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->NEW_LINE.

ENDFORM.


ALSO READ:

- ALV Blocked In HR ABAP.

- ALV With Some Columns In Bold Letters.

- ALV Data In Different Languages.

- ALV Hierarchical For Tables.


..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.



1 comment:

  1. Hello,, I'm newbie here, and i have copy-paste ur script :) for self learning.. thanks for sharing...
    But i have a question here, when we use "I_CALLBACK_HTML_TOP_OF_PAGE", why the header not show up in the print preview or printout..?
    Thanks..

    ReplyDelete