Skip to Content
0
Former Member
Aug 25, 2008 at 01:53 AM

How to print multiple items in SAPScripts

77 Views

Hi gurus,

I have a list of items to print out in SAPScript but I can implement it. I've searched this forum for over a day and I can't find the correct answer. I post my code here. Hope you can help me. Thanks in advance.

__P/S:__ I found that someone here solved this by using index. Can you tell me how to implement it?

DATA: BEGIN OF ITAB OCCURS 0,

  • Elements here

END OF ITAB.

DATA: BEGIN OF XTAB OCCURS 0,

  • Elements here

END OF XTAB.

DATA: WA_XTAB LIKE XTAB.

DATA: ZOPTIONS LIKE ITCPO OCCURS 0 WITH HEADER LINE.

DATA: ZPAGE TYPE I.

START-OF-SELECTION.

PERFORM PREPARE.

PERFORM FORM_OPEN.

PERFORM FORM_WRITE.

PERFORM FORM_CLOSE.

FORM PREPARE.

  • Add data to itab & xtab.

ENDFORM.

FORM FORM_OPEN.

CLEAR : ZOPTIONS.

ZOPTIONS-TDDEST = 'LOCLSVC'.

  • ST_OPTIONS-TDPRINTER =

ZOPTIONS-TDPREVIEW = 'X'.

ZOPTIONS-TDIMMED = 'X'.

ZOPTIONS-TDDELETE = 'X'.

ZOPTIONS-TDPROGRAM = SY-REPID.

ZOPTIONS-TDTELELAND = 'VN'.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

DEVICE = 'PRINTER'

FORM = 'ZF_CC_CI'

LANGUAGE = SY-LANGU

OPTIONS = ZOPTIONS

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

OPTIONS = 4

UNCLOSED = 5.

IF SY-SUBRC <> 0.

MESSAGE E001 WITH 'Output was cancelled'

'by the user.'.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " FORM_OPEN

FORM FORM_WRITE.

CLEAR ZPAGE.

LOOP AT ITAB.

ZPAGE = ZPAGE + 1.

PERFORM FORM_START.

PERFORM WRITE_TITLE.

PERFORM END_FORM.

ENDLOOP.

ENDFORM.

FORM FORM_START.

CALL FUNCTION 'START_FORM'

EXPORTING

FORM = 'ZF_CC_CI'

LANGUAGE = SY-LANGU

  • PROGRAM = SY-REPID

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 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.

ENDFORM.

FORM WRITE_TITLE.

DATA: NCOUNT TYPE I,

NI TYPE I.

NI = 1.

DESCRIBE TABLE XTAB LINES NCOUNT.

DO NCOUNT TIMES.

CLEAR WA_XTAB.

READ TABLE XTAB INTO WA_XTAB INDEX NI .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM'

TYPE = 'BODY'

WINDOW = 'ITEM'.

NI = NI + 1.

ENDDO.

ENDFORM. " WRITE_TITLE

FORM END_FORM.

CALL FUNCTION 'END_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDFORM. " END_FORM

FORM FORM_CLOSE.

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDFORM. " FORM_CLOSE