On the other day, I was reading through SCN and this question came up. There wasn’t any suitable answer, which can get the watermark in SAPScript. So, I decided to give a try. I have tried couple of times with different techniques like calling the subroutine which SmartForm uses for background processing from SAPScript, putting the graphics in various windows and call them from driver program, etc. But today, I got a good solution, which I thought would be useful to everybody.
How it looks with Watermark?
There are couples of hurdles in the way to get it working:
一、First is the Graphics:
Watermark Graphics should have some specific property. This kind of graphics should not have the “Reserve Height Automatically” as ON in their attributes.
Whenever we import any .bmp file as the graphics in the SE78, system by default sets the indicator “Reserve Height Automatically” as ON. So, when we include this graphics in our SAPScript, system will reserve predefined space on the page which will prevent the next line to print in that space.
The Graphics with the “Reserve Height Automatically” as ON generates output like this:
二、Second is how to get the watermark on each page:
To get the graphics on every page we have couple of options:
Option 1: Create a GRAPHICS window on the center of the page and include the watermark.
This option is not working because: System starts the processing of the windows in the sequence maintained on the page window of SAPScript. So, Main window will be executed before Graphics window. This will overlap the content of the main window by the Graphics (which is not our purpose).
Option 2: Call a Graphics inside the MAIN window.
This option seems to work with little logic to print the watermark on each page.
I have attached my SAPScript, Little driver program code and the test watermark image for your reference.
三、报表脚本:
You can save this block as .txt file and use report RSTXSCRP to import into your system. You need to save this SAPScript with name ZTEST_WATERMARK.
SFORMZTEST_WATERMARK
HFORMZTEST_WATERMARK
OLANE
HEADFORM ZTEST_WATERMARK SAP DEF ETesting ZTEST_WATERMARK 00005NPATEL 640 20070716103554NPATEL 640 2008052016390213200010 E0 150
LINE/:FORM CPI 10; LPI 6; TAB-STOP 1 CM; START-PAGE FIRST; PARAGRAPH A1; RDI;
LINE/:FORM RDIDEV;
LINE/:PARAGRAPH A1 LINE-SPACE 1 LN;
LINE/:PARAGRAPH A1 TAB 1 2 CM LEFT;
LINE/:WINDOW GRAPHICS TYPE VAR;
LINE/:WINDOW LAST TYPE VAR;
LINE/:WINDOW MAIN
LINE/:PAGE FIRST NEXT FIRST;
LINE/:PAGE FIRST MAIN 0 1 CM 2 CM 10 CM 8 CM;
LINE/:PAGE FIRST WINDOW LAST 5 CM 15 CM 5 CM 2 CM;
END
HEADFORM ZTEST_WATERMARK SAP TXT ETesting ZTEST_WATERMARK 00005NPATEL 640 20070716103554NPATEL 640 2008052016390213200019 E0 150
LINE/:FORM TEXT 'Testing';
LINE/:PARAGRAPH A1 TEXT 'default';
LINE/:WINDOW GRAPHICS TEXT 'graphics';
LINE/:WINDOW LAST TEXT 'last windoe';
LINE/:WINDOW MAIN TEXT 'Main Window';
LINE/:PAGE FIRST TEXT 'First';
LINE/WLAST
LINE/ELAST
LINE* last window
LINE/WGRAPHICS
LINE/:BITMAP 'ZTEST_NP' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 75
LINE/WMAIN
LINE/:DEFINE &W_PAGE& := 0
LINE/EMAIN
LINEA1&W_COUNT&,,TESTING OF THE WATERMARK
LINE/:IF &PAGE& <> &W_PAGE&
LINE/:BITMAP 'ZTEST_NP' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 75
LINE/:DEFINE &W_PAGE& := &PAGE&
LINE/:ENDIF
END
ACTVSAP
E
四、代码:
*&---------------------------------------------------------------------*
*& Report ZTEST_NP_SCRIPT
*&
*&---------------------------------------------------------------------*
*& Test Program to test Watermark in SAPScript
*&---------------------------------------------------------------------*
REPORT ZTEST_NP_SCRIPT.
DATA: W_COUNT TYPE I.
PARAMETERS: P_NUM TYPE I DEFAULT 20.
START-OF-SELECTION.
IF P_NUM IS INITIAL.
P_NUM = 20.
ENDIF.
*
CALL FUNCTION 'OPEN_FORM'
EXPORTING
APPLICATION = 'TX'
DEVICE = 'PRINTER'
DIALOG = 'X'
FORM = 'ZTEST_WATERMARK'
LANGUAGE = SY-LANGU.
*
DO P_NUM TIMES.
W_COUNT = SY-INDEX.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'MAIN'
WINDOW = 'MAIN'.
ENDDO.
*
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'LAST'
WINDOW = 'LAST'.
IF SY-SUBRC <> 0.
ENDIF.
*
CALL FUNCTION 'CLOSE_FORM'
.
Watermark Image:
I have used this image for my testing:
Note: I have tried this on ECC 5.0. I am not sure about other systems.
source: https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9789