cancel
Showing results for 
Search instead for 
Did you mean: 

error with small sap script program

Former Member
0 Kudos

REPORT  ZFORM1                                  .
TABLES : ZGTABLE.
types:begin of warea,
      trackid type zgtable-trackid,
      artist type zgtable-artist,
      end of warea.
data:itable like zgtable occurs 0 with header line.
     
      
CALL FUNCTION 'OPEN_FORM'
 EXPORTING
*   APPLICATION                       = 'TX'
*   ARCHIVE_INDEX                     =
*   ARCHIVE_PARAMS                    =
*   DEVICE                            = 'PRINTER'
   DIALOG                            = 'X'
   FORM                              = 'ZFORM1'
   LANGUAGE                          = SY-LANGU
*   OPTIONS                           =
*   MAIL_SENDER                       =
*   MAIL_RECIPIENT                    =
*   MAIL_APPL_OBJECT                  =
*   RAW_DATA_INTERFACE                = '*'
* 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 'WRITE_FORM'
 EXPORTING
   ELEMENT                        = 'MAIN'
*   FUNCTION                       = 'SET'
*   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.
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
*   RESULT                         =
*   RDI_RESULT                     =
* TABLES
*   OTFDATA                        =
* EXCEPTIONS
*   UNOPENED                       = 1
*   BAD_PAGEFORMAT_FOR_PRINT       = 2
*   SEND_ERROR                     = 3
*   SPOOL_ERROR                    = 4
*   CODEPAGE                       = 5
*   OTHERS                         = 6
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


Inside sapscript:

/E MAIN

*

P1 <B> Track id : </> &ITABLE-TRACKID&

P1 <B> Artist : </> &ITABLE-ARTIST&

output:

Trackid : 00000000000

Artist :

Why the output is like that? I expect the output to be first record of the table.Please help me.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Where is loop ( Internal table ),Just see the bold code

REPORT ZFORM1 .

TABLES : ZGTABLE.

<b>data : begin of itable occurs 0,

trackid type zgtable-trackid,

artist type zgtable-artist,

end of itable .</b>

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

DIALOG = 'X'

FORM = 'ZFORM1'

LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • 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.

<b>select track id artist from zgtable into table itable.

if sy-subrc ne 0.

*message

endif.

loop at itable .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'MAIN'

  • FUNCTION = 'SET'

  • 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.

clear itable.

endif.</b>

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • CODEPAGE = 5

  • OTHERS = 6

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Thanks

Seshu

Former Member
0 Kudos

Thanks seshu I will do the same.Can you please give some points about that exporting element in write form.

Former Member
0 Kudos

Gopi,

You have written the code perfectly but you missed write the select query as well looping the internal table.

Here WRITE_FORM is the function module to pass data between program to form painter.

here you are using /E MAIN Text element ,what ever under this text element will display.

Thanks

Seshu

Former Member
0 Kudos

should we give the same name(which we give in sap script) to same element name in write_form function module.for eg:/E MAIN and same name as

element = 'MAIN' in write_form function module?

Former Member
0 Kudos

Yep,Always you must mention same name(Form painter Text element name) in write_form Function module otherwise system will not understand.

Thanks

Seshu

Former Member
0 Kudos

Seshu I have done the changes as you said.But artist is not getting picked up,only trackid is getting picked.Another problem is that if I run the program again,a error is coming saying 'Write_Form is in invalid,Start_form is missing'.Is start_form necessary?Help me.

Thanks