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

Assign a / to an empty field of an internl table.

Former Member
0 Kudos
2,197

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Kudos
1,239

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

8 REPLIES 8
Read only

Former Member
0 Kudos
1,239

REPLACE ALL OCCURRENCES OF ' S '

IN TABLE wt_FM WITH '/'.

Read only

0 Kudos
1,239

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...

Read only

Former Member
0 Kudos
1,239

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

Read only

BH2408
Active Contributor
0 Kudos
1,239

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

Read only

Former Member
0 Kudos
1,239

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

Read only

Former Member
0 Kudos
1,239

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.

Read only

Former Member
0 Kudos
1,240

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

Read only

0 Kudos
1,239

Thank u Manoj.....

U'r way of explanation is good............

I got the output..........

Ganesh