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

HELP IN SIMPLE SAP SCRIPT

Former Member
0 Likes
559

HALLOW

i buield simple sap script in se71 and i use a program to call it but when i call it in print preview i get empty page what what i miss this is my first sap script so plz help?

REGARDS

tables : PA0002 .

data : begin of i_PA0002 occurs 0 .

include structure PA0002 .

data : end of i_PA0002 .

data : msy_subrc like sy-subrc .

  • ======================================================================

  • Selection Screen Default

  • ======================================================================

select-options : PERNR for PA0002-PERNR .

  • ======================================================================

  • Start of Selection

  • ======================================================================

start-of-selection .

select * from PA0002 into corresponding fields of table i_pa0002

where PERNR in PERNR.

  • ======================================================================

  • End of Selection

  • ======================================================================

End-of-Selection .

perform open_form using msy_subrc .

loop at i_PA0002 .

perform Start_form using msy_subrc .

perform write_form using 'OUR_ADDR' SPACE 'SET' msy_subrc .

perform write_form using 'CUSTADDR' SPACE 'SET' msy_subrc .

perform write_form using 'HEADER' SPACE 'SET' msy_subrc .

perform write_form using 'MAIN' 'ITEM_HEADER' 'SET' msy_subrc .

perform write_form using 'MAIN' 'ITEM_LINE' 'APPEND' msy_subrc .

perform end_form using msy_subrc .

endloop .

perform close_form using msy_subrc .

&----


*& Form open_form

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM open_form using msy_subrc .

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

DIALOG = 'X'

FORM = 'Z_EXAMPLE2'

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

OTHERS = 11

.

msy_subrc = SY-SUBRC .

ENDFORM. " open_form

&----


*& Form close_form

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM close_form using msy_subrc .

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

OTHERS = 5

.

msy_subrc = SY-SUBRC .

ENDFORM. " close_form

&----


*& Form Start_form

&----


  • text

----


  • -->P_MSY_SUBRC text

----


FORM Start_form USING MSY_SUBRC.

CALL FUNCTION 'START_FORM'

EXPORTING

  • ARCHIVE_INDEX =

FORM = 'Z_EXAMPLE2'

  • LANGUAGE = ' '

  • STARTPAGE = ' '

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

OTHERS = 7

.

msy_subrc = SY-SUBRC .

ENDFORM. " Start_form

&----


*& Form stop_form

&----


  • text

----


  • -->P_MSY_SUBRC text

----


FORM end_form USING P_MSY_SUBRC.

CALL FUNCTION 'END_FORM'

  • IMPORTING

  • RESULT =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4

.

msy_subrc = SY-SUBRC .

ENDFORM. " stop_form

&----


*& Form write_form

&----


  • text

----


  • -->P_MWINDOW text

  • -->P_MELEMENT text

  • -->P_MFUNCTION text

  • -->P_MSY_SUBRC text

----


FORM write_form USING MWINDOW

MELEMENT

MFUNCTION

MSY_SUBRC.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = MELEMENT

FUNCTION = MFUNCTION

TYPE = 'BODY'

WINDOW = MWINDOW

  • IMPORTING

  • PENDING_LINES =

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

OTHERS = 9

.

msy_subrc = SY-SUBRC .

ENDFORM.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
528

Hi,

declare <b>RESULT</b> as :

<b>DATA: BEGIN OF RESULT.

INCLUDE STRUCTURE ITCPP .

DATA: END OF RESULT.

Uncomment the exporting parameter DEVICE & RESULT & equate RESULT = RESULT.</b>

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

<b>* DEVICE = 'PRINTER'</b>

DIALOG = 'X'

FORM = 'Z_EXAMPLE2'

LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

<b>* RESULT =</b>

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

OTHERS = 11

.

msy_subrc = SY-SUBRC .

ENDFORM. " open_form

<b>Uncomment the parameter STARTPAGE = ' ' & give ur page name as its value.</b>

CALL FUNCTION 'START_FORM'

EXPORTING

  • ARCHIVE_INDEX =

FORM = 'Z_EXAMPLE2'

  • LANGUAGE = ' '

<b>* STARTPAGE = ' '</b>

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

OTHERS = 7

.

msy_subrc = SY-SUBRC .

ENDFORM. " Start_form

<b>Uncomment the parameter RESULT & put it equal to RESULT</b>

CALL FUNCTION 'END_FORM'

  • IMPORTING

<b>* RESULT =</b>

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4

<b>Uncomment the parameter RESULT & put it equal to RESULT</b>CALL FUNCTION 'CLOSE_FORM'

<b>* IMPORTING

  • RESULT =</b>

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

OTHERS = 5

Hope this helps.

Reward if helpful.

Regards,

Sipra

4 REPLIES 4
Read only

Former Member
0 Likes
528

hi frinds

plz i need help or advice im stuck.

Regards

Read only

0 Likes
528

tables : PA0002 .

data : begin of i_PA0002 occurs 0 .

include structure PA0002 .

data : end of i_PA0002 .

data : msy_subrc like sy-subrc .

  • ======================================================================

  • Selection Screen Default

  • ======================================================================

select-options : PERNR for PA0002-PERNR .

  • ======================================================================

  • Start of Selection

  • ======================================================================

start-of-selection .

select * from PA0002 into corresponding fields of table i_pa0002

where PERNR in PERNR.

  • ======================================================================

  • End of Selection

  • ======================================================================

End-of-Selection .

perform open_form using msy_subrc .

loop at i_PA0002 .

perform Start_form using msy_subrc .

perform write_form using 'OUR_ADDR' SPACE 'SET' msy_subrc .

perform write_form using 'CUSTADDR' SPACE 'SET' msy_subrc .

perform write_form using 'HEADER' SPACE 'SET' msy_subrc .

perform write_form using 'MAIN' 'ITEM_HEADER' 'SET' msy_subrc .

perform write_form using 'MAIN' 'ITEM_LINE' 'APPEND' msy_subrc .

perform end_form using msy_subrc .

endloop .

perform close_form using msy_subrc .

&----


*& Form open_form

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM open_form using msy_subrc .

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

DIALOG = 'X'

FORM = 'Z_EXAMPLE2'

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

OTHERS = 11

.

msy_subrc = SY-SUBRC .

ENDFORM. " open_form

&----


*& Form close_form

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM close_form using msy_subrc .

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

OTHERS = 5

.

msy_subrc = SY-SUBRC .

ENDFORM. " close_form

&----


*& Form Start_form

&----


  • text

----


  • -->P_MSY_SUBRC text

----


FORM Start_form USING MSY_SUBRC.

CALL FUNCTION 'START_FORM'

EXPORTING

  • ARCHIVE_INDEX =

FORM = 'Z_EXAMPLE2'

  • LANGUAGE = ' '

  • STARTPAGE = ' '

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

OTHERS = 7

.

msy_subrc = SY-SUBRC .

ENDFORM. " Start_form

&----


*& Form stop_form

&----


  • text

----


  • -->P_MSY_SUBRC text

----


FORM end_form USING P_MSY_SUBRC.

CALL FUNCTION 'END_FORM'

  • IMPORTING

  • RESULT =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4

.

msy_subrc = SY-SUBRC .

ENDFORM. " stop_form

&----


*& Form write_form

&----


  • text

----


  • -->P_MWINDOW text

  • -->P_MELEMENT text

  • -->P_MFUNCTION text

  • -->P_MSY_SUBRC text

----


FORM write_form USING MWINDOW

MELEMENT

MFUNCTION

MSY_SUBRC.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

<b>ELEMENT = 'MELEMENT'

FUNCTION = 'MFUNCTION'

TYPE = 'BODY'

WINDOW = 'MWINDOW'</b>

  • IMPORTING

  • PENDING_LINES =

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

OTHERS = 9

.

msy_subrc = SY-SUBRC .

ENDFORM.

I think there might problem in the highlighted part.....

Please do verify. You need to put the characters in <b>' '</b>

Regards,

Pavan

Read only

0 Likes
528

hi paven

thankes

i try it but noting change the page is empty.

Regards

Read only

Former Member
0 Likes
529

Hi,

declare <b>RESULT</b> as :

<b>DATA: BEGIN OF RESULT.

INCLUDE STRUCTURE ITCPP .

DATA: END OF RESULT.

Uncomment the exporting parameter DEVICE & RESULT & equate RESULT = RESULT.</b>

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

<b>* DEVICE = 'PRINTER'</b>

DIALOG = 'X'

FORM = 'Z_EXAMPLE2'

LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

<b>* RESULT =</b>

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

OTHERS = 11

.

msy_subrc = SY-SUBRC .

ENDFORM. " open_form

<b>Uncomment the parameter STARTPAGE = ' ' & give ur page name as its value.</b>

CALL FUNCTION 'START_FORM'

EXPORTING

  • ARCHIVE_INDEX =

FORM = 'Z_EXAMPLE2'

  • LANGUAGE = ' '

<b>* STARTPAGE = ' '</b>

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

OTHERS = 7

.

msy_subrc = SY-SUBRC .

ENDFORM. " Start_form

<b>Uncomment the parameter RESULT & put it equal to RESULT</b>

CALL FUNCTION 'END_FORM'

  • IMPORTING

<b>* RESULT =</b>

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4

<b>Uncomment the parameter RESULT & put it equal to RESULT</b>CALL FUNCTION 'CLOSE_FORM'

<b>* IMPORTING

  • RESULT =</b>

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

OTHERS = 5

Hope this helps.

Reward if helpful.

Regards,

Sipra