Вы находитесь на странице: 1из 15

ECC 6.

0
Solutions: SAPScript SAP Development ABAP Training

Exercise 1
Output Program name - YSPXXOUTPROG_1
SAPScript Form Name – YSPXXFORM_1

Steps To Create the SAPScript Form:

 Go to Transaction SE71.
 Type the Form name and press the create button.
 The Header Section of the SAPScript Form will appear.

 Give a Description of the program and click the save button to save the program in the
appropriate package and CTS.
 Now click on the Pages button and go to the Pages section of the form.
 Use the menu path Edit -> Create element to create a new page (PAGE1 in this case).
Specify the next page as PAGE1 itself because we will use only one page. Leave rest of
the fields to their default values.

Dec-2008
Page 1
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 Now click on the Paragraph formats button and create the necessary paragraph formats.
In our case, we will use 3 paragraph formats P1, P2, P3 for the Header, Footer and Main
windows respectively. The windows will be created later. Use the menu path Edit ->
Create Element to create the paragraph formats .

Dec-2008
Page 2
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 Give appropriate values to the attributes of the paragraph formats like Font family, Font
size, Bold/Italic/Underline, Tab positions etc. The main window is required to output the
line items of a table, so you have to specify Tab positions for the paragraph P3 which is
the default paragraph for the main window. For the other two paragraph formats, you
need not specify the Tab positions.

Dec-2008
Page 3
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 Now save the SAPScript Form once again and go to the header section. Click on the
icon with a picture of a Hat or press F5 to go to Header Section.
 Click on the Basic Settings button and give the value PAGE1 for First Page and give P3
as Default paragraph. Keep rest of the fields to their default values.

Dec-2008
Page 4
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 Now Click on the Character formats button to create the Character formats needed for
this program.

Dec-2008
Page 5
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 We are using 3 Character Formats in our program. The Character format A is Bold and
Large size which is used to print the text “Invoice Print”, Character format B will be used
for bold texts with small font size and Character format C is used for the page no. part of
the footer window. Give appropriate font size and Bold/Italic/Underline as needed.
 Now we will create the windows necessary to the SAPScript Form. We will create 3
windows HDR (Header Window), MAIN (Main Window) and FTR (Footer Window). To
create the windows and give them appropriate sizes, we will use the Graphical Form
Painter.
 Use the menu path Settings -> Form Painter. On clicking the menu, you will get one
popup screen in which you have to check the Graphical Form Painter Checkbox and
uncheck the Graphical PC Editor checkbox and press ‘Enter’. Now you will get the
Graphical Form Painter.

Dec-2008
Page 6
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 First we have to create one Graphics object for the IBM logo. To create this, use
transaction SE78.
 After creating the Graphics object, right click on the Layout Editor and select the menu
“Create graphic”. A screen will appear, where you have to choose the Graphics object
you need.

Dec-2008
Page 7
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 After choosing the Graphic object, press “Enter”. On the Layout you can see one blue
rectangle representing the graphic object. Now move or resize that rectangle as per your
requirement on the layout set.
 Now we will create 3 windows on the layout. Right click on the layout and select “Create
window” menu. A white rectangle will appear on the top left hand corner of the layout.
Now Drag the window to appropriate position and give it appropriate shape. You can
change the name, description, type, size, and position etc of the window from the left
hand side of the screen. A screenshot is shown below with all the windows created.

Dec-2008
Page 8
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 Now come back to the Graphical PC Editor using the menu path Settings -> Form
painter. You will see that all the windows for the page PAGE1 are shown in the Page
Windows section.
 Now double click on HDR window and click on the Text elements button or press F9. You
will land up on the basic editor where we have to add the code for the window. Use the
menu path Goto -> Change editor to get the second form of editor which is easy to use.

Dec-2008
Page 9
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 The screen shot above shows the code added to the HDR window. The hard coded text
“Date:” is enclosed within character format B. We have to show the date, that’s why we
have used the SAP system field &SY-DATUM&. The text “Invoice Print” is embedded
within character format A.
 Follow the same path for the rest of the windows to go to their corresponding editors and
add code there.

Dec-2008
Page 10
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 In the MAIN window, we have printed the invoice number which is coming from the
selection screen of the output program. We are using &SY-UNAME& system field for
printing the name of the person. We have used ‘,,’ separated hard coded texts for the
column names of the tables. ‘,,’ represents tab separation. The corresponding tab
positions have been specified in the paragraph format P3. We have used one Text
Element ‘TEXT_ELE’ which is repeatedly called from the output program to print the
contents of the internal table.

Dec-2008
Page 11
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

 In the FTR window, we have added some hard coded texts. The page number in ‘Page x
of x’ format is printed using two SAPScript Form symbols &PAGE& and &SAPSCRIPT-
FORMPAGES&.

The Output Program:

 The output program first gets the value of invoice number from the user through a
selection screen. Now it uses that value to retrieve data from the database and stores it
in an internal table. The code snippet is given below-

TYPES: BEGIN OF TAB,


POSNR LIKE VBRP-POSNR,
MATNR LIKE VBRP-MATNR,
FKIMG LIKE VBRP-FKIMG,
VRKME LIKE VBRP-VRKME,
NETWR LIKE VBRP-NETWR,
END OF TAB.

PARAMETERS: INVOICE LIKE VBRP-VBELN.

Dec-2008
Page 12
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

DATA: I_TAB TYPE STANDARD TABLE OF TAB INITIAL SIZE 0 WITH HEADER
LINE,
UP TYPE P DECIMALS 2 VALUE 0.

SELECT POSNR MATNR FKIMG VRKME NETWR FROM VBRP INTO TABLE
I_TAB WHERE
VBELN = INVOICE.

IF SY-SUBRC <> 0.

MESSAGE I000 (YTRABAPMSG) WITH 'INVOICE NO. DOES NOT EXIST'.


LEAVE LIST-PROCESSING.

ENDIF.

 Now the function module OPEN_FORM is called. Form name is specified in the
EXPORTING parameter FORM.

CALL FUNCTION 'OPEN_FORM'


EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
FORM = 'YSPXXFORM_1'
* LANGUAGE = SY-LANGU
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
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

Dec-2008
Page 13
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

OTHERS = 12
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 Then, while looping at I_TAB, Unit Price is calculated and WRITE_FORM is called in each
iteration.

LOOP AT I_TAB.
IF I_TAB-FKIMG <> 0.
UP = I_TAB-NETWR / I_TAB-FKIMG.
ELSE.
UP = 0.
ENDIF.

CALL FUNCTION 'WRITE_FORM'


EXPORTING
ELEMENT = 'TEXT_ELE'
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'MAIN'
* IMPORTING
* PENDING_LINES =
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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 Then at last CLOSE_FORM is called to close the form.

CALL FUNCTION 'CLOSE_FORM'


* IMPORTING
* RESULT =
* RDI_RESULT =
* TABLES

Dec-2008
Page 14
ECC 6.0
Solutions: SAPScript SAP Development ABAP Training

* OTFDATA =
EXCEPTIONS
UNOPENED =1
BAD_PAGEFORMAT_FOR_PRINT =2
SEND_ERROR =3
SPOOL_ERROR =4
CODEPAGE =5
OTHERS =6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 Run the Output Program and check the output in “Print Preview”.

Dec-2008
Page 15

Вам также может понравиться