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

move reference table data to flat file on application server

pujavjaiswal
Explorer
0 Likes
1,323

Hello Experts,

I have requirement to move data from reference table to a flat file on application server in CSV format.

Please help me with some example code

My code:

DATA : lr_pay_data TYPE REF TO data.

FIELD-SYMBOLS : <gt_pay_data> TYPE ANY TABLE,

<ls_itab> TYPE ANY.

.

cl_salv_bs_runtime_info=>set(
EXPORTING
display = abap_false
metadata = abap_false
data = abap_true
).

SUBMIT (<lv_repid>)
USING SELECTION-SET p_slset
AND RETURN.

TRY.
cl_salv_bs_runtime_info=>get_data_ref(
IMPORTING r_data = lr_pay_data ).
ASSIGN lr_pay_data->* TO <gt_pay_data>.

CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.


OPEN DATASET p_srvfl FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE gv_mess.
IF sy-subrc <> 0.
MESSAGE gv_mess TYPE gcv_e.
ENDIF.

LOOP AT <gt_pay_data> ASSIGNING <ls_itab>.
TRANSFER <ls_itab> TO p_srvfl. --------------------------------------> getting dump here
ENDLOOP.

CLOSE DATASET p_srvfl.

Thanks in Advance.

5 REPLIES 5
Read only

Velu
Explorer
1,233

Could you please share the ABAP dump which you are getting?

Read only

Sandra_Rossi
Active Contributor
1,233

You are transferring a structure which probably contains a mix of characters and non-characters fields, and eventually STRING/XSTRING fields which are considered like reference variables, so they can't be transferred via its structure too. You should convert all these non-character fields to character fields, concatenate them, and then TRANSFER the concatenated string.

Read only

Former Member
0 Likes
1,233

Hi Puja try as i have done below, concatenate it as sandra suggested.

:

:

:

if sy-subrc = 0.

clear wa_filedata.
concatenate text-005 text-021 text-009 text-006 text-014 text-016 text-015 text-013 into wa_filedata separated by ','.
transfer wa_filedata to p_file.


loop at it_p2002 into wa_p2002.
concatenate wa_p2002-pernr
wa_p2002-nxdfl
wa_p2002-begda
wa_p2002-endda
wa_p2002-awart
wa_p2002-beguz
wa_p2002-enduz
lv_stdaz_temp
into wa_filedata separated by ','.
transfer wa_filedata to p_file.
clear: wa_p2002, lv_stdaz_temp.
endloop.
endif.
close dataset p_file.

:

:

:

Read only

pujavjaiswal
Explorer
0 Likes
1,233

The structure is dynamic .. so can not convert and concatenate on basis of field.

ABAP dump I am getting is of Type conflict..

Is there any way we can generate spool of this submit report and upload spool in application server

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,233

You can access fields dynamically:

DATA(line) = ||.
DO.
  ASSIGN COMPONENT sy-index OF STRUCTURE <ls_itab> TO FIELD-SYMBOL(<field>).
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  IF line = ||.
    line = |{ <field> }|. " convert field to text
  ELSE.
    line = |{ line };{ <field> }|.
  ENDIF.
ENDDO.
TRANSFER line TO p_srvfl.