on 01-11-2008 2:42 PM
hi
How to send data from print program to Script?
thanks in advance
bramara k
Hi Bramara,
Here is a sample print program for a script.
Go through it and you will understand the concept better.
Inorder to send the data from the print program to the script,
we use the function module WRITE_FORM.
OPEN_FORM and CLOSE_FORM are to be used before and after WRITE_FORM.
We create an internal table in the print program and using a select querry we fill the internal table by taking the values from the data base tables.
Now we loop at that internal table and in the loop we need to call the function module WRITE_FORM,so that all the entries in the internal table are printed in the script.
&----
*& Report ZFLOC_SCRIPT
*&
&----
*&
*&
&----
report zfloc_script message-id zfloc.
tables: iflot.
--
data: begin of itab occurs 10,
tplnr like iflot-tplnr,
pltxt like iflo-pltxt,
invnr like iflot-invnr,
objnr like iflot-objnr,
erdat like iflot-erdat,
fltyp like iflot-fltyp,
iwerk like iflot-iwerk,
class like klah-class,
clint like kssk-clint,
iloan like iflot-iloan,
mapar like iflot-mapar,
tplkz like iflot-tplkz,
ernam like iflot-ernam,
end of itab.
--
parameters p_tplnr like iflot-tplnr memory id kas.
----
select single tplnr from iflot into iflot where tplnr eq p_tplnr.
if sy-subrc ne 0.
message e001.
endif.
--
call function 'OPEN_FORM'
exporting
APPLICATION = 'TX'
ARCHIVE_INDEX = ARCHIVE_INDEX
ARCHIVE_PARAMS = ARCHIVE_PARAMS
DEVICE = 'PRINTER'
DIALOG = 'X'
form = 'ZFLOC'
LANGUAGE = SY-LANGU
OPTIONS = OPTIONS
MAIL_SENDER = MAIL_SENDER
MAIL_RECIPIENT = MAIL_RECIPIENT
MAIL_APPL_OBJECT = MAIL_APPL_OBJECT
RAW_DATA_INTERFACE = '*'
SPONUMIV = SPONUMIV
IMPORTING
LANGUAGE = LANGUAGE
NEW_ARCHIVE_PARAMS = NEW_ARCHIVE_PARAMS
RESULT = 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.
--
start-of-selection.
select
i~tplnr
f~pltxt
i~invnr
i~objnr
i~erdat
i~fltyp
i~iwerk
a~class
k~clint
i~iloan
i~mapar
i~tplkz
i~ernam
into corresponding fields of table itab
from ( ( ( iflot as i inner join iflo as f on ftplnr = itplnr )
inner join kssk as k on kobjek = itplnr )
inner join klah as a on aclint = kclint )
where i~tplnr eq p_tplnr .
end-of-selection.
loop at itab.
--
call function 'WRITE_FORM'
exporting
element = 'LINE_ITEMS.'
FUNCTION = 'SET'
TYPE = 'BODY'
window = 'MAIN'
IMPORTING
PENDING_LINES = 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.
--
call function 'CLOSE_FORM'
IMPORTING
RESULT = RESULT
RDI_RESULT = RDI_RESULT
TABLES
OTFDATA = 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.
--
Now coming to the script,go to the text elements of the page windows.
Here we have to give the corresponding fields of the internal table used in the print program to print it on the script.
The field name should be written in between two ampersand.
For example : &ITAB-OBJNR&.
Only then the script reconizes that it is a field from the internal table itab.
By giving the same name of the internal in the script and in the print program,they both get linked
and when the WRITE_FORM written in the loop of the itab,the values are passed to the script and they are printed.
Regards,
Kashyap
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
plz try like this,
it may probably help you,
plz reward if helpful.
&----
*& Report Z71815_SAPSCRIPT
*&
&----
*&
*&
&----
report z71815_sapscript.
tables: vbrk.
select-options s_vbeln for vbrk-vbeln .
types: begin of s_itab,
vbeln type vbeln_vf,
kunrg type kunrg,
fkdat type fkdat,
xblnr type xblnr_v1,
waerk type waerk,
end of s_itab,
begin of s_itab2,
name1 type ad_name1,
street type ad_street,
city1 type ad_city1,
post_code1 type ad_pstcd1,
country type land1,
tel_number type ad_tlnmbr1,
end of s_itab2,
begin of s_itab3,
matnr type matnr,
arktx type arktx,
fkimg type fkimg,
vrkme type vrkme,
netwr type netwr_fp,
end of s_itab3.
data: itab type standard table of s_itab,
itab2 type standard table of s_itab2,
itab3 type standard table of s_itab3,
wa_itab type s_itab,
wa_itab2 type s_itab2,
wa_itab3 type s_itab3,
wa_adrnr type kna1-adrnr.
data : p(3) type p decimals 1,
wa_total type vbrk-netwr value 0.
select vbeln
kunrg
fkdat
xblnr
waerk
from vbrk
into corresponding fields of table itab
where vbeln in s_vbeln.
call function 'OPEN_FORM'
exporting
APPLICATION = 'TX'
ARCHIVE_INDEX =
ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
form = 'Z71815SAPSCRIPT1'
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.
loop at itab into wa_itab.
call function 'START_FORM'
exporting
ARCHIVE_INDEX =
form = 'Z71815SAPSCRIPT1 '
language = sy-langu
startpage = 'PAGE1 '
program = sy-repid
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 = 'HEADER '
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
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.
call function 'WRITE_FORM'
exporting
element = 'LEFT WINDOW'
FUNCTION = 'SET'
TYPE = 'BODY'
window = 'WINDOW1'
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 single adrnr from kna1 into wa_adrnr where kunnr = wa_itab-kunrg .
if sy-subrc = 0.
select single name1
street
city1
post_code1
country
tel_number
from adrc
into wa_itab2
where addrnumber = wa_adrnr and date_from <= sy-datum and date_to >= sy-datum.
endif.
call function 'WRITE_FORM'
exporting
element = 'RIGHT WINDOW'
FUNCTION = 'SET'
TYPE = 'BODY'
window = 'WINDOW2'
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.
call function 'WRITE_FORM'
exporting
element = 'MAIN'
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 matnr
arktx
fkimg
vrkme
netwr
from vbrp
into table itab3
where vbeln = wa_itab-vbeln .
clear p.
p = '0.5' .
loop at itab3 into wa_itab3 .
call function 'WRITE_FORM'
exporting
element = 'ITEM '
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.
wa_total = wa_total + wa_itab3-netwr.
p = p + '0.4' .
endloop .
call function 'WRITE_FORM'
exporting
element = 'TOTAL '
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.
call function 'WRITE_FORM'
exporting
element = 'FOOTER '
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
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.
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.
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.
regards,
srikanth tulasi,,,,
Edited by: srikanth tulasi on Jan 11, 2008 5:42 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bramara,
you can send the data from print program to script using the functions ..
open_form (Opens the layout set output)
write_form (Calls a layout set element)
close_form (Ends the layout set output)
all the three functions are Mandatory.
Reward points if helpful..
Regards,
Goutham.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.