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

File reading into internal table without defined structure

vijy_mukunthan
Active Contributor
0 Likes
3,163

Dear Experts

I am trying to achieve dynamic reading of file from presentation server. The file structure will be know only at run time. i tried to do it but i am getting # between every column. Please find the code below.



SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}

PARAMETERS: p_tabnam TYPE tabname,

            p_selfl1 TYPE edpline,

            p_value  TYPE edpline,

            p_where1 TYPE edpline.



PARAMETERS: p_file TYPE ibipparms-path.

DATA: file TYPE string.



DATA: it_tab TYPE TABLE OF zfile,

      wa_tab TYPE zfile.





DATA: lt_where    TYPE TABLE OF edpline,

      lt_sel_list TYPE TABLE OF edpline,

      l_wa_name   TYPE string,

      ls_where    TYPE edpline,

      l_having    TYPE string,

      dref        TYPE REF TO data,

      itab_type   TYPE REF TO cl_abap_tabledescr,

      struct_type TYPE REF TO cl_abap_structdescr,

      elem_type   TYPE REF TO cl_abap_elemdescr,

      comp_tab    TYPE cl_abap_structdescr=>component_table,

      comp_fld    TYPE cl_abap_structdescr=>component.



TYPES: f_count TYPE i.



FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,

                "*                <ls_outtab> TYPE ANY,

                <l_fld>     TYPE any.







AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      field_name = 'P_FILE'

    IMPORTING

      file_name  = p_file.

  file = p_file.




SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}

 CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

      filename            = file

      filetype            = 'ASC'

      has_field_separator = ' '

*     HEADER_LENGTH       = 0

*     READ_BY_LINE        = 'X'

*     DAT_MODE            = ' '

*     CODEPAGE            = ' '

*     IGNORE_CERR         = ABAP_TRUE

*     REPLACEMENT         = '#'

*     CHECK_BOM           = ' '

*     VIRUS_SCAN_PROFILE  =

*     NO_AUTH_CHECK       = ' '

*   IMPORTING

*     FILELENGTH          =

*     HEADER              =

    TABLES

      data_tab            = it_tab.

In the IT_TAB i am getting the fields name with #. Even i tried to replace the # with blank for all occurrence but its not working.

How to remove this. Since the structure is declared as char 999. I am getting like this. Please let me know how to achieve this.

Thanks and Regards

Vijay

9 REPLIES 9
Read only

roberto_forti
Contributor
0 Likes
2,709

Hi,

Consider below parameter or FM ALSM_EXCEL_TO_INTERNAL_TABLE

has_field_separator  = 'X'  "file is TAB delimited

Regards,

Read only

roberto_forti
Contributor
0 Likes
2,709

Hi,

Consider below parameter or FM ALSM_EXCEL_TO_INTERNAL_TABLE

has_field_separator  = 'X'  "file is TAB delimited

Regards,

Read only

2,709

Hi Roberto

If i use has_field_seperator = 'X' only first field getting populated. I am using tab delimited txt file.

Thanks and Regards

vijay

Read only

DoanManhQuynh
Active Contributor
2,709

i think # is present for horizion tab which is CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB in abap. can you try like this:

REPLACE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB IN ls_tab WITH SPACE.
Read only

0 Likes
2,709

Same question i asked to Neenu below: how could this solve the issue to generate a dynamic table from a file with undefined structure?

Read only

0 Likes
2,709

So you should read the question more carefully, he asked about how to resolve the replace of # characters when upload file to abap, above is my suggestion to achive it. Clearly, as we see his code, he going to use RTTS to do dynamic table.

Read only

matt
Active Contributor
0 Likes
2,709

When you post code, please use right-click "paste as plain text".

Read only

RaymondGiuseppi
Active Contributor
2,709

The upload has correctly uploaded the file as you gave it no clues of not doing so.

  • Read line 1, spit the record at the separator # (supposedly cl_abap_char_utilities=>horizontal_tab) and build an internal table once fields identified (rtts)
  • Then split each other lines at same separator into a new final table record or a text table. Use second case for fields with conversion-exit or more generally an external format different from internal format, so you will have to map those fields yourself to SAP expected format (calling conversion_xxx_ input type FM)

NB: Also replace FM gui_upload by method cl_gui_frontend_services=>gui_upload.

Read only

SimoneMilesi
Active Contributor
2,709

Why do you suggest this?
The request is to create a dynamic table based on a variable file structure.

How could your suggestion to solve such issue?