‎2008 Jan 05 8:21 AM
Hi Experts,
I would like to learn scripts and smartform.
Kindly explain me
1. What is the tcode for creating scripts.
2. A small example code
3. How to enter the code and execute.
Thanks,
Shilpa
‎2008 Jan 05 8:54 AM
Hi shilpa,
I will explain step by step procudure for creating scrips.Follow the procedure.
1. What is the tcode for creating scripts.
A. SE71.
A small example code
STEP 1: Goto se38 and create one new report there and write the following code there.
-
&----
*
*& Report YSCRIPT_SALESORDER *
*& *
&----
*& DEVELOPER : KIRAN KUMAR.G *
*& PURPOSE : CREATING SALES ORDER REPORT FOR A CUSTOMER *
*& CREATION DT: 6/12/2007 *
*& REQUEST : ERPK900035 *
&----
REPORT YSCRIPT_SALESORDER.
----
Tables
----
TABLES: vbak, "Sales Document: Item Data
vbap. "Sales Document: Header Data
----
Internal Table
----
DATA: BEGIN OF gt_data OCCURS 0,
kunnr LIKE vbak-kunnr, "Sold-to party
vbeln LIKE vbak-vbeln, "Sales Document
posnr LIKE vbap-posnr, "Sales Document Item
matkl LIKE vbap-matkl, "Material Group
netpr LIKE vbap-netpr, "Net Price
name1 LIKE kna1-name1, "Name 1
ort01 LIKE kna1-ort01, "City
pstlz LIKE kna1-pstlz, "Postal Code
regio LIKE kna1-regio, "Region (State, Province, County)
END OF gt_data.
----
Global Data
----
DATA: gvar LIKE sy-tabix.
----
Selection Screen
----
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_kunnr FOR vbak-kunnr,
s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN : END OF BLOCK b1.
----
Initilization
----
INITIALIZATION.
PERFORM initial_data.
----
Fetch Data
----
START-OF-SELECTION.
PERFORM fetch_data.
----
Dispaly Data (Transfer data form print program to layout set)
----
END-OF-SELECTION.
PERFORM display_data.
&----
*& Form initial_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM initial_data .
s_kunnr-sign = 'I'.
s_kunnr-option = 'BT'.
s_kunnr-low = '1001'.
s_kunnr-high = '1390'.
APPEND s_kunnr.
s_vbeln-sign = 'I'.
s_vbeln-option = 'BT'.
s_vbeln-low = '0000004969'.
s_vbeln-high = '0000005000'.
APPEND s_vbeln.
ENDFORM. " initial_data
&----
*& Form fetch_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM fetch_data.
refresh : gt_data.
clear : gt_data.
SELECT a~kunnr
a~vbeln
b~posnr
b~matkl
b~netpr
c~name1
c~ort01
c~pstlz
c~regio
FROM vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln
INNER JOIN kna1 AS c ON akunnr = ckunnr
INTO TABLE gt_data
WHERE a~kunnr IN s_kunnr
AND a~vbeln IN s_vbeln.
ENDFORM. " fetch_data
-
STEP 2: we have to transfer above data to script layout ok..
For that the necessary conditions are
1.We have to open the Form..
call function module :OPEN_FORM
2.For printng the data we use the function module WRITE_FORM.
3.Finally we close the Form.
The code for above 3 steps is as below:
CALL FUNCTION 'OPEN_FORM'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX =
ARCHIVE_PARAMS =
device = 'PRINTER'
DIALOG = 'X'
form = 'ZSCRIPT_SO'
language = sy-langu
OPTIONS =
MAIL_SENDER =
MAIL_RECIPIENT =
MAIL_APPL_OBJECT =
RAW_DATA_INTERFACE = '*'
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.
Here FORM NAME IS "ZSCRIPT_SO"(SE71 = SCRIPT NAME)
LOOP AT gt_data. "Internal table name: gt_data
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.
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.
-
Award points if helpful.
Kiran Kumar.G
Have a Nice Day..
‎2008 Jan 05 8:41 AM
hai pls use se71 for scripts ....see predefined form name as medruck. its for purchase order application. if u face any problem i will send u step by step...
‎2008 Jan 05 8:43 AM
T.Code SE71 to Create SAP Script.
Check the following links for understanding SAP Scripts:
http://www.sap-img.com/sapscripts.htm
http://help.sap.com/saphelp_crm40/helpdata/en/16/c832857cc111d686e0000086568e5f/content.htm
http://www.experts-exchange.com/Database/Software/ERP/SAP/Q_21650686.html
http://www.sap-img.com/sapscripts/a-sample-sap-scripts-reports.htm
http://www.thespot4sap.com/Articles/SAPscript_example_layout%20set.asp
http://sapabaplive.blogspot.com/2007/12/sap-script-structure-of-text-components.html
Reward points if helpful.
‎2008 Jan 05 8:51 AM
Scripts Tcode : SE71
Sample Scripts : MEDRUCK------Purchase Order
RVORDER01--- Sales Order
RVINVOICE01---Invoice
Smartforms Tcode : SMARTFORMS
Sample Forms : BC470_DATAS
BC470_FLOWD_COPIES
To Write Code : Goto- Global DefinationInitialization
Or
Create Program Lines Here You can
Write ABAP Code
Regards,
Nagaraju
‎2008 Jan 05 8:54 AM
Hi shilpa,
I will explain step by step procudure for creating scrips.Follow the procedure.
1. What is the tcode for creating scripts.
A. SE71.
A small example code
STEP 1: Goto se38 and create one new report there and write the following code there.
-
&----
*
*& Report YSCRIPT_SALESORDER *
*& *
&----
*& DEVELOPER : KIRAN KUMAR.G *
*& PURPOSE : CREATING SALES ORDER REPORT FOR A CUSTOMER *
*& CREATION DT: 6/12/2007 *
*& REQUEST : ERPK900035 *
&----
REPORT YSCRIPT_SALESORDER.
----
Tables
----
TABLES: vbak, "Sales Document: Item Data
vbap. "Sales Document: Header Data
----
Internal Table
----
DATA: BEGIN OF gt_data OCCURS 0,
kunnr LIKE vbak-kunnr, "Sold-to party
vbeln LIKE vbak-vbeln, "Sales Document
posnr LIKE vbap-posnr, "Sales Document Item
matkl LIKE vbap-matkl, "Material Group
netpr LIKE vbap-netpr, "Net Price
name1 LIKE kna1-name1, "Name 1
ort01 LIKE kna1-ort01, "City
pstlz LIKE kna1-pstlz, "Postal Code
regio LIKE kna1-regio, "Region (State, Province, County)
END OF gt_data.
----
Global Data
----
DATA: gvar LIKE sy-tabix.
----
Selection Screen
----
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_kunnr FOR vbak-kunnr,
s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN : END OF BLOCK b1.
----
Initilization
----
INITIALIZATION.
PERFORM initial_data.
----
Fetch Data
----
START-OF-SELECTION.
PERFORM fetch_data.
----
Dispaly Data (Transfer data form print program to layout set)
----
END-OF-SELECTION.
PERFORM display_data.
&----
*& Form initial_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM initial_data .
s_kunnr-sign = 'I'.
s_kunnr-option = 'BT'.
s_kunnr-low = '1001'.
s_kunnr-high = '1390'.
APPEND s_kunnr.
s_vbeln-sign = 'I'.
s_vbeln-option = 'BT'.
s_vbeln-low = '0000004969'.
s_vbeln-high = '0000005000'.
APPEND s_vbeln.
ENDFORM. " initial_data
&----
*& Form fetch_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM fetch_data.
refresh : gt_data.
clear : gt_data.
SELECT a~kunnr
a~vbeln
b~posnr
b~matkl
b~netpr
c~name1
c~ort01
c~pstlz
c~regio
FROM vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln
INNER JOIN kna1 AS c ON akunnr = ckunnr
INTO TABLE gt_data
WHERE a~kunnr IN s_kunnr
AND a~vbeln IN s_vbeln.
ENDFORM. " fetch_data
-
STEP 2: we have to transfer above data to script layout ok..
For that the necessary conditions are
1.We have to open the Form..
call function module :OPEN_FORM
2.For printng the data we use the function module WRITE_FORM.
3.Finally we close the Form.
The code for above 3 steps is as below:
CALL FUNCTION 'OPEN_FORM'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX =
ARCHIVE_PARAMS =
device = 'PRINTER'
DIALOG = 'X'
form = 'ZSCRIPT_SO'
language = sy-langu
OPTIONS =
MAIL_SENDER =
MAIL_RECIPIENT =
MAIL_APPL_OBJECT =
RAW_DATA_INTERFACE = '*'
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.
Here FORM NAME IS "ZSCRIPT_SO"(SE71 = SCRIPT NAME)
LOOP AT gt_data. "Internal table name: gt_data
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.
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.
-
Award points if helpful.
Kiran Kumar.G
Have a Nice Day..
‎2008 Feb 01 1:19 PM
hi kiran,
I am a new abapper. I saw your posts and i must say that you help a people lot by detailing every step. Thanks for your help as you contribute a lot for new abbapers like us.