Skip to Content

Author                : Ramani Nagarajan

Title                     : Dynamic tray selection while printing forms through ABAP Code

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:

  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:

  1. OPEN_FORM
  2. CLOSE_SMARTFORM
  3. CLOSE_SAPSCRIPT
  4. WRITE_SMARFORM
  5. WRITE_SAPSCRIPT
  6. 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:
Sample Program.jpg

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

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Nagarajan K

    Hi Ramani,

    Thank you sharing your knowledge in SCN. but this is not correct forum for your subject.

    This is SAP Business one reporting and printing forum. Please find correct forum and repost above document so that, the relevant member get benefits.

    Best regards,

    Nagarajan

    (0) 
  2. Jurand Wolff

    Hello Ramani,

    it’s a very clever solution. Please where can we find the attachment for the code of the custom class “ZCL_PRNTR_ATTRIBUTE” as mentioned in the blog.

    With best regards

    Jurand

    (0) 

Leave a Reply