Step1:What is package size in SAP ABAP? Important

Package size is used to process limited set of records at a time to avoid overloading of memory, this technique will increase performance of a program at a greater level.

Syntax for using Package size in select statements

SELECT <FIELD LIST> FROM <DB TABLE> INTO TABLE <INTERNAL TABLE> PACKAGE SIZE <SIZE>
<WHERE CONDITION> .
  IF SY-SUBRC = 0.
**Process records (add logic)
 ENDIF.
ENDSELECT.
By using package size we process set of records at a time between SELECT and ENDSELECT, we have to add our business logic between SELECT and ENDSELECT....see the example use of package size in next step.

Step2:Example of using Package Size in SAP ABAP 

The below is the example of using PACKAGE SIZE in SAP ABAP programs using SELECT and ENDSELECT.
In the below example we are getting data from MARA based on a package and downloading the data into an excel sheet.
REPORT ZSAPN_PACKAGE.
DATA : IT_MARA TYPE TABLE OF MARA.
DATA : IT_MARA1 TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.

PARAMETERS P_MTART TYPE MARA-MTART.

SELECT * FROM MARA INTO TABLE IT_MARA PACKAGE SIZE 100 UP TO 1000 ROWS
  WHERE MTART = P_MTART .
  IF SY-SUBRC = 0.
    APPEND LINES OF IT_MARA TO IT_MARA1. "append data to another internal table
  ENDIF.
ENDSELECT.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                    =
    FILENAME = 'C:\MARA.XLS'
    FILETYPE = 'ASC'
*   APPEND   = ' '
*   WRITE_FIELD_SEPARATOR           = ' '
*   HEADER   = '00'
*   TRUNC_TRAILING_BLANKS           = ' '
*   WRITE_LF = 'X'
*   COL_SELECT                      = ' '
*   COL_SELECT_MASK                 = ' '
*   DAT_MODE = ' '
*   CONFIRM_OVERWRITE               = ' '
*   NO_AUTH_CHECK                   = ' '
*   CODEPAGE = ' '
*   IGNORE_CERR                     = ABAP_TRUE
*   REPLACEMENT                     = '#'
*   WRITE_BOM                       = ' '
*   TRUNC_TRAILING_BLANKS_EOL       = 'X'
*   WK1_N_FORMAT                    = ' '
*   WK1_N_SIZE                      = ' '
*   WK1_T_FORMAT                    = ' '
*   WK1_T_SIZE                      = ' '
*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*   SHOW_TRANSFER_STATUS            = ABAP_TRUE
*   VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'
* IMPORTING
*   FILELENGTH                      =
  TABLES
    DATA_TAB = IT_MARA1
*   FIELDNAMES                      =
* EXCEPTIONS
*   FILE_WRITE_ERROR                = 1
*   NO_BATCH = 2
*   GUI_REFUSE_FILETRANSFER         = 3
*   INVALID_TYPE                    = 4
*   NO_AUTHORITY                    = 5
*   UNKNOWN_ERROR                   = 6
*   HEADER_NOT_ALLOWED              = 7
*   SEPARATOR_NOT_ALLOWED           = 8
*   FILESIZE_NOT_ALLOWED            = 9
*   HEADER_TOO_LONG                 = 10
*   DP_ERROR_CREATE                 = 11
*   DP_ERROR_SEND                   = 12
*   DP_ERROR_WRITE                  = 13
*   UNKNOWN_DP_ERROR                = 14
*   ACCESS_DENIED                   = 15
*   DP_OUT_OF_MEMORY                = 16
*   DISK_FULL                       = 17
*   DP_TIMEOUT                      = 18
*   FILE_NOT_FOUND                  = 19
*   DATAPROVIDER_EXCEPTION          = 20
*   CONTROL_FLUSH_ERROR             = 21
*   OTHERS   = 22
  .
IF SY-SUBRC = 0.
  WRITE : / 'data is downloaded'.
ENDIF. 
 
 
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP MM SD Consultant
Contact : serkurumsal@yandex.com