cancel
Showing results for 
Search instead for 
Did you mean: 

Printing totals in sapscript

Former Member
0 Kudos

Hi

I have a problem in wich i need to print the totals at the end of all the line items but at the end of the page .

All my data comes from the driver program in the main box and i dont have an option of changing the driver program cause it is also used to send the same data to third party for printing.

My problem is that the totals should print at the bottom of the main box instead of immediately after the line items but if there are more line items than 1 page then it should print on the last page .

Can i fix the postion of the place that i print my totals .

Any suggestions ?

Thanks in advance

Anjali

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

To calculate totals and sub totals in sap scripts you have to use subroutines.

Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever that value is picked write this routine

/: DEFINE &TOT_PRICE&

/: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM

Then write the variable where ever you want it to be printed (mostly it will be in footer window)

Then create subroutine pool program and you have to write the code.

FORM F_GET_PRICE tables int_cond structure itcsy

outt_cond structure itcsy. data : value type kbert.

statics value1 type kbert.

Read int_cond table index 1.

value = int_cond-value.

value1 = value1 + value.

Read outt_cond table index 1.

outt_cond-value = value1.

Modify outt_cond index 1.

ENDFORM.

I have given a rough outline, please be aware of the variable conversions as Int_cond-value and outt_cond-value are characters.

Hope this works for you.

Thanks........

Former Member
0 Kudos

hi,

you can use /: BOTTOM

and /: ENDBOTTOM

then it will print at the bottom of your main window.

because totals are printed only once at the end of the main window you can use this.

see syntax below:

BOTTOM: Define footer text in a window

For MAIN, determine the lines, also known as footer texts, which are always automatically output at the bottom of that window.

Syntax:

/: BOTTOM

:

:

/: ENDBOTTOM

The text lines between the two commands are output at the bottom of MAIN.

To switch a footer text off, enter the command pair BOTTOM .. ENDBOTTOM with no text lines in between:

/: BOTTOM

/: ENDBOTTOM

Answers (6)

Answers (6)

Former Member
0 Kudos

Create new window as total.

place this window above footer window and below main window on first and second page.

in this window

/: IF &NEXTPAGE& = 0

  • TOTAL

/: ENDIF

Former Member
0 Kudos
/: IF &PAGE& = &SAPSCRIPT-FORMPAGES&
P1 &Total&
/: ENDIF

&PAGE&--->Current Page NO

&SAPSCRIPT-FORMPAGES& ---> &TOTAL PAGES&

&SAPSCRIPT-JOBPAGES&--->Total pages

If both are equal it means its the last page.

Regards,

Gurpreet

Former Member
0 Kudos

Hi

I tried the NextPage command as you suggested but inspite of my sapscript having only 1 page it gives me the value of 2 .

What are the other commands i can use to check the last page .

Also my totals are printing immediately after my line items finish . how can i print them relative to the window.

Thanks

Anjali

Former Member
0 Kudos

You can keep track that whether your line items will exceed more than one page using &NEXTPAGE&.

IF &NEXTPAGE& = 0 " No further page is available..

Use it in the text editor:

😕  If &NEXTPAGE& = 0
P1 &TOTAL&
:/ENDIF

&NEXTPAGE& will always return zero if there are no next page available.

P1 is your default paragraph.

Regards,

Gurpreet

Former Member
0 Kudos

Hi Anjali,

Take a variable window and assign it below your main window.Calculate the totals and print them on that window.

If your data is spanning through pages then you can validate it using &nextpage&.

If the data is more than one page.

then

if &nextpage& = 0. (that is last page*)

print your totals.

endif.

Much Regards,

Amuktha.

Former Member
0 Kudos

hi use a footer window to print ur totals