cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Script

Former Member
0 Kudos

Hallo friends,

I have a practical interview very soon. Just to be on the save side, I want to create and develop a simple form, using script. I have created and modify forms using SmartForm before. I also have enough Tutorials (pdf) on script.

Nevertheless, I would appriciate if someone can guide me through step-by-step on creating/developing a simple form(SAPscript). Data: Sflight ...

Please like this:

Step 1.

what I have to do .....

Step 2.

what I have to do....

etc.

Example of selection:

data ITAB type Standard table of sflight.

Select * from sflight

into ITAB

where

carrid = p_carrid and

connid = p_connid.

<b>Please no links, except if it gives very very simply and uncomplicated explanation in Step-by-Step as my wish, else guide me through as I wish above.</b>

Blacky.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi BlackMoses ,

The select statement you wrote is a report program..

First of all you need to create a layout in Se71 which describes how u need to format the output. Here you create pages, windows, paragraph formats and character formats.. Windows are assigned to a page using page window.. Hence u need to provide the coordinates when u are assigning a page to page window.

I assume u have a simple layout ready...

Now to print data we use &itab-field1& as the way to print it here in any window.

Windows are of 2 types : Main n variable windows.

Main window can display continuous data while variable can display only one record no matter what the size of the window is.

Eg : &itab-f1&,,&itab-f2&,,&itab-f3&

Plz note the ",," is used to demarcate tabs which are created in paragraph formats.

Now in the report program u created to fetch data, u need to call this script and pass data to it. For this we need 3 function modules.

1) open_form

Pass the script name

2) Write_form

To pass data from the report to the script.

Eg : loop at itab.

Call function Write_form.

......

Endloop.

3) Close_form

To complete the writing

Ps : Please reward points if helpful.

Former Member
0 Kudos

Thanks for your all the replies I got. Especially the link from Anji. I will take the time to read through carefully. Nevertheless I still have the following Questions.

Questions:

1. Program symbols

How do I generate the program symbols. Example &Sflight-carrid&. Does the system generate the program symbols, from my ABAP code, automatically at run time or I have to write it hard in Windows-Text Elements?

In one of the pdf Tutorials that I have, it is stated that the symbols has to be defined in Data Dictionary and fille with values by the output program.

2. Text Symbols

3. Windows-Text Elements

How do I get the Program symbols into the windows-text elements?

In Smart Form, we get program symbols in the Windows-text Element with Drag and Drop.

Blacky.

I have given points

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks guys

Blacky.

Former Member
0 Kudos

<b> hi,

step 1. Go to transaction SE71.

step 2. Design your form.

First create a first page using the page button.

If you want to create a next page create it.

In the first page , set the next page attribute to next page &

for the second page set it to the same page itself.

step 3. go to header->basic settings & provide the start page

as the first page.

step 4. create the no. of windows you want. (use window button)

for simplicity create 3 windows.

- a main window

- a logo window

- a footer window.

step 5. go to page windows & choose the windows you want for each page.

Also provide the co-ordinates for each page window .

Thumb rule: vertical distance - unit should be ln(lines)

horizontal distance - unit should be ch(characters)

step 6 go to form painter & resize the window.

note: keep the width of the main window same on both the

pages (this of course happens automatically)

step 7 write the driver program.

1. create an internal table of 3 fields say.

2. select the data for them & populate the internal table

3. use the function module open_form.

4. use the function module write_form.

To print all the contents of internal table, use the

following style.

LOOP AT ITAB .

call the function module write_form.

Also remember to pass the text element (any meaningful name),

window name, set the Function parameter to 'Append' & Type

parameter to 'Body'.

Endloop.

step 8. go to page windows & choose the main window, double click it

& press F9.

Then a line editor comes up.

On the left corner put /E (indicates text element) & follow

the name of the text element given & then provide the

internal table field name between &&

e.x. &wa_kna1-kunnr&

Thats all you have to do & plz reward some pts. if it helps you,

Thank you.

</b>

Former Member
0 Kudos

Hi

see the sample script program

&----


*& Report ZTEST12121

*& SAPScripts Example 1

&----


REPORT ztest12121.

*DATABASE TABLES

TABLES: ekko,ekpo,lfa1.

*INTERNAL TABLES AND STRUCTURES

DATA i_ekko LIKE ekko.

DATA i_ekpo LIKE ekpo OCCURS 0 WITH HEADER LINE.

DATA i_lfa1 LIKE lfa1.

*PARAMETERS

PARAMETERS: p_ebeln LIKE ekko-ebeln.

*VARIABLES

DATA MAT TYPE STRING VALUE 'MAT NO'.

DATA iTe TYPE STRING VALUE 'ITEM NO'.

DATA QTY TYPE STRING VALUE 'QTY'.

DATA UOM TYPE STRING VALUE 'UOM'.

DATA NET TYPE STRING VALUE 'NET PRICE'.

Data var type integer value 0.

*DATABASE SELECTS

*Header data

SELECT SINGLE * FROM ekko INTO i_ekko WHERE ekko~ebeln = p_ebeln.

IF sy-subrc = 0.

*Item Data

SELECT * FROM ekpo INTO TABLE i_ekpo WHERE ekpo~ebeln = p_ebeln.

IF sy-subrc NE 0.

WRITE 'PURCHASE DOCUMENT ITEM DATA ERROR'.

ELSE.

*Vendor Details

SELECT SINGLE * FROM lfa1 INTO i_lfa1 WHERE lfa1~lifnr = i_ekko-lifnr.

IF sy-subrc NE 0.

WRITE 'VENDOR DOCUMENT ITEM DATA ERROR'.

ENDIF.

ENDIF.

ELSE.

WRITE 'THIS PURCHASE DOCUMENT NUMBER DOESNOT EXISTS'.

ENDIF.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

  • DIALOG = 'X'

form = 'ZSCRIPT_1'

language = sy-langu

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • 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

  • CODEPAGE = 11

  • OTHERS = 12

.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'OFFICEAD'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'OFFICEAD'

.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'PODET'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'PODET'

.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'TOP'

FUNCTION = 'SET'

TYPE = 'TOP'

WINDOW = 'MAIN'

.

IF sy-subrc <> 0.

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

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

ENDIF.

LOOP AT I_EKPO.

var = i_ekpo-netpr * i_ekpo-menge.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'BODY'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • CODEPAGE = 5

  • OTHERS = 6

.

IF sy-subrc <> 0.

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

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

ENDIF.

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 alows 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'.

Link for SAP Scripts (step by step procedure)

http://smoschid.tripod.com/How_to_do_things_in_SAP/How_To_Create_A_SAPSCRIPT_Form/How_to_Create_SAPS...

Regards

Anji

Former Member
0 Kudos

Thanks for your all the replies I got. Especially the link from Anji. I will take the time to read through carefully. Nevertheless I still have the following Questions.

Questions:

1. Program symbols

How do I generate the program symbols. Example &Sflight-carrid&. Does the system generate the program symbols, from my ABAP code, automatically at run time or I have to write it hard in Windows-Text Elements?

In one of the pdf Tutorials that I have, it is stated that the symbols has to be defined in Data Dictionary and fille with values by the output program.

2. Text Symbols

3. Windows-Text Elements

How do I get the Program symbols into the windows-text elements?

In Smart Form, we get program symbols in the Windows-text Element with Drag and Drop.

Blacky.

I have given points