onlyforbopi
3/8/2018 - 8:04 AM

ABAP - FUNCTION MODULES

Useful Modules:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' TRIMS LEADING AND TRAILING SPACES / ZEROS seek file

*&---------------------------------------------------------------------*
*&      Form  seek_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--PP_OUT     text
*----------------------------------------------------------------------*
FORM seek_file  CHANGING pp_out.
  DATA: l_filetab        TYPE filetable,
        l_filetab_h      TYPE filetable WITH HEADER LINE,
        initial_dir_path TYPE string,
        l_rc             TYPE i.

*  if p_op1 = 'X'.
*    refresh l_filetab.
*    initial_dir_path = 'C:\'.
*    call method cl_gui_frontend_services=>file_open_dialog
*      exporting
*        window_title            = 'Select Data file'
*        initial_directory       = initial_dir_path
*        multiselection          = space
*      changing
*        file_table              = l_filetab
*        rc                      = l_rc
*      exceptions
*        file_open_dialog_failed = 1
*        cntl_error              = 2
*        error_no_gui            = 3
*        not_supported_by_gui    = 4
*        others                  = 5.
*    if sy-subrc ne 0.
*      WRITE:/ 'Error while selecting the input file'.
*    else.
*      loop at l_filetab into l_filetab_h.
*        pp_out = l_filetab_h-filename.
*        exit.
*      endloop.
*    endif.
*  else.
  CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
    EXPORTING
          i_location_flag = 'A'
          i_server        = lc_server
          i_path          = lc_path
          fileoperation   = lc_foper
  IMPORTING
          o_path     = lv_path_salida
*          abend_flag = lv_flag_salida
    EXCEPTIONS
            rfc_error             = 1
            OTHERS                = 2.

  pp_out = lv_path_salida.
*  endif.

ENDFORM.                    "SEEK_FILE


****************************************************************
* Called as :

AT SELECTION-SCREEN
  "On value request: Once the field has been clicked
  "Call fun seek_file.
  ON VALUE-REQUEST FOR p_out.
    PERFORM seek_file CHANGING p_out.
FUNCTION CONVERSION_EXIT_ALPHA_OUTPUT.
*"----------------------------------------------------------------------
*" Function module
*" Removes leadign / trailing spaces and zeroes
*"
*" Used as: 
*"
*"
*"* Final output loop + controls
*"* Looping at output table
*"* Checking values of fields, and writing.
*"  LOOP AT gt_rf_out.
*"
*"    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
*"      EXPORTING
*"        input  = gt_rf_OUT-vkont
*"      IMPORTING
*"        output = gt_rf_OUT-vkont.
*"
*"
*"    " Format output line
*"    CONCATENATE gt_rf_OUT-vkont
*"                gt_rf_OUT-rf_code
*"                gt_rf_OUT-vkona
*"                INTO line_out
*"                SEPARATED BY delim.
*"
*"    CONCATENATE line_out
*"                ';'
*"                INTO line_out.
*"
*"    " Move line to filename
*"    TRANSFER line_out TO ext_filename.
*"    "WRITE: / gt_fkkvkp-gpart, gt_fkkvkp-vkont, GT_FKKVKP-EBVTY, GT_FKKVKP-ABVTY.
*"  ENDLOOP.
*"
*"  CLOSE DATASET ext_filename.



*"
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(INPUT) TYPE  CLIKE
*"  EXPORTING
*"     VALUE(OUTPUT) TYPE  CLIKE
*"----------------------------------------------------------------------

  CALL 'CONVERSION_EXIT_ALPHA_OUTPUT' ID 'INPUT'  FIELD INPUT
                                      ID 'OUTPUT' FIELD OUTPUT.

ENDFUNCTION.