‘Column view’ in SAPScripts/ Smartforms
As developers, many of us would have faced this challenge atleast once – the ‘Terms and Conditions’ Page. Most customers have T&C pages looking like this – with column view.
This is easily achievable in MS Word, using the option under Page Layout.
How do you achieve this in SAP? Traditional wisdom may tell you to keep 2 text boxes – on left & right and 2 text objects to include in them. But, what if the text content changes or the font changes? When using 2 text boxes, the text from 1st box doesn’t overflow to the 2nd box automatically.
Some other posts on SCN tells to scan the entire T&C Page as an image and include that as a graphic on the form. But, wouldn’t that require a transport whenever the text content needed to be changed (Agreed that T&C doesn’t change very often)? Also, including a high clarity image on the file means, increasing the file size.
Solution – Play with the generated OTF. OTF data is a series of commands and contents. If you know how to play around with the commands, you can insert/delete/modify the structure of the output, different from the way it was originally designed in the Smartform/ SAPScript.
Here, I am taking an example of 2 column view. You may extend concept this to any number of columns.
Goto SO10, create the text, containing T&C details – or as an example upload any dummy text file.
Create a Smartform with 2 pages, both containing MAIN windows, at required column positions. Page1 should have Page2 as the next page and Page2 should have Page1 as the next page.
My Page 2:
Now, include the text object in the MAIN window.
Create a driver program to call the Smartform and get back OTF data.
Without any modifications to the OTF structure, the output looks like this:
Just like the way it was designed in the Smartform.
Now, OTF analysis:
Everytime a new page begins, OTF uses command OP and everytime a page ends, OTF uses command EP (Full list of OTF commands are listed in program RSTXDATAOTF). If you delete OP and EP commands from OTF data, system wouldn’t know to split the page/ start a new page. This is the technique I am going to use here. Lets debug:
Here is my OTF data:
I have circled here the first OP command, which tells the system to begin the 1st page. Lets find the next page – that is by finding the next OP command.
Here is the next OP command. Here, you will see that 1st page is closed with EP command and the next page is started with OP command.
Lets delete these entries and see what happens.
Now, SAP wouldn’t know to start the next page and will think that the contents of the 2nd page in the Smartform is actually part of the 1st page in the output.
Have a look at this output. You will see that the contents from both pages have merged together to form a single page.
With this method, even if text or font changes in the included text, the contents adjust automatically. Please take note that common portions of page – like heading, logo, address, other texts etc, need to be defined only on Page1. If you need more columns in the output, you will need to have more intermediate pages in the Smartform.
Eg. to build a 3 column view:
Page1 (with logo, address, other constant texts, main window equivalent to the size of 1st column), having Next page as Page2
Page2 (main window equivalent to the size of 2nd column), having Next page as Page3
Page3 (main window equivalent to the size of 3nd column), having Next page as Page1
And, build a looping logic to delete OP commands for Pages 2 & 3 (so that 2nd & 3rd pages doesn’t start), and EP commands for Pages 1 & 2 (so that 1st & 2nd pages doesn’t close).
Once you have the manipulated OTF, use function modules CONVERT_OTF_2_PDF to convert it to PDF or PRINT_OTF to send it to printer spool.
Please let me know if any portion of this document is not clear, so that I may improve the relevant portions.
Thanks for reading,
Overlaying pages - sounds pretty cool and very doable. I've "manipulated" OTF to:
- feed "layout independent" OMS control commands as PostScript comments using OTF RD command;
- merge 2 Smartforms into one "document" where we had no control over opening and closing of forms
My dream is to one day find the time to get around the BDS storage for bitmap output (IGS charts without saving them to BDS first).
OTF reference may be helpful to aspiring OTF manipulators 🙂
Wow, this is some hard core artisanal stuff. 🙂 Nice work with the blog!
My dream is that one day "one main window" restriction will be gone. But I guess this happens when we can print the vertical text. Or pigs fly. Whichever comes first.
Thanks very much for your kind words.
nice idea,never thought it this way ➕
Thank God, we have an OMS in place 😀 From SAP we generate Smartforms as XSF only, the forms are generated by the OMS.
All fancy stuff & magic happens in OMS.
It is not clear how manipulating the OTF data changes the spool 😕
Thanks for the feedback. I have added that information now. Thanks, Juwin
Hi Juwin, Thanks for your article. It really help me and I am able to get the desired result using this. There is a small problem I am facing here. If I am getting the OTF Data print preview doesn't work. But the user wants to have the print preview option for him. Can you please help me with PRINT_OTF how can I show the print preview to user?
Preview can be shown to the user, using DISPLAY_OTF function module.
Nice idea, I always used split page into windows as LHS & RHS windows as 2 columns and printed information:) this is something new learning to try ! Great job.
Hi Sunil, is that approach (LHS & RHS) works even when the data has graphics in header the line items are in nested tables?
it should work for terms and conditions usually.if you need Graphic in header you have to design the windows size & positions accordingly. Each window will work independently and you should be clear of what is printed inside and even if you loop data the information will remain in the window size. hope I answered you if not please provide details will try to clarify.
It worked for me with graphics. The example I had created, had graphics on it - not captured in screenshot.
That's a new learning for me today. Thanks Juwin for clearly explained document.
Another major contribution! Will be very useful for me when I have to do something similar (HAHA), thanks for sharing Juwin 😀