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.
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.
Now copy and paste following form routine codes in current SAP Smartform Form Routines tab as a new form routine.
In an ABAP code block, use the following form call for above Smartform form routine as follows
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.
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.
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.