2006 Dec 29 3:36 AM
Hi
Would anyone have sample code to display records to a screen in color with centered headers to share? I am writing the results to the screen using WRITE, ULINE, etc. statements but the screen looks so plain. I would want to display color and nice centered headers for the company name, page number , date, hour, report name, etc.
Thanks
Will
2006 Dec 29 5:34 PM
My company uses a function module to write all report handings, it shows the report name(variant used), user name, system, date, time, Program title in the center and can handle the centering whether the report width is 80 or 132 characters across, it calculates the center at runtime. Here is the code.
FUNCTION z_standard_page_header .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(PAGE_NUMBER) LIKE SY-PAGNO DEFAULT SY-PAGNO
*" VALUE(REPORT_NAME) LIKE SY-REPID
*" VALUE(REPORT_TITLE) LIKE SY-TITLE DEFAULT SY-TITLE
*" VALUE(REPORT_WIDTH) LIKE SY-LINSZ DEFAULT SY-LINSZ
*" VALUE(RUN_DATE) LIKE SY-DATUM DEFAULT SY-DATUM
*" VALUE(RUN_TIME) LIKE SY-UZEIT DEFAULT SY-UZEIT
*" VALUE(SUB_TITLE) DEFAULT SPACE
*" VALUE(VARIANT_NAME) LIKE SY-SLSET DEFAULT SY-SLSET
*"----------------------------------------------------------------------
* Working storage
DATA: center_start LIKE sy-linsz,
right_align LIKE sy-linsz,
title_length LIKE sy-linsz,
pgm_var(23),
system_info(7).
** * * * * * * * S T A R T O F F U N C T I O N * * * * * * * **
* set system id and client
CONCATENATE sy-sysid sy-mandt INTO system_info
SEPARATED BY space.
*-> LINE 1
* Calculate center and right positions for the first line
* CENTER_START = ( REPORT_WIDTH - 20 ) / 2 + 1.
center_start = report_width / 2 - 7.
right_align = report_width - 19.
* Write the first header line using the positions calculated
IF variant_name = space.
WRITE: /000 report_name.
ELSE.
CONCATENATE report_name '-' variant_name INTO pgm_var.
CONDENSE pgm_var NO-GAPS.
WRITE: /000 pgm_var.
ENDIF.
* Report title
POSITION center_start.
WRITE: 'Your Company'.
POSITION right_align.
WRITE: 'Page No :',
page_number USING EDIT MASK 'LL_______'.
* END OF LINE 1
*-> LINE 2
* Calculate center and right positions for the second line
title_length = strlen( report_title ).
center_start = ( report_width - title_length ) / 2 + 1.
right_align = report_width - 19.
* write the report user name
WRITE: / sy-uname.
* Write the second header line using the positions calculated
IF NOT report_title IS INITIAL.
POSITION center_start.
WRITE: report_title.
ENDIF.
* write Run Date
POSITION right_align.
WRITE: 'Run date:',
run_date MM/DD/YYYY.
*-> LINE 3
* write system id and client
WRITE: /000 system_info.
* Calculate center position and write the sub title if it exists
* write title for line 3 if passed
IF sub_title NE space.
title_length = strlen( sub_title ).
center_start = ( report_width - title_length ) / 2 + 1.
POSITION center_start.
WRITE: sub_title.
ENDIF.
POSITION right_align.
WRITE: 'Run time:',
run_time USING EDIT MASK '__:__'.
* Finally, underline the header
ULINE.
* Test for record lock contention
ENDFUNCTION.
You can then call this function module in the TOP-OF-PAGE event.
top-of-page.
* Write Standard Header
call function 'Z_STANDARD_PAGE_HEADER'
exporting
page_number = sy-pagno
report_name = 'ZREPORT_NAME'
report_title = sy-title
report_width = sy-linsz
run_date = sy-datum
run_time = sy-uzeit
sub_title = space
variant_name = sy-slset.
Regards,
Rich Heilman
2006 Dec 29 3:49 AM
Hi Will ,
There is a command called FORMAT , you can use this to format the output ,e.g. set color , set hotspot e.t.c
A sample code to assign color is given below
Data : v_string type string.
Start-of-selection.
Format color 1.
Write / 'TEST'.
format color 3 .
Write / 'test'.
Regards
Arun
Reward with points if reply is helpful
2006 Dec 29 3:55 AM
Hi Arun and Eswar,
Is there a standard FM that I can use to display the header of the report where all I have to provide is the Compnay name, report name, date, hour, etc and get a page header?
Thanks
Message was edited by:
Will Ferrell
2006 Dec 29 3:57 AM
Hi Will ,
I dont think there is a stanrdard FM , but i have seen many clients having a custom FM which takes care of the TOP-OF-PAGE and END-OF-PAGE stuff.
Regards
Arun
2006 Dec 29 3:59 AM
Hi Arun,
I have seen it from several projects but never get around to copy the code.
Thanks
2006 Dec 29 3:55 AM
Hi Will
Check this sample code for a work around solution.
write:/49 ' '.
format color col_heading.
write: 50 'Heading'.
format reset.
Regards
Eswar
2006 Dec 29 4:48 PM
You can use FORMAT with following options to display your output to the screen:
1. ... COLOR n [ON] or ... COLOR OFF
2. ... INTENSIFIED [ON] or ... INTENSIFIED OFF
3. ... INVERSE [ON] or ... INVERSE OFF
4. ... HOTSPOT [ON] or ... HOTSPOT OFF
5. ... INPUT [ON] or ... INPUT OFF
6. ... RESET
Check SAP Help for further information.
Thanks,
Santosh
2006 Dec 29 4:57 PM
Hi Will,
check this example programs from SAP for different color codes and usage.
REPORT demo_list_format_color_1.
DATA i TYPE i VALUE 0.
DATA col(15) TYPE c.
WHILE i < 8.
CASE i.
WHEN 0. col = 'COL_BACKGROUND '.
WHEN 1. col = 'COL_HEADING '.
WHEN 2. col = 'COL_NORMAL '.
WHEN 3. col = 'COL_TOTAL '.
WHEN 4. col = 'COL_KEY '.
WHEN 5. col = 'COL_POSITIVE '.
WHEN 6. col = 'COL_NEGATIVE '.
WHEN 7. col = 'COL_GROUP '.
ENDCASE.
FORMAT INTENSIFIED COLOR = i.
WRITE: /(4) i, AT 7 sy-vline,
col, sy-vline,
col INTENSIFIED OFF, sy-vline,
col INVERSE.
i = i + 1.
ENDWHILE.
-------------
REPORT demo_list_format_color_2 NO STANDARD PAGE HEADING LINE-SIZE 70.
TABLES: spfli, sflight.
DATA sum TYPE i.
TOP-OF-PAGE.
WRITE 'List of Flights' COLOR COL_HEADING.
ULINE.
GET spfli.
FORMAT COLOR COL_HEADING.
WRITE: 'CARRID', 10 'CONNID', 20 'FROM', 40 'TO'.
FORMAT COLOR COL_KEY.
WRITE: / spfli-carrid UNDER 'CARRID',
spfli-connid UNDER 'CONNID',
spfli-cityfrom UNDER 'FROM',
spfli-cityto UNDER 'TO'.
ULINE.
FORMAT COLOR COL_HEADING.
WRITE: 'Date', 20 'Seats Occupied', 50 'Seats Available'.
ULINE.
sum = 0.
GET sflight.
IF sflight-seatsocc LE 10.
FORMAT COLOR COL_NEGATIVE.
ELSE.
FORMAT COLOR COL_NORMAL.
ENDIF.
WRITE: sflight-fldate UNDER 'Date',
sflight-seatsocc UNDER 'Seats Occupied',
sflight-seatsmax UNDER 'Seats Available'.
sum = sum + sflight-seatsocc.
GET spfli LATE.
ULINE.
WRITE: 'Total Bookings: ' INTENSIFIED OFF,
sum COLOR COL_TOTAL.
ULINE.
SKIP.
---------
and your required FM
FUNCTION Z_PRINT_REPORT_TITLE.
*"---------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_COMPANY_NAME) LIKE SY-TITLE OPTIONAL
*" VALUE(I_RPT_NAME) LIKE SY-REPID DEFAULT SY-CPROG
*" VALUE(I_TITLE1) LIKE RS38M-ITEX DEFAULT SY-TITLE
*" VALUE(I_TITLE2) LIKE RS38M-ITEX OPTIONAL
*" VALUE(I_TITLE3) LIKE RS38M-ITEX OPTIONAL
*" VALUE(I_TITLE4) LIKE RS38M-ITEX OPTIONAL
*" VALUE(I_TITLE5) LIKE RS38M-ITEX OPTIONAL
*" VALUE(I_TITLE6) LIKE RS38M-ITEX OPTIONAL
*"----------------------------------------------------------------------
DATA: L_TEXT LIKE SY-REPID. "Text for right side of title
*---------------------------------------------------------------------
* Default the company name
IF I_COMPANY_NAME IS INITIAL.
I_COMPANY_NAME = TEXT-BAR.
ENDIF.
* Begin framing report title
ULINE.
PERFORM PRINT_TITLE_LEFT USING TEXT-905
I_RPT_NAME.
PERFORM PRINT_TITLE_RIGHT USING SPACE
SPACE.
PERFORM PRINT_TITLE_LEFT USING TEXT-901
SY-DATUM.
PERFORM PRINT_TITLE_CENTER USING I_COMPANY_NAME.
PERFORM PRINT_TITLE_RIGHT USING TEXT-904
SY-PAGNO.
PERFORM PRINT_TITLE_LEFT USING TEXT-902
SY-UZEIT.
PERFORM PRINT_TITLE_CENTER USING I_TITLE1.
PERFORM PRINT_TITLE_RIGHT USING TEXT-906
SY-SYSID.
PERFORM PRINT_TITLE_LEFT USING TEXT-903
SY-UNAME.
PERFORM PRINT_TITLE_CENTER USING I_TITLE2.
PERFORM PRINT_TITLE_RIGHT USING TEXT-907
SY-MANDT.
IF NOT I_TITLE3 IS INITIAL.
PERFORM PRINT_TITLE_LEFT USING SPACE
SPACE.
PERFORM PRINT_TITLE_CENTER USING I_TITLE3.
PERFORM PRINT_TITLE_RIGHT USING SPACE
SPACE.
ENDIF.
IF NOT I_TITLE4 IS INITIAL.
PERFORM PRINT_TITLE_LEFT USING SPACE
SPACE.
PERFORM PRINT_TITLE_CENTER USING I_TITLE4.
PERFORM PRINT_TITLE_RIGHT USING SPACE
SPACE.
ENDIF.
IF NOT I_TITLE5 IS INITIAL.
PERFORM PRINT_TITLE_LEFT USING SPACE
SPACE.
PERFORM PRINT_TITLE_CENTER USING I_TITLE5.
PERFORM PRINT_TITLE_RIGHT USING SPACE
SPACE.
ENDIF.
IF NOT I_TITLE6 IS INITIAL.
PERFORM PRINT_TITLE_LEFT USING SPACE
SPACE.
PERFORM PRINT_TITLE_CENTER USING I_TITLE6.
PERFORM PRINT_TITLE_RIGHT USING SPACE
SPACE.
ENDIF.
* End framing report title
ULINE.
ENDFUNCTION.
*---------------------------------------------------------------------*
* FORM PRINT_TITLE_LEFT *
*---------------------------------------------------------------------*
* This routine prints the left portion of the report title. *
*---------------------------------------------------------------------*
* --> VALUE(P_DESC) *
* --> VALUE(P_TEXT) *
*---------------------------------------------------------------------*
FORM PRINT_TITLE_LEFT USING VALUE(P_DESC)
VALUE(P_TEXT).
WRITE: AT / SY-VLINE.
IF NOT P_TEXT IS INITIAL.
WRITE: P_DESC,
P_TEXT.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM PRINT_TITLE_RIGHT *
*---------------------------------------------------------------------*
* This routine prints the right portion of the report title. *
*---------------------------------------------------------------------*
* --> VALUE(P_DESC) *
* --> VALUE(P_TEXT) *
*---------------------------------------------------------------------*
FORM PRINT_TITLE_RIGHT USING VALUE(P_DESC)
VALUE(P_TEXT).
DATA: L_POS TYPE I. "Output position
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
IF NOT P_TEXT IS INITIAL.
L_POS = SY-LINSZ - G_COLS_RIGHT.
WRITE: AT L_POS P_DESC,
P_TEXT.
ENDIF.
WRITE AT SY-LINSZ SY-VLINE.
ENDFORM.
*---------------------------------------------------------------------*
* FORM PRINT_TITLE_CENTER *
*---------------------------------------------------------------------*
* This routine centers and prints the center of the report *
* title. *
*---------------------------------------------------------------------*
* --> VALUE(P_TEXT) *
*---------------------------------------------------------------------*
FORM PRINT_TITLE_CENTER USING VALUE(P_TEXT).
DATA: L_POS TYPE I. "Output position
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
IF NOT P_TEXT IS INITIAL.
* Center the text on the report line
L_POS = ( SY-LINSZ - STRLEN( P_TEXT ) ) / 2.
WRITE AT L_POS P_TEXT.
ENDIF.
ENDFORM.
In this FM for write you can assign colors and can use.
Regards,
Raghav
2006 Dec 29 5:34 PM
My company uses a function module to write all report handings, it shows the report name(variant used), user name, system, date, time, Program title in the center and can handle the centering whether the report width is 80 or 132 characters across, it calculates the center at runtime. Here is the code.
FUNCTION z_standard_page_header .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(PAGE_NUMBER) LIKE SY-PAGNO DEFAULT SY-PAGNO
*" VALUE(REPORT_NAME) LIKE SY-REPID
*" VALUE(REPORT_TITLE) LIKE SY-TITLE DEFAULT SY-TITLE
*" VALUE(REPORT_WIDTH) LIKE SY-LINSZ DEFAULT SY-LINSZ
*" VALUE(RUN_DATE) LIKE SY-DATUM DEFAULT SY-DATUM
*" VALUE(RUN_TIME) LIKE SY-UZEIT DEFAULT SY-UZEIT
*" VALUE(SUB_TITLE) DEFAULT SPACE
*" VALUE(VARIANT_NAME) LIKE SY-SLSET DEFAULT SY-SLSET
*"----------------------------------------------------------------------
* Working storage
DATA: center_start LIKE sy-linsz,
right_align LIKE sy-linsz,
title_length LIKE sy-linsz,
pgm_var(23),
system_info(7).
** * * * * * * * S T A R T O F F U N C T I O N * * * * * * * **
* set system id and client
CONCATENATE sy-sysid sy-mandt INTO system_info
SEPARATED BY space.
*-> LINE 1
* Calculate center and right positions for the first line
* CENTER_START = ( REPORT_WIDTH - 20 ) / 2 + 1.
center_start = report_width / 2 - 7.
right_align = report_width - 19.
* Write the first header line using the positions calculated
IF variant_name = space.
WRITE: /000 report_name.
ELSE.
CONCATENATE report_name '-' variant_name INTO pgm_var.
CONDENSE pgm_var NO-GAPS.
WRITE: /000 pgm_var.
ENDIF.
* Report title
POSITION center_start.
WRITE: 'Your Company'.
POSITION right_align.
WRITE: 'Page No :',
page_number USING EDIT MASK 'LL_______'.
* END OF LINE 1
*-> LINE 2
* Calculate center and right positions for the second line
title_length = strlen( report_title ).
center_start = ( report_width - title_length ) / 2 + 1.
right_align = report_width - 19.
* write the report user name
WRITE: / sy-uname.
* Write the second header line using the positions calculated
IF NOT report_title IS INITIAL.
POSITION center_start.
WRITE: report_title.
ENDIF.
* write Run Date
POSITION right_align.
WRITE: 'Run date:',
run_date MM/DD/YYYY.
*-> LINE 3
* write system id and client
WRITE: /000 system_info.
* Calculate center position and write the sub title if it exists
* write title for line 3 if passed
IF sub_title NE space.
title_length = strlen( sub_title ).
center_start = ( report_width - title_length ) / 2 + 1.
POSITION center_start.
WRITE: sub_title.
ENDIF.
POSITION right_align.
WRITE: 'Run time:',
run_time USING EDIT MASK '__:__'.
* Finally, underline the header
ULINE.
* Test for record lock contention
ENDFUNCTION.
You can then call this function module in the TOP-OF-PAGE event.
top-of-page.
* Write Standard Header
call function 'Z_STANDARD_PAGE_HEADER'
exporting
page_number = sy-pagno
report_name = 'ZREPORT_NAME'
report_title = sy-title
report_width = sy-linsz
run_date = sy-datum
run_time = sy-uzeit
sub_title = space
variant_name = sy-slset.
Regards,
Rich Heilman
2006 Dec 29 5:41 PM
2006 Dec 29 5:47 PM
2006 Dec 29 6:06 PM
Hi Rich,
You know something is really strange about my account. It seems that the points are automatically marked for point number 6. I tell you I didn't mark them myself. I will try to mark yours solved, so you could be the best of the BEST... Isn't that what you wanted?
Ha Ha Ha...
Thanks
2006 Dec 29 6:11 PM
Ok... I am not sure what's going on with my account but it would not let me mark this post resolved. The resolved button is greyed out. I tried to unassign to tget the button to be selectable but it is not working.
2006 Dec 29 6:11 PM
<i>It seems that the points are automatically marked for point number 6.</i>
Not sure what that is all about.... 😮
<i>I will try to mark yours solved, so you could be the best of the BEST... Isn't that what you wanted?</i>
No, not at all. If the code in my answer has helped you solve the problem, then yes, mark as solved, but if it didn't, then don't. You should always mark solved next to the post which solved your problem or answer your question completely, this may when the next developer comes along with the same question, he can see on this post that it was answered and get the solution.
Regards,
Rich Heilman
2006 Dec 29 6:14 PM
Hi Rich,
It's a sign of stress... A humor will get me out of this mode..
Anyway, I am not sure why it wouldn't let me. Believe me I want to award everyone the most points and close the thread. Who should I communicate this to get this resolved on my account?
Thanks
Will
2006 Dec 29 6:19 PM