cancel
Showing results for 
Search instead for 
Did you mean: 

Inserting address line after every line item in SAP Script

Former Member
0 Kudos

Hi,

I have a requirement as per following scenario,

My form is triggered through ME22N transaction (MEDRUCK - Standard), In my

customized form, we have line items. So for each line item the ship to plant varies. I need to print the address for each line item after item. Since line items are coming inside 6 column table, the address line is interpreted inside the box itself - so thus the table line interfere and I am not able to solve this.

Please suggest.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member196280
Active Contributor
0 Kudos

Under line item element, after each line item get the address using subroutine and print.

Rgds,

SaiRam

Former Member
0 Kudos

Yes Sai,

I am using a subroutine, but the line items are having a column borders. So in between these the address is getting printed after every line item.

So these lines are interpreting in between.

Like is it possible to print a seperate line after every line item (with column border) and again next line item and so on.

Former Member
0 Kudos

Hi,

To print the ship to plant varies you have the Element in the main window, there in that some fields will be there, after the values just write the Address number, this should be inside the Element itself, so that it will call for every time of the line item

Regards

Sudheer

Former Member
0 Kudos

Sudheer,

I need to print detailed address,

Name, Street and PO Box. (One line content)/

Former Member
0 Kudos

There is no justify command in SAP Scripts. Think this document may help you...

SapScript

Transaction codes:

SE71 Form painter

SE72 Style maintenance

SE73 SapScript font maintenance

SO10 Create standard text module

Contents

Symbols and Control commands

Frames, Lines and Shading

Calling ABAP subroutines

The Print Program

Styles

Modifications

Symbols and Control commands

Symbols are placeholders for values that are inserted during print formatting.

Symbols are identified by name surrounded by "&" and are not case sensitive

· Types of symbols

· Formatting

· Control commands

Types of symbols

System symbols

DATE Date

DAY Day

NAME_OF_DAY Name of day

MONTH Month

YEAR Year

TIME Time

HOURS Hours

MINUTES Minutes

SECONDS Seconds

PAGE Page number

NEXTPAGE Number of next pagre

DEVICE Output device

SPACE Blank space

ULINE Underline

VLINE Vertical line

Standard symbols

Standard symbols are user defined and are maintained in table TTDG. You use transaction SM30 to change or display standard symbols.

An examples of standard symbols is &MFG& fot "Yours faithfully"

Standard text

Standard texts is predifined texts that can be used in more than one form. Standard texts are can be created, changed and displayed using transaction SO10.

The text ID is used to classify texts.

To include a standard text in a form, use the INCLUDE command:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD

When formatting the standard text the PARAGRAPH parameter is used. To center the text use:

/: INCLUDE

Parameters:

OBJECT E.g. TEXT, DOKU (Document), DSYS (Hypertext).

ID Text ID -Text ID is a way to group texts - Se transaction SO10

LANGUAGE If the parameter is not specefied, the logon language will be used

PARAGRAPH The text to be included is formatted using the style allocated. The PARAGRAPH parameter can be used to redefine the standard paragraph for this style for the current call. All *-paragraphs in the included text will then be formatted using the paragraph specified here.

· Object

· ID

· Language

· Paragraph

Standard texts are maintained in transaction SO10.

Example 1:

You have created a standard text in SO10 Named MYTEXT and with Text Id ST

/: INCLUDE MYTEXT OBJECT text ID st

Example 2:

You can also use a dynamic name so that you can retreive a ext depeding of the name variable:

/: INCLUDE &SCUSTOM-NAME& text ID st.

Depending on the name in the variable &SCUSTOM-NAME& different texts will be shown. Note that a text with the name in the variable &SCUSTOM-NAME& name must be created in SO10.

DEFINE

/: DEFINE &SYMBOL& = 'String1 String2'

/: DEFINE &CUST& = '00000021'.

ADDRESS-ENDDRESS

The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of the recipient's country, as defined in the

country parameter.

/: ADDRESS DELIVERY PARAGRAPH AD

/: NAME &KNA1-NAME&

/: STREET &KNA1-STRAS&

/: POSTCODE &KNA1-PSTLZ&

/: CITY &KNA1-ORT01&

/: COUNTRY &KNA1-LAND1&

/: FROMCOUNTRY 'DE'

/: ENDADDRESS

Time Date and decimal format

Examples:

/: SET TIME MASK = 'HH:MM'

/: SET DATE MASK = 'DD.MMMM.YYYY'

/: SET COUNTRY 'USA'

PROTECT-ENDPROTECT

Is used to avoid pagebreaks in a paragraph. The text lines to be protected are enclosed between the two commands. If there is not enough room on the page, the PROTECT command acts as a NEW-PAGE command and inserts a page break.

/: PROTECT

:

:

/: ENDPROTECT

5. Conditonal text ouput IF - ENDIF and CASE - ENDCASE

You can use IF/ENDIF and CASE/ENDCASE like in a normal ABAP program

/: IF condition

:

:

/: ENDIF

and

/: IF condition

:

/: ELSE

:

/: ENDIF

Example:

/: IF &SPFLI-CITYTO& = "BERLIN"

  • ..... put some text here

/: ENDIF

/: CASE

The intensity is the grey scale of the box as %. The frame parameters is the thickness of the frame. Default is 0.

Each of the paramteters ypos, xpos, width, height and frame muts be followed of the measurement unit:

· TW (twip)

· PT (point)

· IN (inch)

· MM (millimeter)

· CM (centimeter)

· LN (line)

· CH (character).

Examples:

/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10 FRAME 0 TW

/: BOX FRAME 10 TW

Draws a frame around the current window with a frame thickness of 10 TW (= 0.5 PT).

/: BOX INTENSITY 10

Fills the window background with shading having a gray scale of 10 %.

/: BOX HEIGHT 0 TW FRAME 10 TW

Draws a horizontal line across the complete top edge of the window.

/: BOX WIDTH 0 TW FRAME 10 TW

Draws a vertical line along the complete height of the left hand edge of the window.

/: BOX WIDTH '17.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15

/: BOX WIDTH '17.5' CM HEIGHT '13.5' CM FRAME 10 TW

/: BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW

/: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW

Draws two rectangles and two lines to construct a table of three columns with a highlighted heading section.

POSITION and SIZE

You can use the POSITION and SIZE commands to set default parmeters for a box. This can be usefull if you have several boxes that share the same parameters.

Example:

/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM

/: SIZE HEIGHT '2' MM WIDTH '76' MM

/: BOX FRAME 10 TW INTENSITY 10

If you want to set the position realtively to the window use POSITION WINDOW to set the position to the top/left start of the window. Then use POSITION to set the current position relatively to the start of the Window. Note that

you uses "+" or "-" in the ORIGIN position to the set the position relatively.

/: POSITION WINDOW

/: POSITION XORIGIN '5' MM YORIGIN '10' MM

the position is now 5 MM from the left and 10 MM from the top of the window.

NOTE: After using the position command you can move the current position realtively to the last used position

/: POSITION XORIGIN '10' MM YORIGIN '20' MM

Now the position will be X = 15 and Y = 30

More examples:

/: POSITION WINDOW

Sets the origin for the coordinate system to the upper left corner of the window.

/: POSITION XORIGIN 2 CM YORIGIN '2.5 CM'

Sets the origin for the coordinate system to a point 2 cm from the left edge and 2.5 cm from the upper edge of the output page.

/: POSITION XORIGIN '-1.5' CM YORIGIN -1 CM

Shifts the origin for the coordinates 1.5 cm to the left and 1 cm up.

Drawing a line

You can draw a line by setting the Height or Width of a box to 0 and add a frame. E.g. a horizontal line:

/: SIZE HEIGHT '0' MM WIDTH '200' MM

/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100

Window and Page

WINDOW sets the values for the width and height to the values of the current window (default setting).

PAGE Sets the values for the width and height to the values of the current output page.

Examples:

/: SIZE WINDOW

Sets WIDTH and HEIGHT to the current window dimensions.

/: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM

Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm.

/: POSITION WINDOW

/: POSITION XORIGIN -20 TW YORIGIN -20 TW

/: SIZE WIDTH +40 TW HEIGHT +40 TW

/: BOX FRAME 10 TW

A frame is added to the current window. The edges of the frame extend beyond the edges of the window itself, so as to avoid obscuring the leading and trailing text characters.

Calling ABAP subroutines

Back to SapScript menu

You can call an ABAP subroutine from SapScript using the PERFORM statment. You can use this to get data without havning to cnahge the print program. In the examole below NAME is retreived from table SCUSTOM.

SapScript

/:DEFINE &CUST& = '00000021'.

/:PERFORM GET_NAME IN PROGRAM Z_BC460_EX4_HF

/: USING &CUST&

/: CHANGING &NAME&

/:ENDPERFORM.

Dear &NAME&

The ABAP routine

The ABAP routine could be defined as follows:

IMPORTANT: The structure itcsy must be used for the parameters.

REPORT Z_HENRIKF_SCRIPT_FORM .

TABLES scustom.

FORM get_name tables in_tab structure itcsy out_tab structure itcsy.

read table in_tab index 1.

select single * from scustom

where id = in_tab-value.

if sy-subrc = 0.

read table out_tab index 1.

move scustom-name to out_tab-value.

modify out_tab index sy-tabix.

else.

read table out_tab index 1.

move 'No name' to out_tab-value.

modify out_tab index sy-tabix.

endif.

    • You could also fill the ouput parameter table this way

  • READ TABLE out_par WITH KEY 'NAME1'.

  • out_par-value = l_name1.

  • MODIFY out_par INDEX sy-tabix.

ENDFORM.

Note that if you use more than one parameter you must use Using or Changing before every parameter !

/: PERFORM

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

The Print Program

Back to SapScript menu

Structure of a print program

OPEN_FORM function

CLOSE_FORM function

WRITE_FORM

START_FORM function

END_FORM function

CONTROL_FORM function

The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options.

Function modules in a printprogram:

· When you print a form you must used the staments OPEN_FORM and CLOSE_FORM. To combine forms into a single spool request use START_FORM and END_FORM.

· To print textelements in a form use WRITE_FORM. The order in which the textelements are printed, is determined by the order of the WRITE_FORM statements. Note: for printing lines in the body, you can also use the WRITE_FORM_LINES function module.

· To transfer control command to a form use CONTROL_FORM.

Structure of a print program

  • Read data

Tables: xxx.

SELECT *

FROM xxx.

  • Open form printing - Must be called before working with any of the other form function modules.

  • Must be ended with function module CLOSE FORM

call function 'OPEN_FORM'.....

  • To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM

call funtion 'START_FORM'.....

  • Write text elements to a window of the form

call function 'WRITE_FORM'.....

  • Ends spool request started with START_FORM

call funtion 'END_FORM'.....

  • Closes form printing

call function 'CLOSE_FORM'...

OPEN_FORM function

Syntax:

CALL FUNCTION 'OPEN_FORM'

  • EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

  • DIALOG = 'X'

  • FORM = ' '

  • LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

  • EXCEPTIONS

  • CANCELED = 1

  • DEVICE = 2

  • FORM = 3

  • OPTIONS = 4

  • UNCLOSED = 5

  • MAIL_OPTIONS = 6

  • ARCHIVE_ERROR = 7

  • INVALID_FAX_NUMBER = 8

  • MORE_PARAMS_NEEDED_IN_BATCH = 9

  • SPOOL_ERROR = 10

  • OTHERS = 11

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Some important parameters:

FORM Name of the form

DEVICE · PRINTER : Print output using spool · TELEFAX: Fax output · SCREEN: Output to screen

OPTIONS Used to control attrubutes for printing or faxing (Number of copies, immediate output....The input for the parameter is structure ITCPO.

CLOSE_FORM function

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Paramerters:

RESULT Returns status information and print/fax parameters after the form has been printed. RESULT is of structure ITCPP.

WRITE_FORM function

CALL FUNCTION 'WRITE_FORM'

  • EXPORTING

  • ELEMENT = ' '

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

  • WINDOW = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • OTHERS = 9

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Some important parameters:

ELEMENT Specifies which textelement is printed

WINDOW Specifies which window is printed

TYPE Specifies the output area of the main window. This can be:· TOP - Used for headers · BODY · BOTTOM - Used for footers

FUNCTION Specifies whether text is to be appended, replaced or added

Example of how to use the WRITE_FORM function module together with a script.

Form layout of the MAIN window

/E INTRODUCTION

  • Dear Customer

...........................

/E ITEM_HEADER

IH Carrier, Departure

/E ITEM_LINE

IL &SBOOK-CARRID&, &SPFLI-DEPTIME&

/E CLOSING_REMARK

The print program

  • Writing INTRODUCTION

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'INTRODUCTION'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

.

  • Writing ITEM_HEADER

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

.

  • Set ITEM_HEADER into TOP area of main window for subsequent pages

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'SET'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

  • Write ITEM_LINE

LOOP AT .....

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_LINE'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8.

ENDLOOP.

  • Delete ITEM_HEADER from TOP area of main window

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'DELETE'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

  • Print CLOSING_REMARK

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'CLOSING_REMARK'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

START_FORM function

CALL FUNCTION 'START_FORM'

  • EXPORTING

  • ARCHIVE_INDEX =

  • FORM = ' '

  • LANGUAGE = ' '

  • STARTPAGE = ' '

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

  • EXCEPTIONS

  • FORM = 1

  • FORMAT = 2

  • UNENDED = 3

  • UNOPENED = 4

  • UNUSED = 5

  • SPOOL_ERROR = 6

  • OTHERS = 7

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

END_FORM function

CALL FUNCTION 'END_FORM'

  • IMPORTING

  • RESULT =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SPOOL_ERROR = 3

  • OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CONTROL_FORM function

The CONTROL_FORM function module allows you to create SapScript control statements from within an APAB program.

Syntax:

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command =

  • EXCEPTIONS

  • UNOPENED = 1

  • UNSTARTED = 2

  • OTHERS = 3

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Example:

Protecting the text element ITEM_LINE

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'PROTECT'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

TEXELEMENT = 'ITEM_LINE'.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'ENDPROTECT'.

Styles

Styles are used to predefine paragraph and character formats for forms. SAP provides several standard styles e.g. for Address includes, on-line documentation and so on. You can define your own styles.

To find styles, create styles and maintainse styles, use transaction SE72.

You assign style to a text by using menu Format -> Style

You can make temporary style changes using the control command /: STYLE

Modifications

Considerations in connection with modifications

The standard SAP print program should only be changed when it is absolutely necessary. If additional data is needed, these can in many cases be retrieved using a a PERFORM statement in the form instead of changing the print program..

There can be the following reasons to change the print program:

· Structureal changes

· New text eloements are needed

· Print program to be used to print additional forms

Determine/change which forms and printprograms that are used for printing

The forms and print programs for a given output type and application can be found in table TNAPR Processing programs for output

Use view V_TNAPR in (Transaction SE30) to change entries.

Graphics on SAPScript

The program RSTXLDMC can be used to upload graphics (file extension .tif on PC files) into individual standard text.

Helpful reports

RSCLTCOP Copy tables across clients

RSAVGL00 Table adjustment across clients

RSINCL00 Extended program list

RSBDCSUB Release batch-input sessions automatically

RSTXSCRP Transport SAPScript files across systems

RSORAREL Get the Oracle Release

RGUGBR00 Substitution/Validation utility

RSPARAM Display all instance parameters

RSUSR003 Check the passwords of users SAP* and DDIC in all clients

RSUSR006 List users last login

rewards point for helpful answer.