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

Blank Fields while concatenating

Former Member
0 Likes
2,252

Hi all,

I have a requirement wherein I have to concatenate some fields to get my new concatenated field.There are some blank records in the table i m taking data from.say like this

Columns: A B C D

DATA: 23 bhd g56

Column C is blank in this case n I want to concatenate A,B,C and D seperated by '-'

Now after concatenation output is 23-bhd--g56

I dnt want hyphen to cm for blank fields aswell

sud cm like this 2-bhd-g56

Is it possible?

1 ACCEPTED SOLUTION
Read only

former_member210123
Active Participant
0 Likes
1,934

add this statement after concatenate.

REPLACE ALL OCCURRENCES OF '--' IN:

text1 WITH '-'.

This will solve your problem.

11 REPLIES 11
Read only

former_member210123
Active Participant
0 Likes
1,935

add this statement after concatenate.

REPLACE ALL OCCURRENCES OF '--' IN:

text1 WITH '-'.

This will solve your problem.

Read only

0 Likes
1,934

Hi Bharath,

This will work if there is only one fields missing but wat if we two missing filds in continuation?

Read only

0 Likes
1,934

REPLACE ALL OCCURRENCES OF '--*' IN:

text1 WITH '-'

This will work.

Read only

0 Likes
1,934

After replace occurences statement use

CONDENSE text NO-GAPS.

Read only

0 Likes
1,934

It is working fine for previous replace code.but if i give '--*' it is not working for any of them

Read only

0 Likes
1,934

Hi,

Hope it will solve yer prob.

while sy-subrc = 0.

REPLACE ALL OCCURRENCES OF '--' IN text WITH '-'.

endwhile.

Read only

0 Likes
1,934

Thanx Shameem,it worked:)

one silly question- wat exactly sy-subrc does?

Read only

0 Likes
1,934

Hi,

It checks whether expression or statement or condition is successful or not

Return value set by the following ABAP statements. In general, a content of 0 means that the statement was executed without problems.

Read only

asik_shameem
Active Contributor
0 Likes
1,934

Hi,

before concatenating, check c is initial or not.

IF NOT c IS INITIAL.
  CONCATENATE A B C D INTO NEW SEPARATED BY '-'.
ELSE.
    CONCATENATE A B D INTO NEW SEPARATED BY '-'.
ENDIF.

Read only

Former Member
0 Likes
1,934

Hi deepika...

Write the below code..

if a = space.

then do..

concatenate b '-' c '-' d .

endif.

if b = space.

then do..

concatenate a '-' c '-' d .

endif.

if c = space.

then do..

concatenate a '-'b '-' d .

endif.

if d = space.

then do..

concatenate a '-' b '-' c.

endif.

reward points always gives motivation....

Read only

former_member156446
Active Contributor
0 Likes
1,934

Hi Deepika if you ABCD are the coulmns of internal table

you can use the code below:


LOOP AT p_final_table ASSIGNING <fs_record>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
lf_buf = <fs_comp>.
CLEAR lf_buf.
ENDDO.
if not A is initial and not B is initial and not C is initial  "<<<<<< look
CONCATENATE lf_line co_line_feed INTO lf_line sperated by '-'.

hope its helpful...

Edited by: Jackandjay on Mar 31, 2008 2:41 AM