Application Development 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: 

reading data from application server

Former Member
0 Kudos

Hi

I have created a dynamic internal table . Now i want to read data from application server which has a flat file with tab delimited records.

the flat file format is like this

PERNR#SUBTY#TMART#TERMN#MNDAT#ANZHL#ZEINX

00000010#04#04#21.11.2007#20.11.2007#1#123

00000058#04#04#21.11.2007#20.11.2007#1#123

00000054#04#04#21.11.2007#20.11.2007#1#123

00000007#04#04#21.11.2007#20.11.2007#1#123

below is the piece of code for

****creating dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_fieldcat_at

IMPORTING

ep_table = new_table.

ASSIGN new_table->* TO <dyn_table>.

*Create dynamic work area and assign to FS

CREATE DATA new_line LIKE LINE OF <dyn_table>.

ASSIGN new_line->* TO <dyn_wa>.

CREATE DATA new_line1 LIKE LINE OF <dyn_table>.

ASSIGN new_line1->* TO <dyn_wa1>.

OPEN DATASET l_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE s000(zwb) .

ELSE.

DO .

READ DATASET l_file_path INTO wa_data.

IF sy-index = 2.

do l_col times. "where l_col is no. of columns in extract file

SPLIT wa_data AT c_tab INTO <dyn_wa1> wa_data.

endif.

enddo.

now i want to seperate each entity (column value) and place it in corresponding filed of the dynamic internal table. But in the above code for splitting i can't specify column for the field symbol <dyn_wa1>..

ex: <dyn_wa1>-pernr is not possible in the split statement.

so iam not able to move the entries into corresponding fields of

the dynamic internal table..

could anybody please provide the solution.

it's urgent.

Badri

4 REPLIES 4

Former Member
0 Kudos

After

SPLIT ... AT ... INTO

you have to name all components of your workarea. You have to name a component for each column.

ex.:

Let`s say your target structure (TGT_STRUCT) has three components (COMP1, COMP2 and COMP3), then you have to execute the following:

SPLIT wa_data AT c_tab INTO tgt_struct-comp1 tgt_struct-comp2 tgt_struct-comp3.

Reward point, if reply is applicable

0 Kudos

HI

the target structure is not know until run time. So how do i specify component name after the field-symbol.

regards

Badri

Former Member
0 Kudos

Hi Badri, try this code.

DATA: lw_fieldvalue(40) TYPE c,

lw_fieldname(30) TYPE c.

gwa_output TYPE REF TO data.

FIELD-SYMBOLS: <gwa_output> TYPE ANY.

FIELD-SYMBOLS: <l_fvalue> TYPE ANY.

*---Create a pointer to store the workarea of the final output table.

CREATE DATA gwa_output LIKE LINE OF <git_output>.(this is the output table)

*---Assign it to a fieldsymbol which will be used in populating the

*---final output table.

ASSIGN gwa_output->* TO <gwa_output>.

Loop at i_tab into wa_tab.

move wa_tab-field1 to v_fieldvalue. (moving the first field value into field value variable).

CONDENSE v_fieldvalue NO-GAPS. (Condense the output).

CLEAR: <gwa_output>.

ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <gwa_output> TO <l_fvalue>.

<l_fvalue> = V_fieldvalue.

Repeat the same with other fields

*---Append the current record to final output table.

APPEND <gwa_output> TO <git_output>.

endloop.

hope this helps.

cheers,

Hema.

mnicolai_77
Active Participant
0 Kudos

hi,

try this way.


data:delimiter(1) type c value '#'.
field-symbols:<fs_val> type any,
              <fs_data> type any.	
data: begin of lt_values occurs 0,
        field_value type string,
      end of lt_values.

OPEN DATASET l_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
if sy-subrc = 0.
  DO.
    READ DATASET l_file_path INTO wa_data.
    IF sy-subrc <> 0.
      EXIT.
    ELSE.
      CHECK sy-index > 1.
      SPLIT wa_data AT lv_delimiter INTO table lt_values.
      LOOP AT lt_values ASSIGNING <fs_val>.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE wa_data TO <fs_data>.
        IF sy-subrc = 0.
          <fs_data> = <fs_val>.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDDO.
ELSE.
  MESSAGE s000(zwb) .
ENDIF.

Regards

Marco