Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Recursive last page in Sapscript

SimoneMilesi
Active Contributor
0 Likes
932

Hello Gurus!

i'm changing a sapscript with this structure

into this

Because before i got 2 fixed pages at the end (gen_cond + GEN_CON1, each one with a text include) but now the number of text includes to be printed are changed and they are not the same for each document

i got the famigerate message TD405

My code in printing is

DO nb_max TIMES.
       nb_page = nb_page + 1.


       IF nb_page = '01'."1st condtion page
         CLEAR ztxt_gpc.
         CONCATENATE ztext nb_page INTO ztxt_gpc.
         CONDENSE ztxt_gpc.
         CALL FUNCTION 'CONTROL_FORM'
           EXPORTING
             command   = 'NEW-PAGE GEN_COND'
           EXCEPTIONS
             unopened  = 1
             unstarted = 2
             OTHERS    = 3.
       ELSE. "other condition pages
         CLEAR ztxt_gpc2.
         CONCATENATE ztext nb_page INTO ztxt_gpc2.
         CONDENSE ztxt_gpc2.
       ENDIF.
     ENDDO.

Basically, 1st text, i call the new page, then i fill the text variables.

Any hints? To be honest, are ages i do not touch a sapscrit so i'm getting confused!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
837

1- In sapscript For GEN_COND page

In the MAIN you need to declare an element

/ECONDITION
/:INCLUDE &ZTXT_GPC& OBJECT TEXT ID ST LANGUAGE &NAST-SPRAS&

And in your Code

IF ztxt_gpc2 IS INITIAL AND ztxt_gpc IS NOT INITIAL.

     CALL FUNCTION 'CONTROL_FORM'

       EXPORTING

         command   = 'NEW-PAGE GEN_COND'

       EXCEPTIONS

         unopened  = 1

         unstarted = 2

         OTHERS    = 3.

   ELSEIF ztxt_gpc IS NOT INITIAL AND ztxt_gpc2 IS NOT INITIAL.

     nb_page = 0.

     DO nb_max TIMES.

       nb_page = nb_page + 1.

       concatenate ztext nb_page into ztxt_gpc.

       condense ztxt_gpc.

       if nb_page = '01'.     --> For the first page we trigger the new page and print the first page else

                                         we got an empty page

          CALL FUNCTION 'CONTROL_FORM'

           EXPORTING

            command   = 'NEW-PAGE GEN_COND'

            EXCEPTIONS

            unopened  = 1

            unstarted = 2

            OTHERS    = 3.

                CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'CONDITION'

          WINDOW                         = 'MAIN'.

        else.

       CALL FUNCTION 'CONTROL_FORM'   --> we call new-window command to go to the next Main

        EXPORTING

         command   = 'NEW-WINDOW'

        EXCEPTIONS

         unopened  = 1

         unstarted = 2

         OTHERS    = 3.

       CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'CONDITION'

          WINDOW                         = 'MAIN'.

      endif.

     ENDDO.

   ENDIF.

2 REPLIES 2
Read only

Former Member
0 Likes
838

1- In sapscript For GEN_COND page

In the MAIN you need to declare an element

/ECONDITION
/:INCLUDE &ZTXT_GPC& OBJECT TEXT ID ST LANGUAGE &NAST-SPRAS&

And in your Code

IF ztxt_gpc2 IS INITIAL AND ztxt_gpc IS NOT INITIAL.

     CALL FUNCTION 'CONTROL_FORM'

       EXPORTING

         command   = 'NEW-PAGE GEN_COND'

       EXCEPTIONS

         unopened  = 1

         unstarted = 2

         OTHERS    = 3.

   ELSEIF ztxt_gpc IS NOT INITIAL AND ztxt_gpc2 IS NOT INITIAL.

     nb_page = 0.

     DO nb_max TIMES.

       nb_page = nb_page + 1.

       concatenate ztext nb_page into ztxt_gpc.

       condense ztxt_gpc.

       if nb_page = '01'.     --> For the first page we trigger the new page and print the first page else

                                         we got an empty page

          CALL FUNCTION 'CONTROL_FORM'

           EXPORTING

            command   = 'NEW-PAGE GEN_COND'

            EXCEPTIONS

            unopened  = 1

            unstarted = 2

            OTHERS    = 3.

                CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'CONDITION'

          WINDOW                         = 'MAIN'.

        else.

       CALL FUNCTION 'CONTROL_FORM'   --> we call new-window command to go to the next Main

        EXPORTING

         command   = 'NEW-WINDOW'

        EXCEPTIONS

         unopened  = 1

         unstarted = 2

         OTHERS    = 3.

       CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'CONDITION'

          WINDOW                         = 'MAIN'.

      endif.

     ENDDO.

   ENDIF.

Read only

0 Likes
837

Thanks, it worked