[{ALLOW view All}]
[{ALLOW edit Markus}]
{{{
*&---------------------------------------------------------------------*
*& Report Z_READTABLES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_readtables.
*&---------------------------------------------------------------------*
*& Report Z_MARKUS001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS readtabs DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS readtabs DEFINITION.
PUBLIC SECTION.
METHODS: main, storelocal.
PRIVATE SECTION.
"CONSTANTS dset TYPE string VALUE 'D:\temp\sap.csv'.
DATA: lt_xmlstr TYPE TABLE OF string,
fn TYPE fieldname,
field_lengths TYPE TABLE OF i.
ENDCLASS. "demo DEFINITION
SELECTION-SCREEN BEGIN OF BLOCK tabs WITH FRAME TITLE text-s02.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-s01.
PARAMETERS: tabfrom(10) TYPE c OBLIGATORY DEFAULT 'T000'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-s02.
PARAMETERS: tabthru(10) TYPE c OBLIGATORY DEFAULT 'T000'.
SELECTION-SCREEN COMMENT 25(10) text-s03.
PARAMETERS: totalr AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK tabs.
SELECTION-SCREEN BEGIN OF BLOCK data WITH FRAME TITLE text-s04.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-s04.
PARAMETERS: showdata AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 18(12) text-s05.
PARAMETERS: maxdata TYPE i DEFAULT 5.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK data.
SELECTION-SCREEN BEGIN OF BLOCK download WITH FRAME TITLE text-s06.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(14) text-s06.
PARAMETERS: downfile(80) TYPE c OBLIGATORY DEFAULT 'D:\temp\tabs.csv'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK download.
*----------------------------------------------------------------------*
* CLASS demo IMPLEMENTATIO
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS readtabs IMPLEMENTATION.
METHOD main.
TYPES: BEGIN OF mytable,
tabname TYPE tabname,
ddtext TYPE ddtext,
ddtext_de TYPE ddtext,
END OF mytable.
FIELD-SYMBOLS: <tab> TYPE ANY TABLE,
<wa> TYPE ANY,
<field> TYPE ANY.
DATA: rs TYPE cursor,
help TYPE string,
help2 TYPE string,
text1 TYPE string,
text2 TYPE string,
text3 TYPE string,
text4 TYPE string,
statustext TYPE c LENGTH 50,
fieldnames TYPE string,
fieldlabels TYPE string,
total TYPE i,
idx TYPE i,
where_cl TYPE string,
order_cl TYPE string,
tabparam TYPE tabname.
DATA: tabdata TYPE mytable,
tables TYPE TABLE OF mytable,
totaltabs TYPE i,
cc TYPE i,
out TYPE i,
perc TYPE i.
DATA BEGIN OF tabfields.
DATA: fieldname TYPE fieldname,
inttype TYPE inttype,
intlen TYPE intlen,
fldlabel TYPE ddtext,
domlabel TYPE ddtext.
DATA END OF tabfields.
REFRESH: lt_xmlstr.
SELECT
a~tabname
b~ddtext
c~ddtext
FROM dd02l AS a
LEFT outer JOIN dd02t AS b
ON b~tabname = a~tabname
AND b~ddlanguage = 'EN'
LEFT OUTER JOIN dd02t AS c
ON c~tabname = a~tabname
AND c~ddlanguage = 'DE'
INTO TABLE tables
WHERE a~tabname between tabfrom AND tabthru
AND a~tabclass = 'TRANSP'
ORDER BY a~tabname.
CLEAR field_lengths.
DESCRIBE TABLE tables LINES totaltabs.
cc = 1.
out = 1.
LOOP AT tables INTO tabdata.
tabparam = tabdata-tabname.
perc = cc MOD 20.
IF perc EQ 0.
help = totaltabs.
text3 = cc.
CONCATENATE 'Processing' text3 '/' help INTO statustext SEPARATED BY ' '.
CALL FUNCTION 'PROGRESS_INDICATOR'
EXPORTING
i_text = statustext
i_processed = cc
i_total = totaltabs
i_output_immediately = 'X'.
"COMMIT WORK.
ENDIF.
cc = cc + 1.
IF STRLEN( tabparam ) > 1.
" count rows
IF totalr IS NOT INITIAL.
CLEAR total.
SELECT SINGLE COUNT( * ) INTO total FROM (tabparam).
help2 = total.
ELSE.
help2 = ''.
ENDIF.
" starting csv line
text3 = out.
CONCATENATE text3 tabdata-tabname tabdata-ddtext help2 INTO text1 SEPARATED BY ';'.
out = out + 1.
" get fields
CONCATENATE 'a~tabname = ''' tabparam '''' INTO where_cl.
order_cl = 'a~position'.
CLEAR fieldnames.
CLEAR fieldlabels.
SELECT a~fieldname
a~inttype
a~intlen
b~ddtext
c~ddtext
FROM dd03l AS a
LEFT OUTER JOIN dd03t AS b
ON b~tabname = a~tabname
AND b~fieldname = a~fieldname
AND b~ddlanguage = 'EN'
LEFT OUTER JOIN dd01t AS c
ON c~domname = a~domname
AND c~ddlanguage = 'EN'
INTO tabfields
WHERE (where_cl)
ORDER BY (order_cl).
text3 = tabfields-inttype.
text4 = tabfields-intlen.
APPEND tabfields-intlen TO field_lengths.
CONCATENATE fieldnames tabfields-fieldname ' (' text3 text4 ');' INTO fieldnames.
IF tabfields-fldlabel IS NOT INITIAL.
CONCATENATE fieldlabels tabfields-fldlabel ';' INTO fieldlabels.
ELSE.
CONCATENATE fieldlabels tabfields-domlabel ';' INTO fieldlabels.
ENDIF.
ENDSELECT.
CONCATENATE text1 fieldnames INTO text3 SEPARATED BY ';'.
APPEND text3 TO lt_xmlstr.
concatenate ';;' tabdata-ddtext_de ';' into text3.
CONCATENATE text3 fieldlabels INTO text3 SEPARATED BY ';'.
APPEND text3 TO lt_xmlstr.
" get data
IF showdata IS NOT INITIAL.
*----- Referencer for Itab and Itab Workarea
DATA ref_itab TYPE REF TO data.
DATA ref_itwa TYPE REF TO data.
*----- Dereferencer for Itab Body
FIELD-SYMBOLS: <fs_itab> TYPE STANDARD TABLE.
*----- Dereferencer for Itab Workarea
FIELD-SYMBOLS: <fs_itwa> TYPE ANY.
*----- Dereferencer for Itab Workarea Components
FIELD-SYMBOLS: <fs_comp> TYPE ANY.
TRY.
*----- Define Itab for all DB-Records
CREATE DATA ref_itab TYPE STANDARD TABLE OF (tabparam).
*----- Make Content of Itab accessible
* Dereference (->*) Pointer ref_itab into a <fs>
ASSIGN ref_itab->* TO <fs_itab>.
*----- Read all DB-Records into Itab
SELECT * FROM (tabparam) UP TO maxdata ROWS INTO TABLE <fs_itab>.
IF sy-subrc NE 0.
APPEND ';;;;no data' TO lt_xmlstr.
ELSE.
*----- Define Workarea for Itab
CREATE DATA ref_itwa TYPE (tabparam).
*----- Make content of Itab Workarea accessible
ASSIGN ref_itwa->* TO <fs_itwa>.
LOOP AT <fs_itab> INTO <fs_itwa>.
text1 = ';;;;'.
DO.
*----- Assign via do-loop every component of itab workarea
* to a component fieldsymbol and access content for write
ASSIGN COMPONENT sy-index OF STRUCTURE
<fs_itwa> TO <fs_comp>.
*----- Abort endless loop after assign of last component
IF sy-subrc NE 0. EXIT. ENDIF.
text2 = <fs_comp>.
CONCATENATE text1 text2 ';' INTO text1.
ENDDO.
APPEND text1 TO lt_xmlstr.
ENDLOOP.
ENDIF.
CATCH cx_root. "DB-Table does not exist
APPEND ';;;;data error' TO lt_xmlstr.
ENDTRY.
ENDIF. " showdata
ENDIF. " strlen
ENDLOOP. " at tables
text1 = out.
text2 = totaltabs.
CONCATENATE text1 '/' text2 'tables read.' INTO text3 SEPARATED BY ' '.
MESSAGE text3 TYPE 'I'.
ENDMETHOD. "demo
METHOD storelocal.
DATA dset TYPE string.
dset = downfile.
*.. Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = dset
TABLES
data_tab = lt_xmlstr
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.
WRITE 'Error'.
ENDIF.
ENDMETHOD. "storeLocal
ENDCLASS. "demo IMPLEMENTATIO
*&---------------------------------------------------------------------*
*& Implementations
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*WRITE text.
DATA demo TYPE REF TO readtabs.
CREATE OBJECT demo.
demo->main( ).
demo->storelocal( ).
LEAVE SCREEN.
}}}