‎2007 Jun 22 9:21 AM
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 process fund fund center cmmt item
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.
thank you for your help
‎2007 Jun 22 9:41 AM
Hello Andrew
I assume you have the header/line marker in the records of your data itab. Thus, you could us the following logic:
DATA: ld_idx TYPE 1.
LOOP AT lt_itab INTO ls_record
WHERE ( header = 'H' ).
ld_idx = syst-tabix + 1.
" Read all lines for header
LOOP AT lt_itab INTO ls_record_x FROM ld_idx.
IF ( ls_record_x-header ne 'L' ).
EXIT. " leave loop
ENDIF.
" collect lines for header
...
ENDLOOP.
" Ignore header if it has no lines???
IF ( syst-subrc ne 0 ).
...
ENDIF.
ENDLOOP.Regards
Uwe
‎2007 Jun 22 12:02 PM
Thanks for the reply ewe
still having a problem..attached is my code:
DATA: ld_idx.
LOOP AT t_data INTO st_data
WHERE ( HEAD_IND = 'H' ).
ld_idx = syst-tabix + 1.
Read all lines for header
LOOP AT t_data INTO st_data FROM ld_idx.
IF ( st_data-head_ind ne 'L' ).
EXIT. " leave loop
ENDIF.
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.
PERFORM store_period USING '7' st_data-per07.
PERFORM store_period USING '8' st_data-per08.
PERFORM store_period USING '9' st_data-per09.
PERFORM store_period USING '10' st_data-per10.
PERFORM store_period USING '11' st_data-per11.
PERFORM store_period USING '12' st_data-per12.
no period data
IF st_data+150(360) IS INITIAL.
st_item-total_amount = st_data-total.
st_item-distkey = st_data-distkey.
ELSE.
CLEAR st_item-total_amount.
CLEAR st_item-distkey.
ENDIF.
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.
st_header-process = st_data-process.
w_year = '2007'.
st_header-version = st_data-version.
w_budtype = st_data-budtype.
other header data
st_header_add-header_text = p_htext.
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.
st_item-valtype = st_data-valtype.
st_item-fund = st_data-fund.
st_item-funds_ctr = st_data-funds_ctr.
st_item-cmmt_item = st_data-cmmt_item.
st_item-measure = st_data-measure.
st_item-grant_nbr = st_data-grant_nbr.
st_item-budtype = w_budtype.
APPEND st_item TO t_item.
Validate the data. This is done in the BAPI (via BAdI
FMKU_BEDGET_EVNT_CC) but the errors are not presented
in a user-friendly manner on the report
PERFORM validate_record CHANGING w_error.
ENDLOOP.
ENDFORM. " process_records