Printing internal table contents dynamically in SAPScript

By C.Lakshmi Prasanna, Stride Software

Here is a Script in which an internal table is displayed with each record enclosed with a box and can grow according to the no of records given as the input.  

Scenario: 1  

Here the input is given as 4 records  

 

And the Script is displaying the 4 records with each record enclosed in a Box

Scenario: 2

Here the no of records chosen is 12  

Observe that now 12 records are enclosed with the boxes.  

 

And now follows the listing of the code which is the Driver program for the above Script 

*&-------------------------------------------------------------*
*& Report  ZSCRIPT
*&-------------------------------------------------------------*
REPORT  ZSCRIPT.
data:begin of itab occurs 0,
      matnr type matnr,
      maktx type maktx,
     end of itab.
PARAMETERS:P_SNO TYPE I.
data:i type i.
move p_sno to i.
select matnr maktx from makt into table itab up to i rows.
CALL FUNCTION 'OPEN_FORM'
 EXPORTING
   FORM                              = 'ZSCRIPT_NEW'
 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.
loop at itab.
CALL FUNCTION 'WRITE_FORM'
 EXPORTING
   ELEMENT                        = 'ELEMENT '
   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 '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.

Now the details of the LAYOUT  

The Script is designed with two pages FIRST and NEXT with a Main window laid on it  

(I have not enclosed the details of the steps involved in creating the Pages)  

In the following Text element I have used two Box commands one enclosing MATNR and one enclosing MAKTX but as they are both laid next to each other the out come is a single BOX enclosing MATNR and MAKTX with a vertical separator  

Line1:Sapscript-counter_0 is the variable which iam using to dynamically increase the YPOS for drawing the BOX around each record as and when the internal table grows  

Line2:Element begins  

Line3:the first BOX command which is enclosing the MATNR,,observe that here the sapscript_counter is incremented by 1 which is achieved by &SAPSCRIPT-COUNTER_0(+)&  

Line4: again the sapscript-counter value is reinitialized to its previous value as the next BOX enclosing MAKTX has to be at the same YPOS as that of the BOX enclosing MATNR  

Line5: another BOX command this time to enclose MAKTX  

Line6: writing of the internal table variables MATNR and MAKTX to enable them to be displayed on the output  

Text Element  

MAIN

1.DEFINE &SAPSCRIPT-COUNTER_0& = -1

2.ELEMENT

3.BOX YPOS &SAPSCRIPT-COUNTER_0(+)& LN WIDTH '2' CM HEIGHT '1' LN    FRAME 10 TW DEFINE 4.&SAPSCRIPT-COUNTER_0& = &SAPSCRIPT-COUNTER_0(-)&

5.BOX YPOS &SAPSCRIPT-COUNTER_0(+)& LN  XPOS '2'CM WIDTH '10' CM HEIGHT '1'LN  FRAME 10 TW

6.&itab-matnr&                         &itab-maktx&  

I am also giving the screen shot for the text element MAIN in Character editor  

 

I have omitted all the regular steps involved to build the LAYOUT(like creation of PAGES, PAGE WINDOWS,WINDOWS,PARAGRAPH ,CHARACTER) to come out as an entity just to avoid the clutter and focus on the utilization of SAPSCRIPT-COUNTER variable.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image