Sapscripts SAPSCRIPTS SAP Print forms to generate printable documents in SAP
Sap scripts and Components of Sap scripts SAP Scripts are client dependent and components of SAP Scripts SAP SCRIPT SAP Script is a tool which is used to printable business documents in SAP like invoice form, Sales Order form, Delivery form, other form related to HR etc. Scripts are older version of SAP print forms, advanced version to scripts are smartforms( we will learn in next chapters ). SAP Scripts are client dependent, that is if we develop a script in client 200, it will not be visible in other clients like 300, 100. Advanced version of scripts, smartforms are client independent, they will be visible in all clients.
Why SAP Scripts are client dependent ? If we generate a SAP Script, it will be internally stored as texts. Texts are nothing but a data, as per SAP all data is client dependent, so SAP Scripts are client dependent. SE71 is the T-code for SAP scripts.
Components of SAP Scripts 1. Header ( Administrative data and basic settings ). 2. Pages. 3. Windows. 4. Page windows. 5. Paragraph format.
6. Character Format. 7. Layout.
Header It contains header information of SAP Script i:e administrative data and basic settings of SAP script. Administrative Data: It contains administrative data like package, client, user and language. Basic Settings: It contains settings like page format, first page, default paragraph etc.
Pages SAP Script is a group of pages, each page contains layout. The layout is used to design page. Page is a group of windows. In SAP Scripts we can create 99 pages only.
Windows A window is a container which contains some information to display, the entire page is designed using windows. There are four types of windows. Main window: A Window which automatically expands depending upon the data is called main window. Each page contains only one main Window. As there are 99 pages only in scripts, we can have maximum 99 main windows only The main Window data is divided into blocks called as text elements. Text Element: It is used to display the specific block of information. Text elements are represented by /E The entire main Window data is divided into blocks called as text elements. Now,Display a particular text element, so that only that specific info related to text element is displayed. Constant Window:
A Window which is constant for all the pages is called constant Window. Variable Window: A Window which does not expand i.e., width and height is fixed . Graphical Window: A window which is used to display graphics or images.
Page windows: The windows assigned to particular page are called page windows.
Paragraph format : It is used to specify a particular format (font size/family/Bold/italic/underlined) for all the characters in a paragraph . We can also specify TABS. Tabs : Tabs are used to specify a position in sap script so that the text will be displayed at that particular position. Tabs are represented by ,, (2 commas).
Character format : A format which is used by a group of characters inside a paragraph is called a character format .
Layout: It is a place where we design the page with windows.
Function Modules used in SAP Scripts
We use some function modules to develop SAP Scripts, explained below.
OPEN_FORM This is used to open a form for execution by loading it into memory.
WRITE_FORM It is used to write Some information on the SAP Script form using Text Element.
CLOSE_FORM It is used to close the form which is opened by open form.
START_FORM It is used to call another SAP Script into current SAP Script(Nested Scripts).
END_FORM It is used to end the form which started by START_FORM.
Driver Program A program which contains business logic statements i.e., all select statements ,loops,appends etc, is called Driver prg. In simple words, a program which is used to drive or print the script. All the variables ,work areas ,internal tables which are declared in the driver program will be automatically transferred to SAP Scripts. If we want to display the variables or workarea values we need to follow below syntax. Syntax : &variable& &workarea-fname&
Purchase Order SAP Script Developing Purchase order SAPScript with totals, subtotals, terms in SAP ABAP programming Requirement: Develop a purchase order with Logo, Address and page no. A Real Time Scenario on Purchase Order SAP Script Form Business Req : Create a PO form with the below layout. Please follow the below steps Step 1 : Create a Page by name PAGE1 Step 2 : Create Required no of Window as per the layout given Step 3: Create Page Windows and specify height/width Step 4 : Create Paragraph Formats Step 5 : Create a TABS for Paragraph Formats Step 6 : Create a Character Format Step 7 : Write the code for Printing Headings, Line item information, Grand total in Mainwindow Step 8 : Write the code for Printing Vendor address in Address window Step 9 : Write the code for Printing Footer information in Footer window Step 10 : Write the code for Printing Logo in Logo window Step 11 : Similarly, Write the code for Printing PO Details/PageNo/Title Step 12 : Print the standard text using SO10 Tcode Step13 : Arrange all the windows as per the given Layout. Step14 : Create a Driver Program Step15 : EXECUTE THE driver program Step16 : Create a Second Page Layout Step17 : Increase the height of MAIN window Step18 : Printing Terms&Conditions using STARTFORM AND END FORM Step19 : Change the Driver Program for using STARTFORM AND END FORM Detailed Steps:
1. Se71->Give formname ->ZV_PO ->create. 2. give Meaning->click on BASIC settings. 3. Select page format /landscape Step 1 : Create a Page by name PAGE1 4. Click on PAGES->EDIT->CRATE ELEMENT->give page as page1 and meaning as page1>>Give Next Page as Page1 5. click on WINDOWS(by default, main window will be added) Step 2 : Create Required no of Window as per the layout given 6. click on EDIT->create element->give window name as TITLE and meaning as title. Repeat the same step and add the below windows.
Step 3: Create Page Windows and specify height/width 7. Click on Page windows-> EDIT->CRATE ELEMENT->Double click on each window so that the window would be added to the page. Give the appropriate height, width, left/right margin as below for each window Step 4 : Create Paragraph Formats Create the 4 paragraph Formats as below. Step 5 : Create a TABS for Paragraph Formats Give Tabs for HEADER paragraph format as below . And the 4th tab as 55 chars right justified . Give font family as COURIER AND size as 12 for all paragraph formats, except for TITLE paragraph. Give 16 for this TITLE paragraph. Step 6 : Create a Character Format Create character format as below . Step 7 : Write the code for Headings, Line item information, Grand total in Mainwindow Goto->Pagewindows->Double click on main window and click on texteditorCLICK ON GOTO CHANGE EDITOR--->write the below code. Here… /:TOP…ENDTOP is used to print header information in the main window so that the it flows on to every page . /EBODY----this is used to print body. All the line item values .
/E-Total----used to print total at the end of main window .. This element is called after the loop..endloop..so that Grand total is printed immediately After the main window . Step 8 : Write the code for Printing Vendor address in Address window Goto->Pagewindows->Double click on ADDRESS window and click on texteditor->write the below code. Step 9 : Write the code for Printing Footer information in Footer window Goto->Pagewindows->Double click on FOOTER window and click on texteditor->write the below code. FT--&ULINE(60)& FT--ALL RIGHTS RESERVED TO IBM> INDIA PVT.LTD Here FT is paragraph format And C1 is char format with bold. Step 10 : Write the code for Printing Logo in Logo window Goto->Pagewindows->Double click on LOGO window and click on texteditor->write the below code or Click on INSERT->GRAPHICS->Select Stored on Document Server->Give Name 'IBM'(Image name Uploaded through SE78)-> Give object : GRAPHICS ID : BMAP Select color Bitmap Image->Press Continue->the Below syntax will come automatically BITMAP 'IBM' OBJECT GRAPHICS ID BMAP TYPE BCOL Step 11 : Similarly, Write the code for Printing PO Details/PageNo/Title Similarly, for all windows write the below code in the text editor Goto->Pagewindows->Double click on PO_NO window and click on texteditor->write the below code DF-- PO No : &wa_ekko-ebeln& DF-- PO Date : &wa_ekko-aedat& Goto->Pagewindows->Double click on PAGE_NO window and click on texteditor->write the below code DF--Page.No : &PAGE&/&SAPSCRIPT-FORMPAGES(C)&
Goto->Pagewindows->Double click on TITLE window and click on texteditor->write the below code TL----Purchase Order Step 12 : Print the standard text using SO10 Tcode Goto->Pagewindows->Double click on TEXT window and click on texteditor->write the below text. We can write the text directly in the window. But in the real time we use a concept called standard Text. So Lets use the standard Text now. Goto SO10->give text name->click on Create-> CLICK ON GOTO->CHANGE EDITOR Write the below text->click on save->go back and click on print preview. Go back to script Goto->Pagewindows->Double click on TEXT window and click on texteditor->write the below text. /: INCLUDE ZV_PO_TEXT OBJECT TEXT ID ST THIS IS STD TEXT THRU SO10 TXN. Or CLick on Insert->Text->Standard->a pop will appear->give text name as ZV_PO_TEXT->press enter-> The code will be displayed automatically. Step13 : Arrange all the windows as per the given Layout Finally, Lets Re-arrange all the window positions again by going to Graphical Form Painer. Click on SETTINGS->FORM PAINTER->Select checkbox Graphical Form Painter And press enter The form should look as below. If not arrange all the windows as below by dragging and dropping. Now goback to PC EDITOR . Save and activate script Specify default paragraph and first page Save and activate script
Step14 : Create a Driver Program And the driver prg is : REPORT ZV_PO_DRIVER. TABLES : ADRC,LFA1,EKKO. PARAMETERS : P_EBELN TYPE EKKO-EBELN . *DATA DECLARATIONS DATA : WA_EKKO TYPE EKKO . DATA : WA_EKPO TYPE EKPO . DATA : IT_EKPO TYPE TABLE OF EKPO . DATA : WA_LFA1 TYPE LFA1 . DATA : WA_ADRC TYPE ADRC . DATA : V_TOT TYPE EKPO-NETWR . *READ PO HEADER DETAILS SELECT SINGLE * FROM EKKO INTO WA_EKKO WHERE EBELN = P_EBELN . *READ PO ITEM DETAILS SELECT * FROM EKPO INTO TABLE IT_EKPO WHERE EBELN = P_EBELN . READ TABLE IT_EKPO INTO WA_EKPO INDEX 1. DO 100 TIMES . APPEND WA_EKPO TO IT_EKPO . ENDDO. *READ VENDOR MASTER DATA TO FIND THE ADDRESS NUMBER SELECT SINGLE * FROM LFA1 INTO WA_LFA1 WHERE LIFNR = WA_EKKO-LIFNR . SELECT SINGLE * FROM ADRC INTO WA_ADRC WHERE ADDRNUMBER = WA_LFA1ADRNR . *OPEN THE FORM CALL FUNCTION 'OPEN_FORM'
EXPORTING FORM = 'ZV_PO' LANGUAGE = SY-LANGU. *PRINT EACH ITEM IN MAIN WINDOW LOOP AT IT_EKPO INTO WA_EKPO . *CALCLUATE GRAND TOTAL V_TOT = V_TOT + WA_EKPO-NETWR . WA_EKPO-MATNR = 'APACHE-160' . CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'BODY' WINDOW = 'MAIN'. *PRIINT THETOTAL AFETR ANIN WINDOW BODY PAGE AT LAST . CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TOTAL' WINDOW = 'MAIN'. ENDAT. ENDLOOP . CALL FUNCTION 'CLOSE_FORM'. Step15 : EXECUTE THE driver program EXECUTE THE driver program->Give PO number as 4151508223 and execute->Below is the output . Step16 : Create a Second Page Layout Now Create a second Page PAGE2 and copy the Main Window, Page No Window, Footer Window. Click on PAGES->EDIT->CRATE ELEMENT->give page as page2 and meaning as page2>>Give Next Page as Page2 Double click on Page1->give next page as Page2.
Double click on Page2->give next page as Page2.
7. Click on Page windows-> Give Page as Page2->Click on EDIT->CRATE ELEMENT->Double click on Main Window, Page No Window, Footer Window so that the windows would be added to the page2. Step17 : Increase the height of MAIN window Now Lets Re-arrange the MAIN window position i.e. Just Increase the height of MAIN window as below by going to Graphical Form Painer. Click on SETTINGS->FORM PAINTER->Select checkbox Graphical Form Painter
The form should look as below. Save->activate the form and again test it from Driver Prg. The Page1 Should look as below. And the Page2 Should look as below. USING STARTFORM AND END FORM Step18 : Printing Terms&Conditions using STARTFORM AND END FORM Crate another Sap Script by name ZV_PO_TERMS with below attributes. Page : Page1 Windows : Main Window, Create a new window by name TERMS. Page Windows : Copy MAIN window and TERMS windows onto page1 . Double click on the Main Window->Write the below text. Double click on the TERMS Window->Write the below text. Create a title paragraph format and write the below text with font size 22 points Also create defuakt paragraph format with font size 16 points Save , Activate the program. Define irst page and default paragraph Step19 : Change the Driver Program for using STARTFORM AND END FORM Write the below code in the above driver program i.e. just add the below code to the above code CALL FUNCTION 'CLOSE_FORM'. CALL FUNCTION 'END_FORM' . *The start form is used to call a different form for printing TREMS&CONDITIONS.
*This for is reusable as it is only for printing * TREMS&CONDITIONS CALL FUNCTION 'START_FORM' EXPORTING * ARCHIVE_INDEX = ARCHIVE_INDEX form = 'ZV_PO_TERMS' language = sy-langu . CALL FUNCTION 'WRITE_FORM' EXPORTING element = 'TERMS' window = 'MAIN'. CALL FUNCTION 'END_FORM' . CALL FUNCTION 'CLOSE_FORM'. The Terms and conditions will be printed on the Last Page . *&---------------------------------------------------------------------* *& Report ZV_PO_DRIVER *& *&---------------------------------------------------------------------* REPORT ZV_PO_DRIVER. TABLES : ADRC,LFA1,EKKO. PARAMETERS : P_EBELN TYPE EKKO-EBELN . *DATA DECLARATIONS DATA : WA_EKKO TYPE EKKO . DATA : WA_EKPO TYPE EKPO . DATA : IT_EKPO TYPE TABLE OF EKPO . DATA : WA_LFA1 TYPE LFA1 . DATA : WA_ADRC TYPE ADRC . DATA : V_TOT TYPE EKPO-NETWR . *READ PO HEADER DETAILS
SELECT SINGLE * FROM EKKO INTO WA_EKKO WHERE EBELN = P_EBELN . *READ PO ITEM DETAILS SELECT * FROM EKPO INTO TABLE IT_EKPO WHERE EBELN = P_EBELN . READ TABLE IT_EKPO INTO WA_EKPO INDEX 1. DO 100 TIMES . APPEND WA_EKPO TO IT_EKPO . ENDDO. *READ VENDOR MASTER DATA TO FIND THE ADDRESS NUMBER SELECT SINGLE * FROM LFA1 INTO WA_LFA1 WHERE LIFNR = WA_EKKO-LIFNR . SELECT SINGLE * FROM ADRC INTO WA_ADRC WHERE ADDRNUMBER = WA_LFA1ADRNR . *OPEN THE FORM CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = 'ZV_PO' LANGUAGE = SY-LANGU. *PRINT EACH ITEM IN MAIN WINDOW LOOP AT IT_EKPO INTO WA_EKPO . *CALCLUATE GRAND TOTAL V_TOT = V_TOT + WA_EKPO-NETWR . WA_EKPO-MATNR = 'APACHE-160' . CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'BODY' WINDOW = 'MAIN'. *PRIINT THETOTAL AFETR ANIN WINDOW BODY PAGE
AT LAST . CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TOTAL' WINDOW = 'MAIN'. ENDAT. ENDLOOP . CALL FUNCTION 'END_FORM' . *The start form is used to call another SAP SCRIPT form for printing TERMS&CONDITIONS. *This form can be reusable by al forms as it is only for printing TREMS&CONDITIONS CALL FUNCTION 'START_FORM' EXPORTING * ARCHIVE_INDEX = ARCHIVE_INDEX FORM = 'ZV_PO_TERMS' LANGUAGE = SY-LANGU . CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TERMS' WINDOW = 'MAIN'. CALL FUNCTION 'END_FORM' . CALL FUNCTION 'CLOSE_FORM' .