SAP Smartforms Table Parameter in Form Routine
Smartform developers use Form Routines just like ABAP functions to reuse common ABAP codes for specific purposes. A form routine can be called within SAP Smartform code blocks and help ABAP developer with a clear readable code. Although it is easy to pass parameters to a Smartform Form Routine, passing internal tables sometimes causes compile errors.
I'ld like to share a tip with ABAP and Smartform developers how they can pass internal tables to a Smartform Form Routine for calculations in this tutorial.
As a sample case, I'll try to pass pricing condition details in a KOMV internal table to my sample Smartform Form Routine.
In Smartform Global Data, I have defined TKOMV as table variable using TYPE TABLE OF type assignment with KOMV associated type.
TKOMV TYPE TABLE OF KOMV
In the Initialization code block, I've called RV_PRICE_PRINT_REFRESH and PRICING_GET_CONDITIONS functions to get pricing conditions and store them in global variable tkomv table.
CALL FUNCTION 'PRICING_GET_CONDITIONS'
EXPORTING
comm_head_i = komk
TABLES
tkomv = tkomv.
Now copy and paste following form routine codes in current SAP Smartform Form Routines tab as a new form routine.
FORM CALCITEMDISCOUNT
USING lwa_vbap TYPE vbap
tkomv TYPE TABLE OF komv
CHANGING lv_discount TYPE kawrt.
*** ABAP CODE here reading tkomv table parameter for discount calculation
ENDFORM.
In an ABAP code block, use the following form call for above Smartform form routine as follows
PERFORM calcitemdiscount
USING
gwa_vbap
tkomv
CHANGING
lv_discount.
Unfortunately when I compile or activate Smartform document, the following error message is displayed preventing the Smartform to activate successfully.
@8O@ DISCOUNT Different number of parameters in FORM and PERFORM (routine: CALCITEMDISCOUNT, number of formal parameters: 5, number of actual
Solution requires a simple trick. First of all ABAP developers will realize that in Form Routine definition the ABAP code is not parsed correctly although the Check tool in Form Routine tab did not throw an exception.
First, go to Types tab in Smartform Global Definitions (under Global Settings node) and define a new type as table type of target structure.
TYPES tkomv2 TYPE TABLE OF komv.
Now we can replace the table parameter in form routine definition with this new table type definition as follows. Only change the parameter definition, leave remaining ABAP code unchanged.
FORM CALCITEMDISCOUNT
USING lwa_vbap TYPE vbap
tkomv TYPE tkomv2
CHANGING lv_discount TYPE kawrt.
*** ABAP CODE here reading tkomv table parameter for discount calculation
ENDFORM.
After above change is completed, you will be able to activate Smartform successfully and make PERFORM form routine calls within other ABAP code blocks in the Smartform document.