Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------**& Report ZAPPSERVBROWSER

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*REPORT ZAPPSERVBROWSER

NO STANDARD PAGE HEADING LINE-SIZE 1023

LINE-COUNT 36 . .

TABLES : SSCRFIELDS.

INCLUDE <ICON>.

CLASS LCL_APPLICATION DEFINITION DEFERRED.

CLASS CL_GUI_CFW DEFINITION LOAD.

DATA : MAIN_CONTAINER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

CONT_LEFT TYPE REF TO CL_GUI_CONTAINER,

CONT_RIGHT TYPE REF TO CL_GUI_CONTAINER,

PCOL_TREEM TYPE REF TO CL_COLUMN_TREE_MODEL,

ACOL_TREEM TYPE REF TO CL_COLUMN_TREE_MODEL,

O_EVENTS_A TYPE REF TO LCL_APPLICATION,

HANDLE TYPE REF TO CL_GUI_FRONTEND_SERVICES,

CTMENU TYPE REF TO CL_CTMENU.

DATA: ITEM_TABLE TYPE TREEMCITAB,

ITEM TYPE TREEMCITEM,

NODE_KEY TYPE TM_NODEKEY,

NODE_KEY_ROOT TYPE TM_NODEKEY,

HIERARCHY_HEADER TYPE TREEMHHDR,

TREE_NAME TYPE STRING,

MOD_TIME(20) TYPE C,

FILENAME TYPE RLGRAP-FILENAME.

DATA : CMD LIKE SY-UCOMM,

ISFOLDER_FLAG(1),

EXPANDER_FLAG(1),

ITEMS_INCOMP(1),

RECUR_FLAG(1),

SLASH(1),

TITLE_STR(255),

LENG TYPE I,

COUNT TYPE I,

L_OPSYS LIKE SY-OPSYS,

SRC_FILE TYPE STRING,

LOAD(1),

IT_EXCLUDE LIKE TABLE OF RSEXFCODE WITH HEADER LINE,

IT_SDOKPATH LIKE TABLE OF SDOKPATH WITH HEADER LINE.

DATA: G_NODE_KEY(30) TYPE C,

G_ITEM_NAME TYPE TV_ITMNAME,

EVENT TYPE CNTL_SIMPLE_EVENT,

EVENTS TYPE CNTL_SIMPLE_EVENTS.

DATA:

BEGIN OF GS_FILE,

DIRECTORY(500) TYPE C, " name of directory.

NAME(75) TYPE C, " name of entry.

" (possibly truncated.)

TYPE(10) TYPE C, " type of entry: directory, file

LEN(16) TYPE P, " length in bytes

OWNER(8) TYPE C, " owner of the entry

MTIME(6) TYPE P, " last modification date,

" seconds since 1970

MODE(9) TYPE C, " like "rwx-r-x--x":

" protection mode

ERRNO(3) TYPE C,

ERRMSG(40) TYPE C,

MOD_DATE TYPE D,

MOD_TIME(8) TYPE C, " hh:mm:ss

SUBRC LIKE SY-SUBRC,

END OF GS_FILE.

DATA : BEGIN OF IT_FCONTENT OCCURS 0,

LINES(1023) TYPE C,"string,

END OF IT_FCONTENT.

DATA : BEGIN OF IT_RESULT OCCURS 0,

LINE(100) TYPE C,

END OF IT_RESULT.

CONSTANTS : C_X(1) VALUE 'X'.

*---------------------------------------------------------------------*

* CLASS lcl_application DEFINITION

*---------------------------------------------------------------------*

* Class for Handling Events *

*---------------------------------------------------------------------*

CLASS LCL_APPLICATION DEFINITION.

PUBLIC SECTION.

METHODS:

HANDLE_EXPAND_NO_CHILDREN

FOR EVENT EXPAND_NO_CHILDREN

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY,

HANDLE_NODE_DOUBLE_CLICK

FOR EVENT NODE_DOUBLE_CLICK

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY,

* handle_header_click

* FOR EVENT header_click

* OF cl_column_tree_model

* IMPORTING header_name,

HANDLE_HEADER_CONTEXT_MENU_REQ

FOR EVENT HEADER_CONTEXT_MENU_REQUEST

OF CL_COLUMN_TREE_MODEL

IMPORTING HEADER_NAME MENU,

HANDLE_HEADER_CONTEXT_MENU_SEL

FOR EVENT HEADER_CONTEXT_MENU_SELECT

OF CL_COLUMN_TREE_MODEL

IMPORTING HEADER_NAME FCODE,

HANDLE_DEFAULT_CONTEXT_REQ

FOR EVENT DEFAULT_CONTEXT_MENU_REQUEST

OF CL_COLUMN_TREE_MODEL

IMPORTING MENU,

HANDLE_DEFAULT_CONTEXT_SEL

FOR EVENT DEFAULT_CONTEXT_MENU_SELECT

OF CL_COLUMN_TREE_MODEL

IMPORTING FCODE,

HANDLE_ITEM_DOUBLE_CLICK

FOR EVENT ITEM_DOUBLE_CLICK

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY ITEM_NAME,

HANDLE_NODE_CONTEXT_MENU_REQ

FOR EVENT NODE_CONTEXT_MENU_REQUEST

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY MENU,

HANDLE_NODE_CONTEXT_MENU_SEL

FOR EVENT NODE_CONTEXT_MENU_SELECT

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY FCODE,

HANDLE_ITEM_CONTEXT_MENU_REQ

FOR EVENT ITEM_CONTEXT_MENU_REQUEST

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY ITEM_NAME MENU,

HANDLE_ITEM_CONTEXT_MENU_SEL

FOR EVENT ITEM_CONTEXT_MENU_SELECT

OF CL_COLUMN_TREE_MODEL

IMPORTING NODE_KEY ITEM_NAME FCODE .

ENDCLASS. "lcl_application DEFINITION

*---------------------------------------------------------------------*

* CLASS LCL_APPLICATION IMPLEMENTATION

*---------------------------------------------------------------------*

* Event Handler Methods *

*---------------------------------------------------------------------*

CLASS LCL_APPLICATION IMPLEMENTATION.

METHOD HANDLE_EXPAND_NO_CHILDREN.

DATA : DIR(500).

DIR = NODE_KEY.

PERFORM GET_FILE_LIST USING DIR.

CALL METHOD ACOL_TREEM->EXPAND_NODE

EXPORTING

NODE_KEY = NODE_KEY

EXCEPTIONS

NODE_NOT_FOUND = 1.

ENDMETHOD. "handle_expand_no_children

METHOD HANDLE_NODE_DOUBLE_CLICK.

" this method handles the node double click event of the tree

" model instance

ENDMETHOD. "handle_node_double_click

* METHOD handle_header_click.

* " this method handles header click event of the tree

* " model instance

* ENDMETHOD.

METHOD HANDLE_HEADER_CONTEXT_MENU_REQ.

" this method handles header click event of the tree

" model instance

CALL METHOD HANDLE_DEFAULT_CONTEXT_REQ

EXPORTING

MENU = MENU.

ENDMETHOD. "handle_header_context_menu_req

METHOD HANDLE_HEADER_CONTEXT_MENU_SEL.

CALL METHOD HANDLE_DEFAULT_CONTEXT_SEL

EXPORTING

FCODE = FCODE.

ENDMETHOD. "handle_header_context_menu_sel

METHOD HANDLE_DEFAULT_CONTEXT_REQ.

DATA : FUNC TYPE UI_FUNC.

MOVE 'FIND' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Find'.

MOVE 'COLL' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Collapse All Nodes'.

DATA : SUB_MENU TYPE REF TO CL_CTMENU.

CREATE OBJECT SUB_MENU.

MOVE 'ABOUT_DESC' TO FUNC.

CALL METHOD SUB_MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'An ApplicationServerBrowser by IMM'.

CALL METHOD MENU->ADD_SEPARATOR.

MOVE 'ABOUT' TO FUNC.

CALL METHOD MENU->ADD_SUBMENU

EXPORTING

MENU = SUB_MENU

TEXT = 'About ZAPPSERVBROWSER'.

* ICON =

* DISABLED =

* HIDDEN =

* ACCELERATOR = .

* call method menu->add_function

* exporting

* fcode = func

* text = 'About ZAPPSERVBROWSER'.

MOVE 'HELP' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Help'

DISABLED = C_X.

MOVE 'EXIT' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Exit Browser'.

ENDMETHOD. "handle_default_context_req

METHOD HANDLE_DEFAULT_CONTEXT_SEL.

CASE FCODE.

WHEN 'FIND' .

PERFORM FIND_NODE.

WHEN 'COLL' .

CALL METHOD ACOL_TREEM->COLLAPSE_ALL_NODES .

WHEN 'ABOUT'.

WINDOW STARTING AT 45 10 ENDING AT 60 12.

WRITE 'Last window'.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMETHOD. "handle_default_context_sel

METHOD HANDLE_ITEM_DOUBLE_CLICK.

" this method handles the item double click event of the tree

" model instance

DATA : NODE_PROPERTIES TYPE TREEMSNOD.

CALL METHOD ACOL_TREEM->NODE_GET_PROPERTIES

EXPORTING

NODE_KEY = NODE_KEY

IMPORTING

PROPERTIES = NODE_PROPERTIES

EXCEPTIONS

NODE_NOT_FOUND = 1

OTHERS = 2.

IF NODE_PROPERTIES-ISFOLDER = C_X.

CALL METHOD O_EVENTS_A->HANDLE_EXPAND_NO_CHILDREN

EXPORTING

NODE_KEY = NODE_KEY.

ELSE.

PERFORM DISPLAY_NODE_CONTENT USING NODE_KEY.

ENDIF.

ENDMETHOD. "handle_item_double_click

METHOD HANDLE_NODE_CONTEXT_MENU_REQ.

PERFORM ADD_NODE_MENU_FUNCTIONS USING NODE_KEY MENU.

ENDMETHOD. "handle_node_context_menu_req

METHOD HANDLE_NODE_CONTEXT_MENU_SEL.

PERFORM CONTEXT_MENU_SEL USING NODE_KEY FCODE.

ENDMETHOD. "handle_node_context_menu_sel

METHOD HANDLE_ITEM_CONTEXT_MENU_REQ.

PERFORM ADD_NODE_MENU_FUNCTIONS USING NODE_KEY MENU.

ENDMETHOD. "handle_item_context_menu_req

METHOD HANDLE_ITEM_CONTEXT_MENU_SEL.

PERFORM CONTEXT_MENU_SEL USING NODE_KEY FCODE.

ENDMETHOD. "handle_item_context_menu_sel

ENDCLASS. "lcl_application IMPLEMENTATION

*SELECTION - SCREEN

SELECTION-SCREEN : BEGIN OF BLOCK BLK1 WITH FRAME TITLE TIT1.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(29) COMMENT1.

PARAMETERS : P_ADIR(20) LOWER CASE.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(29) COMMENT2.

PARAMETERS : P_FMASK(20) DEFAULT '*'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN COMMENT 1(29) COMMENT3.

SELECTION-SCREEN : PUSHBUTTON 31(4) YES USER-COMMAND YES.

SELECTION-SCREEN : PUSHBUTTON 36(4) NO USER-COMMAND NO.

SELECTION-SCREEN : END OF BLOCK BLK1.

SELECTION-SCREEN : BEGIN OF SCREEN 100 AS WINDOW TITLE TIT2.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(22) COMMENT4.

PARAMETERS : P_FILE1(128) OBLIGATORY LOWER CASE." like rlgrap-filename

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(22) COMMENT5.

PARAMETERS : P_FILE2(128) OBLIGATORY LOWER CASE." like ibipparms-path .

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN : END OF SCREEN 100.

*SELECTION-SCREEN FUNCTION KEY 1.

*----------------------------------------------------------------------*

* INITIALIZATION *

*----------------------------------------------------------------------*

INITIALIZATION .

TIT1 = 'File Navigator'.

COMMENT1 = 'Directory/Path'.

COMMENT2 = 'File Mask'.

COMMENT3 = 'Proceed to File Navigator? '.

COMMENT4 = 'Source File'.

COMMENT5 = 'Destination File'.

YES = ICON_OKAY.

NO = ICON_CANCEL.

IT_EXCLUDE-FCODE = 'ONLI'.

APPEND IT_EXCLUDE.

SY-TITLE = 'App.Server Utility Program'.

CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'

EXPORTING

P_STATUS = SY-PFKEY

* p_program = repid

TABLES

P_EXCLUDE = IT_EXCLUDE.

*----------------------------------------------------------------------*

* AT SELECTION-SCREEN *

*----------------------------------------------------------------------*

AT SELECTION-SCREEN.

IF O_EVENTS_A IS INITIAL.

CREATE OBJECT O_EVENTS_A.

ENDIF.

CMD = SSCRFIELDS-UCOMM.

CASE CMD.

WHEN 'NO'.

IF NOT MAIN_CONTAINER IS INITIAL.

CALL METHOD CONT_LEFT->FREE.

CALL METHOD MAIN_CONTAINER->FREE.

ENDIF.

LEAVE PROGRAM.

WHEN 'YES'.

IF NOT ACOL_TREEM IS INITIAL.

CALL METHOD ACOL_TREEM->DELETE_ALL_NODES.

ENDIF.

PERFORM INIT_CONTAINER.

PERFORM INIT_CONTAINER_TREE

CHANGING ACOL_TREEM CONT_LEFT O_EVENTS_A.

"Fill List of App Server.

PERFORM ADD_ROOT.

WHEN 'CRET'.

IF LOAD = 'U'.

PERFORM UPLOAD_FILE .

ELSE.

PERFORM DOWNLOAD_FILE .

ENDIF.

ENDCASE.

CLEAR : CMD.

*----------------------------------------------------------------------*

* AT USER-COMMAND *

*----------------------------------------------------------------------*

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'E' OR 'ENDE' OR 'ECAN'.

LEAVE LIST-PROCESSING.

ENDCASE.

*----------------------------------------------------------------------*

* AT SELECTION-SCREEN ON VALUE--REQUEST FOR P_FILE1 *

*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE1.

IF LOAD = 'U'.

PERFORM F4_PRES_FILE.

ENDIF.

*----------------------------------------------------------------------*

* AT SELECTION-SCREEN ON VALUE--REQUEST FOR P_FILE2 *

*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE2.

IF LOAD = 'D'.

PERFORM F4_PRES_FILE.

ENDIF.

*----------------------------------------------------------------------*

* TOP-OF-PAGE *

*----------------------------------------------------------------------*

TOP-OF-PAGE .

FORMAT COLOR 7 INTENSIFIED ON.

NEW-LINE NO-SCROLLING.

WRITE : AT SY-COLNO 'File Name :', TITLE_STR,

AT 100 'Page' ,SY-PAGNO.

ULINE.

FORMAT RESET.

*&---------------------------------------------------------------------*

*& Form init_container

*&---------------------------------------------------------------------*

* Initialize Container

*----------------------------------------------------------------------*

FORM INIT_CONTAINER.

IF MAIN_CONTAINER IS INITIAL.

CREATE OBJECT MAIN_CONTAINER

EXPORTING

* link_dynnr = '1000'

* LINK_REPID =

* SHELLSTYLE =

* LEFT = 7

* TOP = 7

* WIDTH = 40

* HEIGHT = 30

* METRIC = cntl_metric_dynpro

* ALIGN = 15

PARENT = CL_GUI_CONTAINER=>SCREEN0

ROWS = 1

COLUMNS = 1

* NO_AUTODEF_PROGID_DYNNR =

NAME = 'XXX'.

CALL METHOD MAIN_CONTAINER->SET_TOP

EXPORTING

TOP = 40.

CALL METHOD MAIN_CONTAINER->SET_HEIGHT

EXPORTING

HEIGHT = 270.

CONT_LEFT = MAIN_CONTAINER->GET_CONTAINER( ROW = 1 COLUMN = 1 ).

ENDIF.

ENDFORM. " init_container

*&---------------------------------------------------------------------*

*& Form init_container_tree

*&---------------------------------------------------------------------*

FORM INIT_CONTAINER_TREE CHANGING

COL_TREEM TYPE REF TO CL_COLUMN_TREE_MODEL

CONT_P TYPE REF TO CL_GUI_CONTAINER

O_EVENTS TYPE REF TO LCL_APPLICATION.

IF COL_TREEM IS INITIAL.

HIERARCHY_HEADER-HEADING = 'Folder/File'. "#EC NOTEXT

HIERARCHY_HEADER-WIDTH = 30. " width: 30 characters

HIERARCHY_HEADER-TOOLTIP = 'Folder/File Name'.

CREATE OBJECT COL_TREEM

EXPORTING

NODE_SELECTION_MODE = CL_COLUMN_TREE_MODEL=>NODE_SEL_MODE_SINGLE

ITEM_SELECTION = C_X

HIERARCHY_COLUMN_NAME = 'FOLDER'

HIERARCHY_HEADER = HIERARCHY_HEADER

EXCEPTIONS

ILLEGAL_NODE_SELECTION_MODE = 1

ILLEGAL_COLUMN_NAME = 2

OTHERS = 3.

CALL METHOD COL_TREEM->ADD_COLUMN

EXPORTING

NAME = 'LOCATION'

WIDTH = 45

HEADER_TEXT = 'Path'

HEADER_IMAGE = 'WIPRO'

HEADER_TOOLTIP = 'Path Of The File'.

CALL METHOD COL_TREEM->ADD_COLUMN

EXPORTING

NAME = 'SIZE'

ALIGNMENT = CL_COLUMN_TREE_MODEL=>ALIGN_RIGHT

WIDTH = 20

HEADER_IMAGE = 'LOGO'

HEADER_TEXT = 'Size(in Bytes)'

HEADER_TOOLTIP = 'Size Of The File'.

CALL METHOD COL_TREEM->ADD_COLUMN

EXPORTING

NAME = 'OWNER'

ALIGNMENT = CL_COLUMN_TREE_MODEL=>ALIGN_LEFT

WIDTH = 25

HEADER_TEXT = 'Owner'

HEADER_TOOLTIP = 'Owner Of The File'.

CALL METHOD COL_TREEM->ADD_COLUMN

EXPORTING

NAME = 'MTIME'

WIDTH = 25

HEADER_TEXT = 'Last Modified'

HEADER_TOOLTIP = 'Last Changed Time'.

CALL METHOD COL_TREEM->CREATE_TREE_CONTROL

EXPORTING

PARENT = CONT_P.

* define the events which will be passed to the backend

CALL METHOD COL_TREEM->SET_CTX_MENU_SELECT_EVENT_APPL

EXPORTING

APPL_EVENT = C_X.

" node double click

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_NODE_DOUBLE_CLICK.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

" item double click

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_ITEM_DOUBLE_CLICK.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_HEADER_CONTEXT_MEN_REQ.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_NODE_CONTEXT_MENU_REQ.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_ITEM_CONTEXT_MENU_REQ.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_DEF_CONTEXT_MENU_REQ.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

EVENT-EVENTID = CL_COLUMN_TREE_MODEL=>EVENTID_HEADER_CLICK.

EVENT-APPL_EVENT = C_X.

APPEND EVENT TO EVENTS.

CALL METHOD COL_TREEM->SET_REGISTERED_EVENTS

EXPORTING

EVENTS = EVENTS

EXCEPTIONS

ILLEGAL_EVENT_COMBINATION = 1

UNKNOWN_EVENT = 2.

* assign event handlers in the application class to each desired event

SET HANDLER O_EVENTS->HANDLE_EXPAND_NO_CHILDREN FOR COL_TREEM.

* SET HANDLER o_events->handle_header_click FOR col_treem.

SET HANDLER O_EVENTS->HANDLE_NODE_DOUBLE_CLICK FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_ITEM_DOUBLE_CLICK FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_HEADER_CONTEXT_MENU_REQ FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_HEADER_CONTEXT_MENU_SEL FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_NODE_CONTEXT_MENU_REQ FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_NODE_CONTEXT_MENU_SEL FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_ITEM_CONTEXT_MENU_REQ FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_ITEM_CONTEXT_MENU_SEL FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_DEFAULT_CONTEXT_REQ FOR COL_TREEM.

SET HANDLER O_EVENTS->HANDLE_DEFAULT_CONTEXT_SEL FOR COL_TREEM.

ENDIF.

ENDFORM. " init_container_tree

*&---------------------------------------------------------------------*

*& Form add_nodes_app

*&---------------------------------------------------------------------*

* Add Root Node

*----------------------------------------------------------------------*

FORM ADD_ROOT.

IF P_ADIR IS INITIAL.

L_OPSYS = SY-OPSYS.

TRANSLATE L_OPSYS TO UPPER CASE.

CASE L_OPSYS.

WHEN 'WINDOWS NT'.

P_ADIR = 'c:'.

WHEN OTHERS.

P_ADIR = '/'.

ENDCASE.

ENDIF.

CASE L_OPSYS.

WHEN 'WINDOWS NT'.

SLASH = '\'.

WHEN OTHERS.

SLASH = '/'.

ENDCASE.

NODE_KEY_ROOT = P_ADIR.

CLEAR ITEM_TABLE.

CLEAR ITEM.

ITEM-ITEM_NAME = 'FOLDER'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = P_ADIR .

APPEND ITEM TO ITEM_TABLE.

ITEM-ITEM_NAME = 'LOCATION'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = 'Root' .

APPEND ITEM TO ITEM_TABLE.

ISFOLDER_FLAG = C_X.

EXPANDER_FLAG = C_X.

CALL METHOD ACOL_TREEM->ADD_NODE

EXPORTING

NODE_KEY = NODE_KEY_ROOT

ISFOLDER = ISFOLDER_FLAG

EXPANDER = EXPANDER_FLAG

ITEM_TABLE = ITEM_TABLE.

ENDFORM. " .3add_nodes_app

*&---------------------------------------------------------------------*

*& Form get_file_list

*&---------------------------------------------------------------------*

* Get File List

*----------------------------------------------------------------------*

FORM GET_FILE_LIST USING DIR.

*Some Declarations

*-----------------------------------*

DATA:

L_COUNTER TYPE I,

L_COUNTER_PACKAGE TYPE I,

L_CHAR10(10),

L_TEXT(100),

L_SUBRC LIKE SY-SUBRC,

LS_FILE LIKE GS_FILE,

PT_FILE LIKE TABLE OF GS_FILE WITH HEADER LINE.

*-----------------------------------*

CALL 'C_DIR_READ_FINISH'

ID 'ERRNO' FIELD LS_FILE-ERRNO

ID 'ERRMSG' FIELD LS_FILE-ERRMSG.

CALL 'C_DIR_READ_START'

ID 'DIR' FIELD DIR

ID 'FILE' FIELD '*'

ID 'ERRNO' FIELD LS_FILE-ERRNO

ID 'ERRMSG' FIELD LS_FILE-ERRMSG.

IF SY-SUBRC <> 0.

IF NOT LS_FILE-ERRMSG IS INITIAL.

MESSAGE I034(/SAPDMC/LSMW_OBJ_060) WITH LS_FILE-ERRMSG.

ENDIF.

EXIT.

ENDIF.

DO .

CLEAR LS_FILE.

CALL 'C_DIR_READ_NEXT'

ID 'TYPE' FIELD LS_FILE-TYPE

ID 'NAME' FIELD LS_FILE-NAME

ID 'LEN' FIELD LS_FILE-LEN

ID 'OWNER' FIELD LS_FILE-OWNER

ID 'MTIME' FIELD LS_FILE-MTIME

ID 'MODE' FIELD LS_FILE-MODE

ID 'ERRNO' FIELD LS_FILE-ERRNO

ID 'ERRMSG' FIELD LS_FILE-ERRMSG.

L_SUBRC = SY-SUBRC.

LS_FILE-SUBRC = SY-SUBRC.

IF L_SUBRC = 1.

EXIT.

ELSEIF L_SUBRC = 5.

LS_FILE-TYPE = '???'.

LS_FILE-OWNER = '???'.

LS_FILE-MODE = '???'.

ENDIF.

LS_FILE-DIRECTORY = DIR.

ADD 1 TO L_COUNTER.

ADD 1 TO L_COUNTER_PACKAGE.

IF L_COUNTER_PACKAGE = 100.

L_TEXT = '& Einträge gelesen'.

L_CHAR10 = L_COUNTER.

REPLACE '&' WITH L_CHAR10 INTO L_TEXT.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

TEXT = L_TEXT.

L_COUNTER_PACKAGE = 0.

ENDIF.

* Machine time into date/time of day convert

PERFORM P6_TO_DATE_TIME_TZ(RSTR0400) USING LS_FILE-MTIME

LS_FILE-MOD_TIME

LS_FILE-MOD_DATE.

* Only the files, which fit the sample(mask)

CASE LS_FILE-TYPE(1).

WHEN 'F' OR 'f'. " File

IF LS_FILE-NAME CP P_FMASK.

APPEND LS_FILE TO PT_FILE.

ENDIF.

WHEN OTHERS.

APPEND LS_FILE TO PT_FILE.

ENDCASE.

ENDDO.

SORT PT_FILE BY TYPE DESCENDING NAME DESCENDING.

PERFORM TREE_ADD_FILE TABLES PT_FILE.

CALL 'C_DIR_READ_FINISH'

ID 'ERRNO' FIELD LS_FILE-ERRNO

ID 'ERRMSG' FIELD LS_FILE-ERRMSG.

CLEAR PT_FILE[].

ENDFORM. " get_file_list

*&---------------------------------------------------------------------*

*& Form tree_add_file

*&---------------------------------------------------------------------*

FORM TREE_ADD_FILE TABLES GT_FILE STRUCTURE GS_FILE.

CLEAR ITEM_TABLE.

CLEAR ITEM.

DATA : COUNT TYPE I.

CLEAR RECUR_FLAG.

LOOP AT GT_FILE.

ITEM-ITEM_NAME = 'FOLDER'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = GT_FILE-NAME.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-ITEM_NAME = 'LOCATION'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = GT_FILE-DIRECTORY.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-ITEM_NAME = 'SIZE'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = GT_FILE-LEN.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-ITEM_NAME = 'OWNER'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

ITEM-TEXT = GT_FILE-OWNER.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-ITEM_NAME = 'MTIME'.

ITEM-CLASS = CL_COLUMN_TREE_MODEL=>ITEM_CLASS_TEXT.

WRITE GT_FILE-MOD_DATE TO MOD_TIME DD/MM/YYYY.

CONCATENATE MOD_TIME GT_FILE-MOD_TIME

INTO ITEM-TEXT SEPARATED BY SPACE.

* item-text = gt_file-mtime.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

IF GT_FILE-TYPE+0(1) = 'F' OR GT_FILE-TYPE+0(1) = 'f'.

ISFOLDER_FLAG = ''.

EXPANDER_FLAG = ''.

ITEMS_INCOMP = ''.

ELSE.

ISFOLDER_FLAG = C_X.

EXPANDER_FLAG = C_X.

ITEMS_INCOMP = C_X.

ENDIF.

IF GT_FILE-DIRECTORY NE SLASH.

CONCATENATE GT_FILE-DIRECTORY SLASH GT_FILE-NAME INTO NODE_KEY.

ELSE.

CONCATENATE GT_FILE-DIRECTORY GT_FILE-NAME INTO NODE_KEY.

ENDIF.

NODE_KEY_ROOT = GT_FILE-DIRECTORY.

CALL METHOD ACOL_TREEM->ADD_NODE

EXPORTING

NODE_KEY = NODE_KEY

RELATIVE_NODE_KEY = NODE_KEY_ROOT

RELATIONSHIP = CL_TREE_MODEL=>RELAT_FIRST_CHILD

ISFOLDER = ISFOLDER_FLAG

EXPANDER = EXPANDER_FLAG

ITEM_TABLE = ITEM_TABLE

EXCEPTIONS

NODE_KEY_EXISTS = 1

NODE_KEY_EMPTY = 2

ILLEGAL_RELATIONSHIP = 3

RELATIVE_NODE_NOT_FOUND = 4

ERROR_IN_ITEM_TABLE = 5

OTHERS = 6.

CLEAR : ISFOLDER_FLAG ,EXPANDER_FLAG,

NODE_KEY,NODE_KEY_ROOT ,

ITEM ,ITEM_TABLE .

ENDLOOP.

ENDFORM. " tree_add_file

*&---------------------------------------------------------------------*

*& Form display_node_content

*&---------------------------------------------------------------------*

* Display Leaf

*----------------------------------------------------------------------*

FORM DISPLAY_NODE_CONTENT USING FNAME.

DATA : STR TYPE STRING , MSG(60).

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC EQ 0.

DO.

READ DATASET FNAME INTO STR." it_fcontent-lines.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

IT_FCONTENT-LINES = STR.

APPEND IT_FCONTENT.

CLEAR IT_FCONTENT.

ENDDO.

CLOSE DATASET FNAME.

ELSE.

PERFORM ERROR_READ_FILE USING FNAME.

ENDIF.

TITLE_STR = FNAME.

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 1000.

LOOP AT IT_FCONTENT.

WRITE:/ IT_FCONTENT-LINES.

ENDLOOP.

CLEAR : IT_FCONTENT[] , TITLE_STR .

ENDFORM. " display_node_content

*&---------------------------------------------------------------------*

*& Form add_menu_functions

*&---------------------------------------------------------------------*

* Add Context Menu

*----------------------------------------------------------------------*

FORM ADD_NODE_MENU_FUNCTIONS USING NODE_KEY TYPE TM_NODEKEY

MENU TYPE REF TO CL_CTMENU.

DATA : FUNC TYPE UI_FUNC,

NODE_PROPERTIES TYPE TREEMSNOD,

NODE_TEXT TYPE GUI_TEXT.

MOVE NODE_KEY TO NODE_TEXT.

MOVE 'DETAIL' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = NODE_TEXT

DISABLED = C_X

CHECKED = C_X

ACCELERATOR = ''.

CALL METHOD MENU->ADD_SEPARATOR .

CALL METHOD ACOL_TREEM->NODE_GET_PROPERTIES

EXPORTING

NODE_KEY = NODE_KEY

IMPORTING

PROPERTIES = NODE_PROPERTIES

EXCEPTIONS

NODE_NOT_FOUND = 1

OTHERS = 2.

IF NODE_PROPERTIES-ISFOLDER = C_X.

MOVE 'OPEN' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Open Folder'.

ELSE.

MOVE 'DISP' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Display File'.

ENDIF.

MOVE 'UPLOAD' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Upload New File'.

MOVE 'DOWNLOAD' TO FUNC.

CALL METHOD MENU->ADD_FUNCTION

EXPORTING

FCODE = FUNC

TEXT = 'Download File'.

ENDFORM. " add_node_menu_functions

*&---------------------------------------------------------------------*

*& Form context_menu_sel

*&---------------------------------------------------------------------*

* Context Menu Selection

*----------------------------------------------------------------------*

FORM CONTEXT_MENU_SEL USING NODE_KEY FCODE.

DATA : NODE_PROPERTIES TYPE TREEMSNOD.

CASE FCODE.

WHEN 'OPEN'.

CALL METHOD O_EVENTS_A->HANDLE_EXPAND_NO_CHILDREN

EXPORTING

NODE_KEY = NODE_KEY.

WHEN 'DISP'.

PERFORM DISPLAY_NODE_CONTENT USING NODE_KEY.

WHEN 'DETAIL'.

CALL METHOD ACOL_TREEM->NODE_GET_PROPERTIES

EXPORTING

NODE_KEY = NODE_KEY

IMPORTING

PROPERTIES = NODE_PROPERTIES

EXCEPTIONS

NODE_NOT_FOUND = 1

OTHERS = 2.

IF NODE_PROPERTIES-ISFOLDER = C_X.

CALL METHOD O_EVENTS_A->HANDLE_EXPAND_NO_CHILDREN

EXPORTING

NODE_KEY = NODE_KEY.

ELSE.

PERFORM DISPLAY_NODE_CONTENT USING NODE_KEY.

ENDIF.

WHEN 'UPLOAD'.

TIT2 = 'Upload File'.

LOAD = 'U'.

P_FILE2 = NODE_KEY.

CLEAR P_FILE1.

CALL SELECTION-SCREEN 100 STARTING AT 20 20." ending at 25 25 .

WHEN 'DOWNLOAD'.

TIT2 = 'Download File'.

LOAD = 'D'.

P_FILE1 = NODE_KEY.

CLEAR P_FILE2.

CALL SELECTION-SCREEN 100 STARTING AT 20 20." ending at 25 25 .

ENDCASE.

ENDFORM. " context_menu_sel

*&---------------------------------------------------------------------*

*& Form Error_read_file

*&---------------------------------------------------------------------*

* Display Error Reading File

*----------------------------------------------------------------------*

FORM ERROR_READ_FILE USING FNAME.

MOVE 'Error opening the file' TO IT_FCONTENT-LINES.

APPEND IT_FCONTENT.

MOVE FNAME TO IT_FCONTENT-LINES.

APPEND IT_FCONTENT.

ENDFORM. " Error_read_file

*&---------------------------------------------------------------------*

*& Form find_node

*&---------------------------------------------------------------------*

* Search Node

*----------------------------------------------------------------------*

FORM FIND_NODE.

DATA : I_TREEMIKS TYPE TREEMIKS,

WA_TREEMIKS LIKE LINE OF I_TREEMIKS,

CHOICE TYPE I,

PATTERN(1),CANCELED(1),

FIND_STRING TYPE STRING.

CALL FUNCTION 'TREEM_SHOW_FIND_POPUP'

IMPORTING

FIND_STRING = FIND_STRING

PATTERN = PATTERN

CANCELED = CANCELED.

IF NOT CANCELED IS INITIAL.

EXIT.

ENDIF.

CALL METHOD ACOL_TREEM->FIND_ALL

EXPORTING

SEARCH_STRING = FIND_STRING

PATTERN_SEARCH = PATTERN

IMPORTING

RESULT_ITEM_KEY_TABLE = I_TREEMIKS

EXCEPTIONS

START_NODE_NOT_FOUND = 1

OTHERS = 2.

IF NOT I_TREEMIKS IS INITIAL.

SORT I_TREEMIKS BY NODE_KEY ASCENDING.

LOOP AT I_TREEMIKS INTO WA_TREEMIKS.

MOVE WA_TREEMIKS-NODE_KEY TO IT_RESULT-LINE .

APPEND IT_RESULT TO IT_RESULT[].

ENDLOOP.

DESCRIBE TABLE IT_RESULT LINES COUNT.

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'

EXPORTING

ENDPOS_COL = 40

ENDPOS_ROW = COUNT

STARTPOS_COL = 1

STARTPOS_ROW = 1

TITLETEXT = 'Search Result'

IMPORTING

CHOISE = CHOICE

TABLES

VALUETAB = IT_RESULT

EXCEPTIONS

BREAK_OFF = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

CLEAR : I_TREEMIKS[] , IT_RESULT[].

EXIT.

ENDIF.

READ TABLE I_TREEMIKS INTO WA_TREEMIKS INDEX CHOICE.

CALL METHOD ACOL_TREEM->SET_SELECTED_NODE

EXPORTING

NODE_KEY = WA_TREEMIKS-NODE_KEY

EXCEPTIONS

SINGLE_NODE_SELECTION_ONLY = 1

NODE_NOT_FOUND = 2

OTHERS = 3.

ENDIF.

CLEAR : I_TREEMIKS[] , IT_RESULT[].

ENDFORM. " find_node

*&---------------------------------------------------------------------*

*& Form upload_file

*&---------------------------------------------------------------------*

* Upload File to App. Server

*----------------------------------------------------------------------*

FORM UPLOAD_FILE.

DATA : AUTH_FILE TYPE AUTHB-FILENAME,

ANSWER(1).

AUTH_FILE = P_FILE2.

CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'

EXPORTING

* DEFAULTOPTION = 'Y'

DIAGNOSETEXT1 = P_FILE1

DIAGNOSETEXT2 = 'to be Uploaded to App.Server'

TEXTLINE1 = 'Confirm Upload?'

TITEL = 'Confirm Upload'

IMPORTING

ANSWER = ANSWER .

IF ANSWER NE 'J'.

LEAVE SCREEN .

ENDIF.

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'

EXPORTING

* PROGRAM = SY-REPID

ACTIVITY = 'WRITE'

FILENAME = AUTH_FILE

EXCEPTIONS

NO_AUTHORITY = 1

ACTIVITY_UNKNOWN = 2

OTHERS = 3

.

IF SY-SUBRC EQ 1.

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

TITEL = 'File Not Written'

TXT1 = 'No Authorization to write file in'

TXT2 = P_FILE2

TXT3 = 'Re-Enter Target Filename '.

LEAVE SCREEN .

ELSE.

SRC_FILE = P_FILE1.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = SRC_FILE

* FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_FCONTENT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2 .

OPEN DATASET P_FILE2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT IT_FCONTENT.

TRANSFER IT_FCONTENT TO P_FILE2 .

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

CLEAR IT_FCONTENT.

ENDLOOP.

CLOSE DATASET P_FILE2.

ENDIF.

ENDFORM. " upload_file

*&---------------------------------------------------------------------*

*& Form download_file

*&---------------------------------------------------------------------*

* Routine to Download File

*----------------------------------------------------------------------*

FORM DOWNLOAD_FILE.

DATA : AUTH_FILE TYPE AUTHB-FILENAME,

ANSWER(1).

AUTH_FILE = P_FILE1.

CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'

EXPORTING

* DEFAULTOPTION = 'Y'

DIAGNOSETEXT1 = P_FILE1

DIAGNOSETEXT2 = 'to be Downloaded to PC'

TEXTLINE1 = 'Confirm Download?'

TITEL = 'Confirm Downoad'

IMPORTING

ANSWER = ANSWER .

IF ANSWER NE 'J'.

LEAVE SCREEN .

ENDIF.

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'

EXPORTING

* PROGRAM =

ACTIVITY = 'READ'

FILENAME = AUTH_FILE

EXCEPTIONS

NO_AUTHORITY = 1

ACTIVITY_UNKNOWN = 2

OTHERS = 3

.

IF SY-SUBRC EQ 1.

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

TITEL = 'File Not Written'

TXT1 = 'No Authorization to Read file '

TXT2 = P_FILE1.

LEAVE SCREEN .

ENDIF.

OPEN DATASET P_FILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET P_FILE1 INTO IT_FCONTENT .

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND IT_FCONTENT.

CLEAR IT_FCONTENT.

ENDDO.

CLOSE DATASET P_FILE1.

IF NOT IT_FCONTENT[] IS INITIAL.

SRC_FILE = P_FILE2.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = SRC_FILE

* FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_FCONTENT

EXCEPTIONS

FILE_WRITE_ERROR = 1 .

ENDIF.

CLEAR IT_FCONTENT[].

ENDFORM. " download_file

*&---------------------------------------------------------------------*

*& Form f4_pres_file

*&---------------------------------------------------------------------*

* F4 for FrontEnd File

*----------------------------------------------------------------------*

FORM F4_PRES_FILE.

DATA : FIELD_NAME LIKE DYNPREAD-FIELDNAME.

IF LOAD = 'U'.

FIELD_NAME = 'P_FILE1'.

ELSE.

FIELD_NAME = 'P_FILE2'.

ENDIF.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

FIELD_NAME = FIELD_NAME

IMPORTING

FILE_NAME = P_FILE1.

IF LOAD = 'D'.

P_FILE2 = P_FILE1.

CLEAR P_FILE1.

ENDIF.

ENDFORM. " f4_pres_file

  • No labels