Friday, 14 June 2013

Steps for Creating SAPScript


1.       Go to  transaction SE71.
 
2.       Enter the use of your program in meaning text box. It is mainly useful for understanding what the program does.  Now SAVE your program clicking on Save button.

 
3.       Before proceeding further first ensure by going to Settings> Form Painter  under the SAPScript Tab both Form Painter and PC editor checkbox are unchecked. If not, uncheck them.
 

4.       Now goto Paragraph Formats Tab and create a paragraph. Give all the Font and alignment settings you want for your output here. If you wish to have more than one paragraph formats for your script create another one. Save the script.



Don’t forget to press Enter Key after you create your paragraph as the Enter Key works as  submit in SAP. Many people face issues due to this.
5.       Now goto Pages Tab.  Create a Page with any page name and give it some description. If your output is long and wont come in a single page and you wish to show the remaining part in another page (probably with different page settings) then you need to give the description of same in NEXT PAGE text box. By default, the same page would be used to display the output. Save the script.



6.       After creating Pages we need to create Windows. Please note that on a single Page there could be multiple windows. Goto Windows tab for creating Windows. By default you could see that a MAIN window is already been given by SAP.  For every page there could possibly be only one MAIN window.  Therefore, for further divisions of a page SAP provides us with 2 other window types other than MAIN window :-  Constant and Variable.
                -The width of the main window remains the same on each form page in which it appears. "Continuous" text is output in the main window (text which covers several pages).
             -Constant windows are the same size and have the same contents on all form pages in which they appear. They therefore only need to be edited once when output. The text editing process is quicker if a window is defined as constant.
           -Variable windows, on the other hand, can be various sizes and have different contents on different pages.
Now create one header window by entering details as shown below. Also assign default paragraph to Header window as well as Page Window.

MAIN Window Attributes:-


7.       As of now we have created Paragraphs, Page and windows.  Now we will assign the window to the page we have created. For that goto Page Windows tab. At the Tab goto Edit > Create Elements




Now, double click on HEADER window. At the Standard Attributes block give some values for windows width and height. We will change it later as per our suitability. Repeat the Same Procedure for MAIN window and Save the script.
Also, if you want you can use your MAIN window multiple times in a single page, while other windows VAR or CONST could only be used once.

8.       Now, goto Settings > Form Painter and then go on SAPScript tab. The Form Painter and PC Editor Checkbox which we unchecked at starting of program, check them now and click on OK.


9.       A  Form Painter window will appear where you could see the page we have created. On the page you could also see the windows we created. Now adjust the page windows as per your requirement.  After adjusting the windows just save the Script. And again Uncheck the Form Painter and PC editor checkboxes by going to System > Form Painter.



10.   Now, Suppose we have to display the Sales Details in our Script. For that first we would create Text Elements in our MAIN window. Now go to Page Windows point cursor on MAIN window. Then goto Edit > Text Elements. Write the code as shown


click on back button. Then click on Save.

11.    Similarly, do it for header window


click on back button. Then click on Save.


12.    Now click on Header button.  After that click on
In the window that appears,  fill in details about Default Para and First Page.


13.   Save your script. And goto Form to Activate it.

14.   Now we need to create a report to call our Script. For that goto SE38 transaction and create a report.

*&---------------------------------------------------------------------*
*& Report  ZTEST_PARTH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_PARTH.

TABLES: VBAP, VBAK, KNA1.

 SELECT-OPTIONS: S_VBELN 
FOR VBAK-VBELN no-extension no intervals.

 DATA: P_KUNNR 
TYPE VBAK-KUNNR,
       P_VBELN 
TYPE VBAP-VBELN.

 TYPES: 
BEGIN OF IT_KNA1,
          NAME1 
TYPE KNA1-NAME1,
          NAME2 
TYPE KNA1-NAME2,
          ADRNR 
TYPE KNA1-ADRNR,
          TELF1 
TYPE KNA1-TELF1,
       
END OF IT_KNA1,

       
BEGIN OF IT_VBAP,
          VBELN 
TYPE VBAP-VBELN,
          POSNR 
TYPE VBAP-POSNR,
         MATNR 
TYPE VBAP-MATNR,
         PMATN 
TYPE VBAP-PMATN,
         VRKME 
TYPE VBAP-VRKME,
      
END OF IT_VBAP.

 DATA: GT_KNA1 
TYPE IT_KNA1, "OCCURS 0 with header line,
       GT_VBAP 
TYPE IT_VBAP. "OCCURS 0 with header line.

 
AT SELECTION-SCREEN.

   
SELECT KUNNR VBELN FROM VBAK INTO (P_KUNNR, P_VBELN) WHERE VBELN IN S_VBELN.
     ENDSELECT.

     
IF SY-SUBRC <> 0.
       
MESSAGE ID 'zparthmessage' TYPE 'E' NUMBER '002' WITH 'erooorrr'.
     ENDIF.

 START-OF-SELECTION.

  
SELECT NAME1 NAME2 ADRNR TELF1 FROM KNA1 INTO CORRESPONDING FIELDS OF  GT_KNA1
      
WHERE KUNNR = P_KUNNR.
    endselect.
     
IF SY-SUBRC <> 0.
       
MESSAGE ID 'zparthmessage' TYPE 'E' NUMBER '002' WITH 'erooorrr kna1'.
     ENDIF.
  
SELECT VBELN POSNR MATNR PMATN VRKME
    
INTO CORRESPONDING FIELDS OF GT_VBAP
     
FROM VBAP
      
WHERE VBELN = P_VBELN.
    endselect.
     
IF SY-SUBRC <> 0.
       
MESSAGE ID 'zparthmessage' TYPE 'E' NUMBER '002' WITH 'erooorrr vbap'.
     ENDIF.

     
CALL FUNCTION 'OPEN_FORM'
      
EXPORTING
        
FORM                              'ZTEST_DEMO12'
      
EXCEPTIONS
        
OTHERS                            1.

     
CALL FUNCTION 'START_FORM'
      
EXPORTING
*        ARCHIVE_INDEX          =
        
FORM                   'ZTEST_DEMO12'
*        LANGUAGE               = ' '
*        STARTPAGE              = ' '
        
PROGRAM                'ZTEST_PARTH'
*        MAIL_APPL_OBJECT       =
*      IMPORTING
*        LANGUAGE               =
      
EXCEPTIONS
*        FORM                   = 1
*        FORMAT                 = 2
*        UNENDED                = 3
*        UNOPENED               = 4
*        UNUSED                 = 5
*        SPOOL_ERROR            = 6
*        CODEPAGE               = 7
        
OTHERS                 8
               .
     
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
        
WINDOW 'HEADER'
        ELEMENT = 
'CUST_DETAILS'
      
EXCEPTIONS
        
OTHERS                            1.



     
CALL FUNCTION 'WRITE_FORM'
      
EXPORTING
        
WINDOW 'MAIN'
        ELEMENT = 
'E1'
      
EXCEPTIONS
        
OTHERS                            1.

     
CALL FUNCTION 'CLOSE_FORM'.



RUN the Report.


Output 
You have successfully created your first SAPScript. And you can run it through your Report.

7 comments:

  1. suman priyadarshi21 October 2013 at 04:23

    thanks.....its really nice........

    ReplyDelete
  2. Hi there,

    Thank you so much for the detailed tutorial. I tried to make my 1st sap script followed by your tutorial step by step. However finally only the manual text are displaying while the data received from database are not. I tried to debug, there is no problem before OPEN_FORM. Could you help me?

    Many thanks

    ReplyDelete
    Replies
    1. Hi,
      It seems like you are passing the wrong element value.. Please check it once

      Delete
    2. even im facing the same issue, debugging gives proper values in internal tables, but its not displayed in script output. pls help

      :-(

      Delete
  3. Your Blog is amazing and a perfect guide for beginners like me. Thank you parth!!
    Please keep posting:)

    ReplyDelete