howto: list directory on server with matchcode

Question:
hi m8's
pls does anybody know how to list files in directory on server with matchcode in report dynpro
example:
files are in /temp, i'd like to choose name of the file into the entry field with matchcode option
i can't find any solution for this
tia
_________________
opsys  VMWARE - W2k AS SP4
rel    MiniWAS 6.20
db     MSSQL 2k Ent.Ed. 8 SP3a
kernel version - 640
patch level - 71
SPlvl  spam/saint - 18
       basis - 51
       abap - 51
Answer:
Hi,
Program below will display the directory structure in tree format and allow you to select one.
Convert it into FM and use the FM in your report in event
AT SELECTION-SELECTION SCREEN ON VALUE-REQUEST.....
*----------------------------------------------------------------------*
*Program to browse the application server folder /usr.The will then    *
*display the file/folder selected(double clicked).                     *
*----------------------------------------------------------------------*
*Create a Screen 100 as Model Dialog Box. On this screen define a      *
*container of name 'TREE_CONTAINER'.Also specify g_ok_code as the okcod*
*variable in the field elements of the screen.
*----------------------------------------------------------------------*
*Create a Pf-Status 'MAIN' with two buttons with function code OK and  *
*CANCEL                                                                *
*----------------------------------------------------------------------*
report zserver_file_list message-id zms no standard page heading.
types: node_table_type like standard table of mtreesnode
                            with default key.
data: g_event(30),
      g_node_key type tv_nodekey.
class lcl_application definition deferred.
class cl_gui_cfw definition load.
data: g_application type ref to lcl_application,
      g_custom_container type ref to cl_gui_custom_container,
      g_tree type ref to cl_gui_simple_tree,
      g_ok_code type sy-ucomm.
include simple_tree_control_democl1.
data : begin of searchtab occurs 0,
        dir(100),
        name(100),
       end   of searchtab.
data : searchtab1 like searchtab occurs 0 with header line.
data: begin of file,
        level       type i,
        dirname(75) type c,
        name(75)    type c,
        name1(100)  type c,
        name2(75)   type c,
        type(10)    type c,
        len(8)      type p,
        owner(8)    type c,
        mtime(6)    type p,
        mode(9)     type c,
        useable(1)  type c,
        subrc(4)    type c,
        errno(3)    type c,
        errmsg(40)  type c,
        mod_date    type d,
        mod_time(8) type c,
        seen(1)     type c,
        changed(1)  type c,
      end of file.
data : file_list like file occurs 0 with header line.
data : file_listf like file occurs 0 with header line.
data : v_level type i value 1.
data : v_name(75).
data: v_n(5) type n value '00001'.
data: node like mtreesnode.
data: begin of itab occurs 0,
       id(5) type n,
       type(1) type c,
       name(75) type c,
       parent(5) type n,
      end   of itab.
data : v_index type i.
data : file1 like file_list.
data : itab1 like itab.
start-of-selection.
* Default the search directory as '/USR'
  move : '/USR' to searchtab-dir.
  append searchtab.
* Get the File List for default directory
  do.
    if searchtab[] is initial.
      exit.
    endif.
    loop at searchtab.
      call 'C_DIR_READ_START' id 'DIR'    field searchtab-dir
                              id 'FILE'   field '*'
                              id 'ERRNO'  field file-errno
                              id 'ERRMSG' field file-errmsg.
      if sy-subrc <> 0.
        continue.
      endif.
      do.
        clear file.
        call 'C_DIR_READ_NEXT'
          id 'TYPE'   field file-type
          id 'NAME'   field file-name
          id 'LEN'    field file-len
          id 'OWNER'  field file-owner
          id 'MTIME'  field file-mtime
          id 'MODE'   field file-mode
          id 'ERRNO'  field file-errno
          id 'ERRMSG' field file-errmsg.
        file-dirname = searchtab-dir.
        move sy-subrc to file-subrc.
        if sy-subrc ne 0.
          exit.
        endif.
        if not file-name eq '.' and
           not file-name eq '..'.
          move-corresponding file to file_list.
          move : v_level to file_list-level.
     concatenate searchtab-dir file-name into file_list-name1 separated
                                                                by '/'.
          move : v_name to file_list-name2.
          append file_list.
          if file_list-type(1) eq 'd' .
            move : file_list-name1 to searchtab1-dir.
            append searchtab1.
          endif.
        endif.
      enddo.
      call 'C_DIR_READ_FINISH'
          id 'ERRNO'  field file_list-errno
          id 'ERRMSG' field file_list-errmsg.
      v_level = v_level + 1.
      v_name = file_list-name.
    endloop.
    refresh : searchtab. clear searchtab.
    append lines of searchtab1 to searchtab.
    refresh : searchtab1.clear searchtab1.
  enddo.
  create object g_application.
* Call screen to display the directory details
  call screen 100 starting at 5 1
                      ending at 50 15.
* Display the file path of the selected node
  if not g_node_key is initial.
    read table itab with key id = g_node_key.
    read table file_list with key name = itab-name.
    write:/ file_list-name1.
  else.
    write:/ 'No Entry Selected'.
  endif.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'MAIN'.
  if g_tree is initial.
    perform create_and_init_tree.
  endif.
endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
module user_command_0100 input.
  data: return_code type i.
* Get the node key of the node on which double click occured
  call method cl_gui_cfw=>dispatch
    importing return_code = return_code.
  if return_code <> cl_gui_cfw=>rc_noevent.
    clear g_ok_code.
    exit.
  endif.
* Leave screen in case OK/CANCEL
  if g_ok_code eq 'OK' or
     g_ok_code eq 'CANCEL'.
    clear g_node_key.
    leave to screen 0.
  endif.
endmodule.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*
form create_and_init_tree.
  data: node_table type node_table_type,
        events type cntl_simple_events,
        event type cntl_simple_event.
* create a container for the tree control
  create object g_custom_container
    exporting
      " the container is linked to the custom control with the
      " name 'TREE_CONTAINER' on the dynpro
      container_name = 'TREE_CONTAINER'
    exceptions
      cntl_error = 1
      cntl_system_error = 2
      create_error = 3
      lifetime_error = 4
      lifetime_dynpro_dynpro_link = 5.
  if sy-subrc <> 0.
    message a000.
  endif.
* create a tree control
  create object g_tree
    exporting
      parent              = g_custom_container
      " single node selection is used
      node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single
    exceptions
      lifetime_error              = 1
      cntl_system_error           = 2
      create_error                = 3
      failed                      = 4
      illegal_node_selection_mode = 5.
  if sy-subrc <> 0.
    message a000.
  endif.
* define the events which will be passed to the backend
  event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
  event-appl_event = 'X'. " process PAI if event occurs
  append event to events.
  event-eventid = cl_gui_simple_tree=>eventid_expand_no_children.
  event-appl_event = 'X'.
  append event to events.
* Set the registered events
  call method g_tree->set_registered_events
    exporting
      events = events
    exceptions
      cntl_error                = 1
      cntl_system_error         = 2
      illegal_event_combination = 3.
  if sy-subrc <> 0.
    message a000.
  endif.
*
** assign event handlers in the application class to each desired event
  set handler g_application->handle_node_double_click for g_tree.
  set handler g_application->handle_expand_no_children for g_tree.
  perform build_node_table using node_table.
* Create the tree with nodes
  call method g_tree->add_nodes
    exporting
      table_structure_name = 'MTREESNODE'
      node_table           = node_table
    exceptions
      failed                         = 1
      error_in_node_table            = 2
      dp_error                       = 3
      table_structure_name_not_found = 4
      others                         = 5.
  if sy-subrc <> 0.
    message a000.
  endif.
endform.                    " CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*
*&      Form  BUILD_NODE_TABLE
*&---------------------------------------------------------------------*
form build_node_table using
                  node_table type node_table_type.
  loop at file_list.
    move : sy-tabix to v_index.
    if v_index eq 1.
      move : v_n to itab-id,
             file_list-type(1) to itab-type,
             file_list-dirname to itab-name,
             '00000' to itab-parent.
      append itab. clear itab.
      v_n = v_n + 1.
      move: v_n to itab-id,
              file_list-type(1) to itab-type,
              file_list-name to itab-name,
              '00001' to itab-parent.
      append itab. clear itab.
      v_n = v_n + 1.
    else.
      move: v_n to itab-id,
            file_list-type(1) to itab-type,
            file_list-name to itab-name.
      read table file_list into file with key
                            name1 = file_list-dirname.
      read table itab into itab1 with key name = file-name.
      move : itab1-id to itab-parent.
      append itab. clear itab.
      v_n = v_n + 1.
    endif.
  endloop.
* Filling the node table
  loop at itab.
    move : itab-id to node-node_key.
    if itab-id eq '00001'.
      clear node-relatkey.
      clear node-relatship.
    else.
      move : itab-parent to node-relatkey,
             cl_gui_simple_tree=>relat_last_child to node-relatship.
    endif.
    node-hidden = ' '.
    node-disabled = ' '.
    node-isfolder = 'X'.
    clear node-expander.
    if itab-type eq 'd'.
      clear node-n_image.
      clear node-exp_image.
    else.
      node-n_image =   '@0P@'.
      node-exp_image = '@0P@'.
    endif.
    move : itab-name to node-text.
    append node to node_table.
    clear node.
  endloop.
endform.                    " BUILD_NODE_TABLE
Regards,
Sudhir/Mohit
Answer:
thanx for fast reply dude
im not so good in abap programming, so it doesn't make a sense for me, but my colleague will take a look on it
thx a lot
_________________
opsys  VMWARE - W2k AS SP4
rel    MiniWAS 6.20
db     MSSQL 2k Ent.Ed. 8 SP3a
kernel version - 640
patch level - 71
SPlvl  spam/saint - 18
       basis - 51
       abap - 51

More Articles:

Strange Behaviour?
IMG tree?
Homemade reporting tool?
BADI - Forms?
how to use the barcode?
How determine selection screen values?