2014 Jan 13 7:36 PM
Hello... I've got a program I've been asked to modify. I've been asked to modify a program which uploads 1 of 5 different files and store them into 1 of 5 corresponding tables. The files input will by delimited by a tilde "~". The files are specified by the user via 5 radio buttons and they select the file from their desktop. I was hoping to simplify the processing of the input files using RTTS. I've included a much simpler version of my problem below using only 2 files. The questions are documented in the program code. For some reason I just can't figure out how to do 3 of the tasks.
type-pools: abap.
types: begin of gt_upload,
record type string.
types: end of gt_upload.
data: go_structdescr type ref to cl_abap_structdescr,
go_fielddescr type ref to cl_abap_datadescr.
data: git_filetable type table of file_table,
git_spfli type table of spfli,
git_scarr type table of scarr,
git_upload type table of gt_upload.
data: gk_filetable like line of git_filetable,
gk_spfli like line of git_spfli,
gk_scarr like line of git_scarr,
gk_upload like line of git_upload,
gk_component type abap_compdescr.
data: g_fieldcount type i,
g_return type i,
g_result type string.
field-symbols: <gfs_struct> type any,
<gfs_table> type standard table.
selection-screen begin of block b1 with frame title text-001.
parameters: p_fname like rlgrap-filename.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters: rb_spfli radiobutton group rb01 default 'X', "Input file will contain spfli "~" delimited file
rb_scarr radiobutton group rb01. "Input file will contain scarr "~" delimited file
selection-screen end of block b2.
at selection-screen on value-request for p_fname.
* do the file open dialog stuff here to store the filename
* in parameter p_fname.
start-of-selection.
* Question 1: is there a way to do this with the structure definition
* instead of the data dictionary object? I.E., can I do this
* using 'gk_spfli' or 'gk_scarr' insead of 'spfli' and 'scarr'
* respectively
if rb_spfli = abap_true.
go_structdescr ?= cl_abap_structdescr=>describe_by_name( 'SPFLI' ).
else.
go_structdescr ?= cl_abap_structdescr=>describe_by_name( 'SCARR' ).
endif.
* Get the number of delimited fields
g_fieldcount = lines( go_structdescr->components ).
perform read_input_file.
* Loop at each record (row) in the input file
loop at git_upload from 2 into gk_upload.
* loop through each "field" in the delimited file
do g_fieldcount times.
clear g_result.
try.
* split off each field and store value into g_result
g_result = segment( val = gk_upload-record
index = sy-index
sep = '~' ).
catch cx_sy_strg_par_val.
exit.
endtry.
* first get the corresponding field name from our structure for the
* sy-index field
read table go_structdescr->components into gk_component index sy-index.
* Question 2: How do a store the value in g_result into the correct table-field?
* Something to the effect of doing the following which I know is
* syntatically incorrect but what I'm trying to figure out:
* <gfs_struct>-gk_component-field = g_result.
enddo.
* Question 3: How do I then store the values in my structure <gfs_struct>
* into my table <gfs_table>>
* something like
* append <gfs_struct> into <gfs_table>.
endloop.
form read_input_file .
* Do the file upload processing
* which stores the input file
* in table git_upload.
* git_upload will contain either the
* "~" delimited data for table spfli or scarr
endform. " read_input_file
2014 Jan 13 11:06 PM
Hi,
So
1. You need to use a type declaration (TYPES/DATA: BEGIN OF..END OF)
2. assign component gk_component-field of structure <gfs_struct> to <val>.
<val> = g_result. (with <val> of type ANY)
3. insert <gfs_struct> into table <gfs_table>
Cheers,
Manu.
2014 Jan 13 11:06 PM
Hi,
So
1. You need to use a type declaration (TYPES/DATA: BEGIN OF..END OF)
2. assign component gk_component-field of structure <gfs_struct> to <val>.
<val> = g_result. (with <val> of type ANY)
3. insert <gfs_struct> into table <gfs_table>
Cheers,
Manu.
2014 Jan 14 2:44 PM
Thanks Manu..
Not only did I use your points I also changed my strategy a bit. I now create a dynamic table that's based on one of the 5 underlying internal table types that's already being used in the program. So basically I build a dynamic table structured to the selected input file type and it gets stored in <gfs_table> using your 3 answers. Then later in the existing program ther'es a check to see if rb_1, rb_2, rb_3... rb_5 is selected and does all the existing logic in the program for each of the 5 internal tables. All I had to do is add an if <gfs_table> is assigned to that logic and if so simply move <gfs_table> to the relative internal table based on the radio button and then the program could continue processing.