Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Want to print page n of 'total pages + 1' in SAPSCRIPT FORM

Former Member
0 Kudos

Hi,

I want to print page n of 'total pages + 1' in the footer section of my SAPSCRIPT FORM. I have used a PERFORM to add 1 to value of SAPSCRIPT-FORMPAGES symbol. But the problem is that it works fine on second page (prints page 2 of 3) but on the first page it always prints page 1 of 1.

I think the value of SAPSCRIPT-FORMPAGES symbol is not getting passed to the PERFORM parameter on first page but is working fine on subsequent pages.

/: DEFINE &PAGEOUT& = '&SPACE(5)'

/: PERFORM PAGE_SUMM IN PROGRAM ZAPFM06P

/: USING &SAPSCRIPT-FORMPAGES(C)&

/: CHANGING &PAGEOUT&

/: ENDPERFORM

AS <B>Page &PAGE& of &PAGEOUT&</>

Please advice.

Thanks for your help in advance.

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

See if the text element you are using is being conditionally triggered.

Regards,

ravi

14 REPLIES 14

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You only need this line of code in your sapscript.

Page  &PAGE& of &SAPSCRIPT-FORMPAGES&

Regards,

Rich Heilman

0 Kudos

Rich,

I want to print page n of 'total pages + 1'. for example if there are total 2 pages, I want to print

'page 1 of 3' on the first page and

'page 2 of 3' on second / last page.

Thanks,

Sanjay Gera

former_member188685
Active Contributor
0 Kudos

Hi,

you can use this ..

&PAGE& &SAPSCRIPT-FORMPAGES&

but why you want +1.

if that is the case try this..

&PAGE& &SAPSCRIPT-FORMPAGES + 1&

Regards

vijay

0 Kudos

Vijay,

Business requirement is to print page n of 'total pages + 1'

I have tried &PAGE& of &SAPSCRIPT-FORMPAGES + 1& but it does not work.

Thanks,

Sanjay Gera

former_member181962
Active Contributor
0 Kudos

See if the text element you are using is being conditionally triggered.

Regards,

ravi

0 Kudos

Ravi,

There is no conditional statement around the text symbol. I have pasted the exact code in the question.

Thanks,

Sanjay Gera

0 Kudos

I think it's because sapscript doesn't know how many pages it's going to print in the fist page and FORMPAGES variable is not yet populated with total pages.

Regards

Sridahr

0 Kudos

Wow, I would really like to know the logic behind this. If the last page says 2 of 3? How does this make any sense to the user? I think you or your functional lead may want to rethink this.

Regards,

Rich Heilman

0 Kudos

Rich,

Business users always attach an extra page to the printed Purchase order. That is the reason they want me to print 'total number of pages + 1'.

Thanks,

Sanjay Gera

0 Kudos

Sridhar,

If I print the SAPSCRIPT-FORMPAGES symbol as it is, it is printing the total number of pages. But when I try to assign it's value to a text symbol using DEFINE statement or if I try to pass it to my PERFORM as a parameter to increment it by 1, It does not transfer the value.

Thanks,

Sanjay Gera

0 Kudos

Sanjay,

Create an Empty page after your 2 pages & call that page as a last page with a START_FORM.I am not sure it would work but give it a try.

0 Kudos

It's printing total number of pages when u use SAPSCRIPT-FORMPAGES, because, sapscript loads all pages into memory after close_form and replaces variable SAPSCRIPT-FORMPAGES with the new total number.

Try the following:

1. set parameter OPTIONS when calling OPEN_FORM function module as OPTIONS-TDPAGESLCT = '2-'.

This parameter tells sapscript to print from page 2.

2. Create a text element in FIRST page

/E PBREAK

/: NEW-PAGE FIRST

Call this text element after OPEN_FORM using WRITE_FORM

3. Before printing page number: subtract 1 from PAGE variable and populate it into NEW_PAGE variable using PERFORM and print the page# as:

AS <B>Page &NEW_PAGE& of &SAPSCRIPT-FORMPAGES&</>

Regards

Sridhar

Message was edited by: Sridhar K

0 Kudos

Sridhar,

Your solution has worked perfectly. And you know, I don't have to subtract 1 from the &PAGE& variable either as it is been already taken care due to tdpageslct = '2-' option.

You are great.

Thanks a lot. I am posting reward points for you.

Regards,

Sanjay Gera

Former Member
0 Kudos

Hi Sanjay,

In your case where you want to increment the value of the total number of pages always use <b>&SAPSCRIPT-JOBPAGES&</b> and for the individual page <b>&PAGE&</b>.

Since you have to increment the value of the total number of pages, pass the value to a variable increment the variable and then display that variable.

: PERFORM CHECK_PAGE IN PROGRAM Z_SCRIPT

: USING &SAPSCRIPT-JOBPAGES&

: CHANGING &WS_PAGE&

: ENDPERFORM

FORM check_page TABLES p_page STRUCTURE itcsy

p_page1 STRUCTURE itcsy.

READ TABLE p_page INDEX 1.

IF sy-subrc = 0 .

p_page1-value = p_page-value + 1.

MODIFY p_page1 INDEX sy-tabix.

ENDIF.

ENDFORM. "check_page

Now your total number of pages would have been increased by 1 and display this variable in the script. But one point is <b>dont declare</b> the variable <b>WS_PAGE</b> in the driver program. If you declare the value will be reset. It will work believe me it works.

Reward if helpful.

Regards,

Tushar