Basics of SAP Script - Part 2



What are the components of SAP Script Form?
SAP Script Form is made of following coponents or subobjects

  1. Header
  2. Pages
  3. Windows
  4. Page Window
  5. Paragraph Formats
  6. Character Formats
  7. Documentation

Goto Tcode SE71 to check subojects


Header data - 
Header has 2 parts, Administrative data and Basic settings.
Administrative data to hold the Form name, Meaning, Package, Created by, Changed by and Language.
Basic settings consists of Page Setup like Page format, Orientation of Page, First Page of Form, default paragraph used, Font family and Font size.

Pages -
Pages define the layout of the form. You might have to create multiple pages to accommodate different layouts, if there is a requirement that the document will differ for subsequent pages. For example, the First page of the document will hold only the customer details like Name, Address, Contact and the Items purchased will be displayed from next page. Achieve this by creating multiple pages.

Windows -
Windows are positioned on pages. By changing the position of windows on page, you alter the layout of the page.
Window also does the job of holding related texts together. For example, you would to place all texts related to Address in one window.
A window can be placed on multiple pages, if your document has multiple pages.

Page window -
Page window defines the area that you want the window to occupy on the page and the coordinates at which the Window is placed on the Page. It calculates the coordinates from left and upper edge of Page.

Paragraph Formats
Defines the formatting of a paragraph.

Character Formats
Used to define the formatting of individual character or character strings within a paragraph.

Documentation
Used to maintain document related to a form.


Basics of SAP Script ( Getting Started ) - Part 1




Basics of SAP SCRIPT - Part 1

When dealing with forms in SAP, we have three options :
1. SAP Scripts
2. Smart Forms and more recently
3. SAP Adobe forms.

In this tutorial we will discuss the basics of SAP Script. You may refer the tutorials on SAP Scripts and SAP Adobe forms to know more about them.

Any business has to deal with various different types of print documents. The documents may belong to any business department and may change country wise as per the laws of different countries. Some common examples of print documents are Invoices, Sales Orders, Goods receipt, Payslips, etc. These might have to be printed in large numbers.

SAP Script is a tool to easily create or modify the layout of these forms as per the business requirement. SAP has provided standard Scripts for almost all different types of applications in business. An ABAPer job might be to change the existing layout or create a new layout along with its driver program as per the business requirement.

Driver program is also know as print program and is responsible to fetch and provide data to the form for print.

What is the Tocde to work with SAPScript?
Tocde for SAP Script is SE71

Components of SAP Script
SAP Script has two components
1. Form layout
2. Print or driver program


WORKING WITH TABLES IN SMARTFORMS

WORKING WITH TABLES IN SMARTFORMS:

Tables are used to print the data in tabular format. Table contains three sections.

                 1. Header
                 2. Main area
                 3. Footer

Based on the given purchasing document number, display the purchase order details as below.



1. Execute transaction 'SMARTFORMS'.
2. provide the smartform name ( Eg: ZF_TABLE_SFORM ) and click on create.



3. Provide short description and double click on 'Form Interface' in the left panel.





4. In the import tab provide the following details ( Input variable and data work area which are coming from print program. Here I created one global workarea with the following fields ).








5. In the Tables tab provide the following details ( In this internal table is declared with table type ( ZT_PUR_ITEM ) why bcz whenever the internal table data is coming from print program we need one table type ( global table type ). We can use pre-defined global table type with our required fields ( Eg: /SAPSLL/EKPO_R3_T ) or customized table type with our required fields ).





6. Now double click on Global definitions tab in the left panel and provide the details as below ( This is a local work area to loop the internal table data which is coming from print program ).


7. Now click on Types tab and declare the types as follows.



8. Now click on Currency/ Quantity fields tab and provide the details as below. ( Whenever we are working with currency and quantity fields we must provide the reference fields )





9. All the declarations are completed now we are going to design the layout.
10. Expand the Pages and widows and select the page. Right click on the page. Create. Window. ( To print the header text and page numbers )



11. Provide window name ( Eg: PUR_HEADER_DATA ) and meaning ( Eg: Header data and page no ).



12. Select the header window and right click . Create . Text.



13. Provide the text name ( Eg: Text_header_data ) and meaning ( Eg: header data text ).



14. Now select the main window. Create. Table.




15. Now select the line type ( Eg: LTYPE1 ) right click and select the rename line ( Eg: LINE1 ).





16. Select the line ( Eg: LINE1 ). Right click. Select insert. Select Empty line underneath to create a new line and rename the line as ( Eg: LINE2 ).



17. Now the window is as below.




18. Select the LINE1 and click on Details button to divide the line.



19. Here LINE1 is used for Main window ( Header and Main area bcz these two are similar in structure ) and LINE2  is used for Main window ( Footer ).
20. Click on Table painter. Now the lines structure becomes like this.



21. Now double click on Main window header. Right click. Create. Select Table line.



22. Select line type as LINE1 and window becomes like this.



23. Follow steps 21 and 22 for Main window main area to select line type as LINE1 and for footer select line type as LINE2.
24. Now the screen is as below.



25. Now select the each cell. Right click. Create. Text. ( To print the data in the window ). Name them according to field text and field value to understand who will going to work on this smartform.



26. After creating the texts the screen becomes like this.



27. Now double click on Table and click on data tab and provide the details as follows.




27. Now in the right hand set layout according to your design by drag and drop. If it is not visible Click on form painter in the application tool bar and adjust the layout design as below.



28. Save, Check and Activate the program.


Develop the print program

*&---------------------------------------------------------------------*
*& Report  ZP_PUR_PRINT_PROGRAM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zp_pur_print_program.
PARAMETERS : p_ebeln TYPE ekko-ebeln.
DATA fm TYPE rs38l_fnam.
*work area for header data
DATA BEGIN OF LS_EKKO.

INCLUDE STRUCTURE ZST_PUR_HEA.
DATA END OF LS_EKKO.
*work area and internal table for item data
data begin of ls_ekpo.
include STRUCTURE ztpuritem.
data end of ls_ekpo.
data lt_ekpo like table of ls_ekpo.
*Fetching header and item data.
SELECT SINGLE ebeln
              bsart
              aedat
              
FROM ekko
              
INTO ls_ekko
              
WHERE ebeln p_ebeln.
if ls_ekko is not initial.
SELECT ebeln
       ebelp
       menge
       meins
       netpr
       
FROM ekpo
       
INTO TABLE lt_ekpo
       
WHERE ebeln ls_ekko-ebeln.

  
endif.
*Calling the smartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  
EXPORTING
    formname                 
'ZF_TABLE_SFORM'
*   VARIANT                  = ' '
*   DIRECT_CALL              = ' '
 
IMPORTING
   FM_NAME                  
FM* EXCEPTIONS
*   NO_FORM                  = 1
*   NO_FUNCTION_MODULE       = 2
*   OTHERS                   = 3
          
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*Exporting data to smartforam
  
CALL FUNCTION FM
    
EXPORTING
*     ARCHIVE_INDEX              =
*     ARCHIVE_INDEX_TAB          =
*     ARCHIVE_PARAMETERS         =
*     CONTROL_PARAMETERS         =
*     MAIL_APPL_OBJ              =
*     MAIL_RECIPIENT             =
*     MAIL_SENDER                =
*     OUTPUT_OPTIONS             =
*     USER_SETTINGS              = 'X'
      i_ebeln                    
P_EBELN
      ls_ekko                    
LS_EKKO*   IMPORTING
*     DOCUMENT_OUTPUT_INFO       =
*     JOB_OUTPUT_INFO            =
*     JOB_OUTPUT_OPTIONS         =
    
TABLES
      lt_ekpo                    
LT_EKPO*   EXCEPTIONS
*     FORMATTING_ERROR           = 1
*     INTERNAL_ERROR             = 2
*     SEND_ERROR                 = 3
*     USER_CANCELED              = 4
*     OTHERS                     = 5
            
.
  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.



Now execute the print program 

Provide input.
Provide output device ( Eg: LP01 ) and click on print preview.
It will display the empty layout why bcz we are not written code in the smartform to print.




Now go to smartform and write the code in the text editor to print the data.

1. Open the smartform in change mode.
2. Expand the page. Expand header window and double click on text.












ENHANCEMENT POINTS - EXPLICIT ENHANCEMENT

ENHANCEMENT POINTS

Enhancement points are nothing but empty places / empty slots where we can add our code to extend the standard SAP software.

These are not SUB-ROUTINE / FUNCTIONS / METHODS , But these are a ENHANCEMENT POINTS (New technology).

EXPLICIT ENHANCEMENT

Explicit Enhancement are of 2 types.

1. Enhancement Point : Here we can add additinal functionality to our program, and then our program executes with enhanced function.

2. Enhancement Section : Here our program wont be executed , the enhanced program will execute.

EXAMPLE

This Custom programs displays the output with no headings.Now we will create a EXPLICIT ENHANCEMENT POINT with header information.

BEFORE ENHANCEMENT :







OUTPUT:





Now we will work on EXPLICIT ENHANCEMENT.

STEP 1

Place the cursor where we need to create ENHANCEMENT POINT.

Just right Click On it.







Now provide ENHANCEMENT POINT NAME.

Select the radio button CODE.

Provide the ENHANCEMENT SPOT name as below.



Click on Continue.

ENHANCEMENT POINT will be created in our program.





Now click on the ENHANCE icon .





Now Right on our enhancement point and choose enhancement -> create.







Provide the ENHANCEMENT IMPLEMENTATION name as below.




Click on Continue.

Now write the logic.






ACTIVATE the ENHANCEMENT.

Now the OUTPUT will be:






HEN