SAP_ABAP_FI
SAP/TABLE Dynamic Where / File Download 본문
Main Program
INCLUDE zrtech0100top.
Source
*&---------------------------------------------------------------------*
*& Include ZRTECH0100TOP
*&---------------------------------------------------------------------*
TABLES : sscrfields.
DATA: gt_ranges TYPE rsds_trange,
gt_range TYPE TABLE OF rsdsfields.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t01.
PARAMETERS: p_table LIKE dd02t-tabname MEMORY ID buk.
PARAMETERS: p_path TYPE string.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (20) btn_text USER-COMMAND user01.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
INCLUDE zrtech0100f01.
Source
*&---------------------------------------------------------------------*
*& Include ZRTECH0100F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form INIT_SCR
*&---------------------------------------------------------------------*
FORM init_scr .
btn_text = 'Download'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PBO_SCR
*&---------------------------------------------------------------------*
FORM pbo_scr USING p_dynnr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PAI_SCR
*&---------------------------------------------------------------------*
FORM pai_scr USING p_dynnr.
CASE p_dynnr.
WHEN 1000.
CASE sscrfields-ucomm.
WHEN 'USER01'.
PERFORM open_screen.
ENDCASE.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DOWN_DATA
*&---------------------------------------------------------------------*
FORM down_data.
DATA: lt_where TYPE rsds_twhere,
ls_where TYPE rsds_where.
FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE,
<fs_wa> TYPE any,
<fs_val> TYPE any.
DATA: lr_table TYPE REF TO cl_abap_tabledescr,
lr_struct TYPE REF TO cl_abap_structdescr.
DATA: lr_tab TYPE REF TO data,
lr_str TYPE REF TO data.
DATA: lv_path TYPE string.
DATA: lt_dfies TYPE TABLE OF dfies.
DATA: lt_data TYPE TABLE OF string,
ls_data TYPE string,
ls_data_f TYPE string,
lv_field TYPE string.
CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
EXPORTING
field_ranges = gt_ranges[]
IMPORTING
where_clauses = lt_where.
READ TABLE lt_where INTO ls_where INDEX 1.
lr_struct ?= cl_abap_structdescr=>describe_by_name( p_table ).
CREATE DATA lr_str TYPE HANDLE lr_struct.
CHECK lr_str IS BOUND.
ASSIGN lr_str->* TO <fs_wa>.
lr_table ?= cl_abap_tabledescr=>create( p_line_type = lr_struct ).
CREATE DATA lr_tab TYPE HANDLE lr_table.
ASSIGN lr_tab->* TO <fs_tab>.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE <fs_tab>
FROM (p_table)
WHERE (ls_where-where_tab).
CHECK <fs_tab> IS NOT INITIAL.
CONCATENATE p_path '\' p_table INTO lv_path.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = p_table
* IMPORTING
* x030l_wa =
TABLES
dfies_tab = lt_dfies
EXCEPTIONS
not_found = 1
OTHERS = 2.
DELETE lt_dfies WHERE fieldname = 'MANDT'.
LOOP AT lt_dfies INTO DATA(ls_dfiels).
IF ls_data IS INITIAL.
ls_data = ls_dfiels-fieldtext.
ls_data_f = ls_dfiels-fieldname.
ELSE.
CONCATENATE ls_data ls_dfiels-fieldtext INTO ls_data
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
CONCATENATE ls_data_f ls_dfiels-fieldname INTO ls_data_f
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDIF.
AT LAST.
APPEND : ls_data TO lt_data,
ls_data_f TO lt_data.
ENDAT.
ENDLOOP.
CLEAR: ls_data.
LOOP AT <fs_tab> ASSIGNING <fs_wa>.
LOOP AT lt_dfies INTO ls_dfiels.
ASSIGN COMPONENT ls_dfiels-fieldname OF STRUCTURE <fs_wa> TO <fs_val>.
IF sy-subrc EQ 0.
lv_field = <fs_val>.
ENDIF.
IF ls_data IS INITIAL.
ls_data = lv_field.
ELSE.
CONCATENATE ls_data lv_field INTO ls_data
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDIF.
ENDLOOP.
APPEND : ls_data TO lt_data.
CLEAR: ls_data.
ENDLOOP.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
write_field_separator = abap_true
* codepage =
CHANGING
data_tab = lt_data
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
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form OPEN_SCREEN
*&---------------------------------------------------------------------*
FORM open_screen.
DATA: lt_dfies TYPE TABLE OF dfies,
lt_field TYPE TABLE OF rsdsfields,
ls_field TYPE rsdsfields,
lt_tables TYPE TABLE OF rsdstabs,
ls_tables TYPE rsdstabs.
DATA: ls_selid TYPE rsdynsel-selid.
CHECK p_table IS NOT INITIAL.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
tabname = p_table
* IMPORTING
* x030l_wa =
TABLES
dfies_tab = lt_dfies
EXCEPTIONS
not_found = 1
OTHERS = 2.
CHECK lt_dfies IS NOT INITIAL.
DELETE lt_dfies WHERE fieldname = 'MANDT'.
LOOP AT lt_dfies INTO DATA(ls_dfies) WHERE keyflag EQ abap_true.
ls_field-tablename = p_table.
ls_field-fieldname = ls_dfies-fieldname.
APPEND ls_field TO lt_field.
CLEAR: ls_field.
ENDLOOP.
ls_tables-prim_tab = p_table.
APPEND ls_tables TO lt_tables.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
IMPORTING
selection_id = ls_selid
TABLES
tables_tab = lt_tables
fields_tab = lt_field[]
EXCEPTIONS
fields_incomplete = 1
area_no_field = 19
OTHERS = 20.
CHECK ls_selid IS NOT INITIAL.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = ls_selid
title = 'Selection'
status = 1
as_window = abap_true
IMPORTING
field_ranges = gt_ranges[]
TABLES
fields_tab = lt_field[]
EXCEPTIONS
internal_error = 1
no_action = 2
selid_not_found = 3
illegal_status = 4
OTHERS = 5.
ENDFORM.
'SAP_ABAP_Source' 카테고리의 다른 글
ST04-Query Version2 (0) | 2021.09.27 |
---|---|
ABAP_DOMAIN_FIELD값 가져오기 (0) | 2021.09.07 |
ST04-Query부분 발췌 (0) | 2021.09.07 |
동적 InterTable 만들기 (0) | 2021.09.07 |
Table _INFO 가져오기 (0) | 2021.09.07 |