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 internal table after each upload

Former Member
0 Likes
1,703

Hi,

My requirement is to create internal tables after each upload at selection screen

I have a selection screen which has two file upload path.When I upload the files 1st time the records should be strored in one internal table.

Again when I upload at the same selection screen, the records should be stored in 2nd internal table.

I do not know how many times the user is going to upload files.That can be thousand times too.So I need a solution where we can capture these things dynamically.

Note:please do not give a solution like the files can be uploaded using GUI_UPLOAD.I know GUI_UPLOAD only uploads file.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,642

Thats fine.But each time the fields of the uploaded file will vary.Now I want to make dynamic internal table with the uploaded field (with records)each time.Is it possible?

I mean using t_file-data.

Edited by: Ginger on Jul 21, 2009 9:19 AM

Hi,

My requirement is to create internal tables after each upload at selection screen

I have a selection screen which has two file upload path.When I upload the files 1st time the records should be strored in one internal table.

Again when I upload at the same selection screen, the records should be stored in 2nd internal table.

I do not know how many times the user is going to upload files.That can be thousand times too.So I need a solution where we can capture these things dynamically.

Note:please do not give a solution like the files can be uploaded using GUI_UPLOAD.I know GUI_UPLOAD only uploads file.

Thanks in advance.

11 REPLIES 11
Read only

Former Member
0 Likes
1,642

You can use a counter and store the variable in ABAP memory using the following statements.

Export to MEMORY ID Variable_name.

IMPORT FROM MEMORY ID Variable_Name..

then you can use your logic to switch internal tables inside the program.Let me know if any issues.

Regards,

Vimal.

Read only

0 Likes
1,642

Hello vimal,

good idea but i need some clarification when will you free the memory.

Thanks,

Shaik.

Read only

Former Member
0 Likes
1,642

Hi

There are several possible solutions.

Best solution is maybe the OO solution. Create a class and create the table as an attribute of the class instance.

Or define a structure with nested table and define top structure as table.

Henk.

Read only

viquar_iqbal
Active Contributor
0 Likes
1,642

Hi

You can capture the press of the button 'UPLOAD' in system field sy-ucomm.

case sy-ucomm.

create a new dynamic internal table .

move the file uploaded to the new internal table.

clear off the path .

endcase.

Hope this resolves the issue.

Viquar Iqbal

Read only

0 Likes
1,642

Yes..this is how I am doing..this is ok when I upload 1st time...how about 1st,2nd,3rd...1000th upload....How the program/system will know that this is the 1000th upload and the 1000th internal table will be created???

Read only

Former Member
0 Likes
1,642

Hi

U can try to use an internal table having an internal table as fields:

TYPES: TY_RECORD TYPE STRING.

TYPES: BEGIN OF TY_FILE,
         PATH TYPE STRING,
         DATA TYPE TY_RECORD OCCURS 0,
       END   OF TY_FILE.

DATA: T_FILE TYPE TABLE OF TY_FILE.

PARAMETERS: p_file(80).

at SELECTION-SCREEN.

  data: filename type string,
        t_data   type TABLE OF TY_RECORD,
        w_file   type ty_file.

  move p_file to filename.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                      = filename
    TABLES
      DATA_TAB                      = t_data.

  refresh w_file-data.
  w_file-path   = filename.
  w_file-data[] = t_data[].
  append w_file to t_file.

Anyway u make to insert a control in order to limit the file can be uploaded because you've a limit for memory size.

Max

Read only

Former Member
0 Likes
1,643

Thats fine.But each time the fields of the uploaded file will vary.Now I want to make dynamic internal table with the uploaded field (with records)each time.Is it possible?

I mean using t_file-data.

Edited by: Ginger on Jul 21, 2009 9:19 AM

Read only

0 Likes
1,642

I think you can do it by the helip of FieldSymbol.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab. *********Creates a dyanamic internal table*********

perform get_data.

perform write_out.

form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

endform.

form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

Write out data from table.

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <dyn_field>.

else.

write: <dyn_field>.

endif.

enddo.

endloop.

Edited by: ShreeMohan Pugalia on Jul 21, 2009 3:30 PM

Read only

0 Likes
1,642

Following is the sample code for creating Dynamic internal table...it is possible...

REPORT zpwtest .

      • Tables

DATA: lt_data TYPE REF TO data.

DATA: lt_fieldcatalog TYPE lvc_t_fcat.

      • Structure

DATA: ls_fieldcatalog TYPE lvc_s_fcat.

      • Data References

DATA: new_line TYPE REF TO data.

      • Field Symbols

FIELD-SYMBOLS: <fs_data> TYPE REF TO data,

<fs_1> TYPE ANY TABLE,

<fs_2>,

<fs_3>.

ls_fieldcatalog-fieldname = 'MANDT'.

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname

ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CONNID'.

ls_fieldcatalog-inttype = 'N'.

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'FLDATE'.

ls_fieldcatalog-inttype = 'D'.

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'PRICE'.

ls_fieldcatalog-inttype = 'P'.

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CURRENCY'.

ls_fieldcatalog-inttype = 'C'.

APPEND ls_fieldcatalog TO lt_fieldcatalog.

ASSIGN lt_data TO <fs_data>.

CALL METHOD cl_alv_table_create=create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fieldcatalog

IMPORTING

ep_table = fs_data

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2

.

IF sy-subrc 0.

ENDIF.

      • So <FS_1> now points to our dynamic internal table.

ASSIGN <fs_data>->* TO <fs_1>.

      • Next step is to create a work area for our dynamic internal table.

CREATE DATA new_line LIKE LINE OF <fs_1>.

      • A field-symbol to access that work area

ASSIGN new_line->* TO <fs_2>.

      • And to put the data in the internal table

SELECT mandt carrid connid fldate price currency

FROM sflight

INTO CORRESPONDING FIELDS OF TABLE <fs_1>.

      • Access contents of internal table

LOOP AT <fs_1> ASSIGNING <fs_2>.

ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.

WRITE: / <fs_3>.

ENDLOOP.

Regards,

Vimal

Read only

0 Likes
1,642

Uhm

Probably, but it could be hard and wouldn't make a sense, probably u need to have the correct structure when u need to read every file, so while looping the table with file data:

TYPES: TY_RECORD TYPE STRING.

TYPES: BEGIN OF TY_FILE,
         PATH TYPE STRING,
         DATA TYPE TY_RECORD OCCURS 0,
       END   OF TY_FILE.

DATA: T_FILE TYPE TABLE OF TY_FILE.

DATA: FILENAME TYPE STRING,
      T_DATA   TYPE TABLE OF TY_RECORD,
      W_FILE   TYPE TY_FILE.

DATA: WA TYPE STRING.

PARAMETERS: P_FILE(80).

AT SELECTION-SCREEN.

  MOVE P_FILE TO FILENAME.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME = FILENAME
    TABLES
      DATA_TAB = T_DATA.

  REFRESH W_FILE-DATA.
  W_FILE-PATH   = FILENAME.
  W_FILE-DATA[] = T_DATA[].
  APPEND W_FILE TO T_FILE.

START-OF-SELECTION.

  LOOP AT T_FILE INTO W_FILE.
    LOOP AT W_FILE-DATA INTO WA.
"----> Move the data to a new table created dynamically?      
    ENDLOOP.
  ENDLOOP.

Now the problem is how u can determine the right structure of the file you're reading

Max

Read only

0 Likes
1,642

Hey Max...Thank you very much for the solution.