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

Replace empty records in a file

Former Member
0 Likes
1,467

Hi experts,

I am generating a file trough an abap program. I am retrieving my records in a BW infocube (to simplify let's say a SAP table).

The issue is that empty information are generated as ‘#’ in my file. I would like to suppress all ‘#” from my file which contains 5 columns.

The file today is like this:

Field A

Field B

Field C

Field D

Field E

A

AA

AAA

AAAA

20

B

BB

BBB

#

55

What I would lik to do is this:

Field A

Field B

Field C

Field D

Field E

A

AA

AAA

AAAA

20

B

BB

BBB

55

I don’t know if in abap there exit something like this (i am also looking for a performant statement because my file may contain too much records):


Loop at all columns of the file
REPLACE ALL OCCURRENCES OF '#'  WITH ' '. .
ENDLOOP.


Thanks for your advices.

Amine

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,440

Use field symbols during LOOP, and as BW set the field to # for initial values, don't use a CPU consuming statement like REPLACE but check for each subfield values.

LOOP AT itab ASSIGNING <record>.
   DO 5 TIMES.
     ASSIGN COMPONENT sy-index OF STRUCTURE <record> TO <fs>.
     IF <fs> EQ '#'.
       CLEAR <fs>.
     ENDIF.
   ENDDO.
ENDLOOP.


Regards,

Raymond

Hi experts,

I am generating a file trough an abap program. I am retrieving my records in a BW infocube (to simplify let's say a SAP table).

The issue is that empty information are generated as ‘#’ in my file. I would like to suppress all ‘#” from my file which contains 5 columns.

The file today is like this:

Field A

Field B

Field C

Field D

Field E

A

AA

AAA

AAAA

20

B

BB

BBB

#

55

What I would lik to do is this:

Field A

Field B

Field C

Field D

Field E

A

AA

AAA

AAAA

20

B

BB

BBB

55

I don’t know if in abap there exit something like this (i am also looking for a performant statement because my file may contain too much records):


Loop at all columns of the file
REPLACE ALL OCCURRENCES OF '#'  WITH ' '. .
ENDLOOP.


Thanks for your advices.

Amine

13 REPLIES 13
Read only

former_member210266
Active Participant
0 Likes
1,440

Hi Amine

You can use REPLACE ALL OCCURRENCE IN TABLE command

Regards

Swati

Read only

gouravkumar64
Active Contributor
0 Likes
1,440

Hi,

As # is some garbage character.

You can try like this with this class .

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf in text with space.

There are few thread on this,search also.

Thanks

Gourav.


Read only

Former Member
0 Likes
1,440

Hi Amine,

The coding works fine in ABAP but here the # is coming while display in Excel.

Even if you write code in Customer Exit will not work.

Read only

0 Likes
1,440

Hi Sai,

Actually, when i consult my file in AL11, the '#" occurences are already present...

Amine

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,441

Use field symbols during LOOP, and as BW set the field to # for initial values, don't use a CPU consuming statement like REPLACE but check for each subfield values.

LOOP AT itab ASSIGNING <record>.
   DO 5 TIMES.
     ASSIGN COMPONENT sy-index OF STRUCTURE <record> TO <fs>.
     IF <fs> EQ '#'.
       CLEAR <fs>.
     ENDIF.
   ENDDO.
ENDLOOP.


Regards,

Raymond

Read only

0 Likes
1,440

Hi Raymond,

Thank you for your answer.

What would be <record>? Table/Column..... How should i declare it?

And  <fs> i guess it's field symbol.How do you advice me to declare it? (type all?)

Thanks.

Amine

Read only

0 Likes
1,440

Both Field symbols,for <FS> TYPE ANY, for <RECORD>, eithe ANY or actual type.

Regards,

Raymond

Read only

0 Likes
1,440

Ok thanks. I will let you know after my tests on the system.

Amine

Read only

0 Likes
1,440

Hi Raymond,

I have a question regarding the statment : DO 5 times

It's because i have 5 columns, right?

Amine

Read only

0 Likes
1,440

Yes, you could also use RTTI tools (like class CL_ABAP_TYPEDESCR) to calculate number of sub-fields for a more generic tool.

Regards,

Raymond

Read only

0 Likes
1,440

Ok thanks for your explanations.

Amine

Read only

Clemenss
Active Contributor
0 Likes
1,440

This really scares me: I don't know where is documentation for this: In SAP, # usually means the character can not be displayed because it is a control character like tab, newline etc.

Please use debugger, check hexadecimal value of what looks like # and replace using CL_ABAP_CHAR_UTILITIES attributes, i.e. HORIZONTAL_TAB, VERTICAL_TAB, NEWLINE, CR_LF, FORM_FEED or BACKSPACE.

Regards

Clemens

Read only

Former Member
0 Likes
1,440

Thx Clemens for your advice.

Amine