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

Transfer Dataset

Former Member
0 Likes
6,476

Hi all,

I have declared an internal table in the following way.

tyeps: begin of tys_sample,

a(9),

b(9),

end of tys_sample.

data: gt_sample type standard table of tys_sample,

gs_sample type tys_sample.

made some operations on the internal table and appended with data, now I need to transfer this internal table content into a dataset.

Did in the following way.

open dataset gv_file for input in text mode " gv_file contains the file path.

transfer gt_sample to dataset gv_file.

while doing syntax check for this program I am getting an error that GT_sample is not an internal table.

I can efford to loop the internal table into work area and pass the work are to the file.

Please let me know the answer. It is urgent.

Thanks in advance.

Regards,

Mungala.

Hi all,

I have declared an internal table in the following way.

tyeps: begin of tys_sample,

a(9),

b(9),

end of tys_sample.

data: gt_sample type standard table of tys_sample,

gs_sample type tys_sample.

made some operations on the internal table and appended with data, now I need to transfer this internal table content into a dataset.

Did in the following way.

open dataset gv_file for input in text mode " gv_file contains the file path.

transfer gt_sample to dataset gv_file.

while doing syntax check for this program I am getting an error that GT_sample is not an internal table.

I can efford to loop the internal table into work area and pass the work are to the file.

Please let me know the answer. It is urgent.

Thanks in advance.

Regards,

Mungala.

7 REPLIES 7
Read only

Former Member
0 Likes
5,872

decalre one varaibel as string

data v_data type string.

loop at gt_sample.

concatenate gt_sample-fld1 ',' gt_sample-fld2 into v_data.

transfer v_data to dataset gv_file.

endloop.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
5,872

You must loop the internal table into a work area and transfer the work area.

tyeps: begin of tys_sample,
a(9),
b(9),
end of tys_sample.

data: gt_sample type standard table of tys_sample,
gs_sample type tys_sample.

open dataset gv_file for input in text mode " gv_file contains the file path.

loop at gt_sample into gs_sample.
   transfer gs_sample to gv_file.
endloop.

close dataset gv_file.

Regards,

Rich Heilman

Read only

former_member196280
Active Contributor
0 Likes
5,872

Hi Praveen.

*Change your syntax like this.

LOOP AT gt_sample INTO gs_sample.

TRANSFER gs_sample TO gv_file.

ENDLOOP.

Reward points to all useful answers.

Regards,

SaiRam

Read only

Former Member
0 Likes
5,872

hi Praveena,

do this way ...


tyeps: begin of tys_sample,
        a(9),
        b(9),
end of tys_sample.

data: gt_sample like tys_sample occurs 0 with header line,
      gs_sample type tys_sample.

open dataset gv_file for input in text mode " gv_file contains the file path.

loop at gt_sample into gs_sample.
   transfer gs_sample to gv_file.
endloop.

close dataset gv_file

Regards,

Santosh

Read only

Former Member
0 Likes
5,872

Hey praveena,

There is no direct way to move internal table directly to a file. You will have to loop through each record.

IF you dont wanna move records to work area then, define header line for internal table:

tyeps: begin of tys_sample,

a(9),

b(9),

end of tys_sample.

data: gt_sample type standard table of tys_sample <b>WITH HEADER LINE</b>

gs_sample type tys_sample.

open dataset gv_file for input in text mode " gv_file contains the file path.

loop at GT_SAMPLE.

<b>transfer gt_sample to gv_file</b>.

ENDLOOP.

Read only

Kalaiselvan_S
Explorer
0 Likes
5,709

Hi, 
Yes can transfer whole internal table to dataset without loop

first convert your internal as CSV using method (cl_ilm_stor_mon_csv_converter ). It will convert multiple column table into single column (CSV separated) row by row it converts.
Now move csv converted data to internal table (string type). Then concatenate all the lines of CSV to single string and convert as XSTRING with UTF-8. Then Transfer single string to open dataset.

DATA: lt_csv          TYPE ilm_stor_mon_csv_t_csv_data,
      lt_tab       TYPE TABLE OF string,
      lv_bigstring TYPE string,
      lv_xstr      TYPE xstring.

"internal table to CSV table
    lo_csv->if_ilm_stor_mon_csv_converter~set_delimiter(
                  EXPORTING
                    iv_delimiter = ',' ).

      lo_csv->if_ilm_stor_mon_csv_converter~data_to_csv(
                                 EXPORTING
                                   iv_data =  lt_internal_table
                                   iv_header = abap_true
                                 IMPORTING
                                   et_csv = lt_csv ).

"string table
lt_tab = VALUE #( FOR row IN lt_csv ( row-dataline ) ).

      "Concatenate the internal table into one string separated by newline
      CONCATENATE LINES OF lt_tab  INTO lv_bigstring SEPARATED BY cl_abap_char_utilities=>newline.

      "Convert to XSTRING in UTF-8
      lv_xstr = cl_bcs_convert=>string_to_xstring(
                   iv_string   = lv_bigstring
                   iv_codepage = 'UTF-8' ).

      "Write in one shot
      OPEN DATASET lv_txt_file FOR OUTPUT IN BINARY MODE.
      IF sy-subrc = 0.
        TRANSFER lv_xstr TO lv_txt_file.
        CLOSE DATASET lv_txt_file.
      ENDIF.

This CONCATENATE will handle 35Lakh lines of internal table. 

Regards, 
Kalaislevan S.

 

 

 

 

Read only

0 Likes
4,104

Nice find.  Of course when I go to use it the constructor has the below.
    "==============================================
    " As of the release of NetWeaver 7.50 SPS04
    " is the ILM Store Monitor obsolete
    RAISE EXCEPTION TYPE cx_ilm_stor_mon_runtime
      EXPORTING
        textid = cx_ilm_stor_mon_runtime=>obsolete.
    "==============================================
The (as usual) terrible SAP documentation states that it is obsolete w/o suggesting a replacement.
WTFrig is wrong w/SAP managers that they ship code as such? Sad thing is it appears to work actually.