Author : Ramani Nagarajan
Organization : IBM India Pvt Ltd
Title : Dynamic Printer-Tray selection while printing forms through ABAP Code
Mail-id -personal: ramani600091@gmail.com
Requirement
The current requirement is to set the "Resource-Name" attribute of both Smartforms (or) SAPScript dynamically just before the form is printed.
Printing the forms on the required tray
Incase of Smart forms, currently there are 2 ways to print the forms on the required tray as below:
- By assigning the "Resource Name" attribute field on the Smartforms designer with the below values:
TRY01 for Tray-1
TRY02 for Tray-2
and so on up to 9
2. Or, by changing the default tray on the SPAD transaction
Incase of SAPScript, the above said point-1 is the only way
Challenges
There is no dynamic value assignment capability available for the field "Resource Name" on both the forms. Owing to the best practice, an alternative way to be discovered for assigning the tray values at run time before the printing, instead of Hardcoding or changing the SPAD settings (incase of Smartforms).
Proposed solution
Upon exploring the SAP approach on the "Form printing", it is found that, the Print-Attribute entered in the design time of both Smartforms & SAPScript are Exported to Memory database table as below:
Incase of SAPScript : STXL(xx)
Incase of Smartforms : STXFCONTR(sf)
Below given is the screen shot of the Import Procedure being done by the Standard coding of SAP:
And the print routine, imports the Print Attributes from the above memory database table and assign it to printing.
Logic for proposed solution
- Import the relevant print attribute of the concerned form
- Keep a local copy of it
- Lock the Memory Database Table record
- Change the Resource Name with the required TRAY on the imported internal table
- Export the above modified internal table back to the Memory Database Table
- Call the Form Printing routine
- Export the Local Copy of internal tables from Step(2) back to the Memory Database Table
- Unlock the Memory Database Table
Code Snippet:
The complete code written on a Class named as "ZCL_PRNTR_ATTRIBUTE" is attached for reference.
There are 5 methods implemented as below:
OPEN_FORM
WRITE_SMARTFORM
WRITE_SAPSCRIPT
CLOSE_SMARTFORM
CLOSE_SAPSCRIPT
REFRESH_MEMORY
Note:
Following steps are to be written in the Driver-Program in the same sequence:
(1) OPEN_FORM is the main form which is to be called through the Driver Program.
(2) As the second step, the normal printing routine from the driver program is called
(3) Finally the CLOSE_SMARTFORM or CLOSE_SAPSCRIPT is to be called
How to invoke the coding?
Here is the screen shot for calling procedure through Driver-program:
Note: Highlighted rows are our new methods.