Skip to main content

Uploading downloading and displaying the .csv file in ALV format

*&---------------------------------------------------------------------*
*& Report  ZTEST_EXCEL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  ztest_excel message-id ztest_excel_msg.
type-pools:slis.

types: begin of output,
            field1      type    string,
            field2      type    string,
            field3      type    string,
            field4      type    string,
            field5      type    string,
            field6      type    string,
            field7      type    string,
            field8      type    string,
            field9      type    string,
            field10     type    string,
            field11     type    string,
            field12     type    string,
       end of output,

begin of readfile,
    line(4000) type c,
end of readfile.

data: g_file        type  ibipparms-path,
      g_file_name   type  string,
      g_file_name2  type  string,
      g_repid       type  sy-repid,
      wa_output     type  output,
      wa_output2    type  output,
      wa_readfile   type  readfile,
      it_readfile   type  standard table of readfile,
      t_output      type  standard table of output,
      t_output2     type  standard table of output,
      byte          type  i,
      wa_fieldcat   type  slis_fieldcat_alv,
      it_fieldcat   type  slis_t_fieldcat_alv.

initialization.
  clear:g_repid,
        g_file,
        g_file_name,
        g_file_name2.

  g_repid = sy-repid.

  selection-screen begin of block b1 with frame title text-001.
  parameters: p_file type ibipparms-path default text-002,
              p_file_s type ibipparms-path.
  selection-screen end of block b1.



at selection-screen on value-request for p_file.
  call function 'F4_FILENAME'
   exporting
     program_name        = g_repid
*     DYNPRO_NUMBER       = SYST-DYNNR
     field_name          = 'P_FILE'
   importing
     file_name           = p_file
            .
  g_file_name = p_file.

at selection-screen on value-request for p_file_s.
  call function 'F4_FILENAME'
 exporting
   program_name        = g_repid
*     DYNPRO_NUMBER       = SYST-DYNNR
   field_name          = 'P_FILE_SAVE'
 importing
   file_name           = p_file_s
          .
  g_file_name2 = p_file_s.

start-of-selection.


  if g_file_name is initial and p_file_s is initial.
    message i002.
    leave list-processing.
  else.
    call function 'GUI_UPLOAD'
      exporting
       filename                      = g_file_name
       filetype                      = 'ASC'
       has_field_separator           = 'X'
*     HEADER_LENGTH                 = 0
*     READ_BY_LINE                  = 'X'
*     DAT_MODE                      = ' '
*     CODEPAGE                      = ' '
*     IGNORE_CERR                   = ABAP_TRUE
*     REPLACEMENT                   = '#'
*     CHECK_BOM                     = ' '
*     VIRUS_SCAN_PROFILE            =
*     NO_AUTH_CHECK                 = ' '
*   IMPORTING
*     FILELENGTH                    =
*     HEADER                        =
      tables
        data_tab                      = it_readfile
     exceptions
       file_open_error               = 1
       file_read_error               = 2
       no_batch                      = 3
       gui_refuse_filetransfer       = 4
       invalid_type                  = 5
       no_authority                  = 6
       unknown_error                 = 7
       bad_data_format               = 8
       header_not_allowed            = 9
       separator_not_allowed         = 10
       header_too_long               = 11
       unknown_dp_error              = 12
       access_denied                 = 13
       dp_out_of_memory              = 14
       disk_full                     = 15
       dp_timeout                    = 16
       others                        = 17
              .
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.

    loop at it_readfile into wa_readfile.
      split wa_readfile at ','
      into wa_output-field1
           wa_output-field2
           wa_output-field3
           wa_output-field4
           wa_output-field5
           wa_output-field6
           wa_output-field7
           wa_output-field8
           wa_output-field9
           wa_output-field10
           wa_output-field11
           wa_output-field12.
      append wa_output to t_output.
    endloop.
  endif.

  loop at t_output into wa_output .
    move wa_output-field1 to wa_output2-field1.
    move wa_output-field3 to wa_output2-field3.
    move wa_output-field4 to wa_output2-field4.
    move wa_output-field5 to wa_output2-field5.
    move wa_output-field6 to wa_output2-field6.
    move wa_output-field7 to wa_output2-field7.
    move wa_output-field8 to wa_output2-field8.
    move wa_output-field10 to wa_output2-field10.
    move wa_output-field11 to wa_output2-field11.
    append wa_output2 to t_output2.
  endloop.



end-of-selection.

  call function 'GUI_DOWNLOAD'
     exporting
*   BIN_FILESIZE                    =
      filename                        = g_file_name2
      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'
*   WK1_N_FORMAT                    = ' '
*   WK1_N_SIZE                      = ' '
*   WK1_T_FORMAT                    = ' '
*   WK1_T_SIZE                      = ' '
*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*   SHOW_TRANSFER_STATUS            = ABAP_TRUE
  importing
    filelength                      = byte
     tables
       data_tab                        = t_output2
*   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.


  message i001.

  perform bld_fdcat.

  call function 'REUSE_ALV_GRID_DISPLAY'
   exporting
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
     i_callback_program                = g_repid
   i_callback_pf_status_set          = 'STANDARD'
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
     it_fieldcat                       = it_fieldcat[]
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
    tables
      t_outtab                          = t_output2
   exceptions
     program_error                     = 1
     others                            = 2
            .
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.



*&---------------------------------------------------------------------*
*&      Form  BLD_FDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form bld_fdcat .


  wa_fieldcat-seltext_m = 'FIELD1'.
  wa_fieldcat-col_pos = 0.
  wa_fieldcat-fieldname = 'FIELD1'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD3'.
  wa_fieldcat-fieldname = 'FIELD3'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD4'.
  wa_fieldcat-fieldname = 'FIELD4'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD5'.
  wa_fieldcat-fieldname = 'FIELD5'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD6'.
  wa_fieldcat-fieldname = 'FIELD6'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD7'.
  wa_fieldcat-fieldname = 'FIELD7'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD8'.
  wa_fieldcat-fieldname = 'FIELD8'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD10'.
  wa_fieldcat-fieldname = 'FIELD10'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD11'.
  wa_fieldcat-fieldname = 'FIELD11'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-seltext_m = 'FIELD12'.
  wa_fieldcat-fieldname = 'FIELD12'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.
endform.                    " BLD_FDCAT

*****************************************************************
* Form Set_pf_status
* Notes: Called by FM REUSE_ALV_GRID_DISPLAY
*****************************************************************
form set_pf_status using rt_extab type slis_t_extab.
  set pf-status 'STANDARD'.
endform. "Set_pf_status

Comments

Popular posts from this blog

Replacement of obsolete F.M. POPUP_TO_CONFIRM_STEP

The obsolete Function Module :     CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'        EXPORTING *          DEFAULTOPTION  = 'Y'             textline1      = text-003 *          TEXTLINE2      = ' '                titel          = 'Mengenbereitstellung' *          START_COLUMN   = 25 *          START_ROW      = 6             cancel_display = ' '        IMPORTING          ...

SPDD and SPAU in Upgrade projects

In upgradiation project SPDD and SPAU Aare the main transactions. Upgradiation project are like 1.Technical Upgrade 2.Functional Upgrade In technical project process steps like 1.System preparation and stack level patch upgrade – Basis Team 2.SPDD Phase – ABAP and Functionals 3.Up gradation of the system – Basis Team 4.SPAU Phase – ABAP and Functionals 5.DBACOCKPIT for indexing – ABAP TEAM 6.Issue resolution and error tracking – ABAP and Functionals 7.Zprograms corrections – obsolete function modules and objects In SPDD Phase This transaction code SPDD is the core step in an upgrade project. The system compares all the dictionary objects – data elements, database tables and structures of the latest system (say ECC) with the previous or the old system (Say 4.6c). These all elements are present under two nodes – with modification assistant and without modification assistant. Objects present under with modification assistant have the mo...