SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

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
Code

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.
Code

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.
Code

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.
Code

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.

Custom Type declaration for Form Routine in Smartform

TYPES tkomv2 TYPE TABLE OF komv.
Code

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.
Code

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.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.