Skip to Content
0

ALV GRID and ALV List Header Headings Issue

Oct 19, 2016 at 08:01 AM

129

avatar image
A N

Dear Experts,

I am facing a problem which is explained below.
I have a report with the ALV GRID OUTPUT. It contains the header text as shown in the attached screenshot.
When I want to see the print preview of it. The Header text is not shown in LIST OUTPUT as it appears on GRID OUTPUT.

Other issue is I want to display 10 rows per page and want to get print. How to achieve this.


Please advice,

Thanks,
MAN

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Raymond Giuseppi
Oct 19, 2016 at 09:44 AM
0

You already build an instance of CL_DD_DOCUMENT in your I_CALLBACK_HTML_TOP_OF_PAGE form, do something similar in a I_CALLBACK_TOP_OF_PAGE form, you could even consider the method PRINT_DOCUMENT if you feel confident or use good old WRITE statements of course.

Regards,
Raymond

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Dear Raymond,

Thanks for your input on this.I am able to display the text as per my requirement.

Now, second issue is the page break that after 10 rows, page break should happen and page number counter should increase after 10 rows.

Please advice on this as well.

Thanks,

0

Read documentation of data element SLIS_CTRLS.

Hint: this data element is used in the SORT structure.

Regards,
Raymond

0
max bianchi Oct 19, 2016 at 08:28 AM
0

Hi

the printpreview is an ALV list, so you should manage the event top-of-list and/or top-of-page for writin

You should try to use a condition in order to break the page after 10 row (you could try to use a hidden field for the sorting)

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Dear Max,

Can you please share code for this. I tried at my level but unable to achieve it.

Below is my code :

*&---------------------------------------------------------------------*
*& Report Z_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

*REPORT Z_TEST.

REPORT ZALVTEST.
TABLES VBAK.
* type pools
TYPE-POOLS SLIS.
* types and internal tables
*Data Declaration
TYPES: BEGIN OF T_VBAK,
PAGEBRK(5) TYPE n,
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,
w_vbak like LINE OF it_vbak.

*ALV Data Declaration
DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
W_FLDCAT TYPE SLIS_FIELDCAT_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV," OCCURS 0,
W_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID TYPE SY-REPID.
DATA: DATE1(10).

DATA:
T_SORT TYPE slis_sortinfo_alv occurs 1,
FS_SORT like line of t_sort.

*data: it_sortcat type slis_sortinfo_alv occurs 1,
* wa_sort like line of it_sortcat.

* selection screen design
SELECT-OPTIONS: VBELN FOR VBAK-VBELN.
* start of selection
START-OF-SELECTION.

SET PF-STATUS 'STATUS'.
*SET TITLEBAR 'MAIN'.

PERFORM DATA_RETRIEVAL.
PERFORM BLD_FLDCAT.
PERFORM BLD_LAYOUT.
PERFORM T_SORT USING 'VBELN' 'IT_VBAK' '' '*'.
* PERFORM T_SORT.
PERFORM DISPLAY_ALV_REPORT.

DATA: g_row TYPE lvc_s_row.


*-----------------------------------------------------------------------
* build catalog
*-----------------------------------------------------------------------
*Build Field Catalog for ALV Report
FORM BLD_FLDCAT.
W_FLDCAT-fieldname = 'PAGEBRK'.
W_FLDCAT-no_out = 'X'.
*W_FLDCAT-KEY = 'X'.
*W_FLDCAT-ICON = 'X'.
*W_FLDCAT-COL_POS = 0.
APPEND W_FLDCAT TO FLDCAT.

W_FLDCAT-FIELDNAME = 'VBELN'.
W_FLDCAT-SELTEXT_M = 'Sales_Document'.
W_FLDCAT-COL_POS = 1.
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 = 2.
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 = 3.
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 = 4.
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 = 5.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.
W_FLDCAT-FIELDNAME = 'NETWR'.
W_FLDCAT-SELTEXT_L = 'Net_Value'.
W_FLDCAT-COL_POS = 6.
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 = 7.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.
W_FLDCAT-FIELDNAME = 'VKGRP'.
W_FLDCAT-SELTEXT_M = 'Sales_Group'.
W_FLDCAT-COL_POS = 8.
W_FLDCAT-EMPHASIZE = 'C801'.
APPEND W_FLDCAT TO FLDCAT.
CLEAR W_FLDCAT.
ENDFORM. "BLD_FLDCAT
*-----------------------------------------------------------------------
* display fatalog
*-----------------------------------------------------------------------
"Build Layout for ALV Grid Report
FORM BLD_LAYOUT.
* GD_LAYOUT-NO_INPUT = 'X'.
* GD_LAYOUT-BOX_FIELDNAME = 'VBELN'.


Data: gv_title(70) type c.
GV_title+1(20) = 'First Title'.
gd_LAYOUT-window_titlebar = 'First Title'.
*APPEND GD_LAYOUT.

*gd_LAYOUT-window_titlebar+40(20) = 'Second Title'.
*gd_layout-window_titlebar = 'Second Title'. "GV_title.

*APPEND W_layout TO GD_LAYOUT.
ENDFORM. "BLD_LAYOUT



FORM T_SORT USING l_FIELD l_TABLE l_UP l_group.
DATA : L_POS TYPE I.

ADD 1 TO L_POS.
FS_SORT-SPOS = L_POS.
FS_SORT-FIELDNAME = 'VBELN'.
FS_SORT-TABNAME = 'IT_VBAK'.
FS_SORT-UP = 'X'.
FS_SORT-group = '*'.
APPEND FS_SORT to T_SORT.

data : l_tot(8) TYPE n,
l_lin(2) TYPE n,
l_pag(2) TYPE N.
BREAK IDADMIN.
SORT it_vbak by vbeln.
DESCRIBE TABLE it_vbak LINES l_tot.
l_lin = 15. "“ "Initial page record length.
l_pag = 1.
LOOP AT it_vbak INTO w_vbak.
IF sy-tabix LE l_tot.
IF sy-tabix LE l_lin.
w_vbak-pagebrk = l_pag.
MODIFY it_vbak FROM w_vbak INDEX sy-tabix
TRANSPORTING pagebrk.
ELSE.
l_lin = l_lin + 15. "“Break after 15 records.
l_pag = l_pag + 1.
w_vbak-pagebrk = l_pag.
MODIFY IT_VBAK FROM w_VBAK INDEX sy-tabix
TRANSPORTING pagebrk.
ENDIF.
ENDIF.
ENDLOOP.


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_SORT = T_SORT[]
IT_FIELDCAT = FLDCAT[]
TABLES
T_OUTTAB = IT_VBAK.
ENDFORM. "DISPLAY_ALV_REPORT
*-----------------------------------------------------------------------
* get data
*-----------------------------------------------------------------------
*Retrieve data from VBAK table and populate itab IT_VBAK
FORM DATA_RETRIEVAL.
break idadmin.
SELECT VBELN
ERDAT
ERNAM
AUDAT
VBTYP
NETWR
VKORG
FROM VBAK
INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
WHERE VBELN IN VBELN.
ENDFORM. "DATA_RETRIEVAL
*-----------------------------------------------------------------------
* build header for alv
*-----------------------------------------------------------------------
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.

DATA : V_PAGNO TYPE N.
* break idadmin.
V_PAGNO = sy-pagno.
* CASE SY-UCOMM.
* WHEN 'P+'.
* V_PAGNO = V_PAGNO + 1.
* ENDCASE.


* break idadmin.
* V_PAGNO = SY-CPAGE."SY-PAGNO.
CALL METHOD R_TOP->INITIALIZE_DOCUMENT.
CALL METHOD R_TOP->VERTICAL_SPLIT
EXPORTING
SPLIT_AREA = R_TOP
SPLIT_WIDTH = '80%'
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.
CONCATENATE 'Page No:' V_PAGNO INTO W_TEXT .
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 = 90.
* TEXT = 'Arshad Textile Mills Limited'.
TEXT = 'XXX Group of Companies'.
CALL METHOD R_TOP->ADD_TEXT
EXPORTING
TEXT = TEXT
SAP_EMPHASIS = 'STRONG'.
CALL METHOD R_TOP->NEW_LINE.
CALL METHOD R_TOP->ADD_GAP
EXPORTING
WIDTH = 86.
* TEXT = 'Arshad Corporation(Pvt) Limited'.
TEXT = 'YYY Report'.
CALL METHOD R_TOP->ADD_TEXT
EXPORTING
TEXT = TEXT
SAP_EMPHASIS = 'STRONG'.
CALL METHOD R_TOP->NEW_LINE.
CALL METHOD R_TOP->ADD_GAP
EXPORTING
WIDTH = 100.
* TEXT = 'Human Resource'.
TEXT = 'XXX Period'.
CALL METHOD R_TOP->ADD_TEXT
EXPORTING
TEXT = TEXT
SAP_EMPHASIS = 'STRONG'.

ENDFORM. "TOP_OF_PAGE_SPLIT

0
max bianchi Oct 19, 2016 at 12:23 PM
0

Hi

if you use PAGEBRK instead of VBELN you should have what you need:

  ADD 1 TO L_POS.
  FS_SORT-SPOS     = L_POS.
  FS_SORT-FIELDNAME = 'PAGEBRK'.
  FS_SORT-TABNAME   = 'IT_VBAK'.
  FS_SORT-UP        = 'X'.
  FS_SORT-GROUP     = '*'.
  APPEND FS_SORT TO T_SORT.

Max

Share
10 |10000 characters needed characters left characters exceeded