Technical Articles
Practical Way Of Enhancing Adobe/Smartforms Form Output
Hi,
In this post, I would like to share with you, how we can enhance a standard adobe or smart forms’ output by applying MVC.
As business requirements may differ from SAP standard form format, we may require to enhance an existing form. What usually happens is, functional consultant tells the name of output program and form and developer copies both to Z versions. And worst, all enhancement code is written under code block of form and many new fields are added to global data of interface.
Actually you do not need to copy the program. Why? Because, all the inputs, those exists on program, are already given to form as import parameters. Therefore, simply copy only the form, create a class and process required data from import parameters within that model class, to create a single deep structure for output, which is to be used in form.
How I do that is, I create a class and call that class in code block of form’s code interface. And as return parameter, I create a deep structure to be used in form context.
Here is an example. In this example adobe form is copied from standard form, and interface is copied as well. In interface code block, model object is called and get_data method fills global docstc deep structure. The docstc structure contains all required extra data. Instead of using many fields, use single deep structure. In that way if you need to add a new field, that can be achieved simply by adding it to structure. Instead of editing interface and form’s related blocks.
Form
Interface Code Block
Form Code Interface
Interface Global Data – this data is passed to form context.
Simple as that, all the complexity is encapsulated in class. And If a new format of the form is required, same class can be used.
Writing code directly under forms code block is a bad practice, it is against mvc, against code reusability and makes developers life definitely more difficult. Simply, using code block just as a controller to pass import parameters to model class and retrieving return data is easier and better practice. Makes code reusable, testable and also modular.
Hope that helps to you.
To have more idea about applying MVC, you can have a look at Applying MVC in ABAP blog post.
Thanks for reading.
If you have huge differences in the forms then you might still want to use different structures. Not just the output, but the input might be also very different. I personally like to see if my code filled up every field that i need without being disturbed by the unneccessary fields of other forms.
Once the structure is not the same, I also cant create a general get_data method because each method needs different structure in the interface.
Tamas, What I am trying to tell in blog is, do not write code directly under code block. Instead apply MVC, use code blog as controller to pass and receive parameters. And instead of passing each parameter one by one, place them in a structure, so you won't need to change controller code with field changes.
That is all.