cancel
Showing results for 
Search instead for 
Did you mean: 

Sapscript - abap program

rodrigo_paisante3
Active Contributor
0 Kudos

Hi,

Can you explain about the program to display a sapscript, with example?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

Sapscript is layout form and you need a driver(ABAP) program to pass the data to the script. In Driver program you select the required data and transfer this data to the script.

There are two ways for this.

1. There are Function module for opening, passing data and closing the form.

OPEN_FORM and CLOSE_FORM are FM for opening and closing the form. You use WRITE_FORM for passing the data to the script. You also use START_FORM and END_FORM to start one new layout.

2. You attach your script and your driver program to an output type in NACE transaction. You can see the entries in TNAPR table also. In NACE you define the program name and the method name (which is mostly with the name ENTRY)

In the driver program you do not use FM's like OPEN_FORM, CLOSE_FORM, START_FORM,END_FORM. You just your method ENTRY which is the entry point and you define all the logic here. Check out some standard script and their driver program. This method is used in Standard scritps.

Hope this explaination helps.

Regards,

Richa

Answers (5)

Answers (5)

rodrigo_paisante3
Active Contributor
0 Kudos

Thanks a lot!

Former Member
0 Kudos

Hi Rodrigo,

We basically use Sapcripts & Smartforms to develop Forms used in the business activities like Invoice Form, Quotation Form etc.

We use 2 components of SAP here:

1.Print Program or Driver Program.

2.SAP script or Smartforms.

<b>

Print Program :</b> A print Program is an normal Executable Z program which is used to retrieve data from different Database tables using the Select Stmt based on several conditions. Within this we use a few Function Modules which are mandatory namely :

(a) OPEN_FORM

(b) WRITE_FORM

(c) CLOSE_FORM

We can also use START_FORM & END_FORM when we want to trigger a new page. This is all about Print Program.

<b>SAP SCRIPT:</b> Here you Define a form , Pages, Windows and Paragraph .

Here is an Simple Example: SE38

In Print Program: ZPRG

REPORT ZPRG no standard page heading.

selection-screen begin of block b1.

parameters : name(20) type c,

designa(20) type c,

signatu(20) type c.

selection-screen end of block b1.

start-of-selection.

call function 'OPEN_FORM'

exporting

form = 'Z_TESTING1'

language = sy-langu.

call function 'WRITE_FORM'

exporting

element = 'MAIN'

type = 'BODY'

window = 'MAIN' .

call function 'CLOSE_FORM'.

Now, goto SE71

Create Form 'ZFORM'.

Go to PAGES , define page : Page1 and the description.

Then goto Window you will find MAIN window ---> Goto Page Windows

---> Click on EDIT ---> Create Element ---> Double click on Main Window .

The Main Window is include in the Page Windows.

when the Main Window is selected(Indication: Blue color)

go to EDIT -


> Text Elements.

In Text Editor:

/E : MAIN

P1: Name: &NAME&

P1: Desination: &DESIGNATION&

P1: Signature: &SIGNATURE&.

Goto Basic Settings.

Page Format : DINA4

First Page : Page1

Default Paragraph: P1

Just Copy & Paste the code it will work.

Hope this will be helpful.

Regards,

Daniel

Former Member
0 Kudos

Hi Rodrigo,

First after designing the form, save and activate it and design a drvier program for it. The driver program is used to call the values reuired from the tables into the SAP Script for dispalying in the output.

In the driver program , use these FM's:

Open_form => It assign the form and printer, It should be first.

Start_form => It start Writing mode. You can use write_form in loop to write more than one lines befor End_form.

End_form => It end writing mode of current page and will require to start again through Start_form.

Close_form=> it end the Form. After this you can not start again for created file.

Sample Driver Prg:

CALL FUNCTION 'OPEN_FORM'

  • EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

  • DIALOG = 'X'

  • FORM = 'ZSCRIPT1'

  • 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 'START_FORM'

EXPORTING

  • ARCHIVE_INDEX =

FORM = 'ZFORM1'

  • LANGUAGE = ' '

  • STARTPAGE = 'X'

PROGRAM = 'ZSCRIPT1'

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

  • EXCEPTIONS

  • FORM = 1

  • FORMAT = 2

  • UNENDED = 3

  • UNOPENED = 4

  • UNUSED = 5

  • SPOOL_ERROR = 6

  • CODEPAGE = 7

  • OTHERS = 8

.

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 = ' '

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

WINDOW = 'HEADER'

  • 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.

write:/ 'ERROR IN HEADER'.

  • 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 = ' '

  • 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.

write:/ 'ERROR IN HEADER'.

  • 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 = ' '

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

WINDOW = 'FOOTER'

  • 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.

write:/ 'ERROR IN HEADER'.

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

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

ENDIF.

CALL FUNCTION 'END_FORM'

  • IMPORTING

  • RESULT =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SPOOL_ERROR = 3

  • CODEPAGE = 4

  • OTHERS = 5

.

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

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

Former Member
0 Kudos

Hai Rodrigo Paisante,

The <b>simplest report</b> to call the script through is below:

DATA:

BEGIN OF FS_EMP,

PNAME LIKE

YASH_PROGRAMMER-PNAME, " Programmer Name

DOB LIKE

YASH_PROGRAMMER-DOB, " Date of Birth

DOJ LIKE

YASH_PROGRAMMER-DOJ, " Date of joining

SALARY LIKE

YASH_PROGRAMMER-SALARY, " Salary

END OF FS_EMP.

"----


  • Internal table to hold spfli data *

"----


DATA:

T_EMP LIKE STANDARD TABLE OF FS_EMP.

SELECT PNAME " Programmer Name

DOB " Date of Birth

DOJ " Date of joining

SALARY " Salary

INTO TABLE T_EMP

FROM YASH_PROGRAMMER. " SELECT PNAME

IF SY-SUBRC NE 0.

MESSAGE 'No records found in YASH_PROGRAMMER table' TYPE 'I'.

STOP.

ENDIF. " IF SY-SUBRC NE 0.

CALL FUNCTION <b>'OPEN_FORM'</b>

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

  • DIALOG = 'X'

FORM = 'YH650_060203'

  • 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. " IF SY-SUBRC <> 0.

LOOP AT T_EMP INTO FS_EMP.

CALL FUNCTION <b>'WRITE_FORM'</b>

EXPORTING

ELEMENT = 'DATA'

  • 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

CODEPAGE = 9

OTHERS = 10

.

IF SY-SUBRC <> 0.

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

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

ENDIF. " IF SY-SUBRC <> 0.

  • ADD FS_EMP-SALARY TO W_F_TOTAL.

  • ADD FS_EMP-SALARY TO W_P_TOTAL.

  • ADD FS_EMP-SALARY TO W_G_TOTAL.

ENDLOOP. " LOOP AT T_EMP INTO FS_EMP.

<b>CALL FUNCTION 'CLOSE_FORM'</b>

  • 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. " IF SY-SUBRC <> 0.

Hope this helps you.

<b>Reward points if it helps you.</b>

Regds,

Rama chary.Pammi

Former Member
0 Kudos

Hi,

The program used to display a SapScript is called as Driver Program/Print Program.It actually passes the relevant data to the SapScript. It uses various Function Modules in this process.For more information,please refer the documentation of those function modules.

Function Module 'Open_Form':This FM initializes the layout set printing.

Function Module 'Start_Form':This FM prints several identical layout sets containing different data within a single spool request.

Function Module 'Write_Form':This FM outputs the text elements in the window of a layout set.

Simple PROGRAM for Example:

Report ZABC.

SELECTION-SCREEN BEGIN OF BLOCK B1.

PARAMETERS : NAME(20) TYPE C,

DESIGNA(20) TYPE C,

SIGNATU(20) TYPE C.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'Z_TESTING1'

LANGUAGE = SY-LANGU

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.

CALL FUNCTION 'START_FORM'

EXPORTING

FORM = 'Z_TESTING1'

LANGUAGE = 'E'

STARTPAGE = 'PAGE1'

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

OTHERS = 7.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'MAIN'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

OTHERS = 9.

CALL FUNCTION 'END_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4.

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

OTHERS = 5.

This program just passes the data entered in the selection screen to the SapScript for display.

Hope this helps.

Please reward if useful.

Thanks,

Srinivasa