1. OPEN_FORM
2. START_FORM
3. WRITE_FORM
4. END_FORM
5. CLOSE_FORM
We can show multiple line items by looping the item table into work area and passing the
work area into the WRITE_FORM.
There is some standard SAP script in the SAP system.
1. Sales order confirmation – RVORDER01
2. Invoice – RVINVOICE01
3. Purchase order – MEDRUCK
4. Packing list – RVDELNOTE etc.
SAP script is client dependent whereas SMARTFORMS is client independent. Let us
suppose we have created a script in 800 client which is development client. Now we
want to test this script in another client 820. Since script is client dependent we won’t
find any data in 820 client.
To fulfill this requirement let’s save the script in a package with a transport request in 800 client.
Now go to SE09 and pick up the transport request number for that script.
after that go to 820 client and enter the transaction SCC1.
Mention the source client and that transport request number and then start immediately.
We can run the script in another client by this way.
Now script contains some development attributes as follows.
1. Header – it contains two sections like administrative data and basic data. Now admin data
contains the description, status, package, client, created by, date, languages etc. Basic data
contains the basic settings of the script like set us page, default values of text formatting etc.
2.
Pages – it defines the pages of a form. Some forms contain more than one page.
On the standard attribute we have to give unique page name if there is more than one page.
3.
Window – it is the various section of a page. We may have header & footer and the main body of the form.
So we have to define a header window, footer window & a main window.
4.
Page Window – it defines which page contains which windows. Suppose we have three windows
like header, footer & main. Now we want to put these windows in page1. So in page2 there must
be some other or same window like footer and another content window. Inside the page window
we can declare this very clearly.
5.
Paragraph Formats – it declares the format of the paragraph like left margin, right margin, alignment etc.
We can use this paragraph format into any window. For different window we can design different
paragraph format also.
6.
Character Formats – similar to paragraph format SAP script gives us the character format.
We can customize the content character by using this. We can use different character formats
for different window content.
7.
Documentation – SAP script provides the documentation in which we can write the technical
documents like form name, pages used, windows used and elements used.
Now we are discussing about the step by step creation of SAP script.
Step 1 – go to SE71 and create a form.
Step 2 – save it in package with transport request.
Step 3 – put a description at header.
Step 4 – create a page name PAGE1 in the page section.
Step 5 – create the windows as follows.
Step 6 – create a paragraph format P1.
Step 7 – create a character format C1.
Step 8 – go to page windows and configure the windows inside that page. Here go to edit and create
Step 9 – double click on the window which you want to put inside this page.
Step 10 – In this way we have configured all the windows.
Step 11 – go to edit and text element to enter some content.
Step 12 – go to change editor and enter text as follows. Here the work areas should be declared between ‘&&’.
Step 13 – go to settings then form painter.
Step 14 – check the graphical form painter and enter.
Step 15 – now we can see the form layout and we also can edit the position and size of any windows.
Step 16 – to enter a graphic right click on the layout > create graphic.
Step 17 – press F4 to get the name of the graphic.
Step 18 – select the required graphic from the list.
Step 19 – a graphic will be loaded like this.
Step 20 – to close this layout go to setting > form painter and uncheck the graphical form painter.
Step 21 – now we can check that the graphic has been added inside the page window also.
Step 22 – activate the form as follows.
Step 23 – now write a print program in SE38. (Mentioned below)
Step 24 – execute that program and we can have the SAP script form as follows.
REPORT zsr_test.
*------Declaring structure for item table------------------------------*
TYPES: BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
END OF ty_ekpo.
*-----Declaring work area for PO header--------------------------------*
DATA: BEGIN OF wa_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
ernam TYPE ekko-ernam,
lifnr TYPE ekko-lifnr,
END OF wa_ekko.
*-----Declaring work area for Vendor Master----------------------------*
DATA: BEGIN OF wa_lfa1,
lifnr TYPE lfa1-lifnr,
land1 TYPE lfa1-land1,
name1 TYPE lfa1-name1,
ort01 TYPE lfa1-ort01,
END OF wa_lfa1.
*-----Declaring work area for Vendor Company Master--------------------*
DATA: BEGIN OF wa_lfb1,
lifnr TYPE lfb1-lifnr,
bukrs TYPE lfb1-bukrs,
erdat TYPE lfb1-erdat,
ernam TYPE lfb1-ernam,
akont TYPE lfb1-akont,
END OF wa_lfb1.
*-----Declaring work area & internal table for line item---------------*
DATA: wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo.
*-----Event Initialization---------------------------------------------*
INITIALIZATION.
PARAMETERS: p_ebeln TYPE ekko-ebeln.
*-----Event Start of Selection-----------------------------------------*
START-OF-SELECTION. PERFORM get_purchase_order.
PERFORM get_po_item.
PERFORM display_script.
*&---------------------------------------------------------------------*
*& Form get_purchase_order
*&---------------------------------------------------------------------*
* Get data from Database table
*----------------------------------------------------------------------*
FORM get_purchase_order .
IF p_ebeln IS NOT INITIAL.
"Select single PO details
SELECT SINGLE ebeln bukrs ernam lifnr
FROM ekko INTO wa_ekko
WHERE ebeln = p_ebeln.
IF sy-subrc = 0.
"Select single Vendor Master details
SELECT SINGLE lifnr land1 name1 ort01
FROM lfa1 INTO wa_lfa1
WHERE lifnr = wa_ekko-lifnr.
IF sy-subrc = 0.
"Select single Vendor Company details
SELECT SINGLE lifnr bukrs erdat ernam akont
FROM lfb1 INTO wa_lfb1
WHERE lifnr = wa_lfa1-lifnr
AND bukrs = wa_ekko-bukrs.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " get_purchase_order
*&---------------------------------------------------------------------*
*& Form get_po_item
*&---------------------------------------------------------------------*
* Get data from item table to internal table
*----------------------------------------------------------------------*
FORM get_po_item.
IF wa_ekko IS NOT INITIAL.
SELECT ebeln ebelp menge meins
FROM ekpo INTO TABLE it_ekpo
WHERE ebeln = wa_ekko-ebeln.
ENDIF.
ENDFORM. "get_po_item
*&---------------------------------------------------------------------*
*& Form display_script
*&---------------------------------------------------------------------*
* Calling the SAP script function modules
*----------------------------------------------------------------------*
FORM display_script .
"Opening the Form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = 'ZSCRIPT_TEST'
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 'Form is not opened successfully' TYPE 'I'.
ENDIF.
"Starting the Form
CALL FUNCTION 'START_FORM'
EXPORTING
form = 'ZSCRIPT_TEST'
program = 'ZSR_TEST'
EXCEPTIONS
form = 1
format = 2
unended = 3
unopened = 4
unused = 5
spool_error = 6
codepage = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE 'Form is not started successfully' TYPE 'I'.
ENDIF.
"Writing the Form element one
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'E1'
window = 'HEADER'
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 'Form is not written for E1' TYPE 'I'.
ENDIF.
"Writing the Heading of PO Item
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'HEAD'
window = 'HEADING'
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 it_ekpo IS NOT INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
"Writing the line Items one by one
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'ITEM'
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.
ENDLOOP.
ENDIF.
"Writing the Form element two
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'COMP'
window = 'COMPANY'
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 'Form is not written for E2' TYPE 'I'.
ENDIF.
"Writing the Form element three
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'E3'
window = 'VENDOR'
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 'Form is not written for E3' TYPE 'I'.
ENDIF.
"Ending the Form
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SPOOL_ERROR = 3
* CODEPAGE = 4
* OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE 'Form is not ended' TYPE 'I'.
ENDIF.
"Closing the Form
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 'Form is not closed' TYPE 'I'.
ENDIF.
ENDFORM. " display_script
Selection Screen:
Printing Output device selection:
The Script: