cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Script in PM form layout

0 Kudos

Hi Experts,

I want to skip the next page creation in sap script depending on the number of entries in the loop.

If the loop is executing the last entry, script should not trigger next page.

my code looks as:

   FORM OPERATIONS_WITH_MAT.
  IAFVGD = SPACE.
  LOOP AT IAFVGD WHERE AUFPL = CAUFVD-AUFPL. "loop on operations
*  only from the current order, no related order operations
    AFVGD = IAFVGD.                    " Set workarea for SAPSCRIPT
    PERFORM CHECK_PRINT_STATUS USING AFVGD-OBJNR
                                     WWORKPAPER-PM_DELTA_P RC.
    CHECK RC = 0.
    IF OP_ENTRIES > 0.                 " single operation print active
      LOOP AT OP_PRINT_TAB WHERE FLG_SEL = 'X'
         AND  VORNR   = AFVGD-VORNR    " was the operation selected
         AND  UVORN   = AFVGD-UVORN.   " for print ???
      ENDLOOP.
      CHECK SYST-SUBRC = 0.            " should this op be printed
    ENDIF.
*... for each operation
    PERFORM READ_OP_TEXT_TABLES.       "operation text tables
*... check that the operation should be printed based on the
*... control key.
    CHECK T430-VRGD = YES.             " jump to next operation

    CALL FUNCTION 'WRITE_FORM'                              "
         EXPORTING
              ELEMENT   = 'OPERATION'  " main operation details
              WINDOW    = 'MAIN'.
*... now print either the interal or external operation details
    IF AFVGD-FLG_FRD = '+'.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING
                ELEMENT = 'EXTERNAL_WORK'
                WINDOW  = 'MAIN'.
    ELSE.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING
                ELEMENT = 'INTERNAL_WORK'  " main operation details
                WINDOW  = 'MAIN'.
    ENDIF.
    PERFORM PRINT_OPERATION_TEXT.      " Longtext to operation
*-> print service package
    IF NOT AFVGD-PACKNO IS INITIAL.
      PERFORM SERVICE_PACKAGE USING AFVGD-PACKNO AFVGD-FLG_FRD.
    ENDIF.
*... now list materials for the main operation
    IRESBD = SPACE.
    LOOP AT IRESBD WHERE XLOEK = SPACE
                   AND   AUFPL = AFVGD-AUFPL   " For unique
                   AND   APLZL = AFVGD-APLZL" operation
      RESBD = IRESBD.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING
                ELEMENT = 'MATERIAL1'
                WINDOW  = 'MAIN'.
      PERFORM PRINT_MAT_LONGTEXT.      "longtext to mat reservation
    ENDLOOP.
                            " loop on materials
    PERFORM NEWWINDOW.
    PERFORM PRT_PRINT USING AFVGD-AUFPL" Plan number
                            AFVGD-APLZL.     " plan counter
*    PERFORM check.
        DATA: line type I.
        DESCRIBE TABLE IAFVGD LINES line.
        if line <> SY-INDEX.
        PERFORM new_page.
        ENDIF.
  ENDLOOP.                             " loop on operations
ENDFORM.

How to restrict the system from triggering next page w.r.t. last loop entry in the table?

Accepted Solutions (1)

Accepted Solutions (1)

former_member576008
Active Participant
0 Kudos

Hi,

What ever you have done is correct.

Have you checked in debugging the value of the sy-index is same after executing your main loop at the if condition?

        DATA: line type I.
        DESCRIBE TABLE IAFVGD LINES line.
        if line <> SY-INDEX.
        PERFORM new_page.
        ENDIF.

If not create one more integer variable and assign the sy-index value after the loop statement, use it in the IF statement.

regards,

Nandha

0 Kudos

Thanks a lot !

Answers (0)