Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 2136

Dynamic printer-tray selection while printing forms through ABAP Code

$
0
0

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:

 

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

 

Smartform ResourceName.jpg

 

     Incase of SAPScript, the above said point-1 is the only way

 

SAPScript ResourceName.jpg

 

 

 

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:

Import Procedure.jpg

 

And the print routine, imports the Print Attributes from the above memory database table and assign it to printing.

 

Logic for proposed solution

 

 

  1. Import the relevant print attribute of the concerned form
  2. Keep a local copy of it
  3. Lock the Memory Database Table record
  4. Change the Resource Name with the required TRAY on the imported internal table
  5. Export the above modified internal table back to the Memory Database Table
  6. Call the Form Printing routine
  7. Export the Local Copy of internal tables from Step(2) back to the Memory Database Table
  8. 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:
Sample Program.jpg

Note: Highlighted rows are our new methods.


Viewing all articles
Browse latest Browse all 2136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>