Wednesday, December 4, 2013

ZRAGHU_ALV_SPL

*&---------------------------------------------------------------------*
*& Report  ZRAGHU_ALV_SPL
*&
*&---------------------------------------------------------------------*
REPORT  ZRAGHU_ALV_SPL.

TYPES : BEGIN OF ST_EKKO,
*INCLUDE STRUCTURE EKKO.
        EBELN TYPE EBELN,
        BUKRS TYPE BUKRS,
        ERNAM TYPE ERNAM,
        ZTERM TYPE DZTERM,
        COLOR(4) TYPE C,
        EXCP TYPE C,
        END OF ST_EKKO.
DATA : IT_EKKO TYPE TABLE OF ST_EKKO,
        WA_EKKO TYPE ST_EKKO,
        IT_SELECTED TYPE TABLE OF ST_EKKO.
DATA : IT_FIELDCATLOG TYPE LVC_T_FCAT,
       WA_FIELDCATLOG TYPE LVC_S_FCAT.

 DATA : O_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
        O_GRID TYPE REF TO CL_GUI_ALV_GRID.

***************************
* DEFINING A LOCAL CLASS  *
***************************
CLASS LCL_EVENTS DEFINITION.
PUBLIC SECTION.
METHODS : HANDLE_BEFORE_USER_COMMAND FOR EVENT BEFORE_USER_COMMAND
          OF CL_GUI_ALV_GRID IMPORTING E_UCOMM.
ENDCLASS.
****************************
*  CLASS IMPLEMENTATION    *
****************************
CLASS LCL_EVENTS IMPLEMENTATION.
METHOD : HANDLE_BEFORE_USER_COMMAND.
DATA : IT_ROWS TYPE LVC_T_ROID,
        WA_ROWS TYPE LVC_S_ROID.
CASE E_UCOMM.
WHEN '&PC'.    "EXPORT
call method O_GRID->GET_SELECTED_ROWS
  IMPORTING
*    ET_INDEX_ROWS =
    ET_ROW_NO     = IT_ROWS
    .

LOOP AT IT_ROWS INTO WA_ROWS.

READ TABLE IT_EKKO INTO WA_EKKO INDEX WA_ROWS-ROW_ID.

APPEND WA_EKKO TO IT_SELECTED.

ENDLOOP.

call function 'GUI_DOWNLOAD'
  exporting
*   BIN_FILESIZE                    =
    FILENAME                        = 'C:\SELECT.TXT'
*   FILETYPE                        = 'ASC'
*   APPEND                          = ' '
   WRITE_FIELD_SEPARATOR           = 'X'
*   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'
* IMPORTING
*   FILELENGTH                      =
  TABLES
    DATA_TAB                        = IT_SELECTED
*   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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
ENDCASE.

call method O_GRID->SET_USER_COMMAND
  exporting
    I_UCOMM  = ' '
    .

ENDMETHOD.
ENDCLASS.

 START-OF-SELECTION.
 CALL SCREEN '0100'.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.

  SET PF-STATUS 'ZRSTATUS'.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  READ_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE READ_DATA OUTPUT.

SELECT EBELN BUKRS ERNAM ZTERM
        FROM EKKO INTO TABLE IT_EKKO UP TO 100 ROWS.

ENDMODULE.                 " READ_DATA  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  DISPLAY_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE DISPLAY_DATA OUTPUT.
DATA  WA_LAYOUT TYPE LVC_S_LAYO.
WA_LAYOUT-INFO_FNAME = 'COLOR'.
WA_LAYOUT-EXCP_FNAME = 'EXCP'.
WA_LAYOUT-SEL_MODE = 'D'.
LOOP AT IT_EKKO INTO WA_EKKO.
*WA_LAYOUT-SEL_MODE = 'D'.
   CASE WA_EKKO-BUKRS.
   WHEN  '1000'.
   WA_EKKO-COLOR = 'C500'.
   WA_EKKO-EXCP = '1'.
   MODIFY  IT_EKKO FROM WA_EKKO TRANSPORTING COLOR EXCP.
   WHEN OTHERS.
   WA_EKKO-COLOR = 'C510'.
   WA_EKKO-EXCP = '2'.
   MODIFY IT_EKKO FROM WA_EKKO TRANSPORTING  COLOR EXCP.
   ENDCASE.
ENDLOOP.

**********************************
*   CREATING CLASS FOR CONTAINER *
**********************************

create object O_CONTAINER
  exporting
    CONTAINER_NAME              = 'CONTAINER'
    .
if SY-SUBRC = 0.
**********************************
*    CREATING CLASS FOR GRID     *
**********************************
create object O_GRID
  exporting
    I_PARENT          = O_CONTAINER
    .
if SY-SUBRC = 0.
******************************
* APPENDING FIELD CATALOG    *
******************************
CLEAR WA_FIELDCATLOG.
WA_FIELDCATLOG-COL_POS = '1'.
WA_FIELDCATLOG-FIELDNAME = 'EBELN'.
WA_FIELDCATLOG-COLTEXT = 'EBELN'.
APPEND WA_FIELDCATLOG TO IT_FIELDCATLOG.

CLEAR WA_FIELDCATLOG.
WA_FIELDCATLOG-COL_POS = '2'.
WA_FIELDCATLOG-FIELDNAME = 'BUKRS'.
WA_FIELDCATLOG-COLTEXT = 'BUKRS'.
APPEND WA_FIELDCATLOG TO IT_FIELDCATLOG.

CLEAR WA_FIELDCATLOG.
WA_FIELDCATLOG-COL_POS = '3'.
WA_FIELDCATLOG-FIELDNAME = 'ERNAM'.
WA_FIELDCATLOG-COLTEXT = 'ERNAM'.
APPEND WA_FIELDCATLOG TO IT_FIELDCATLOG.

CLEAR WA_FIELDCATLOG.
WA_FIELDCATLOG-COL_POS = '4'.
WA_FIELDCATLOG-FIELDNAME = 'ZTERM'.
WA_FIELDCATLOG-COLTEXT = 'ZTERM'.
APPEND WA_FIELDCATLOG TO IT_FIELDCATLOG.

************************************
* CREATING OBJECT FOR LOCAL CLASS  *
************************************

DATA O_HANDLER TYPE REF TO LCL_EVENTS.
CREATE OBJECT O_HANDLER.
SET HANDLER : O_HANDLER->HANDLE_BEFORE_USER_COMMAND FOR O_GRID.

****************************
*  DISPLAYING THE RECORDS  *
****************************
call method O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
*    I_STRUCTURE_NAME              = 'EKKO'
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
     IS_LAYOUT                     = WA_LAYOUT
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
*    IR_SALV_ADAPTER               =
  changing
    IT_OUTTAB                     = IT_EKKO
    IT_FIELDCATALOG               = IT_FIELDCATLOG
*    IT_SORT                       =
*    IT_FILTER                     =
*  EXCEPTIONS
*    INVALID_PARAMETER_COMBINATION = 1
*    PROGRAM_ERROR                 = 2
*    TOO_MANY_LINES                = 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.

endif.

endif.

ENDMODULE.                 " DISPLAY_DATA  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.

IF SY-UCOMM = 'BACK'.
LEAVE TO SCREEN 0.
ENDIF.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

No comments: