You are on page 1of 6

vinod.

chandran: Using Final window in


Smartforms
Posted by Vinod Chandran Aug 23, 2005
For those people who have not tried the Final window in Smartforms then read on…
As you are aware, there are four different types of windows available from SAP Basis release 6.10. They are
Main, Secondary, Final and Copies. Recently I got a chance to use the ‘Final’ window type in
Smartforms. Sometime back I had posted a query in the ABAP forum for a requirement (which is described
here) but didn’t receive any answer. Later I found out a way and thought I can share it here.
Let me explain the properties and use of the ‘Final’ window in this session.
The windows are processed from top to bottom as given in the Smartforms builder navigation tree.

So the execution first skips all the Final windows and completes the processing of other windows. Once all
the non final windows are processed, the Final windows are processed from top to bottom. For example if you
would like to have the total value of all the items on the first page but the value of this is known only at the end
of the form processing, we can use the Final window for displaying the total value. The sum of line items is
calculated in the MAIN window.
Recently I received the following requirement to produce an output for displaying items from the shipment.
These items are from multiple delivery documents and each delivery is associated with a ship-to-party.
Whenever the ship-to-party changes a page break is needed and the page number should reset. For example,
if the first ship-to-party has two pages the page number will be ‘Page 1 of 2’ and ‘Page 2 of
2’. Now for the next ship-to-party the page number again starts from 1 and the total number of pages will
be for that particular ship-to-party.

Generated by Jive on 2015-02-02+01:00


1

vinod.chandran: Using Final window in Smartforms

This cannot be done using the normal method. i.e. using the SFSY structure (SFSY-FORMPAGES and SFSYPAGE). In our example because the total number of pages for a particular ship-to-party is calculated only after
the processing of all its pages are completed. For such cases the ‘Final windows’ can be helpful.
The logic I have followed captures the page numbers for each ship-to-party and then uses the final window
‘PAGE’ to display that.
Step-1 (Make the window as a final window)
Double click on the window and in the ‘General Attributes’ tab select window type as ‘Final
Window’.

Note that once you have selected as final window, the icon changes.

Generated by Jive on 2015-02-02+01:00


2

vinod.chandran: Using Final window in Smartforms

Step-2 (Capture the pages for each ship to party)


In the Main window I am using the LOOP node to loop through each ship-to-party and the TABLE node to loop
through the line items of each selected ship-to-party from the LOOP node. This is because explicit page break
using the ‘Command’ node cannot be called inside TABLE.
In the Global settings
Type
TYPES: BEGIN OF t_pagest,
pagefr(3),
pageto(3),
END OF t_pagest.
TYPES: t_pages TYPE STANDARD TABLE OF t_pagest WITH DEFAULT KEY.
Global Data

A code is written just under the LOOP node to capture the page numbers for the ship to party.

Generated by Jive on 2015-02-02+01:00


3

vinod.chandran: Using Final window in Smartforms

The code for this program line node (GET_PAGE_NO) is given below and will capture pages for all the shipto-parties except the last one. Capturing pages for the final ship-to-party is explained in Step-3. The below
code will not work for the first ship-to-party (IF sfsy-formpages > 1) and will start from the second SHP.
DATA: wa_pageno(3),
wa_pagecnt(3).
* This code starts working from page 2 onwards
IF sfsy-formpages > 1.
wa_pageno = sfsy-formpages - wa_lastpage.
wa_pagecnt = 1.
DO wa_pageno TIMES.
wa_pages-pagefr = wa_pagecnt.
wa_pages-pageto = wa_pageno.
wa_pagecnt

= wa_pagecnt + 1.

APPEND wa_pages TO wt_pages.


ENDDO.
ENDIF.

Generated by Jive on 2015-02-02+01:00


4

vinod.chandran: Using Final window in Smartforms

wa_lastpage = sfsy-formpages.
Step-3 (Capture the pages for final ship to party and format page numbers)
Now we have one more program line node in the final window ‘PAGE’ and this is just before
the page output. Capturing pages for final ship-to-party is coded here because that is the final record in the
LOOP_SHP and the program line node GET_PAGE_NO will not be executed.

Code for ‘PRINT_PAGE’ is as follows.


DATA: wa_page(3),
wa_pagecnt(3).
IF ws_once = 'X'.
* One time for last page
wa_page

= sfsy-formpages - wa_lastpage + 1.

wa_pagecnt = 1.
DO wa_page TIMES.
wa_pages-pagefr = wa_pagecnt.
wa_pages-pageto = wa_page.
wa_pagecnt

= wa_pagecnt + 1.

APPEND wa_pages TO wt_pages.


ENDDO.
CLEAR ws_once.
ENDIF.
*Format Page Numbers

Generated by Jive on 2015-02-02+01:00


5

vinod.chandran: Using Final window in Smartforms

CLEAR wa_pages.
READ TABLE wt_pages INTO wa_pages INDEX 1.
IF sy-subrc = 0.
CONDENSE: wa_pages-pagefr,
wa_pages-pageto.
CONCATENATE 'Page' wa_pages-pagefr 'of' wa_pages-pageto
INTO wa_pageno SEPARATED BY space.
DELETE wt_pages INDEX 1.
ENDIF.

Step-4 (Display Formatted Pages)


In the text node ‘PAGE’ I have given the following.
&WA_PAGENO(C)&

For versions prior to Basis 6.10

The above will not work if you are on 4.6C or 4.6D version. But there is a work around suggested by SAP to
accomplish the same. But the support package level must be on SAPKB46C12 for 4.6C and SAPKB46D04 for
4.6D. This is described in the OSS note 359009.
In order to achieve late (Final) processing of windows do the following.
Create a secondary window that you want to process like FINAL window.
Now on the first page create another secondary window as the first node. In this create a program
line node and call the following subroutine for every window that you want to behave as a Final
window.
PERFORM set_late_window IN PROGRAM saplstxbc USING ‘FNL_WINDOW’
CHANGING l_subrc.
‘FNL_WINDOW’ is the name of the window. If you have several windows, you have to call
the subroutine for all the windows.
2232 Views

karthi keyan
Feb 25, 2008 5:23 AM
I am searching the solution for the page number problem for more than two days finally your blog helped me a
lot to solve the problem.
Thanks.

Generated by Jive on 2015-02-02+01:00


6

You might also like