SAP ABAP Smartforms Print : How to reset page numbering

Requirements: Create a print report using Smartforms. Reset page counter for every documents.

Example:

1) PO # 0001 has 3 pages.
   Page 1 of 3
   Page 2 of 3
   Page 3 of 3
2) PO # 005 has 2 pages
   Page 1 of 2
   Page 2 of 2
and so on...

Got a quick google about the said matter and my quick search turn into hours and hours reading forums and blogs. Good thing I was able find the solution but sad part is, I was not able to bookmarked nor got the URL for the solution as I was overly excited to apply what I have found after hours of scratching my head.

So for the sake of giving back, I decided to post it here hoping it could help for those soul want to learn SAP ABAP and probably to my two daughters. I could not help myself to smile while writing this stuff, imagining in the future to come, my daughters would came across reading this stuff. Anyways, here it is.
The trick here is to have a header table and the detail table, wherein you have to loop in the header table and call smartforms.

Sample output 1
SAP ABAP Smartforms Print reset page number



Sample output 2
SAP ABAP Smartforms Print reset page number

Sample output 3
SAP ABAP Smartforms Print reset page number

Sample output 4
SAP ABAP Smartforms Print reset page number

and here is the code snippet.
*/---------------------------------------------------------------------
 FORM Print_Report.
*/---------------------------------------------------------------------
Data smartform_fx    type rs38l_fnam.
Data lv_ssfcompop    type ssfcompop.
Data: control_parameters TYPE ssfctrlop.
Data: nLines type i, xCtr type i.

lv_ssfcompop-tddest      = 'LOCL'.
lv_ssfcompop-tdimmed     = 'X'.
lv_ssfcompop-tddelete    = 'X'.


cForms = 'ZSF_PRINT_FORM'.
Perform Form_Get_Smarform_name
              using cForms
              changing smartform_fx.

Describe Table iHead Lines nLines.
Loop at iHead Into waHead.
           xCtr = xCtr + 1.
          If nLines gt 1.
              ""iHead contains more records
              if xCtr = 1.
                 ""First Record
                 control_parameters-no_open = ' '.
                 control_parameters-no_close = 'X'.
             elseif xCtr = nLines.
                 ""Last Record
                 control_parameters-no_open = 'X'.
                 control_parameters-no_close = ' '.
             else.
                 ""Nth Records
                 control_parameters-no_open = 'X'.
                 control_parameters-no_close = 'X'.
             endif.
         else.
              ""iHead contains only one record
             control_parameters-no_open = ' '.
             control_parameters-no_close = ' '.
         endif.

        CALL FUNCTION smartform_fx
                   EXPORTING
                           output_options   = lv_ssfcompop
                           user_settings       = space
                          control_parameters = control_parameters
                          waHead           = waHead
                  TABLES
                          iDtl              = iDtl
                 EXCEPTIONS
                         formatting_error = 1
                         internal_error   = 2
                        send_error       = 3
                        user_canceled    = 4
                         others           = 5.
            If sy-subrc <> 0.
                 message id sy-msgid type sy-msgty number sy-msgno
                      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
           Endif.
Endloop.
ENDFORM.       "End of PRINT_REPORT.
*/=====================================================================

That's it. Hope it clears enough and if not, then it will be a learning experience to digest it's process.
Happy Pokemon hunting este ABAPING!

Comments

  1. The ability to reset page numbering in SAP ABAP SmartForms is highly valuable. It allows for precise control over the layout and presentation of documents. How Watch Youtube Appreciating this feature, as it enables developers to create professional and organized reports.

    ReplyDelete

Post a Comment

Popular posts from this blog

SAP ABAP: Capturing CHECK BOX event in FM REUSE_ALV_GRID_DISPLAY / Cell Editing

SAP ABAP: Smartforms/SAPscript formatting

SAP ABAP: Adding leading zero to char or string.