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

Creating an Internal table based on flat file data

Former Member
0 Likes
1,470

Hi,

I have a requirement where i need to create an internal table based on the data present in the flat file .

This flat file

1) has the field names in the first row and

2) has the values in the next rows

3) The field names in the flat file are not in the same order always . The order may change.

I have to create an internal table dynamically based on this flat file.

I have searched in SDN but unfortunately I did not find any solution that matches my requirement.

I even tried using field symbols in my program.

Can any one help me regarding this issue.

Thanks and regards,

Parvatha Reddy.

6 REPLIES 6
Read only

Former Member
0 Likes
947

Hi ..

Try to use GUI_Upload function module ..

hope it helps you ..

Read only

Former Member
0 Likes
947

hi

once your flat file is ready ,then you can make use of upload or ws_upload to transfer data from flat file to the internal table.

then you should make use of BDCDATA structure to transfer the values of the fields to the transaction either through BATCH INPUT method or CALL TRANSACTION method.

hope it helps

regards

Aakash Banga

Read only

0 Likes
947

Hi,

I have mentioned that the field names in the flat file will not be the same each time .

They will keep on changing . I do not think just gui_upload works in this case.

Need some additional code.

Read only

uwe_schieferstein
Active Contributor
0 Likes
947

Hello

You can use RTTI/RTTC in order to create a dynamic itab based on the fieldnames in the first row (where are the technical details, e.g. field length???).

References:

[Creating Flat and Complex Internal Tables Dynamically using RTTI|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/creating%2bflat%2band%2bcomplex%2binternal%2btables%2bdynamically%2busing%2brtti]

[An Insider's Guide to Writing Robust, Understandable, Maintainable State of the Art ABAP Programs, Part 3|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f2dac69e-0e01-0010-e2b6-81c1e8e5ce50]

  • Create dynamic itab having the structure described by the first row in the flat file

  • Upload the flat file into an itab with line type = string

  • Move data from unstructured string into structured itab

For the third step you can use the static method READ_CONTAINER_C of class CL_ABAP_CONTAINER_UTILITIES.

Regards

Uwe

Read only

Former Member
0 Likes
947

Hi,

Create one internal table which should reflect in field count which are there in flat file and also create one more internal table with single field with greater length which used to held the flat file records lines as rows.than get file into single field record.Loop the single field table and than using off set fill the corresponding fields of target table work area and append it.

let say WA is work area of target table and flat is the work area for single field table then use the technique give below.

wa-pernr = flat-record+0(8).

wa-amount = flat-record+8(15).

appens wa to itab.

this may help you .

regards,

Alok

Read only

SujeetMishra
Active Contributor
0 Likes
947

Hello Parvatha,

before steps:

TYPES : ty_excell_data TYPE kcde_cells.

DATA: it_excell_data TYPE STANDARD TABLE OF ty_excell_data.

1.>First you provide one parameter on selection screen from which you will access you flat file data.

eg: PARAMETERS: pr_fname LIKE rlgrap-filename OBLIGATORY.

2.> CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = pr_fname.

3.>

*Function module to capture the excel sheet data into internal table

CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'

EXPORTING

filename = pr_fname

i_begin_col = c_begin_col

i_begin_row = c_begin_row

i_end_col = c_end_col

i_end_row = c_end_row

TABLES

intern = it_excell_data

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

message text-001 type 'E'.

ENDIF.

clear it_excell_data.

Hope its enough for your understanding.

Fell free to ask me if you still get some problems

Have a Nice Day.

Regards,

Sujeet