Sample Sapscripts Label Printing Program

TABLES : ZPACK,ZTRN.

DATA: BEGIN OF ITAB OCCURS 0,
      ZPKSLIP_NO LIKE ZTRN-ZPKSLIP_NO,
      ZCARTON_NO LIKE ZPACK-ZCARTON_NO,
      END OF ITAB.

DATA MVAR(12) TYPE C.
DATA MCTR(6) TYPE C.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: ZSLIP FOR ZTRN-ZPKSLIP_NO NO-EXTENSION NO INTERVALS
OBLIGATORY default 6.
SELECTION-SCREEN END OF BLOCK B1.

SELECT * FROM ZPACK INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE
ZPKSLIP_NO EQ ZSLIP-LOW .

CALL FUNCTION 'OPEN_FORM'
  EXPORTING
    FORM = 'ZTEST_RAJ'.

DO 4 TIMES.

  MCTR = 100000 + SY-INDEX.
  MCTR = MCTR+1(5).
  CONCATENATE '55C/06/' MCTR INTO MVAR.

  DO 80 TIMES.
    ITAB-ZPKSLIP_NO = MVAR.
    ITAB-ZCARTON_NO = SY-INDEX.
    APPEND ITAB.
    CLEAR ITAB.
  ENDDO.

ENDDO.

SORT ITAB BY ZPKSLIP_NO ZCARTON_NO.

CALL FUNCTION 'START_FORM'
  EXPORTING
    FORM = 'ZTEST_RAJ'.

LOOP AT ITAB.

  AT NEW ZPKSLIP_NO.

    CALL FUNCTION 'WRITE_FORM'
      EXPORTING
        ELEMENT = '101'
        WINDOW  = 'MAIN'.

  ENDAT.

  CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      ELEMENT = '102'
      WINDOW  = 'MAIN'.

  AT END OF ZPKSLIP_NO.

    CALL FUNCTION 'END_FORM'.

    CALL FUNCTION 'START_FORM'
      EXPORTING
        FORM = 'ZTEST_RAJ'.

  ENDAT.

ENDLOOP.

CALL FUNCTION 'END_FORM'.

CALL FUNCTION 'CLOSE_FORM'.
 

In sap script write :
 /E   101 
 P1   ,,&ITAB-ZPKSLIP_NO(R)& 
 P1 
 /E   102 
 P1   ,,&ITAB-ZCARTON_NO(R)& 

SAPscripts Tips by : Rajiv Singh

Sapscripts Tips

Fast Links:
SAPscripts FAQ
FAQ for Sap Scripts

ABAP Books
ABAP Programming, Certification, Interview Questions Smartform and SAPscripts  Reference Books

SAP Scripts Tips
SAP Sapscripts Tips and Tricks

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.