Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to do this code in elegant way

Former Member
0 Likes
609

Hallow

there is better way to do that becouse I this is part (I have many )of the table I have to send?

Regards

<b>PERFORM write_2_server TABLES hire_emp_tab.

PERFORM write_2_server TABLES entrance_tab.

PERFORM write_2_server TABLES integration_tab.

PERFORM write_2_server TABLES duty_tab .

PERFORM write_2_server TABLES type_emp_tab.

PERFORM write_2_server TABLES job_part_tab .

PERFORM write_2_server TABLES free_days_tab.

PERFORM write_2_server TABLES status_tab.

PERFORM write_2_server TABLES bank_detailes_tab.</b>

FORM write_2_server TABLES p_tab_data.

FIELD-SYMBOLS: <wa> TYPE ANY.

" MOVE 'D:_pa_test_mmsk_pa1.txt' TO adress.

OPEN DATASET adress IN TEXT MODE

ENCODING DEFAULT FOR OUTPUT.

IF sy-subrc = 0.

no_file = ' '.

LOOP AT p_tab_data ASSIGNING <wa>.

TRANSFER <wa> TO adress.

ENDLOOP.

CLOSE DATASET adress.

ELSE.

no_file = 'X'.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
582

Hi

Your code seems to be good, I believe you can have some little problem while you transfer the data to the file (if you're using only one file):

OPEN DATASET adress IN TEXT MODE should overwrite the file, so the result should be you'll transfer the data of the last table.

U should use the option FOR APPENDING or u open the file just one time or transfer all table in a big table and the transfer it to the file.

I believe the easier solution should be open the file just one time:

PERFORM write_2_server: TABLES hire_emp_tab USING '1',
                              TABLES entrance_tab  USING SPACE,
                              TABLES integration_ta USING SPACE,
                              TABLES duty_tab USING SPACE,
                              TABLES type_emp_tab USING SPACE,
                              TABLES job_part_tab USING SPACE, 
                              TABLES free_days_tab USING SPACE,
                              TABLES status_tab USING SPACE, 
                              TABLES bank_detailes_tab USING '2'.

FORM write_2_server TABLES p_tab_data
                                USING   ACTION.

FIELD-SYMBOLS: <wa> TYPE ANY.

" MOVE 'D:_pa_test_mmsk_pa1.txt' TO adress.


IF ACTION = '1'.
 OPEN DATASET adress IN TEXT MODE ENCODING DEFAULT FOR OUTPUT.
 IF sy-subrc = 0.
   no_file = ' '.
 ELSE.
   no_file = 'X'.
 ENDIF.
ENDIF.

IF NO_FILE = SPACE.
  LOOP AT p_tab_data ASSIGNING <wa>.
     TRANSFER <wa> TO adress.
  ENDLOOP.
ENDIF.

IF ACTION = '2' AND NO_FILE = SPACE.
  CLOSE DATASET adress.
ENDIF.

Max

Hallow

there is better way to do that becouse I this is part (I have many )of the table I have to send?

Regards

<b>PERFORM write_2_server TABLES hire_emp_tab.

PERFORM write_2_server TABLES entrance_tab.

PERFORM write_2_server TABLES integration_tab.

PERFORM write_2_server TABLES duty_tab .

PERFORM write_2_server TABLES type_emp_tab.

PERFORM write_2_server TABLES job_part_tab .

PERFORM write_2_server TABLES free_days_tab.

PERFORM write_2_server TABLES status_tab.

PERFORM write_2_server TABLES bank_detailes_tab.</b>

FORM write_2_server TABLES p_tab_data.

FIELD-SYMBOLS: <wa> TYPE ANY.

" MOVE 'D:_pa_test_mmsk_pa1.txt' TO adress.

OPEN DATASET adress IN TEXT MODE

ENCODING DEFAULT FOR OUTPUT.

IF sy-subrc = 0.

no_file = ' '.

LOOP AT p_tab_data ASSIGNING <wa>.

TRANSFER <wa> TO adress.

ENDLOOP.

CLOSE DATASET adress.

ELSE.

no_file = 'X'.

ENDIF.

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
582

That is definitly one option, I would probably go with that, if not within the OO context, but similarly I would use class/method if I was within the OO context. Another option, which I would not recommend, is to use a macro, problem with that is, you can't debug it.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
582

Hi,

This is definitely good because your program is modularised..Let it remain as it is..

Rgds,

Cmehra

Read only

Former Member
0 Likes
582

You can also do it in this way also...

<b>DATA: BEGIN OF name_of_tables OCCURS 0,

tabname(30) TYPE c,

END OF name_of_tables.

INITIALIZATION.

APPEND 'HIRE_EMP_TAB' TO name_of_tables.

APPEND 'ENTRANCE_TAB' TO name_of_tables.

APPEND 'INTEGRATION_TAB' TO name_of_tables.

START-OF-SELECTION.

APPEND 'HIRE_EMP_TAB' TO hire_emp_tab.

APPEND 'ENTRANCE_TAB' TO entrance_tab.

APPEND 'INTEGRATION_TAB' TO integration_tab.

PERFORM write_2_server TABLES name_of_tables.

FORM write_2_server TABLES p_tab_data STRUCTURE name_of_tables.

FIELD-SYMBOLS: <tab> TYPE table,

<wa> TYPE ANY.

DATA: l_tabname(30) TYPE c.

DELETE DATASET address.

OPEN DATASET address FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

CHECK sy-subrc EQ 0.

LOOP AT p_tab_data.

CONCATENATE p_tab_data-tabname '[]' INTO l_tabname.

ASSIGN (l_tabname) TO <tab>.

ASSIGN (p_tab_data-tabname) TO <wa>.

w_count = w_count + 1.

LOOP AT <tab> INTO <wa>.

TRANSFER <wa> TO address.

ENDLOOP.

ENDLOOP.

CLOSE DATASET address.

CHECK sy-subrc EQ 0.

WRITE:/ 'Done'.

ENDFORM. "write_2_server</b>

Coding is reduced... performance will be almost same ..

Reward points if useful..

regards

Prax

Read only

Former Member
0 Likes
583

Hi

Your code seems to be good, I believe you can have some little problem while you transfer the data to the file (if you're using only one file):

OPEN DATASET adress IN TEXT MODE should overwrite the file, so the result should be you'll transfer the data of the last table.

U should use the option FOR APPENDING or u open the file just one time or transfer all table in a big table and the transfer it to the file.

I believe the easier solution should be open the file just one time:

PERFORM write_2_server: TABLES hire_emp_tab USING '1',
                              TABLES entrance_tab  USING SPACE,
                              TABLES integration_ta USING SPACE,
                              TABLES duty_tab USING SPACE,
                              TABLES type_emp_tab USING SPACE,
                              TABLES job_part_tab USING SPACE, 
                              TABLES free_days_tab USING SPACE,
                              TABLES status_tab USING SPACE, 
                              TABLES bank_detailes_tab USING '2'.

FORM write_2_server TABLES p_tab_data
                                USING   ACTION.

FIELD-SYMBOLS: <wa> TYPE ANY.

" MOVE 'D:_pa_test_mmsk_pa1.txt' TO adress.


IF ACTION = '1'.
 OPEN DATASET adress IN TEXT MODE ENCODING DEFAULT FOR OUTPUT.
 IF sy-subrc = 0.
   no_file = ' '.
 ELSE.
   no_file = 'X'.
 ENDIF.
ENDIF.

IF NO_FILE = SPACE.
  LOOP AT p_tab_data ASSIGNING <wa>.
     TRANSFER <wa> TO adress.
  ENDLOOP.
ENDIF.

IF ACTION = '2' AND NO_FILE = SPACE.
  CLOSE DATASET adress.
ENDIF.

Max