SAPScript Command Protect...Endprotect

Preventing Page Breaks: PROTECT 

You can specify, either in the style or in the form, that a particular paragraph should not be split in two by a page break. If this page protect attribute is set, then the complete paragraph is always printed on one page. This property applies only to that particular paragraph.

This attribute is not intended to be used to protect all paragraphs against a page break. The point is that a page break is by its very nature a dynamic event and the exact point at which it occurs depends on the current state (length and contents) of the preceding text. It is also possible that you may want to protect only certain parts of a paragraph against a page break. One way to achieve this is to use the NEW-PAGE command immediately before the text concerned starts. Explicitly beginning a new page at this point should ensure that a further page break does not occur within the text. However, this technique is not change-friendly. For example, you format your text with the help of the NEW-PAGE command so that no page breaks occur where they should not. At a later time, you insert or delete some lines. These changes cause all the subsequent text to be moved relative to the printed page, and you must check each NEW-PAGE command you previously inserted to see if it is still in the correct place.

To allow you to define the areas to be protected against a page break on an individual basis, SAPscript provides the PROTECT.. ENDPROTECT command pair. If you enclose the text to be protected in these commands, then SAPscript will ensure that each line of this text is printed together on the same page. If the complete text fits in the space remaining on the current page, then it is printed on this page just as it would be if no PROTECT command had been used. If, however, the remaining space is not sufficient for the text, then the PROTECT command has the same effect as a NEW-PAGE command and text is printed on a new page.

Thus the PROTECT/ENDPROTECT commands may be regarded as a kind of conditional NEW-PAGE command, the condition being whether or not the lines enclosed between the two commands fit in the space remaining in the current main window.

Syntax:

/: PROTECT 


/: ENDPROTECT

The text lines to be protected are enclosed between the two commands.

Notes:

An ENDPROTECT command without a preceding PROTECT command has no effect.

If the terminating ENDPROTECT is missing, SAPscript assumes it at the end of the text. 

PROTECT.. ENDPROTECT command pairs cannot be nested. If a second PROTECT command occurs before the first one has been terminated by an ENDPROTECT, it is ignored.

If the text enclosed by a PROTECT.. ENDPROTECT pair is itself too long for a single page, then a page break is generated immediately before the text and the text is printed in the normal way. It is then unavoidable that a page break will occur at some point within the text.
 

Questions

What's a PROTECT...ENDPROTECT in SAPScript form?

When using Scripts, if you don't want to break a paragraph text which a part of text is printed to another page i.e. if you want to display the paragraph without breaking in between two pages, you have to use protect...endprotect. 
 

I am working on a invoice script where I have to print two lines for a material. These two lines should be always be printed together even in the case of a page break. How can I do that. 

include them between protect-endprotect

/: protect
IL X .......
/ Y .......
/: endprotect

SAP Sapscripts

SAPscripts FAQ
BOTTOM ENDBOTTOM Command

ABAP Books
ABAP Programming, Certification, Interview Questions Smartform and SAPscripts  Reference Books

SAP Scripts Tips
SAP Sapscripts Tips and Tricks

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.