09-24-2007 7:23 AM
HI ALL,
Give me example on sap scripts.
How to pass internal table through write_form functional module.
Please send the examples.
09-24-2007 7:24 AM
Hi Rakesh,
Please follow the link given below to explore SAPSCRIPT.
SAPSCRIPT
SAPSCRIPT 2
http://www.sapbrain.com/TUTORIALS/TECHNICAL/SAPSCRIPTS_tutorial.html
http://www.sap-img.com/sapscripts.htm
Link for SAP Scripts (step by step procedure)
http://esnips.com/doc/1ff9f8e8-0a4c-42a7-8819-6e3ff9e7ab44/sapscripts.pdf
http://esnips.com/doc/1e487f0c-8009-4ae1-9f9c-c07bd953dbfa/script-command.pdf
http://esnips.com/doc/64d4eccb-e09b-48e1-9be9-e2818d73f074/faqss.pdf
http://esnips.com/doc/cb7e39b4-3161-437f-bfc6-21e6a50e1b39/sscript.pdf
http://esnips.com/doc/fced4d36-ba52-4df9-ab35-b3d194830bbf/symbols-in-scripts.pdf
SAP SCRIPT FIELDS
http://help.sap.com/saphelp_erp2005vp/helpdata/en/d1/8033ea454211d189710000e8322d00/content.htm
scripts easy material
http://www.allsaplinks.com/sap_script_made_easy.html
Other Links
http://www.virtuosollc.com/PDF/Get_Reporter.pdf
http://help.sap.com/saphelp_47x200/helpdata/en/da/6ada3889432f48e10000000a114084/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/66/bc7d2543c211d182b30000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/5b/d22cee43c611d182b30000e829fbfe/frameset.htm
http://www.virtuosollc.com/PDF/Get_Reporter.pdf
http://help.sap.com/saphelp_47x200/helpdata/en/da/6ada3889432f48e10000000a114084/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/66/bc7d2543c211d182b30000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/5b/d22cee43c611d182b30000e829fbfe/frameset.htm
http://www.thespot4sap.com/Articles/Code_CostCentreReport.asp
http://www.allsaplinks.com/dialog_programming.html
http://help.sap.com/saphelp_webas630/helpdata/en/9f/db9cdc35c111d1829f0000e829fbfe/frameset.htm
http://www.allsaplinks.com/files/using_table_in_screen.pdf
http://www.geocities.com/ZSAPcHAT
http://www.sappoint.com/abap/ssintro.pdf
http://www.sappoint.com/abap/sscript.pdf
http://www.sappoint.com/abap/sscript.pdf
http://www.sappoint.com/abap/lsetssap.pdf
http://www.sappoint.com/abap/sscrtpex1.pdf
http://www.sap-img.com/sapscripts.htm
http://www.thespot4sap.com/Articles/SAPscript_Introduction.asp
http://www.sapbrain.com/TUTORIALS/TECHNICAL/SAPSCRIPTS_tutorial.html
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVSCRPROG/BCSRVSCRPROG.pdf
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVSCRRDI/BCSRVSCRRDI.pdf
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVSCREDIT/BCSRVSCREDIT.pdf
http://www.sappoint.com/abap/sscrtpex1.pdf
http://www.sap-img.com/sapscripts.htm
http://www.esnips.com/doc/1ff9f8e8-0a4c-42a7-8819-6e3ff9e7ab44/sapscripts.pdf
Thanks,
Reward If helpful.
09-24-2007 7:37 AM
Hi
Chek this code.
&----
*& Report
&----
*&
*&
&----
report message-id z8pa.
*Structure declaration.
types: begin of i_vbak,
vbeln type vbeln_va, "sales document
erdat type erdat, "date of creation
kunnr type kunag, "customer number
end of i_vbak.
types: begin of i_vbap,
vbeln type vbeln_va, "sales document
posnr type posnr_va, "item number
matnr type matnr, "material number
arktx type arktx, "material description
arktx1 type arktx, "material description
kwmeng type kwmeng, "quantity
meins type meins, "unit of measurement
netpr type netpr, "amount
end of i_vbap.
types: begin of i_kna1,
kunnr type kunnr, "customer number
adrnr type adrnr, "address
name1 type name1_gp, "name of the customer
ort01 type ort01_gp, "city
end of i_kna1.
types: begin of i_vbpa,
vbeln type vbeln, "sales document
posnr type posnr, "item number
parvw type parvw, "partner function
kunnr type kunnr, "customer number
kunnr1 type kunnr, "customer number
end of i_vbpa.
types: begin of i_final,
vbeln type vbeln_va, "sales document
erdat type erdat, "date of cretaion
kunnr type kunnr, "customer number
kunnr1 type kunnr, "customer number
posnr type posnr_va, "item number
matnr type matnr, "material number
arktx type arktx, "mateial description
arktx1 type arktx, "mateial description
kwmeng type kwmeng, "quantity
meins type meins, "unit of measurement
netpr type netpr, "net price
adrnr type adrnr, "address
name1 type name1_gp, "name
ort01 type ort01_gp, "city
parvw type parvw, "partner function
end of i_final.
*Internal table declaration
data: it_vbak type standard table of i_vbak.
data: it_vbap type standard table of i_vbap.
data: it_kna1 type standard table of i_kna1.
data: it_vbpa type standard table of i_vbpa.
data: it_final type standard table of i_final.
*work area declaration
data: wa_vbak type i_vbak,
wa_vbap type i_vbap,
wa_kna1 type i_kna1,
wa_vbpa type i_vbpa,
wa_final type i_final.
*variables declared with type workarea.
data: v_vbeln type vbak-vbeln.
data: a_vbeln like wa_final-vbeln,
v_posnr like wa_final-posnr,
v_matnr like wa_final-matnr,
v_arktx like wa_final-arktx,
x_arktx like wa_final-arktx,
v_zmeng like wa_final-kwmeng,
v_meins like wa_final-meins,
v_mwsbp like wa_final-netpr,
v_kunnr like wa_final-kunnr,
v_kunnr1 like wa_final-kunnr1,
v_adrnr like wa_final-adrnr,
v_name1 like wa_final-name1,
v_ort01 like wa_final-ort01,
v_erdat like wa_final-erdat.
*DATA: v_amount TYPE netpr.
data: p_netpr like wa_final-netpr.
data: p_kwmeng like wa_final-kwmeng.
data: v_count type i value '0'.
data: v_count1 type i value '0'.
data : v_id type tdid,
v_object type tdobject,
v_name type tdobname.
data : t_text like standard table of tline with header line.
*data: begin of t_text occurs 0.
include structure tline.
*data: end of t_text.
data: v_tdline type tline-tdline.
*select options
selection-screen begin of block blk1 with frame title text-001.
select-options: s_vbeln for v_vbeln.
selection-screen end of block blk1.
*at selection screen
at selection-screen.
*Checks the sales order number exists in database.
select vbeln into v_vbeln
up to 1 rows
from vbak
where vbeln in s_vbeln.
endselect.
*if no single data exists it displays error msgs.
if sy-subrc <> 0.
message e000.
endif.
*start of selection.
start-of-selection.
perform open_form.
select vbeln
erdat
kunnr into corresponding fields of table it_vbak
from vbak
where vbeln in s_vbeln.
if sy-subrc = 0.
sort it_vbak by vbeln.
select vbeln
posnr
matnr
arktx
kwmeng
meins
netpr into corresponding fields of table it_vbap
from vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln.
endif.
if sy-subrc = 0.
sort it_vbap by vbeln posnr.
select vbeln
posnr
parvw
kunnr into table it_vbpa
from vbpa
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
endif.
if sy-subrc = 0.
sort it_vbpa by vbeln.
endif.
*move header data to final table.
loop at it_vbap into wa_vbap.
read table it_vbak into wa_vbak with key vbeln = wa_vbap-vbeln
binary search.
if sy-subrc = 0.
move: wa_vbak-vbeln to wa_final-vbeln,
wa_vbak-erdat to wa_final-erdat,
wa_vbak-kunnr to wa_final-kunnr.
*Move details data to final table.
move: wa_vbap-posnr to wa_final-posnr,
wa_vbap-matnr to wa_final-matnr,
wa_vbap-arktx to wa_final-arktx,
wa_vbap-kwmeng to wa_final-kwmeng,
wa_vbap-meins to wa_final-meins,
wa_vbap-netpr to wa_final-netpr.
endif.
*selecting the customer data as per kunnr in vbak table.
select kunnr
adrnr
name1
ort01 into table it_kna1
from kna1
where kunnr = wa_vbak-kunnr.
*Move customer data to final table
read table it_kna1 into wa_kna1 with key kunnr = wa_vbak-kunnr
binary search.
if sy-subrc = 0.
move: wa_kna1-kunnr to wa_final-kunnr,
wa_kna1-adrnr to wa_final-adrnr,
wa_kna1-name1 to wa_final-name1,
wa_kna1-ort01 to wa_final-ort01.
endif.
*Move partner data to final table.
read table it_vbpa into wa_vbpa with key vbeln = wa_vbap-vbeln
binary search.
if sy-subrc = 0.
if wa_vbpa-parvw = 'AG' . "sold to party
move: wa_vbpa-parvw to wa_final-parvw,
wa_vbpa-kunnr1 to wa_final-kunnr1.
elseif wa_vbpa-parvw = 'WE'. " ship to party
move: wa_vbpa-parvw to wa_final-parvw,
wa_vbpa-kunnr to wa_final-kunnr.
endif.
append wa_final to it_final.
clear wa_final.
endif.
endloop.
*End of selection.
end-of-selection.
*Display the data
perform display_data.
perform close_form.
*& Form DISPLAY_DATA
form display_data .
Looping at final table into work area and moving it all into the variables.
loop at it_final into wa_final.
a_vbeln = wa_final-vbeln.
v_posnr = wa_final-posnr.
v_matnr = wa_final-matnr.
v_arktx = wa_final-arktx+0(23).
x_arktx = wa_final-arktx+23(17).
v_zmeng = wa_final-kwmeng.
v_meins = wa_final-meins.
v_mwsbp = wa_final-netpr.
v_kunnr = wa_final-kunnr.
v_kunnr1 = wa_final-kunnr1.
v_adrnr = wa_final-adrnr.
v_name1 = wa_final-name1.
v_ort01 = wa_final-ort01.
v_erdat = wa_final-erdat.
at new vbeln.
Calling function start-form.
call function 'START_FORM'
exporting
form = 'Z8PA_SO'
exceptions
form = 1
format = 2
unended = 3
unopened = 4
unused = 5
spool_error = 6
codepage = 7
others = 8.
if sy-subrc <> 0.
endif.
calling function write form for window 3
call function 'WRITE_FORM'
exporting
window = 'Sr no'
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.
endif.
calling function write form for window 4
call function 'WRITE_FORM'
exporting
window = 'sold to party'
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.
endif.
calling function write form for window 5
call function 'WRITE_FORM'
exporting
window = 'ship to party'
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.
endif.
endat.
perform z_main.
v_count1 = v_count1 + v_zmeng.
v_count = v_count + v_mwsbp.
calling function write form for Subtotal on each page
call function 'WRITE_FORM'
exporting
element = 'BOTTOM'
function = 'SET'
window = 'MAIN'
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.
endif.
at end of vbeln.
clear: v_count,
v_count1.
perform z_total.
call function 'WRITE_FORM'
exporting
element = 'SO_TEXT2'
function = 'SET'
type = 'BOTTOM'
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.
*
v_id = 'ST'.
v_name = 'EXAMPLE TEXT'.
v_object = 'TEXT'.
call function 'READ_TEXT'
exporting
client = sy-mandt
id = v_id
language = sy-langu
name = v_name
object = v_object
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
tables
lines = t_text
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 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.
loop at t_text.
call function 'WRITE_FORM'
exporting
element = 'SO_TEXT'
function = 'SET'
type = 'BOTTOM'
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.
at last.
sum.
calling function write form for Total
call function 'WRITE_FORM'
exporting
element = 'TOTAL'
function = 'APPEND'
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
codepage = 9
others = 10.
if sy-subrc <> 0.
endif.
endat.
calling function write form for end form
call function 'END_FORM'
exceptions
unopened = 1
bad_pageformat_for_print = 2
spool_error = 3
codepage = 4
others = 5.
if sy-subrc <> 0.
endif.
endat.
endloop.
endform. " DISPLAY_DATA
*& Form open_form
form open_form .
calling function write form for open form
call function 'OPEN_FORM'
exporting
device = 'PRINTER'
language = sy-langu
dialog = ' '
form = 'Z8PA_SO'
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.
endform. " open_form
*& Form close_form
form close_form .
calling function write form for close form
call function 'CLOSE_FORM'
exceptions
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
others = 6.
if sy-subrc <> 0.
endif.
endform. " close_form
*& Form Z_MAIN
form z_main .
calling function write form for main window headings.
call function 'WRITE_FORM'
exporting
element = 'COLOUMN HEADINGS'
function = 'SET'
type = 'TOP'
window = 'MAIN'
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.
endif.
calling function write form for main window details
call function 'WRITE_FORM'
exporting
element = 'DETAILS'
function = 'SET'
type = 'BODY'
window = 'MAIN'.
if sy-subrc <> 0.
endif.
endform. " Z_MAIN
*&Form Z_TOTAL
form z_total.
sum.
p_netpr = wa_final-netpr.
p_kwmeng = wa_final-kwmeng.
calling function write form for Subtotals
call function 'WRITE_FORM'
exporting
element = 'SUBTOTAL'
function = 'SET'
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
codepage = 9
others = 10.
if sy-subrc <> 0.
endif.
endform. " Z_TOTAL
Regards,
Pritha.