Skip to Content
avatar image
Former Member

Page counter over multiple Smartforms

The customer has provided me with a technical Smartforms challenge:

First they have multiple forms that need to be printed in a single job. No problem using the control parameters.

However the first two forms have to use continued page numbering, while the last has to start from 1.

So for example:

Form1 - 2 pages

Form2 - 2 pages

Form3 - 1 page

Should result in:

Page 1 of 4

Page 2 of 4

Page 3 of 4

Page 4 of 4

Page 1 of 1

Currently I get (using FORM and JOBPAGES variables):

Page 1 of 5

Page 2 of 5

Page 1 of 5

Page 2 of 5

Page 1 of 1 (using SFSY-FORMPAGES here, works as expected)

For the first two forms this renders both the SFSY-FORMPAGES as the SFSY-JOBPAGES variables useless... the first will only contain the number of pages in the current form, while the latter contains the number of pages in the entire job.

Is there a way to trick the program/smartforms into combining the page counter of the first two?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 23, 2010 at 07:00 AM

    Yes I tried that and activation isn't the problem. When you actually want to process the form, the system dumps because of the two different MAIN widths.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      You have to first generate OTF ...calculate the pages and then use them in the forms:

      DATA: ssfctrlop TYPE ssfctrlop,

      ssfcrescl TYPE ssfcrescl.

      ssfctrlop-getotf = 'X'.

      CALL FUNCTION '/1BCDWB/SF00000047'

      EXPORTING

      • ARCHIVE_INDEX =

      • ARCHIVE_INDEX_TAB =

      • ARCHIVE_PARAMETERS =

      control_parameters = ssfctrlop

      • MAIL_APPL_OBJ =

      • MAIL_RECIPIENT =

      • MAIL_SENDER =

      • OUTPUT_OPTIONS =

      • USER_SETTINGS = 'X'

      IMPORTING

      • DOCUMENT_OUTPUT_INFO =

      job_output_info = ssfcrescl

      • JOB_OUTPUT_OPTIONS =

      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.

      else.

      delete SSFCRESCL-otfdata[] where TDPRINTPAR NP 'PAGE'.

      if sy-subrc = 0.

      No of lines remaing in the itab is the no pages for the form

      endif.

      ENDIF.

      OTFDATA has two parameters : TDPRINTCOM and TDPRINTPAR

      data returned will be like --> IN |05%PAGE1 where PAGE1 is your smartform page name

      So first generate otfs for the forms. Add up the total no of lines.

      Pass the the total no pages into the form and use it as page nos...

  • avatar image
    Former Member
    Sep 21, 2010 at 11:04 AM

    Hi!

    I think it should work, if you are printing all of the smartforms with the same printer program.

    If you are using the same program, then declare a global variable for counting the pages, like GV_PAGES TYPE i.

    It will seem somehow like this

    - CLEAR the GV_PAGES

    - call SMARTFORM, and declare a variable as export, then write an ABAP code in your SSF to fill this export parameter with SFSY-FORMPAGES

    - after the call of the SSF, add the SSF's export parameter to the GV_PAGES

    - call SMARTFORM, use the GV_PAGES as import parameter, add it's value and the SFSY-FORMPAGES to an another variable

    - CLEAR the GV_PAGES

    - call the last smartform

    What do you think?

    Hmm, the page count of the first print will be not perfect... Maybe you should call the second SSF first, without printing, just for getting back the page count...

    Regards

    Tamás

    Edited by: Tamás Nyisztor on Sep 21, 2010 1:05 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 21, 2010 at 11:16 AM

    That could work, but would indeed require me to call the first two forms prior to actually printing them, just to get the pagecount.

    Although it seems technically possible like this, you'll probably agree that it's not a very nice solution 😉

    <b>Update:</b>

    Implementing this proves harder than it seems... the SFSY structure is not populated at the Initialization of the form, but on the pages themselves. Including a piece of code there, requires quite some logic and conditions to prevent it to start counting every time it's processed. Still trying to make it work 😊

    Edited by: E. Venema on Sep 21, 2010 2:50 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 21, 2010 at 06:37 PM

    First question:

    How will you know how many pages the 2nd form will have until it got generated? I am not aware of anything that will tell you that.

    To me the most logical will be to combine the two forms logically. Why do you need two forms ? Can that be merged. If you tell me more about the business requirement then I can think of something.

    If you merge the two forms , you can always start the 2nd form at a new page. So to the client it would seem two forms but in fact it is just one...

    I hope I have been able to explain myself.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 06:08 AM

    maybe i´m missing something but why dont you place some coding right at the end of your smartform where you store the number of pages used for this one e.G. in SAP or ABAP memory. Or wait cant we just create an exporting parameter for the smartform?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 07:13 AM

    @Pratik:

    You can't know how many pages a form is going to be, up until the form has been generated.

    The most logical would indeed be to combine the two forms into a single Smartform. However, the first form is PORTRAIT and the second LANDSCAPE, resulting in a different width of the MAIN window. That's why I separated the two forms... and besides that it really is another form that's being printed.

    Unless you know a way to implement two MAIN windows without any problems...

    @Florian:

    It doesn't really matter where I put the logic for the page counters, I need the total number of pages to be available on both forms from the very beginning.

    The solution I have now implemented first determines the number of pages for the two forms separately. The first form uses that as an importing parameter and exports its own number of pages. The second form uses both parameters to continue numbering. From what I've seen so far... it works, but it's still not very pretty 😉

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I tried and tested a smartform:

      It had two pages..the first page is in portrait and the 2nd in landscape. And both have different main window widths .

      I actiavted the..it did not give me any errors. Did you try this?

  • avatar image
    Former Member
    Sep 22, 2016 at 09:26 AM

    I know this is like reviving a dinosaur, but for future reference I would like to propose another solution.

    Pratik is right, you first need to generate the final OTFDATA. By final I mean the OTFDATA that contains all merged Smartforms. You can refer to his approach up until the DELETE statement.

    Here I could propose something like this:

    DATA: ls_tmp_otf TYPE ssfcrescl,

               lv_pages   TYPE i.


    DELETE ls_tmp_otf-otfdata[] WHERE tdprintcom <> 'EP'.

    DESCRIBE TABLE ls_tmp_otf-otfdata[] LINES lv_pages.

    According to the SAP documentation, EP indicates the end of page. In the OTFDATA, lines where tdprintcom = EP are usually empty. The amount of these EP lines = the amount of pages printed in the end.

    And surely, the lv_pages you will have to pass to the Smarrtform.

    Hope it helps. 😊

    Add comment
    10|10000 characters needed characters exceeded