Anda di halaman 1dari 16

SMARTFORMS INVOICE PROCEDURE

1. Create 5 windows
main window (default) --> items
4 secondary windows
a)

window 1 --> customer

b)

window 2 --> header

c)

window 3 --> logo

d)

window 4 --> footer

2. Declare the required parameters for smartform


form interface :import :i_kna1

type zmykna1

i_vbak

type zmyvbak

tables :t_vbap

like

zmyvbap (structure)

3. Adjust the windows accordingly in the form painter

4. Upload the logo using se78 and create graphics object as part of
logo window.
Provide the name of the logo

5. As part of customer window, create text element and provide the


following
customer no : &i_kna1-kunnr&
country

: &i_kna1-land1&

name

: &i_kna1-name1&

6. As part of header window, create text element and provide the


following
sales doc

&i_vbak-vbeln&

date

&i_vbak-erdat&

time

&i_vbak-erzet&

person

&i_vbak-ernam&

7. As part of footer window, create text element and provide the


following
page &sfsy-page& of &sfsy-formpages&

8. As part of items window (main window), create table object


Note:- Table object creates header, main area,footer sections
a) define 2 table lines (TABLE tab)
At table level, by default sap provides line type(%ltype1), rename this
to meaningful
name(linetype1)
draw 4 cells as part of linetype1
Right click on linetype1, create emptyline underneath, sap provides line type,
rename it to linetype2
linetype1 --> 4 cells, linetype2 --> 1 cell

b) provide the internal table for the table object


note : declare a work area as part of global
tab
gs_vbap

type zmyvbap

'DATA' tab in tables object:internal table


gt_vbap

into

gs_vbap

definitions 'global data'

c) At the table level, create the table line as

part of header

table line --> linetype1


SAP creates 4 cells based on linetype1

Create text element as part of each cell and


text
cell 1 --> text element --> sales doc
cell 2 --> text element --> item no
cell 3 --> text element --> material
cell 4 --> text element --> net value

provide some static

d) At the table level, create the table line as part of main area
table line --> linetype1
SAP creates 4 cells based on linetype1
Create text element as part of each cell and
fields appropriately
cell 5 --> text element --> &ls_vbap-vbeln&
cell 6 --> text element --> &ls_vbap-posnr&
cell 7 --> text element --> &ls_vbap-matnr&
cell 8 --> text element --> &ls_vbap-netwr&

provide the symbol

e) Declare a variable 'lv_total' type vbap-netwr as part of global


declarations 'global data' tab
Note: Specify variable 'gv_total' as part of initialization in the output
parameter so
that 'warning' 'gv_total has no defined value' is
suppressed.
f) specify the calcuation as part of table level
calculation tab at table object level:operation fieldname
total

target fieldname time

ls_vbap-netwr lv_total

after loop

g) At the table level, create the table line as

part of footer

area
table line --> linetype2
SAP creates 1 cell based on linetype2
Create text element as part of the cell and
fields appropriately

provide the symbol

cell 9 --> text element -->Total value is : &lv_total&

Note:- As part of the work area 'ls_vbap' , we are referring to the field
'netwr' which is a
currency field. Because of this field, when
we execute the smartform from driver program it leads to abort error. We
can avoid this by declaring a variable of type
'vbap-waerk'
which is currency key field (cuky). As part of currency/quantity fields tab
refer the field
'ls_vbap-netwr' to the additional variable.
global definitions 'global data' tab:
lv_waerk

type vbap-waerk

currency/quantity fields:
fieldname

reference field

ls_vbap-netwr

lv_waerk

9. Create the driver program for calling the


(Z9AMSFORM7_CALL)
REPORT

smartform

Z9AMSFORM7_CALL.

types : begin of ty_kna1.


include type zmykna1.
types end of ty_kna1.
data ls_kna1 type ty_kna1.
types : begin of ty_vbak.
include type zmyvbak.
types end of ty_vbak.
data ls_vbak type ty_vbak.
types : begin of ty_vbap.
include type zmyvbap.
types end of ty_vbap.
data lt_vbap type table of ty_vbap.
parameters p_kunnr type kna1-kunnr.
start-of-selection.
perform getcustomerdata.
form GETCUSTOMERDATA .
select single kunnr land1 name1 from kna1 into ls_kna1
where kunnr = p_kunnr.
if sy-subrc eq 0.
perform gethighestvaluesalesorder.
write 'hi'.
else.
message 'No customer data' type 'I'.
endif.
endform.
" GETCUSTOMERDATA
form GETHIGHESTVALUESALESORDER .
select single vbeln erdat erzet ernam from vbak
into ls_vbak where netwr = ( select max( netwr ) from vbak
where kunnr = p_kunnr ) and kunnr = p_kunnr.
if sy-subrc eq 0.

perform getsalesitems.
else.
message 'No Sales data' type 'I'.
endif.
endform.
" GETHIGHESTVALUESALESORDER
form GETSALESITEMS .
select vbeln posnr matnr netwr from vbap into table lt_vbap
where vbeln = ls_vbak-vbeln.
if sy-subrc eq 0.
perform callsmartform.
else.
message 'No sales items' type 'I'.
endif.
endform.
" GETSALESITEMS
form CALLSMARTFORM .
* get the smartform F.M
data lv_fname type rs38l_fnam.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname
= 'Z9AMSFORM7'
IMPORTING
FM_NAME
= lv_fname.
* prepare control
data ls_ctrl type
ls_ctrl-no_dialog
ls_ctrl-preview =

parameters to skip print dialog box


SSFCTRLOP.
= 'X'.
'X'.

* call smartform F.M


call function lv_fname
exporting
CONTROL_PARAMETERS =
i_kna1
=
i_vbak
=
tables
t_vbap
=
endform.

ls_ctrl
ls_kna1
ls_vbak
lt_vbap[].
" CALLSMARTFORM

Anda mungkin juga menyukai