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
Sample output 2
Sample output 3
Sample output 4
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!
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
Sample output 2
Sample output 3
Sample output 4
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!
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