[SAP ABAP] - Read TABLE v01


-->
*&---------------------------------------------------------------------* *& Report YABAP_TOOLS_READ_TABLE_01 * *& * *&---------------------------------------------------------------------* *& Created By : Mawan Sugiyanto * *& Date : 01.07.2008 * *& * *& Edited By : Albertus Reinandang * *& Date : 17.07.2008 * *&---------------------------------------------------------------------*
REPORT yabap_tools_read_table_01 .
TABLES : dd02l, dd03l,soid. DATA : gv_tablename TYPE c LENGTH 100,
gv_tablelist
TYPE STANDARD TABLE OF dd02l WITH HEADER LINE,
gv_tabfield
TYPE STANDARD TABLE OF dd03l WITH HEADER LINE.
DATA : BEGIN OF i_temp OCCURS 0,
linedata
TYPE c LENGTH 4096,
END OF i_temp.

SELECTION-
SCREEN BEGIN OF BLOCK zblk01 WITH FRAME TITLE text_101.
SELECTION-
SCREEN BEGIN OF LINE.
SELECTION-
SCREEN COMMENT 1(19) text_102 FOR FIELD pa_tabnm. PARAMETERS pa_tabnm TYPE dd02l-tabname DEFAULT 'YOUR TABLE NAME' OBLIGATORY.
SELECTION-
SCREEN END OF LINE.
SELECTION-
SCREEN BEGIN OF LINE.
SELECTION-
SCREEN COMMENT 1(19) text_103 FOR FIELD pa_spara. PARAMETERS pa_spara TYPE c LENGTH 3 DEFAULT ',' OBLIGATORY.
SELECTION-
SCREEN END OF LINE.

SELECTION-
SCREEN END OF BLOCK zblk01.

SELECTION-
SCREEN BEGIN OF BLOCK zblk02 WITH FRAME TITLE text_201.

SELECTION-
SCREEN BEGIN OF LINE. SELECT-OPTIONS so_row FOR soid-accnt NO-EXTENSION
DEFAULT 1 TO 1000.
SELECTION-
SCREEN END OF LINE.

SELECTION-
SCREEN END OF BLOCK zblk02.
INITIALIZATION.
text_101 =
'Transport to txt File'.
text_102 =
'Table Name '.
text_103 =
'Sparator'.
text_201 =
'Row Selection'.

START-
OF-SELECTION.

PERFORM get_tableinformation.
PERFORM get_and_download.
END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form GET_TABLEINFORMATION *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2="" span="" text=""> *----------------------------------------------------------------------* FORM get_tableinformation .
SELECT * INTO CORRESPONDING FIELDS OF TABLE gv_tablelist
FROM dd02l
WHERE tabname = pa_tabnm.
IF sy-subrc = 0 AND LINES( gv_tablelist ) = 1.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gv_tabfield FROM dd03l
WHERE tabname = pa_tabnm ORDER BY position ASCENDING.
IF sy-subrc = 0.
ELSE.
MESSAGE 'No field(s) name found.' TYPE 'I'.
ENDIF.
ELSE.
MESSAGE 'Table does not exist, please enter right table name' TYPE 'I'.
ENDIF. ENDFORM. " GET_TABLEINFORMATION
*&---------------------------------------------------------------------* *& Form get_and_download *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2="" span="" text=""> *----------------------------------------------------------------------* FORM get_and_download .
FIELD-SYMBOLS :
TYPE table,
TYPE data,
TYPE ANY.

DATA : fieldcat TYPE lvc_t_fcat , wadata TYPE lvc_s_fcat.
DATA : dyn_itab TYPE REF TO data,wa TYPE REF TO data, gv_tampung TYPE c LENGTH 100.
DATA : i_text(4096) TYPE c OCCURS 0,
lv_row_count
TYPE i,
lv_row_max
TYPE i,
lv_filename
LIKE rlgrap-filename.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = pa_tabnm
CHANGING
ct_fieldcat = fieldcat[].

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fieldcat[]
IMPORTING
ep_table = dyn_itab.

ASSIGN dyn_itab->* TO .
CREATE DATA wa LIKE LINE OF .
ASSIGN wa->* TO .

IF so_row-high > 0.
lv_row_max = so_row-low + so_row-high -
1.
ENDIF.

SELECT * FROM (pa_tabnm) INTO .

lv_row_count = lv_row_count +
1.
IF lv_row_count GE so_row-low.
WRITE :/.
LOOP AT gv_tabfield.
ASSIGN COMPONENT gv_tabfield-fieldname OF STRUCTURE TO .

WRITE TO gv_tampung NO-GROUPING.
CONDENSE gv_tampung.
IF gv_tampung IS INITIAL.
gv_tampung = space.
ENDIF.
CONCATENATE i_temp-linedata gv_tampung INTO i_temp-linedata SEPARATED BY pa_spara.
ENDLOOP.
WRITE :/ i_temp-linedata.
APPEND i_temp.

IF lv_row_max > 0 AND lv_row_count GE lv_row_max.
EXIT.
ENDIF.

CLEAR i_temp.
ENDIF.
ENDSELECT.

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator =
''
TABLES
i_tab_sap_data = i_temp
CHANGING
i_tab_converted_data = i_text
EXCEPTIONS
conversion_failed =
1
OTHERS = 2.

concatenate 'C:\' pa_tabnm '.txt' into lv_filename.

CALL FUNCTION 'DOWNLOAD'
EXPORTING * BIN_FILESIZE = ' ' * CODEPAGE = ' '
filename = lv_filename
* FILETYPE = ' ' * ITEM = ' ' * MODE = ' ' * WK1_N_FORMAT = ' ' * WK1_N_SIZE = ' ' * WK1_T_FORMAT = ' ' * WK1_T_SIZE = ' ' * FILEMASK_MASK = ' ' * FILEMASK_TEXT = ' ' * FILETYPE_NO_CHANGE = ' ' * FILEMASK_ALL = ' ' * FILETYPE_NO_SHOW = ' ' * SILENT = 'S' * COL_SELECT = ' ' * COL_SELECTMASK = ' '
NO_AUTH_CHECK =
' ' * IMPORTING * ACT_FILENAME = * ACT_FILETYPE = * FILESIZE = * CANCEL =
TABLES
data_tab = i_text
* FIELDNAMES = * EXCEPTIONS * INVALID_FILESIZE = 1 * INVALID_TABLE_WIDTH = 2 * INVALID_TYPE = 3 * NO_BATCH = 4 * UNKNOWN_ERROR = 5 * GUI_REFUSE_FILETRANSFER = 6 * OTHERS = 7
.
IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "get_and_download

Comments