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

CSV File read

Former Member
0 Likes
428

Experts

Hopefully you can help me.

I am reading a flat file using GUI_UPLOAD, splitting the file, then using another function module to load the data. The data is loading succesfully. However, all of the lines are loading under one header record. An example of the file format is :

Header bud cat doctype version fm area docstate

H 9F 2 ZBW 9000 1 ENTR DEF A00 RM09

L 9F 2 ZBW 9000 1 ENTR DEF A00 RM09

H 9F 2 ZBW 9000 1 ENTR DEF A00 RM09

L 9F 2 ZBW 9000 1 ENTR DEF A00 RM09

I need to read the file, create the header record then create a line record (denoted by L). When the a new header record is found (H) create a new header and add the lines). At the moment its creating all the lines under one header.

This is part of the code - after this a ic all the BAPI.

FORM process_records .

CLEAR: st_item,

st_period,

st_return.

REFRESH: t_item,

t_period,

t_return.

CLEAR: t_item,

t_period,

t_return.

CLEAR w_item.

DATA: ld_idx.

LOOP AT t_data INTO st_data

IF st_data IS INITIAL.

CONTINUE.

ENDIF.

ADD 1 TO w_item.

w_recs_in = w_recs_in + 1.

w_tabix = sy-tabix.

st_period-item_num = w_item.

PERFORM store_period USING '1' st_data-per01.

PERFORM store_period USING '2' st_data-per02.

PERFORM store_period USING '3' st_data-per03.

PERFORM store_period USING '4' st_data-per04.

PERFORM store_period USING '5' st_data-per05.

PERFORM store_period USING '6' st_data-per06.

  • set up the static header data

st_header-fm_area = st_data-fm_area.

st_header-docdate = p_dcdate.

st_header-doctype = st_data-doctype.

st_header-docstate = st_data-docstate.

  • other item data

st_item-item_num = w_item.

st_item-fisc_year = w_year.

st_item-budcat = st_data-budcat.

  • st_item-func_area = p_func.

st_item-trans_curr = st_data-trans_curr.

st_item-item_text = p_ltext.

APPEND st_item TO t_item.

ENDLOOP.

ENDFORM. " process_records

thank you for your help

2 REPLIES 2
Read only

Former Member
0 Likes
403

Hi

It's not very clear what you need to do, it seems u should check the first chararcter of the record to know the record type (header or line).

Max

Read only

Former Member
0 Likes
403

Hi Andrew

whats the logic that you are using to identify that a particular item record corresponds to one particular header record.

when you are splitting the data from the file and populating it in the internal tables assign a number/char to the header and item records to ensure that each header record has a corresponding item record. And then process the records.

This way u will be able to avoid all the item records getting processed for a single header record.

Cheers