40
Smart forms By Arjun  A real time sce nario on Smar t forms Business Requirement : Develop a Smart form to print the Invoice Details along with Copies/Final windows .The Layout is given in the class.

Sf-zv Invoice Ig

Embed Size (px)

Citation preview

Page 1: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 1/40

Smart forms By Arjun

 A real time scenario on Smart forms

Business Requirement :

Develop a Smart form to print the Invoice Details along with

Copies/Final windows .The Layout is given in the class.

Page 2: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 2/40

Steps :

Goto Smartforms Tcode Select Smartstyle

Give a name as ZINVICE_STYLE

Click on Create

Double click on Paragraph Format Folder 

Click on Create Node

Give Name as TL and desc as Title

Click on Font Tab

Give the options as below

Save it

Double click on Paragraph Format Folder again

Click on Create Node

Give Name as NT and desc as Normal text

Click on Font Tab

Give the options as below

Page 3: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 3/40

Save it

Double click on Paragraph Format Folder again

Click on Create Node

Give Name as RT and desc as Right Aligned text

GIve Alignment as RIGHT Aligned

And Indent-Right Margin as 4 cms(Approximately)

Save it

Double click on Header data Folder 

Specify Standard Paragraph as NT

SAVE, ACTIVATE

Page 4: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 4/40

 

Goto Smartforms Tcode

Select SmartForm

Give a name as ZINVOICE

Click on Create

Give desc->Click on Output Options Tab->Give style Name as

ZINVICE_STYLE

Expand Page1->Rightclick->Create->Window

Page 5: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 5/40

Give Window Name as Title and give desc

Click on Form Painter Button->Adjust the Length, Position

Click on Form Painter Button Again so that it disappears

Right Click on Title Window->Create Text

Write text as INVOICE->Select the entire text and select the Paragraph Format

'TL'

Page 6: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 6/40

Save->Activate->Test it->The output is as Below

Create a Graphics Node and display Image which is uploaded through SE78Tcode.

Right Click on Page1->Create ->Graphic

Give the Name of the image or Press F4 on Name field.

Give the Name AS BELOW IN THE POPUP

Page 7: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 7/40

Click on Execute->select the Image.

Save->Activate->Test it->The output is as Below

Page 8: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 8/40

Expand Page1->Right click->Create->Window

Give Window Name as PAGE_NO and give desc

Click on Form Painter Button->Adjust the Length, Position

Click on Form Painter Button Again so that it disappears

Right Click on PAGE_NO Window->Create Text

Write text as 'Page No : '

Click on Icon

A popup will be displayed

Write the below code

Press Enter 

Put '/' at the end

Click on Icon

A popup will be displayed

Page 9: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 9/40

Write &SFSY-FORMPAGES& in the poup.

Finally It should look as below

Save->Activate->Test it->The output is as Below

Expand Page1->Right click->Create->Window

Give Window Name as INVOICE_DETAILS and give desc

Click on Form Painter Button->Adjust the Length, Position

Page 10: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 10/40

Click on Form Painter Button Again so that it disappears

The INVOICE details will be imported from driver program

So, goto Form Interface and declare Workarea By name

WA_VBRK TYPE VBRK under IMPORTING tab .

Right Click on INVOICE_DETAILS Window->Create Text

Write text as below .

 Now, Write the Driver Program and export Workarea WA_VBRK from the

Dynamically generated Funtion Module .

Below is the code.

REPORT ZINVOICE_DRIVER_PRG.

DATA : FM_NAME TYPE RS38L_FNAM .

DATA : WA_VBRK TYPE VBRK .

PARAMETERS : P_VBELN TYPE VBELN .

SELECT SINGLE * FROM VBRK INTO CORRESPONDING FIELDS OF WA_VBRK

Page 11: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 11/40

  WHERE VBELN = P_VBELN .

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'  EXPORTING

FORMNAME = 'ZINVOICE'

  IMPORTING

FM_NAME = FM_NAME.

CALL FUNCTION FM_NAME  EXPORTING

WA_VBRK = WA_VBRK.

Save->Activate->Test the Driver program->The output is as Below

If we want the the invoice Details to be displayed in a box, Then

Click on the Output Options Tab->Select the checkbox LINES WITH

 

Save->Activate->Test the Driver program->The output is as Below

Page 12: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 12/40

Expand Page1->Right click->Create->Address

Click on Form Painter Button->Adjust the Length, Position

Click on Form Painter Button Again so that it disappears

We Need to give address number in the This number will be imported from driver Program.

So declare an importing parameter in the Form Interface.

V_ADRNR TYPE KNA1-ADRNR.

Page 13: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 13/40

Double click on ADDRESS node give the value as below

Save->Activate.

Modify the driver as below for writing the logic to fetch address number.

Add the below statements to the Driver Program.

DATA : V_ADRNR TYPE KNA1-ADRNR .

SELECT SINGLE ADRNR FROM KNA1 INTO V_ADRNRWHERE KUNNR = WA_VBRK-KUNAG .

CALL FUNCTION FM_NAME  EXPORTING

WA_VBRK = WA_VBRKV_ADRNR = V_ADRNR .

Save->Activate->Test the Driver program->The output is as Below

Page 14: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 14/40

Expand Page1->Right click->Create->Window Give Window Name as INVOICE_TEXT and give desc

Click on Form Painter Button->Adjust the Length, Position

Page 15: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 15/40

Create a standard Text in SO10 Tcode as below .

Click on Create->Write Some text ->save it ->Go back->and Click on print preview .

Goto Smartforms

Double clik on the INVOICE_TEXT ->Right click->Crate Text.

Select Text Type as Include text.

A message will appear->Click on Yes

Give the Details as Below .

Save->Activate Smartform->Test the Driver program->The output is as Below

Page 16: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 16/40

 Now, Lets start to use MAIN window to print Line item Information.

The Line item Information will be imported from driver program

So, Create an internal table under TABLES tab in FORM INTERFACE .

And also Create an workarea WA_VBRP under Global Definations

And also Create an varibale by name V_SNO for displaying Serial No in the table

Page 17: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 17/40

under Global Definations

Right Click oN the MAIN window->Create Table.

Click on the Icon and divide the %LTYPE1 into 4 blocks.

Again Click on the Icon

Select all the 4 Blocks

Click on Ucon

A Poup Will appear 

Click on

Page 18: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 18/40

Select

The Output is Below

 Now,Right CLick on HEADER->Cretae->Table Line

Select Line type as %LTYPE1

Automatically 4 cells will be displayed under % ROW1.

Page 19: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 19/40

Right Click on Cell1->Create Text

Write the text as "Sl.No" .

Repeat the same and create text for each cell and write the texts.

Cell1->Text = "Sl.No" .

Cell2->Text = "Material" .

Cell3->Text = "Quantity" .

Cell4->Text = "Price" .

 Now,Double clickon table

Click on Data Tab

Check the checkbox Internal table and specify the values as below.

This is Because, Each record form internal table should be moved into workarea

And it should displayed in table .

 Now,Right Click on MAIN Area->Create Table line.

Page 20: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 20/40

Select Line type as %LTYPE1

Automatically 4 cells will be displayed under % ROW2.

Right Click on each cell and create text and write the texts as below.

Cell5->Text = &V_SNO(C)& .

Cell6->Text = &wa_vbrp-matnr&.

Cell7->Text = &wa_vbrp-FKIMG(C)&.

Cell8->Text = &wa_vbrp-netwr& .

Here, We are displaying currency/quantity Fields in a table .

So , we Need to specify the reference currency/quantity Fields under 

Global Definitions Tab.

We need to increment the serial no "V_SNO" for each Loop Iteration.

For this, Create Program Lines Under CELL5 TEXT.

Page 21: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 21/40

Write the below code With Input and Output parameters in the Program lines.

Everything is complete for displaying Line item Information.

 Now adjust the Main Window Length, position .

Save->activate the form .

Modify the Driver Program for Including the logic for selecting Line Item

Information.

Add the below lines of code .

DATA : I_VBRP TYPE TABLE OF VBRP .DATA : WA_VBRP TYPE VBRP .

SELECT * FROM VBRPINTO CORRESPONDING FIELDS OF TABLE I_VBRPWHERE VBELN = P_VBELN .

Page 22: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 22/40

READ TABLE I_VBRP INTO WA_VBRP INDEX 1.

DO 100 TIMES .APPEND WA_VBRP TO I_VBRP .

ENDDO.

CALL FUNCTION FM_NAMEEXPORTING

WA_VBRK = WA_VBRK V_ADRNR = V_ADRNR

TABLESI_VBRP = I_VBRP.

Save->Activate the Program->Test it. Below is the Output.

Page 23: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 23/40

 Now, Create Page %PAGE2 , Because we dont need all the windows from page2

As they are required only on %PAGE1.

So, Create Page %PAGE2 , and copy the required windows from page1 to page2

And increase the height the Main Window.

I have copied Title, Page No and Main Window.

Right Click on PAGE1->Create Page

%Page2 will be created .

Page 24: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 24/40

Copy the required windows from page1 to page2

Copy the PAGE NO window from page1

And Paste it on Page2

Repeat the same and copy TITLE window and MAIN window .

The Page2 Should look as below

Page 25: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 25/40

Click On Form Painter Button->Increase the Height of Main window by dragging

It upper side .It should Look as below.

 Now Double click on Page1 and specify Next Page as %PAGE2 .

Save, Activate the Form->Test the driver Program.

Page 26: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 26/40

The first page will be as below .

Page 27: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 27/40

Page 28: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 28/40

Calculating Grand Totals Create A variable in Global Definitions by name V_TOT.

Double lick on the Table

Select Calculations Tab.

We want to calculate the total on WA_VBRP-NETWR field

Give the values as below .

 Now create a text under the node TABLE print the grand total.

Write the text as below and make it as Right Aligned

Page 29: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 29/40

 Now->Go to the conditions tab.... check the checkbox 'ONLY BEFORE END OF MAIN

WINDOW'.

Save, Activate the Form->Test the driver Program.

Go to the Last Page and check the Output .

Page 30: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 30/40

Calculating Sub-Totals for Each Page

Create A variable in Global Definitions by name V_SUBTOT

.

Goto Table->Expand Main Area->Expand ROw->Expand Last Cell->Text Will be visible

Right click on the text->Create Program Lines.

Write the Below Code for calculating Subtotals.

Page 31: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 31/40

Double lick on the Table->Click on Table Tab

Right click on %LTYPE1->Insert->Empty Line UnderNeath

%LTYPE2 will be created

Double lick on Footer->Create Table Line

GIve Line type as %LTYPE2

Automatically 1 cell will be created under Footer 

Right click on Cell->Create Text

Write the below text

Page 32: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 32/40

After Printing the subtotal, We need to clear the value.

So Right CLick on the text and.........follow as below

Program Lines will be created.

Write the below code in it with input and output parameters.

Save Activate test

Page 33: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 33/40

Page 34: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 34/40

Printing Terms and conditions on a separate Page. Create a New Page.

Right Click on Page2->Create Page

Create a window by name "TERMS".

Create a text.

Write some text.

Double click on Page2->Specify Next Page as Blank .

Because...If a page has MAIN window...then only it can point next page as itself.

Here we don't have main window.......that's why...... it is blank.

Expand Page1->Expand Main Window->select text which is under table

And right click -> create a command as below.

Page 35: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 35/40

A command will be displayed.

Select the check box GO to new Page and give page3 as new page

Save, Activate, Test it .

The alst page will be as below.

Page 36: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 36/40

Using Copies Window . Generally this window is used to print the Name of copy like

First copy Name as Original Copy,

Second copy Name as Bank Copy

Third copy as Name as Customer copy.

Steps:

Create a variable under global definition for displaying copy name.

Right Click on Page1->Create a window of type Copies Window..

Adjust the Length, Position.

Right click on copies window->Create Program Lines.

Write the Below Code with input/output parameters.

Page 37: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 37/40

The Smart form system variable SFSY-COPYCOUNT will store weather it is a

First copy or second copy or third copy.

So, as Per my requirement...if it is a first copy, I want the first copy to be as

ORIGINAL COPY etc.

 Now Right click on Program lines->Create Text and display the copy name

Write the below text.

Save, Activate, Test it .

Before clicking the Print Preview Button...Give the Number of copies as 3 .

Click on Now.

Page 38: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 38/40

***********************************************************

The output is as below : First copy will be

*************************************************************

Second copy will be

*************************************************************

Third copy will be

*************************************************************

Page 39: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 39/40

Using FINAL Window .

Final windows are generally processed after all the windows in smart form are

finished.

Generally Smart form will not execute any final windows initially.

It will skip all final windows and it executes remaining windows.

After Finishing all windows....Then it comes back to first page and it will check 

weather 

Any final window is available on page1 or page2 or page3 etc..

If it is available it will execute the final window .

Requirement :

Here My requirement is: Print the Grand total on the first page itself.

But the Grand total is calculated only after all the line items are displayed

from main window .

So to Print Grand total on the first page...lets create a final window on page1.

And print the grand total from the variable V_TOTAL.

Steps:

Right Click on Page1->Create a window of type Copies Window..

Select the Lines with option to provide box if you want .

 

Right click->Create Text.

Write the Below Text and makeit as Right Aligned.

Please remember that Grand total is available in variable V_TOTAL .

Page 40: Sf-zv Invoice Ig

7/29/2019 Sf-zv Invoice Ig

http://slidepdf.com/reader/full/sf-zv-invoice-ig 40/40

Save, Activate, Test it .

 

*****************Finished Guys*****************************

I think I have covered all the concepts. Remaining concepts will be discussed in class.

Thanks and Bye for Now.