cancel
Showing results for 
Search instead for 
Did you mean: 

result of report on a script

Former Member
0 Kudos

Hi all,

how can i get the result of the report on a script.

Thanks in advance

Santosh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Submit the report from a program using the "EXPORTING LIST TO MEMORY AND RETURN" addition, then retrieve the list with function module "LIST_FROM_MEMORY". Then use function module "LIST_TO_ASCI" to turn the result into text. You can then put this in a table of the format for standard texts and save it using SAVE_TEXT function module.

This text can be included in a sapscript form, or printed directly using FM PRINT_TEXT.

Andrew

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

First write the report code with proper data fetching

Don't write the WRITE statements

design a Script layout in SE71 tcode with the data fields of this internal tables data of the report

then call the script in the report using the fun module OPEN_FORM and pass the parameter of the SCript name to it.

And use the fun modules WRITE_FORM in the loop of the internal table to print the data of the report in the script

and finally after loop call the fun module CLOSE_FORM

see the sample program code and do accordingly

&----


*& 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.

<b>Reward points for useful Answers</b>

Regards

Anji