Thursday, November 19, 2009

SAPscript Control Commands- Part 1

Explicit Page Break: NEW-PAGE

SAPscript automatically inserts a page break when the main window of a page (MAIN) is full. You can use the NEW-PAGE command to force a page break in the text at any point you want one. The text following this command will appear on a new page. The page break will always be performed (it is an unconditional page break).

The NEW-PAGE command completes the current page. This means that all the windows that are still on the page will be output immediately. If you use the NEW-PAGE command without parameters then the page defined in the layout set for the current page as the next page will be taken next. If, however, your layout set contains a number of different pages then you can specify any one of these as the next page to be used.


/: NEW-PAGE [page_name]


The current page will be completed and the text in the following lines will be written to the page specified in the layout set.


As above, except that the page S1 will taken as the next page.

• If a page not contained in the layout set is specified in a NEW-PAGE command then this specification is ignored.

• You should take care that there is not an blank line immediately before a NEW-PAGE command. This would serve no useful purpose and may lead to an unexpected blank page being printed. This would happen if an implicit page break would normally occur within the blank line.

Preventing Page Breaks: PROTECT

You can specify either in the style or in the layout set that a particular paragraph should not be split in two by a page break. If the page protect attribute is set then the complete paragraph is always output on a single 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 one may want to protect only certain parts of a paragraph against a page break. In principle one could achieve this through the use of the NEW-PAGE command immediately before the text concerned. 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-resistant. Assume, for example, that you have formatted your text with the help of the NEW-PAGE command such that no page breaks occur where they should not, and that you now insert some new lines or delete some existing lines. These changes will cause all the subsequent text to be moved relative to the printed page, and you will therefore need to check each NEW-PAGE command you had previously inserted to see if it is still in the correct place.

SAPscript provides the PROTECT .. ENDPROTECT command pair to allow you to define the areas to be protected against a page break on an individual basis. 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 output on that 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.






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

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

• If the terminating ENDPROTECT is missing, then it will be assumed 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 will be 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 output in the normal way. It is then unavoidable that a page break will occur at some point within the text.

Next Main Window: NEW-WINDOW

Each page can consist of up to 99 main windows. Each main window is assigned a consecutive identifying number (0..98), and the windows are filled in this order. This feature enables SAPscript to print labels and to output multi-column text. When one main window fills up, the next main window on that page is taken, if there is a next one. A page break is inserted after the last main window.

You can use the NEW-WINDOW command to call the next main window explicitly, even if the current main window is not yet full. If you are in the last main window of the page, the command has the same effect as the NEW-PAGE command.



Assigning a Value to a Text Symbol: DEFINE

Text symbols acquire their values as a result of explicit assignment. This assignment can be performed interactively in the text editor via the menu option Include -> Symbols -> Text. This method is available for all text symbols belonging to a text module as well as those of the associated layout set.

Values defined in this way are lost when the transaction is left. If the text module is to be printed again then the symbol values must all be entered again. The purpose of the DEFINE command is to provide a means of making this value assignment a permanent part of the text, so that the values are available again when the text module is called again. This command can also be used to re-assign a new value to a text symbol part way through the text.


/: DEFINE &symbol_name& = 'value'

/: DEFINE &subject& = 'Your letter of 7/3/95'

The value assigned can have a maximal length of 60 characters. It may itself contain other symbols. A symbol contained within the value assigned to another symbol is not replaced with its own value at the point at which the DEFINE command is executed. Rather, this replacement is made when the symbol defined in the DEFINE command is called in the text.

/: DEFINE &symbol1& = 'mail'

/: DEFINE &symbol2& = 'SAP&symbol1&'

/: DEFINE &symbol1& = 'script'

&symbol2& -> SAPscript

If, however, the DEFINE command is written using the ':=' character rather than the '=' character, then any symbol contained within the value being assigned will be replaced immediately with its current value. The assignment to the target symbol will only be made after all symbols in the value string have been replaced with their values. The total length of the value string may not exceed 80 characters. The target symbol must be a text symbol, as before.

/: DEFINE &symbol1& = 'mail'

/: DEFINE &symbol2& := 'SAP&symbol1&'

/: DEFINE &symbol1& = 'script'

&symbol2& -> SAPmail

Formatting Date Fields: SET DATE MASK

The formatting for date fields can be defined with the SET DATE MASK control command. Executing this command causes all subsequent date fields to be output using the specified format.


/: SET DATE MASK = 'date_mask'

The following codes can be used in the date mask:

• DD: day (two digits)

• DDD: day name - abbreviated

• DDDD: day name - written out in full

• MM: month (two digits)

• MMM: month name - abbreviated

• MMMM: month name - written out in full

• YY: year (two digits)

• YYYY: year (four digits)

• LD: day (formatted as for the L option)

• LM: month (formatted as for the L option)

• LY: year (formatted as for the L option)

All other characters found in a date mask are interpreted as simple text and are copied straight into the output.

Assuming the current system date is March 1st, 1994.

/: SET DATE MASK = 'Foster City, MM/DD/YY'

&DATE& -> Foster City, 03/01/94


&DATE& -> March 01, 1994

The date mask may be reset to the default setting by using an empty string:

/: SET DATE MASK = ' '

The abbreviated and full forms of the names of the days and months are stored in the language dependent TTDTG table under the following keys:

• %%SAPSCRIPT_DDD_dd: abbreviated day name

• %%SAPSCRIPT_DDDD_dd: full form of day name

• %%SAPSCRIPT_MMM_mm: abbreviated month name

• %%SAPSCRIPT_MMMM_mm: full form of month name

dd: day number 01 = Monday, ..., 07 = Sunday

mm: month number 01 = January, ..., 12 = December

No comments:

Post a Comment