‎2009 Jan 12 5:28 AM
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.
‎2009 Jan 12 6:12 AM
Hi ..
Try to use GUI_Upload function module ..
hope it helps you ..
‎2009 Jan 12 6:20 AM
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
‎2009 Jan 12 6:38 AM
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.
‎2009 Jan 12 6:38 AM
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
‎2009 Jan 12 6:39 AM
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
‎2009 Jan 12 6:52 AM
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