Last Updated on August 11, 2022 by admin
SAP Scripts Tutorial
SAP script is a text processing system where it is similar in scope and form to the best text processing systems in the world. SAP Scripts make use of pre-formatted forms to print pre-formatted text.
Components of SAP Scripts
The important five components of SAP Scripts are as follows,
- Editor: – which is used to enter lines of text and edit them.
- Styles & Layouts Sets: – It is used to print layout, and creates individual texts.
- Composer: – It is an output module and not visible to the user.
- Programming interface: – This is the interface that makes it possible for the programmer to include SAP script components in their application programs and to control how the layout sets outputs are displayed.
- Database: – SAP Scripts uses many database tables which are capable of storing large amounts of texts, sets, and styles.
What is a Layout Set in SAP Script?
The purpose of layout sets is to display documents in output form. SAP Script layout sets do not contain any data but are used to describe how the text elements are incorporated into the program and printing is done and may be considered the page design for the document.
Components of SAP Script Layout: – The important components of SAP script layout are as follows
1. Header Data: – It controls how printing is done and it consists of Starting page, paragraph, Page format, Language, and so on.
2. Paragraph, Font, and Character Formats: – Paragraph attributes are page margin, Alignment, etc. Font attribute is the type of font, size, and so on.
3. Windows and Text Elements: – Windows are independent text areas such as header address, date, and footer placed on a page. Windows group the information presented in a document into groups that appear on the printed page in their own area. Text elements are used by the print program by their names and then formatted and printed in their own window.
4. Pages: – The independent pages contained in the document with their own name. Each page may have a different layout and may have different data.
5. Page Windows: – Page windows are elements that contain the page and specify the area with width and height.
Function Modules used in SAP Scripts are OPEN_FORM, CLOSE_FORM, START_FORM, WRITE_FORM, END_FORM
SAP Script program
The below program uses the following layout
REPORT ZOWN_SCRIPT_DRVPRG.
DATA : COMP_ADDR TYPE STRING VALUE ‘Reliance Globalservices pvt ltd’,
CONDT TYPE C VALUE ‘T’.
DATA : BEGIN OF EMPDATA OCCURS 0,
EMPNO TYPE I,
EMPNAME TYPE STRING,
EMPSAL TYPE P,
END OF EMPDATA,
SUBTOT TYPE P,
GRTOT TYPE P.
**POPULATE THE ITAB
EMPDATA-EMPNO = 19001.
EMPDATA-EMPNAME = ‘RAVI’.
EMPDATA-EMPSAL = ‘35000’.
APPEND EMPDATA.
EMPDATA-EMPNO = 19081.
EMPDATA-EMPNAME = ‘AKASH’.
EMPDATA-EMPSAL = ‘35000’.
APPEND EMPDATA.
SORT EMPDATA ASCENDING BY EMPNO.
CALL FUNCTION ‘OPEN_FORM’
EXPORTING
APPLICATION = ‘TX’
DIALOG = ‘X’
FORM = ‘ZOWN_SCRIPT’
LANGUAGE = SY-LANGU.
CALL FUNCTION ‘WRITE_FORM’
EXPORTING
ELEMENT = ‘COMPADDR’
FUNCTION = ‘SET’
TYPE = ‘BODY’
WINDOW = ‘COMPADDR’.
LOOP AT EMPDATA.
**THIS GETS PRINTED ONLY FOR THE FIRST TIME
AT FIRST.
CALL FUNCTION ‘WRITE_FORM’
EXPORTING
ELEMENT = ‘EMPHEAD’
FUNCTION = ‘SET’
TYPE = ‘BODY’
WINDOW = ‘MAIN’.
ENDAT.
CALL FUNCTION ‘WRITE_FORM’
EXPORTING
ELEMENT = ‘EMPDET’
FUNCTION = ‘SET’
TYPE = ‘BODY’
WINDOW = ‘MAIN’.
AT END OF EMPSAL.
SUM.
SUBTOT = SUBTOT + EMPDATA-EMPSAL.
GRTOT = GRTOT + SUBTOT.
CALL FUNCTION ‘WRITE_FORM’
EXPORTING
ELEMENT = ‘STOT’
FUNCTION = ‘SET’
TYPE = ‘BODY’
WINDOW = ‘MAIN’.
CLEAR SUBTOT.
ENDAT.
AT LAST.
CALL FUNCTION ‘WRITE_FORM’
EXPORTING
ELEMENT = ‘FOOTER’
FUNCTION = ‘SET’
TYPE = ‘BODY’
WINDOW = ‘MAIN’.
CLEAR GRTOT.
ENDAT.
ENDLOOP.
CALL FUNCTION ‘CLOSE_FORM’.