cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAPscript Prgram/Form Example

Former Member
0 Likes
3,529

Hi

I'm new to sapscript. so please bear with me.

When using SAPscript one has a program that gets all the data, then a form is created on top of it. I would like to know the following on the program.

1) The ABAP program will retrieve the data, is there any certain place it must place the data for you to be able to make the SAPscript form be able to access the data.

2) Does anyone have a simple example with all the steps. When I say example I would like to see a small program that asks for 1 paramater (document numer,ect), retrieves data based on that parameter. Then step by step how to create that form based on the data from the simple program. Nothing fancy, just show one line, one column (one field) of data on the print. I just hope to get an example where I see just one field printed out that came from the ABAP programs data retrieved from the database.

I will happily reward points for helpfull answers. Full points instantly if I can do number 2 on my side based on feedback from posts.

Thank you in advance

View Entire Topic
Former Member
0 Likes

This is the sample program used to print a script.

REPORT Z1SCRIPT_TO_PDF .

All these are data declarations to select data and pass it to the script.

***************************DECLARATIONS*******************************

DATA: BEGIN OF ITAB OCCURS 0,

CARRID TYPE SFLIGHT-CARRID,

CONNID TYPE SFLIGHT-CONNID,

PRICE TYPE SFLIGHT-PRICE,

END OF ITAB.

DATA: struct TYPE ITCPO.

DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,

DATAB TYPE TABLE OF ITCOO WITH HEADER LINE,

DATA: BINFILESIZE TYPE I,

FILE_NAME TYPE STRING,

FILE_PATH TYPE STRING,

FULL_PATH TYPE STRING.

© 2006 SAP AG 4

***************************END OF DECLARATIONS*******************************

To specify Printer name

struct-tddest = 'LP01'.

To specify no Print Preview

struct-tdnoprev = 'X'.

To access the SAP Script output in OTF format

struct-tdgetotf = 'X'.

**************************SAPSCRIPT GENERATION*******************************

This Function Module is used to open a form for Printing. With out this function module you can't print anything in the form.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

DEVICE = 'PRINTER'

DIALOG = space

FORM = 'ZSCRIPT'

  • LANGUAGE = SY-LANGU

OPTIONS = struct

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

© 2006 SAP AG 5

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

  • LANGUAGE = ' '

  • STARTPAGE = ' '

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

CODEPAGE = 7

OTHERS = 8

.

© 2006 SAP AG 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.

This function module is used to display for particular window and particular text element. In this FM you have to specify the name of the window and element. You have to call this FM as many times as the number of windows you have.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ELEM1'

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.

SELECT CARRID CONNID PRICE FROM SFLIGHT INTO TABLE ITAB.

LOOP AT ITAB.

CALL FUNCTION 'WRITE_FORM'

© 2006 SAP AG 7

EXPORTING

ELEMENT = 'ELEM2'

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.

ENDLOOP.

This is to close the form after printing. With out this function module you can't print any thing. It is mandatory to close the form at end of printing.

CALL FUNCTION 'END_FORM'

  • IMPORTING

  • RESULT =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

CODEPAGE = 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.

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

TABLES

OTFDATA = DATAB[]

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.

**************************END OF SAPSCRIPT GENERATION*******************************

Reward points if helpfull.

with regards,

Srinivasu.....