Skip to Content
-1
Oct 18, 2019 at 07:19 AM

how to implement parallel processing in the dynamic selection of tables

299 Views

I have this requirement where i should be able to dynamically select the tables and its fields from the selection screen and download the data through file splitting.But as it is taking a lot time to download i want to implement parallel processing in my code.So how to implement parallel processing in below code?

REPORT zaa_fdatexta1.

tables :dd02l.
DATA:ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcatlog TYPE slis_fieldcat_alv,
lt_fieldcatlog TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.

DATA: w_dref TYPE REF TO data.
FIELD-SYMBOLS: <t_itab> TYPE STANDARD TABLE , "dynamic internal table to read data from the database
<wa_tab> TYPE any.

DATA: w_dref1 TYPE REF TO data.
FIELD-SYMBOLS: <fi_itab> TYPE STANDARD TABLE, " table to load 1000 records from the t_itab
<wfi_tab> TYPE any.

TYPES: BEGIN OF ty_header, " to create field header in xlsx file
fname(100) TYPE c,
END OF ty_header.

DATA: it_header TYPE TABLE OF ty_header,
wa_header TYPE ty_header.

DATA: BEGIN OF inttab OCCURS 100. "table to read files of given table
INCLUDE STRUCTURE dfies.
DATA: check TYPE checkbox. "additional field to check the condition for selected fields
DATA: END OF inttab.

DATA: wa_tab LIKE LINE OF inttab.

TYPES: BEGIN OF ty_int1 , "structure for selecting fields on the selection screen
fieldname TYPE fieldname,
END OF ty_int1.

DATA: inttab1 TYPE TABLE OF ty_int1, " to load the field names of given data base table
wa_tab1 LIKE LINE OF inttab1.


PARAMETERS: p_table TYPE dd02l-tabname OBLIGATORY default 'MARA'.
PARAMETERS: count TYPE i default '1000'.
PARAMETERS: p_file LIKE rlgrap-filename.
PARAMETERS: p_enable AS CHECKBOX DEFAULT ' ' USER-COMMAND uc1.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
DATA: gt_file_table TYPE filetable,
gwa_file_table TYPE file_table,
gv_rc type i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select a file'
CHANGING
file_table = gt_file_table
rc = gv_rc.
IF sy-subrc = 0.
READ TABLE gt_file_table INTO gwa_file_table INDEX 1.
p_file = gwa_file_table-filename.
ENDIF.

AT SELECTION-SCREEN OUTPUT.


IF p_enable = 'X' .
CALL FUNCTION 'DDIF_FIELDINFO_GET' "to fetch table field information
EXPORTING
tabname = p_table

langu = sy-langu

TABLES
dfies_tab = inttab

EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.


PERFORM popup_display.

ENDIF.

*&---------------------------------------------------------------------*
*& Form popup_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM popup_display.

*FIELD CATALOG FOR POPUP SELECT
CLEAR ls_fieldcat.
ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = '1'.
ls_fieldcat-fieldname = 'CHECK'.
ls_fieldcat-tabname = 'INTTAB'.
ls_fieldcat-seltext_m = 'SELECT'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.


ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = '2'.
ls_fieldcat-fieldname = 'FIELDNAME'.
ls_fieldcat-tabname = 'INTTAB'.
ls_fieldcat-seltext_m = 'FIELDNAME'.
ls_fieldcat-outputlen = 50.
APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = '3'.
ls_fieldcat-fieldname = 'FIELDTEXT'.
ls_fieldcat-tabname = 'INTTAB'.
ls_fieldcat-seltext_m = 'DESCRIPTION'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.

* Display data in a POPUP for selecting the fields
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_zebra = 'X'
it_fieldcat = lt_fieldcat
i_tabname = 'INTTAB'
i_checkbox_fieldname = 'CHECK'
TABLES
t_outtab = inttab.
CLEAR p_enable.

ENDFORM. "popup_display

START-OF-SELECTION.

PERFORM selec.
PERFORM download.

*&---------------------------------------------------------------------*
*& Form SELEC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selec .

CREATE DATA w_dref TYPE STANDARD TABLE OF (p_table). "<t_itab> pointing to structure of data base table
ASSIGN w_dref->* TO <t_itab>.

CREATE DATA w_dref1 TYPE STANDARD TABLE OF (p_table). "<fi_itab> pointing to structure of data base table
ASSIGN w_dref1->* TO <fi_itab>.


IF sy-subrc EQ 0.
DATA: lv_temp TYPE string.
LOOP AT inttab INTO wa_tab WHERE check = 'X'. "selecting field names from inttab to inttab1

CONCATENATE lv_temp wa_tab-fieldname INTO lv_temp SEPARATED BY space.

MOVE wa_tab-fieldname TO wa_header.
APPEND wa_header TO it_header.
CLEAR: wa_tab,wa_header.
ENDLOOP.

SELECT (lv_temp) FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <t_itab>.

LOOP AT inttab1 INTO wa_tab1.

ENDLOOP.
ENDIF.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download .
DATA: cnt TYPE string. " to load n records in fi_itab
DATA: d TYPE string. " to create multiple files of excel e.x. export1 export2....
DATA: file TYPE string. " converting p_file to string
file = p_file.
cnt = 0.

LOOP AT <t_itab> ASSIGNING <wa_tab>. "original table with all records

ASSIGN <wa_tab> TO <wfi_tab>.
APPEND <wfi_tab> TO <fi_itab>.
cnt = cnt + 1.
*
IF cnt eq count.
d = d + 1.
data : lv_string1 type string, lv_string2 type string.
*
file = p_file.
split p_file at '.' into lv_string1 lv_string2.
CONCATENATE lv_string1 '_' d '.' lv_string2 into file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING

filename = file
filetype = 'DAT'
append = 'X'
write_field_separator = 'X'
TABLES
data_tab = <fi_itab>
fieldnames = it_header

.
IF sy-subrc <> 0.

ENDIF.



cnt = 0.
LOOP AT <fi_itab> ASSIGNING <wfi_tab>.
DELETE <fi_itab>.
ENDLOOP.
ENDIF.

ENDLOOP.






ENDFORM.