2009 Feb 12 2:32 PM
Hi Friends,
Query: How to add a '/' in a empty field of an internal table.
Example: I have an internal table with 5 fields. Some select statements has field the values in that internal table like,,
S denotes Empty Space
Fields 1 2 3 4 5
Record 1 S 3 4 S
Record S S 3 4 5
Record S S S 4 5
After this i want to fill the empty space with / like this,
Fields 1 2 3 4 5
Record 1 / 3 4 /
Record / / 3 4 5
Record / / / 4 5
The internal will be fill in a dynamic manner. so we can't say the particualr field is always empty.
So hope the good results.
Thank You Friend
Ganesh
2009 Feb 13 8:07 AM
Hi,
For example say your internal table name is it_tab and correponding work area is wa_tab,
then you to replace all space by '/' you have to write code as belows.
"Data declarations
DATA: ref_desc TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS:
<comp_wa> TYPE abap_compdescr, "For getting the structure details
<fs> TYPE ANY.
...
...
...
ref_desc ?= cl_abap_typedescr=>describe_by_data( wa_tab ). "Get the structure of work area wa_tab
LOOP AT it_tab INTO wa_tab.
LOOP AT ref_desc->components ASSIGNING <comp_wa>.
ASSIGN COMPONENT <comp_wa>-name OF STRUCTURE wa_tab TO <fs>.
IF <fs> EQ space. "if equals space
<fs> = '/'. "assign '/'
MODIFY it_tab FROM wa_tab TRANSPORTING (<comp_wa>-name). "Modify the table
ENDIF.
ENDLOOP.
ENDLOOP.I checked this is working.
Revert in case of issues.
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Feb 13, 2009 9:08 AM
2009 Feb 12 2:34 PM
2009 Feb 13 7:32 AM
Hi
Here (in the forum) i can't give a space so i mentioned S. But in an internal i have a empty space.
I tried with Replace all occurance of ' ' with....... but it goes to short dump.
Need some more anwser...
2009 Feb 12 2:37 PM
hi,
Use:
Loop at itab.
If itab-field1 is initial.
itab-field1 = '/'.
endif.
If itab-field2 is initial.
itab-field2 = '/'.
endif.
If itab-field3 is initial.
itab-field3 = '/'.
endif.
modify Itab.
endloop.
Regards,
Gurpreet
2009 Feb 12 2:41 PM
Hi ,
if the field1 in the internal table itab .
Here i am consider only one field , you have more than one field to modify like this use the all fileds.
loop at itab into w_itab..
if w_itab-field1 is initial .
w_itab-field1 = '/'.
endif.
modify itab ftom w_itab index sy-tabix transporting field1.
endloop.
regards,
bharani.
Edited by: SeethaRamaiah Bharani on Feb 12, 2009 8:12 PM
2009 Feb 12 3:21 PM
hi
do w_n times.
read table itab field value field1 field2 field3 field4 field5.
if field1 is initial.
modify field1 from '/'.
endif.
if field2 is initial.
modify field2 from '/'.
endif.
if field3 is initial.
modify field3 from '/'.
endif.
if field4 is initial.
modify field4 from '/'.
endif.
if field5 is initial.
modify field5 from '/'.
endif.
enddo.
try this
this will solve your problem
Regards
Hareesh
2009 Feb 13 7:34 AM
Hi friends
I have 30 fields and i don't want to hard code all the fields one by one. So can you give some more answers. Any answers with the help of field symbols.
Thank you
Ganesh.
2009 Feb 13 8:07 AM
Hi,
For example say your internal table name is it_tab and correponding work area is wa_tab,
then you to replace all space by '/' you have to write code as belows.
"Data declarations
DATA: ref_desc TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS:
<comp_wa> TYPE abap_compdescr, "For getting the structure details
<fs> TYPE ANY.
...
...
...
ref_desc ?= cl_abap_typedescr=>describe_by_data( wa_tab ). "Get the structure of work area wa_tab
LOOP AT it_tab INTO wa_tab.
LOOP AT ref_desc->components ASSIGNING <comp_wa>.
ASSIGN COMPONENT <comp_wa>-name OF STRUCTURE wa_tab TO <fs>.
IF <fs> EQ space. "if equals space
<fs> = '/'. "assign '/'
MODIFY it_tab FROM wa_tab TRANSPORTING (<comp_wa>-name). "Modify the table
ENDIF.
ENDLOOP.
ENDLOOP.I checked this is working.
Revert in case of issues.
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Feb 13, 2009 9:08 AM
2009 Feb 13 9:36 AM
Thank u Manoj.....
U'r way of explanation is good............
I got the output..........
Ganesh