Skip to Content
avatar image
Former Member

sap script

hi experts

Asa beginner of sap script,i am trying to populate main windoe in sap script with the content of an internal table.. In internal table i have 4 rows.. using loop at writeform ...endloop, i am able to print the internal table datas in four pages , but what i need is to display all datas in one page using sap script.

thank you

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 29, 2009 at 11:10 AM

    Hi

    Use the following driver program:

    *&---------------------------------------------------------------------*
    *& Report  YTESTSS_JAN29                                               *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    
    REPORT  YTESTSS_JAN29                           .
    
    DATA: ITAB TYPE TABLE OF YSTUDENT WITH HEADER LINE.
    SELECT * FROM YSTUDENT INTO TABLE ITAB.
    
    CALL FUNCTION 'OPEN_FORM'
     EXPORTING
    *   APPLICATION                       = 'TX'
    *   ARCHIVE_INDEX                     =
    *   ARCHIVE_PARAMS                    =
    *   DEVICE                            = 'PRINTER'
    *   DIALOG                            = 'X'
       FORM                              = 'YTEST_29'
       LANGUAGE                          = SY-LANGU
    *   OPTIONS                           =
    *   MAIL_SENDER                       =
    *   MAIL_RECIPIENT                    =
    *   MAIL_APPL_OBJECT                  =
    *   RAW_DATA_INTERFACE                = '*'
    *   SPONUMIV                          =
    * IMPORTING
    *   LANGUAGE                          =
    *   NEW_ARCHIVE_PARAMS                =
    *   RESULT                            =
    * EXCEPTIONS
    *   CANCELED                          = 1
    *   DEVICE                            = 2
    *   FORM                              = 3
    *   OPTIONS                           = 4
    *   UNCLOSED                          = 5
    *   MAIL_OPTIONS                      = 6
    *   ARCHIVE_ERROR                     = 7
    *   INVALID_FAX_NUMBER                = 8
    *   MORE_PARAMS_NEEDED_IN_BATCH       = 9
    *   SPOOL_ERROR                       = 10
    *   CODEPAGE                          = 11
    *   OTHERS                            = 12
              .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    
    CALL FUNCTION 'START_FORM'
     EXPORTING
    *   ARCHIVE_INDEX          =
       FORM                   = 'YTEST_29'
       LANGUAGE               = SY-LANGU
       STARTPAGE              = 'PAGE1'
    *   PROGRAM                = ' '
    *   MAIL_APPL_OBJECT       =
    * IMPORTING
    *   LANGUAGE               =
    * EXCEPTIONS
    *   FORM                   = 1
    *   FORMAT                 = 2
    *   UNENDED                = 3
    *   UNOPENED               = 4
    *   UNUSED                 = 5
    *   SPOOL_ERROR            = 6
    *   CODEPAGE               = 7
    *   OTHERS                 = 8
              .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    
    LOOP AT ITAB.
    
    CALL FUNCTION 'WRITE_FORM'
     EXPORTING
       ELEMENT                        = 'TAB'
       FUNCTION                       = 'APPEND'             " appends data to the window
       TYPE                           = 'BODY'
       WINDOW                         = 'MAIN'
    * IMPORTING
    *   PENDING_LINES                  =
    * EXCEPTIONS
    *   ELEMENT                        = 1
    *   FUNCTION                       = 2
    *   TYPE                           = 3
    *   UNOPENED                       = 4
    *   UNSTARTED                      = 5
    *   WINDOW                         = 6
    *   BAD_PAGEFORMAT_FOR_PRINT       = 7
    *   SPOOL_ERROR                    = 8
    *   CODEPAGE                       = 9
    *   OTHERS                         = 10
              .
    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.
    
    CALL FUNCTION 'END_FORM'.
    
    CALL FUNCTION 'CLOSE_FORM'.

    In SE71, in your script, create a text element for your Main window as

    /E TAB " name of text element

    &ITAB-ID& &ITAB-NAME& " itab data

    / " goes to next line

    Hope this helps 😊

    Regards,

    Jayanthi.K

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 29, 2009 at 11:20 AM

    you want to have all the data in one final internal table. Pass this table values to Script using the

    OPEN_FORM, WRITE_FORM, CLOSE_FORM.

    In Script specify the internal table fields within '&' in Text Element of the Window. Like

    /E MAIN

    • &itab-belnr&

    Example Driver Program,

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    FORM = 'Z_TRG_BILL'

    LANGUAGE = SY-LANGU

    EXCEPTIONS

    CANCELED = 1

    DEVICE = 2

    FORM = 3

    OPTIONS = 4

    UNCLOSED = 5

    MAIL_OPTIONS = 6

    ARCHIVE_ERROR = 7

    INVALID_FAX_NUMBER = 8

    MORE_PARAMS_NEEDED_IN_BATCH = 9

    SPOOL_ERROR = 10

    CODEPAGE = 11

    OTHERS = 12

    .

    IF sy-subrc <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    DATA : WA LIKE LINE OF I_DES.

    data vtotal like vbrp-netwr.

    LOOP AT I_VBRP.

    READ TABLE i_des INTO WA WITH KEY MATNR = I_VBRP-MATNR.

    at last.

    sum.

    vtotal = I_VBRP-netwr.

    endat.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'HEAD'

    • FUNCTION = 'SET'

    • TYPE = 'BODY'

    WINDOW = 'MAIN'

    EXCEPTIONS

    ELEMENT = 1

    FUNCTION = 2

    TYPE = 3

    UNOPENED = 4

    UNSTARTED = 5

    WINDOW = 6

    BAD_PAGEFORMAT_FOR_PRINT = 7

    SPOOL_ERROR = 8

    CODEPAGE = 9

    OTHERS = 10

    .

    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.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'TOTAL'

    • FUNCTION = 'SET'

    • TYPE = 'BODY'

    WINDOW = 'MAIN'

    EXCEPTIONS

    ELEMENT = 1

    FUNCTION = 2

    TYPE = 3

    UNOPENED = 4

    UNSTARTED = 5

    WINDOW = 6

    BAD_PAGEFORMAT_FOR_PRINT = 7

    SPOOL_ERROR = 8

    CODEPAGE = 9

    OTHERS = 10

    .

    IF sy-subrc <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CALL FUNCTION 'CLOSE_FORM'.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    Regards,

    Joan

    Edited by: Joan Jesudasan on Jan 29, 2009 12:21 PM

    Add comment
    10|10000 characters needed characters exceeded