Author : Ramani Nagarajan
Organization : IBM India Pvt Ltd
Title : Dynamic tray selection while printing forms through ABAP Code
Mail-id : ramani600091@gmail.com
Requirement
We all know that, any forms can be printed on the required Tray by setting the appropriate value to the "Resource Name" field in the design screen of the form and be activated.
But the current requirement is to set the "Resource-Name" attribute of both Smartforms (or) SAPScript dynamically just before the form is printed.
This article explains how to set it dynamically !!
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
- CLOSE_SMARTFORM
- CLOSE_SAPSCRIPT
- WRITE_SMARFORM
- WRITE_SAPSCRIPT
- REFRESH_MEMORY
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) <Existing print routine> --> No change in these
(3) CLOSE_SMARTFORM or CLOSE_SAPSCRIPT is to be called
Note: Methods (4),(5),(6) are executed internally through other methods. Hence, we do not need to call them.
How to invoke the coding?
Here is the screen shot for calling procedure through Driver-program:
Note: Highlighted rows are our new methods.
How to utilize the attached code?
The code is a generic code, which can be used anywhere. Hence, anyone can copy the code and use it.
**Caution:
During testing, please, let the driver program run the sequence as cited above fully.
Once the OPEN_FORM method is run, CLOSE_SMARTFORM/ CLOSE_SAPSCRIPT method also should be executed sequentially. Hence, do not abort the execution half the way. This would leave the current print attribute values with the Memory Database Table. To reset the values, we have to re-activate the Smartforms / SapScript by changing the Resourse-Name to blank.
Thanks for reading it!!
Ramani Nagarajan
IBM India Private Limited