Skip to Content
-1

how to implement parallel processing in the dynamic selection of tables

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Oct 18, 2019 at 08:00 AM

    Hi

    Could you elaborate on what you mean by parallel processing? Or maybe it is better to tell what the exact issue is that you are facing, is the program running slowly? Or is the SQL taking ages to get the records

    I think the SQL performance is issue is there because there is no "WHERE" statement.. Especially when you are on HANA, basic SQL states lean processing (only select what you need, as well by selecting only the fields you need, but also only fetching the records you need). Your SQL will fetch a set of columns for ALL records in the selected table.. Adding a WHERE statement will probably reduce the performance issue a lot

    kr

    Yor

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Thanks for the response..As I am dealing with huge amount of data, the runtime / execution time should be within the time limit.To overcome this we use parallel processing method. As you can see in my code I am using multiple loops the execution time is more and I want to avoid that and get the data downloaded in no time.

  • Posted on Oct 24, 2019 at 09:56 PM

    Try code below using cursor to fetch data blocks and download them

    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.

    DATA: d TYPE string. " to create multiple files of excel e.x. export1 export2....

    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 .

    DATA c1 TYPE cursor.

    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.


    OPEN CURSOR @c1 FOR SELECT (lv_temp) FROM (p_table) UP TO @count ROWS.
    DO .
    FETCH NEXT CURSOR @c1 INTO CORRESPONDING FIELDS OF TABLE @<t_itab>.
    IF sy-subrc NE 0.
    EXIT.
    ELSE.
    PERFORM download.
    ENDIF.

    ENDDO.

    CLOSE CURSOR @c1.
    * 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.

    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.

    ENDFORM.
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.