Thursday, February 14, 2019

How to download classical report in SAP ABAP ?

Before the start, you need to know what is the classical report, function module, At User command,
set PF Status and SY-UCOMM.
Firstly we clear all concepts and then start the actual code of download classical report's.
Classical Reports:
  • Classical Reports are reports which contain both selection-screen and output screen.
  • SAP ABAP is an event-driven programming language, ABAP programs executed based on events, not line-by-line.  
Function Modules:
  • Function Modules are sub-programs which contains a set of re-usable statements with importing, exporting parameters, exceptions. Unlike include programs Function Modules can be executed independently.
  • You can find the function builder with transaction code SE37.

set pf-status:

  • This event will trigger whenever a user clicks on any custom buttons of the GUI.
  • Syntax: set pf-status. "Triggers user command
 At User Command:
  • This event will trigger whenever a user clicks on any function buttons.
  • Syntax: AT USER-COMMAND. "Triggers user command.
SY-UCOMM:
  • SY-UCOMM is a system variable. It contains the latest user action triggered. It is used for doing the functions what the user wishes to do at that particular event. You can use it in menus and other places. This is mainly used for <pfstatus>.
Create a classical report and download that report in the local machine.
*&---------------------------------------------------------------------*
*& Report  ZCLASSICALDOWN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZCLASSICALDOWN.

TABLES: MARA.  “ Table Name

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: S_MTART TYPE MARA-MTART. “take the input from User material type(FERT)
SELECTION-SCREEN END OF BLOCK B1.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,  “ Material Number.
        MTART TYPE MARA-MTART,    “ Material Type.
        MATKL TYPE MARA-MATKL,     “ Material Group.
  END OF TY_MARA.
DATA: IT_MARA TYPE TABLE OF TY_MARA. “ Internal table of MARA Table.
DATA: WA_MARA TYPE TY_MARA. “ work-area of MARA Table.

START-OF-SELECTION.
  SET PF-STATUS 'MENU'. “ when you double click on the menu, It will trigger in se51 i.e menu painter and create Download button on GUI.

  SELECT MATNR MTART MATKL FROM MARA INTO TABLE IT_MARA WHERE MTART = S_MTART.  “ fetch data from MARA table into Internal table.

 “ Movie data from Internal table to Work-area.

  LOOP AT IT_MARA INTO WA_MARA.
    WRITE: / WA_MARA-MATNR,WA_MARA-MTART, WA_MARA-MATKL. “ print data
  ENDLOOP.

AT USER-COMMAND.
           IF SY-UCOMM = 'DOWN'.
           CALL FUNCTION 'GUI_DOWNLOAD'   “ call function for downloading the report or we can data.
           EXPORTING
**        BIN_FILESIZE                    =
           FILENAME                        = 'E:\MARA TAB\MARA10.TXT'   “ path of file where data will be stored.
           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                      = ' '
**      IMPORTING
**        FILELENGTH                      =
      TABLES
            DATA_TAB                        = IT_MARA  " Internal Table
**        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.
                        MESSAGE: 'DATA SUCCESSFULLY DOWNLOADED' TYPE 'S'. “Pass the message so you will gate notification when file gate downloaded.
            ENDIF.
ENDIF.




Previous Topic                                                                                                                                          Next Topic

No comments:

Post a Comment