solution to the exercise on printing invoices

Upload: raj-rajesh

Post on 14-Apr-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    1/24

    Solution to the exercise on printing Invoices

    By T.N.Swapna, YASH Technologies

    Let us print an Invoice whose output will be as follows:

    Step 1 :

    Go to Transaction SMARTFORMS from the SAP Easy Access Screen.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    2/24

    Give the Smart Form name which starts with Y or Z and click on Create.

    Step 2 :

    Rename Page1 as FIRST by expanding the node Pages and Windows, double click on the node%PAGE1.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    3/24

    As per the Requirement we need to have 5 windows.

    1. 1st

    window for displaying Logo2. 2

    ndwindow for displaying Billing Document Details

    3. 3rd

    window for displaying Customer Details4. 4

    thwindow for displaying the Item Details and the Total Amount

    5. 5

    th

    window for displaying the Footer Details

    Of all these windows the Main window i.e. the window, which holds the Item Details is already defined. Solet us now create the other windows.

    Step 3 :

    Expand the node FIRST to see the main window. Now to create the Logo window.

    The following screen appears. Ensure that the window type is Secondary. Now Rename WINDOW1 asLOGOWIN by double clicking on the node %WINDOW1.

    The following screen appears.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    4/24

    Repeat the same for creating remaining windows. After creating the remaining windows the screenshould look like this:

    Step 4 :

    Now go to the Form Painter by clicking on the button present on the applicationtoolbar. Adjust all the windows as per the requirement.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    5/24

    You can close the Form painter by pressing the button .

    Step 5 :

    Now let us place a Graphic into the LOGOWIN (Logo Window).

    For that we need to first import the image from the local system. To do this Go to transaction SE78 fromthe SAP Easy Access screen. The initial screen for Administration of Form Graphics appears. Expand thenode GRAPHICS and select Bitmap images. Select the Radio Button Color for uploading Coloredimages.

    Now Click on Import Button in order to import an image from your system.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    6/24

    A pop up appears. Give the File path in the File Name, Enter a Name and Description as shown below

    and Continue.

    Click here to continue...

    Step 6 :

    Now go back to the transaction SMARTFORMS. Right Click on the LOGOWIN Create Graphic.

    http://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page2.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page2.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page2.htm
  • 7/27/2019 Solution to the Exercise on Printing Invoices

    7/24

    As per the following screen shot make the changes. In the field NAME with the F4 help select the imagewhich you have imported from SE78.

    Step 7 :

    Now coming to the Declarations. As required the data into the form comes from 3 tables namely,

    KNA1 - For printing the Customer Details in the Customer Details Window.

    VBRK - For printing the Billing Document Header Details in the Billing Document Details Window.

    VBRP - For printing the Item Details in the Main Window.

    The Data Retrieval and printing the Form is done through a Driver Program called ZSF_PRINTINVOICE.

    In the Form we need to declare some Import parameters and also define some Global Definitions.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    8/24

    For declaring Import parameters double click on Form Interface and include the lines as shown below :

    If you have table types defined for VBRK and VBRP tables give those names in the Associated typescolumn.

    IM_FS_KNA1 - The field string for Holding Customer Details.

    IM_T_VBRK - Table to hold Billing Document Header Data.

    IM_T_VBRP - Table to hold Billing Document Item Data.

    For Global Definitions, double click on the Global Definitions and include the lines as follows :

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    9/24

    IM_T_KNA1 - Table to hold Customer Details.

    IM_FS_VBRK - Field String to hold Billing Document Header Data.

    IM_FS_VBRP - Field String to hold Billing Document Item Data.

    W_TOTAL - Stores the Total Amount of the field NETWR.

    If the above screen shot is observed we find a arrow which is placed on Currency/Quant. Fields. Openthis Tab to include the following lines.

    This is to refer the currency field NETWR in the table VBRP to its corresponding currency key field in thetable VBRK.

    Step 8 :

    Displaying the contents in BILLWIN (Billing Window).

    Create a Loop under the node BILLWIN

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    10/24

    Name the Loop as LOOP_BILL, give a description as Loop for Billing Details. In the field Operand givethe details as IM_T_VBRK INTO IM_FS_VBRK. In the where condition give the field name as KUNAG,Select the operator as = and comparison value as IM_FS_KNA1-KUNNR.

    Create Text under the Loop LOOP_BILL to display Billing Document Details

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    11/24

    Give the Name for the TEXT and a Description. To display the fields click on Field List on/offbutton on the application toolbar. A list with field names appear at the bottom left corner as shown in thescreen shot below. Drag & Drop the fields from IM_FS_VBRK on to the editor.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    12/24

    Step 9 :

    Displaying the contents in CUSTWIN (Customer Window)

    Create Text under the node CUSTWIN to display the Customer Details.

    Give the Name for the TEXT and a Description. Click on Field List on/off button on the applicationtoolbar. A list with field names appear at the bottom left corner as shown in the screen shot below. Drag &

    Drop the fields from IM_FS_KNA1 on to the editor.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    13/24

    Click here to continue...

    Step 10 :

    Displaying contents in MAIN (Main Window)

    Create a Table under the node MAIN.

    http://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page3.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page3.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page3.htm
  • 7/27/2019 Solution to the Exercise on Printing Invoices

    14/24

    Give Name for the table and Description. Right click on %LTYPE1 and rename the Line as Line1.

    Since we have to display 5 columns, LINE1 has to be divided into 5 cells. To draw lines Select the button

    Draw Lines and Columns.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    15/24

    Now create a Table line under the node Header and give the Line Type as Line1.

    As soon as you give the Line type as Line1 and press ENTER you can see that under the %ROW1 5Cells namely %CELL1%CELL5 are created. Now Rename each of these as shown below:

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    16/24

    Now under each Cell create TEXT for Displaying the Column Headings.

    Repeat the same steps for the node Main Area.

    Define a Table line. Give the Line Type as LINE1.

    As soon as you give the Line type as Line1 and press ENTER you can see that under the %ROW1 5Cells namely %CELL1%CELL5 are created. Now Rename each of these Cells and Create Textsunder each Cell to display the Details from VBRP. After Creating all these your screen should look likethis :

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    17/24

    In the Main Area Drag and Drop the fields from the field string IM_FS_VBRP to print the Item Details. Soin the Text ITEMNO1 it will be &IM_FS_VBRP-POSNR& and so on as shown above.

    Since we have to display the Total amount in the Footer area, Create a Table Line with one Cell. Tocreate a Table Line Right Click on the Line 1 Insert Empty line underneath . An empty Line appears

    after Line 1. Name this Line as Line2.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    18/24

    Create a Text under the cell TOTAL. Give the Line type as Line 2. The Following screen appears

    In order to calculate the Total (W_TOTAL) go to the Table ITEMDET. Select the Tab Calculations andgive the details as shown in the screen shot below:

    Go back to the Footer Text for Displaying the TOTAL. Drag and Drop W_TOTAL from the Global Data.

    To display the field list Click on the button Field list on/off.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    19/24

    Click here to continue...

    Step 11 :

    Displaying contents in BOTTOMWIN (Footer Details)

    Create a TEXT under the Node BOTTOMWIN to display the Footer Information.

    http://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page4.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page4.htmhttp://saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page4.htm
  • 7/27/2019 Solution to the Exercise on Printing Invoices

    20/24

    Give the Name for the TEXT and a Description an Enter the Text you want to Display in the window. Soyour screen looks something like this:

    Step 12 :

    Finally Save and Activate the Form.

    As we know, when we Activate the Smart Form it generates a Function Module automatically. To view theFunction Module generated for this Smart Form, Go to Environment Function Module Name.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    21/24

    By Clicking on the Function Module Name, a pop up appears which gives the name of the FunctionModule.

    Note down the Function Module name.

    Step 13 :

    Driver program to Execute the form ZSF_INVOICE

    Go to Transaction SE38 from the SAP Easy Access Screen and create an Executable Program withsome name say ZSF_PRINTINVOICE.

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    22/24

    As in the following program, declare the Selection screen elements, Work variables, Internal Tables etcand call the Functions 'SSF_FUNCTION_MODULE_NAME' and /1BCDWB/SF00000201 (The one which

    we got in Smart form by going to Environment Function Module Name). After calling the Function/1BCDWB/SF00000201 just replace it by FM_NAME as shown in the code below:REPORT zsf_printinvoice.

    *"Table Declarations...................................................

    TABLES:

    kna1,vbrk,vbrp.

    *"Select Screen Elements...............................................PARAMETERS :

    p_kunnr LIKE vbrk-kunag,p_vbeln LIKE vbrk-vbeln.

    *"Data Declarations....................................................

    *"--------------------------------------------------------------------** Work Variables

    **"--------------------------------------------------------------------*DATA :

    fm_name TYPE rs38l_fnam. " Name of the Function Module*"--------------------------------------------------------------------*

    * Internal Table to Hold Billing Document Header Details **"--------------------------------------------------------------------*DATA :

    t_vbrk LIKESTANDARD TABLE

    OF vbrk.*"--------------------------------------------------------------------*

    * Internal Table to Hold Billing Document Item Details **"--------------------------------------------------------------------*DATA:

    t_vbrp LIKESTANDARD TABLE

    OF vbrp.

    DATA :fs_kna1 TYPE kna1, " Holds Customer Details

    fs_vbrk LIKE LINE OF t_vbrk, " Holds BillingDoc Header Details

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    23/24

    fs_vbrp LIKE LINE OF t_vbrp. " Holds BillingDoc Item Details

    *"--------------------------------------------------------------------*

    * START-OF-SELECTION EVENT **"--------------------------------------------------------------------*

    START-OF-SELECTION.SELECT SINGLE *

    FROM kna1

    INTO fs_kna1WHERE kunnr EQ p_kunnr.

    SELECT *FROM vbrkINTO TABLE t_vbrk

    WHERE kunag EQ p_kunnr

    AND vbeln EQ p_vbeln.

    SELECT *FROM vbrpINTO TABLE t_vbrp

    FOR ALL ENTRIES IN t_vbrkWHERE vbeln = t_vbrk-vbeln.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTINGformname = 'ZSF_INVOICE'

    IMPORTING

    fm_name = fm_name

    EXCEPTIONSno_form = 1no_function_module = 2

    OTHERS = 3.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 fm_name

    EXPORTING

    im_fs_kna1 = fs_kna1im_t_vbrk = t_vbrkim_t_vbrp = t_vbrp

    EXCEPTIONSformatting_error = 1

    internal_error = 2send_error = 3user_canceled = 4

    OTHERS = 5.IF sy-subrc 0.

    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.

    When the Above Program is Executed the final output would be:

  • 7/27/2019 Solution to the Exercise on Printing Invoices

    24/24