on 03-11-2008 10:38 PM
Hi all,
I'm creating a new sapscript for a billing document, but I'm a bit stuck on how to display all different items...
I'm not sure on how to do a 'loop at...' for all items...
Hai.
check the example codes.
Structure of a print program
OPEN_FORM function
CLOSE_FORM function
WRITE_FORM
START_FORM function
END_FORM function
CONTROL_FORM function
The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options.
Function modules in a printprogram:
When you print a form you must used the staments OPEN_FORM and CLOSE_FORM. To combine forms into a single spool request use START_FORM and END_FORM.
To print textelements in a form use WRITE_FORM. The order in which the textelements are printed, is determined by the order of the WRITE_FORM statements. Note: for printing lines in the body, you can also use the WRITE_FORM_LINES function module.
To transfer control command to a form use CONTROL_FORM.
Structure of a print program
Read data
Tables: xxx.
SELECT *
FROM xxx.
Open form printing - Must be called before working with any of the other form function modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....
To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM
call funtion 'START_FORM'.....
Write text elements to a window of the form
call function 'WRITE_FORM'.....
Ends spool request started with START_FORM
call funtion 'END_FORM'.....
Closes form printing
call function 'CLOSE_FORM'...
OPEN_FORM function
Syntax:
CALL FUNCTION 'OPEN_FORM'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX =
ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
FORM = ' '
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
OTHERS = 11
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Some important parameters:
FORM Name of the form
DEVICE PRINTER : Print output using spool
TELEFAX: Fax output
SCREEN: Output to screen
OPTIONS Used to control attrubutes for printing or faxing (Number of copies, immediate output....
The input for the parameter is structure ITCPO.
CLOSE_FORM function
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT =
RDI_RESULT =
TABLES
OTFDATA =
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 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.
Paramerters:
RESULT Returns status information and print/fax parameters after the form has been printed. RESULT is of structure ITCPP.
WRITE_FORM function
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = ' '
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
OTHERS = 9
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Some important parameters:
ELEMENT Specifies which textelement is printed
WINDOW Specifies which window is printed
TYPE Specifies the output area of the main window. This can be:
TOP - Used for headers
BODY
BOTTOM - Used for footers
FUNCTION Specifies whether text is to be appended, replaced or added
Example of how to use the WRITE_FORM function module together with a script.
Form layout of the MAIN window
/E INTRODUCTION
Dear Customer
...........................
/E ITEM_HEADER
IH Carrier, Departure
/E ITEM_LINE
IL &SBOOK-CARRID&, &SPFLI-DEPTIME&
/E CLOSING_REMARK
The print program
Writing INTRODUCTION
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'INTRODUCTION'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8
.
Writing ITEM_HEADER
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ITEM_HEADER'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8
.
Set ITEM_HEADER into TOP area of main window for subsequent pages
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ITEM_HEADER'
FUNCTION = 'SET'
TYPE = 'TOP'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8
Write ITEM_LINE
LOOP AT .....
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ITEM_LINE'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8.
ENDLOOP.
Delete ITEM_HEADER from TOP area of main window
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ITEM_HEADER'
FUNCTION = 'DELETE'
TYPE = 'TOP'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8
Print CLOSING_REMARK
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'CLOSING_REMARK'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 8
START_FORM function
CALL FUNCTION 'START_FORM'
EXPORTING
ARCHIVE_INDEX =
FORM = ' '
LANGUAGE = ' '
STARTPAGE = ' '
PROGRAM = ' '
MAIL_APPL_OBJECT =
IMPORTING
LANGUAGE =
EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
SPOOL_ERROR = 6
OTHERS = 7
.
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_FORM function
CALL FUNCTION 'END_FORM'
IMPORTING
RESULT =
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SPOOL_ERROR = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CONTROL_FORM function
The CONTROL_FORM function module alows you to create SapScript control statements from within an APAB program.
Syntax:
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
command =
EXCEPTIONS
UNOPENED = 1
UNSTARTED = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Example:
Protecting the text element ITEM_LINE
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
COMMAND = 'PROTECT'.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
TEXELEMENT = 'ITEM_LINE'.
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
COMMAND = 'ENDPROTECT'.
-
&----
*& 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.
regards.
sowjanya.b
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
thanks for the help !
I still have a problem displaying the items.
This is the part in my sapscript :
ITEM_LINE (text element)
&vbdpr-posnr& (command)
in my print program :
LOOP AT tvbdpr.
vbdpr = tvbdpr.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'ITEM_LINE'
window = 'MAIN'
FUNCTION = 'SET'
TYPE = 'BODY'
EXCEPTIONS
OTHERS = 1.
ENDLOOP.
sy-subrc is 0, but when I execute the form, nothing is displayed....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
check the following links you can get detailed idea about scripts
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
Regards,
Sreelatha Gullapalli
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bjorn,
See the below code for displaying the Item details in the Script output.
try to fetch all the Details into a Single internal table,Even if you have all the Details in a Interna Table like the Below one "gt_data" Internal table has all the details.
When you loop at this table call the Write form.
In the Script write all the Command lines having variables for Displaying item Details in One Element.
For Eg. For "ITEM" element given in write form.
when ever the Element is called those details will be displayed in the script output.
Please let me know for any qns.
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.
Reward if usefull.
Gokul
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.