‎2020 Feb 27 9:59 AM
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.
‎2020 Feb 28 8:11 AM
‎2020 Feb 28 8:30 AM
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.
‎2020 Feb 28 8:40 AM
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.
:
:
:
‎2020 Feb 28 9:35 AM
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
‎2020 Feb 28 10:40 AM
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.