*&---------------------------------------------------------------------*
*& Report UPLOAD_TABLE *
*&---------------------------------------------------------------------*
*& Description: Upload data to any table *
*& Created by : *
*& Created on : *
*& Changed by : *
*& Changed on : *
*&---------------------------------------------------------------------*
report upload_table.
tables: dd03l,
dd01l,
dd02t,
dd17s,
dd12t,
dd04t.
data: begin of struct occurs 10,
position like dd03l-position,
fieldname(30),
inttype type c,
intlen type i,
end of struct.
* The dynamic program source table
data: begin of inctabl occurs 10,
line(72),
end of inctabl.
data: lng type i,
typestring(6),
typestring2(20).
*&---------------------------------------------------------------------*
selection-screen begin of block b2 with frame title text-001.
selection-screen begin of line.
selection-screen position 10.
parameters : pawd(10) type c obligatory.
selection-screen end of line.
selection-screen end of block b2.
selection-screen begin of block b1 with frame title text-100.
parameters tab_name like dd03l-tabname obligatory.
selection-screen end of block b1.
*&---------------------------------------------------------------------*
start-of-selection.
* Dynamic internal table stucture
perform select_field_from_table.
* Create the dynamic internal table definition in the dyn. program
perform make_prg.
* Create and run the dynamic program
insert report 'ZDYNPRO' from inctabl.
submit zdynpro via selection-screen.
*&---------------------------------------------------------------------*
*& Form SELECT_FIELD_FROM_TABLE
*&---------------------------------------------------------------------*
form select_field_from_table.
clear dd03l.
select position fieldname inttype intlen
into (dd03l-position,dd03l-fieldname,
dd03l-inttype,dd03l-intlen)
from dd03l
where as4local = 'A'
and tabname = tab_name.
move-corresponding dd03l to struct.
append struct.
endselect.
delete struct where position = 1.
delete struct where inttype eq space.
sort struct by position.
endform. " SELECT_FIELD_FROM_TABLE
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_RESULT
*&---------------------------------------------------------------------*
form download_result.
call function 'DOWNLOAD'
exporting
filename = 'C:\ZTLIXX.txt'
filetype = 'DAT'
tables
data_tab = inctabl.
endform. " DOWNLOAD_RESULT
*&---------------------------------------------------------------------*
*& Form MAKE_ITAB
*&---------------------------------------------------------------------*
form make_itab.
inctabl-line = 'data: begin of dyntab occurs 10,'.
append inctabl.
loop at struct.
inctabl-line = struct-fieldname.
lng = strlen( struct-fieldname ).
if not struct-intlen is initial .
if struct-inttype = 'P'.
typestring = '(13)'.
elseif struct-inttype = 'D'.
typestring = '(10)'.
else.
typestring(1) = '('.
typestring+1 = struct-intlen.
typestring+5 = ')'.
condense typestring no-gaps.
endif.
inctabl-line+lng = typestring.
endif.
inctabl-line+25 = ','. append inctabl.
endloop.
inctabl-line = 'end of dyntab. '.
append inctabl.
endform. " MAKE_ITAB
*&---------------------------------------------------------------------*
*& Form MAKE_PRG
*&---------------------------------------------------------------------*
form make_prg.
inctabl-line = 'REPORT ZDYNPRO MESSAGE-ID ZPP1.'.
append inctabl.
perform make_itab.
concatenate 'DATA CP_TAB LIKE ' tab_name into inctabl-line
separated by space.
concatenate inctabl-line 'OCCURS 0 WITH HEADER LINE.'
into inctabl-line separated by space.
append inctabl.
inctabl-line = 'DATA : file LIKE rlgrap-filename,CNT TYPE I.'.
append inctabl.
inctabl-line =
'SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-100.'.
append inctabl.
inctabl-line =
'PARAMETERS p_fname(128) TYPE c LOWER CASE DEFAULT ''c:w'' OBLIGATORY.'.
append inctabl.
inctabl-line = 'SELECTION-SCREEN END OF BLOCK b1.'. append inctabl.
inctabl-line = 'AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.'.
append inctabl.
inctabl-line = ' PERFORM call_ws_filename_get.'. append inctabl.
inctabl-line = 'START-OF-SELECTION.'. append inctabl.
inctabl-line = 'PERFORM data_uploading.'. append inctabl.
inctabl-line = 'PERFORM insert_data_to_table.'. append inctabl.
inctabl-line = 'FORM call_ws_filename_get.'. append inctabl.
inctabl-line = 'CALL FUNCTION ''WS_FILENAME_GET'''. append inctabl.
inctabl-line = 'EXPORTING'. append inctabl.
inctabl-line = 'def_filename = file'. append inctabl.
inctabl-line = 'def_path = ''c:SAPworkdir'''.
append inctabl.
inctabl-line = 'mask = '',*.txt,*.TXT.'''. append inctabl.
inctabl-line = 'mode = ''O'''. append inctabl.
inctabl-line = 'title = ''Upload data to any table'''.
append inctabl.
inctabl-line = 'IMPORTING'. append inctabl.
inctabl-line = 'filename = p_fname'. append inctabl.
inctabl-line = 'EXCEPTIONS'. append inctabl.
inctabl-line = 'inv_winsys = 1'. append inctabl.
inctabl-line = 'no_batch = 2'. append inctabl.
inctabl-line = 'selection_cancel = 3'. append inctabl.
inctabl-line = 'selection_error = 4'. append inctabl.
inctabl-line = 'OTHERS = 5.'. append inctabl.
inctabl-line = 'ENDFORM.'. append inctabl.
inctabl-line = 'FORM data_uploading.'. append inctabl.
inctabl-line = 'CLEAR: dyntab,dyntab[].'. append inctabl.
inctabl-line = 'CALL FUNCTION ''WS_UPLOAD'''. append inctabl.
inctabl-line = 'EXPORTING'. append inctabl.
inctabl-line = 'codepage = '' '''. append inctabl.
inctabl-line = 'filename = p_fname'. append inctabl.
inctabl-line = 'filetype = ''DAT'''. append inctabl.
inctabl-line = 'TABLES'. append inctabl.
inctabl-line = 'data_tab = dyntab'. append inctabl.
inctabl-line = 'EXCEPTIONS'. append inctabl.
inctabl-line = 'conversion_error = 1'. append inctabl.
inctabl-line = 'file_open_error = 2'. append inctabl.
inctabl-line = 'file_read_error = 3'. append inctabl.
inctabl-line = 'invalid_type = 4'. append inctabl.
inctabl-line = 'no_batch = 5'. append inctabl.
inctabl-line = 'unknown_error = 6'. append inctabl.
inctabl-line = 'Invalid_table_width = 7'. append inctabl.
inctabl-line = 'gui_refuse_filetransfer = 8'. append inctabl.
inctabl-line = 'customer_error = 9.'.append inctabl.
inctabl-line = 'CASE sy-subrc.'. append inctabl.
inctabl-line = 'WHEN 1. MESSAGE i000 WITH ''CONVERSION ERR''.STOP.'.
append inctabl.
inctabl-line = 'WHEN 2. MESSAGE i000 WITH ''FILE OPEN ERR''.STOP.'.
append inctabl.
inctabl-line = 'WHEN 3. MESSAGE i000 WITH ''FILE READ ERR''.STOP.'.
append inctabl.
inctabl-line = 'WHEN 4. MESSAGE i000 WITH ''INVALID TYPE ERR''.STOP.'.
append inctabl.
inctabl-line = 'WHEN 5. MESSAGE i000 WITH ''NO BATCH ERROR''. STOP.'.
append inctabl.
inctabl-line = 'WHEN 6. MESSAGE i000 WITH ''UNKNOWN ERROR''.STOP.'.
append inctabl.
inctabl-line =
'WHEN 7. MESSAGE i000 WITH ''INALID TABLE WIDTH''.STOP.'.
append inctabl.
inctabl-line =
'WHEN 8. MESSAGE i000 WITH ''GUI REFUSE FILETRANSFER''.STOP.'.
append inctabl.
inctabl-line = 'WHEN 9. MESSAGE i000 WITH ''CUSTOMER ERROR''. STOP.'.
append inctabl.
inctabl-line = ' ENDCASE.'. append inctabl.
inctabl-line = 'ENDFORM.'. append inctabl.
inctabl-line = 'FORM insert_data_to_table.'. append inctabl.
inctabl-line = 'LOOP AT dyntab.'. append inctabl.
inctabl-line = 'MOVE-CORRESPONDING dyntab TO cp_tab.'.
append inctabl.
inctabl-line = 'append cp_tab.'. append inctabl.
inctabl-line = 'ENDLOOP.'. append inctabl.
concatenate 'MODIFY' tab_name into inctabl-line separated by space.
concatenate inctabl-line 'FROM TABLE CP_TAB.' into inctabl-line
separated by space.
* inctabl-line = 'MODIFY zppt003 FROM TABLE cp_tab.'.
append inctabl.
inctabl-line = 'ENDFORM.'. append inctabl.
endform. "MAKE_PRG
