2007 Sep 19 6:31 AM
Hi experts,
I have a situation wherein i have to compare the text strings and if it matches i want to copy the below lines to an internal table until it faces some other keyword. Let me explain in detail, I have an internal table like this,
summary
xxxxxx
yyyyyyy
zzzzzzz
project
aaaaaa
bbbbbb
cccccc
dddddd
Now i want to search for summary in the above itab and i want to copy the contents under summary(3 lines here) to another internal table until it encounters project. And I want do same for project also. Pls help me.
Points assured
Regards
Tharanatha
2007 Sep 19 6:52 AM
Is this the sort of thing you need?
Jonathan
report zlocal_jc_split_internal_table.
start-of-selection.
perform split.
*&---------------------------------------------------------------------*
*& Form split
*&---------------------------------------------------------------------*
form split.
data:
l_text(10) type c,
l_which_tab(1) type c,
lt_data like l_text occurs 10,
lt_summ like l_text occurs 10,
lt_proj like l_text occurs 10.
perform data_load "load sample data into memory
tables
lt_data.
loop at lt_data into l_text.
*
*" Flag which table to write to
*
case l_text.
when 'summary'.
l_which_tab = 'S'.
continue.
when 'project'.
l_which_tab = 'P'.
continue.
*" etc
endcase.
*
*" Add the data to the appropriate table
*
case l_which_tab.
when 'S'.
append l_text to lt_summ.
when 'P'.
append l_text to lt_proj.
endcase.
endloop.
*
*" End - lt_summ and lt_proj will be filled
*
break-point. "check it worked!!
endform. "split
*&---------------------------------------------------------------------*
*& Form data_load
*&---------------------------------------------------------------------*
form data_load
tables
ot_data.
clear: ot_data, ot_data[].
append 'summary' to ot_data.
append 'xxxxxx' to ot_data.
append 'yyyyyyy' to ot_data.
append 'zzzzzzz' to ot_data.
append 'project' to ot_data.
append 'aaaaaa' to ot_data.
append 'bbbbbb' to ot_data.
append 'cccccc' to ot_data.
append 'dddddd' to ot_data.
endform. "data_load
2007 Sep 19 6:39 AM
your requirement is still not clear, see again if you can edit your question and add some more info.
Cheers!!!
2007 Sep 19 6:54 AM
Hi Tripat Pal,
The thing is I have a text file like a resume. I want to to extract the contents under projects heading to an internal table and the summary contents to another internal table and personal details to another internal table. Now assume i have uploaded the resume to an internal table, now i want to search the internal table for projects and copy the contents of the projects into another internal table and similarly for the summary and personal details. Hope you have understood my problem.
Thanks and regards,
Tharanatha
2007 Sep 19 7:15 AM
well rajesh's solution is good enough for your requirement, do the same thing for projects and personal details.
Cheers!!!
2007 Sep 19 6:52 AM
Is this the sort of thing you need?
Jonathan
report zlocal_jc_split_internal_table.
start-of-selection.
perform split.
*&---------------------------------------------------------------------*
*& Form split
*&---------------------------------------------------------------------*
form split.
data:
l_text(10) type c,
l_which_tab(1) type c,
lt_data like l_text occurs 10,
lt_summ like l_text occurs 10,
lt_proj like l_text occurs 10.
perform data_load "load sample data into memory
tables
lt_data.
loop at lt_data into l_text.
*
*" Flag which table to write to
*
case l_text.
when 'summary'.
l_which_tab = 'S'.
continue.
when 'project'.
l_which_tab = 'P'.
continue.
*" etc
endcase.
*
*" Add the data to the appropriate table
*
case l_which_tab.
when 'S'.
append l_text to lt_summ.
when 'P'.
append l_text to lt_proj.
endcase.
endloop.
*
*" End - lt_summ and lt_proj will be filled
*
break-point. "check it worked!!
endform. "split
*&---------------------------------------------------------------------*
*& Form data_load
*&---------------------------------------------------------------------*
form data_load
tables
ot_data.
clear: ot_data, ot_data[].
append 'summary' to ot_data.
append 'xxxxxx' to ot_data.
append 'yyyyyyy' to ot_data.
append 'zzzzzzz' to ot_data.
append 'project' to ot_data.
append 'aaaaaa' to ot_data.
append 'bbbbbb' to ot_data.
append 'cccccc' to ot_data.
append 'dddddd' to ot_data.
endform. "data_load
2007 Sep 19 6:56 AM
If i am right, you need to split your internal table
take one internal table with all the keywords you are searching for
loop through your main table and search for any of those keywords
if found, then start appending from sytabix + 1 (you may need a variable to store sy-tabix + 1)
but before appending, check if it exists in the keyword table
if it doesnt then append it
else ignore it and append the next statement in the required table
note: I think you would need one internal table for each keyword
ie: one for summary, one for project etc
2007 Sep 19 6:57 AM
CLEAR itab.
READ TABLE itab WITH KEY string = 'summary'.
IF sy-subrc EQ 0.
w_tabix = sy-tabix + 1.
LOOP AT itab FROM w_tabix.
IF itab-string EQ 'project'.
EXIT.
ELSE.
APPEND itab to itab1.
ENDIF.
ENDLOOP.
ENDIF.
2007 Sep 19 7:55 AM
!!! Check this code !!!
TYPES : BEGIN OF ty_struct ,
sv_string TYPE string,
END OF ty_struct.
DATA : itab_struct1 TYPE TABLE OF ty_struct,
wa_struct1 LIKE LINE OF itab_struct1,
itab_struct2 TYPE TABLE OF ty_struct,
wa_struct2 LIKE LINE OF itab_struct2.
wa_struct1-sv_string = 'efghijkl'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'hmgkdhfl'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'summary'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'xxxxxxx'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'yyyyyyy'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'zzzzzzz'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'project'.
APPEND wa_struct1 to itab_struct1.
wa_struct1-sv_string = 'aaaaaaa'.
APPEND wa_struct1 to itab_struct1.
DATA : lv_string1 TYPE string,
lv_string2 like lv_string1,
summary_index TYPE I,
project_index TYPE I.
lv_string1 = 'summary'.
lv_string2 = 'project'.
READ TABLE itab_struct1 INTO wa_struct1 WITH TABLE KEY sv_string = 'summary'.
IF sy-subrc eq 0.
summary_index = sy-tabix.
summary_index = summary_index + 1.
ENDIF.
READ TABLE itab_struct1 INTO wa_struct1 WITH TABLE KEY sv_string = 'project'.
IF sy-subrc eq 0.
project_index = sy-tabix.
project_index = project_index - 1.
ENDIF.
LOOP AT itab_struct1 INTO wa_struct1 FROM summary_index to project_index.
APPEND wa_struct1 to itab_struct2.
ENDLOOP.
WRITE : 'Done'.
<b>Reward Points If Useful</b>