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

concatenation-flow logic

Former Member
0 Likes
976

Hi,

Pls give the solution for the below.

i have 5 fields say, qmnum, matnr, plant, name & fecod.

i need to concatenate all the 5 fields, separated by '_'.

it means output should come 'qmnum_matnr_plant_name_fecod'.

But,

if any of the values are empty, it should not come _ _.

for example, if matnr is intial.

output should not come like qmnum_ plantname_fecod.

it should come like qmnum_plant_name_fecod.

Regards,

Venkat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

Hi Venkat,

Rasheed Salmaan has already given the solution.

You can also add condense Z after using Replace All.

This will remove any unwanted spaces.

Condense Z [no-gaps]. Use no-gaps if you do not want even single space between your text.

Regards,

Mohaiyuddin

Hi,

Pls give the solution for the below.

i have 5 fields say, qmnum, matnr, plant, name & fecod.

i need to concatenate all the 5 fields, separated by '_'.

it means output should come 'qmnum_matnr_plant_name_fecod'.

But,

if any of the values are empty, it should not come _ _.

for example, if matnr is intial.

output should not come like qmnum_ plantname_fecod.

it should come like qmnum_plant_name_fecod.

Regards,

Venkat

8 REPLIES 8
Read only

Former Member
0 Likes
949

Hi VEnkat

Try this code.

DATA: x(10) VALUE 'HI', y(10) VALUE 'hru',A(10),B(10) VALUE 'KK', Z(10).

CONCATENATE X Y A B INTO Z SEPARATED BY '_'.

REPLACE ALL OCCURRENCES OF '__' In Z with '_'.

WRITE Z.

Regards

Rasheed

Read only

Former Member
0 Likes
949

Hello,

You want to concatenate fields or values.

If you want to concatenate field values then use

Concatenate statement you will get it.

concatenate wa-qmnum '-' wa-matnr '-' ........... into variable..

Read only

Former Member
0 Likes
950

Hi Venkat,

Rasheed Salmaan has already given the solution.

You can also add condense Z after using Replace All.

This will remove any unwanted spaces.

Condense Z [no-gaps]. Use no-gaps if you do not want even single space between your text.

Regards,

Mohaiyuddin

Read only

Former Member
0 Likes
949

Hi Venkata,

As also said by others do it this way as show below:

DATA:
  char1(5) type c,
  char2(5) type c,
  char3(5) type c,
  char4(5) type c,
  char5(5) type c,
  string   type string.

char1 = 'aaaaa'.
*char2 = 'ddddd'.
char3 = 'ccccc'.
*char4 = 'bbbbb'.
char5 = 'zzzzz'.

Concatenate char1 char2 char3 char4 char5 into string separated by '_'.

Replace all occurrences of '__' in string with '_'.

Write: string.

With luck,

Pritam.

Read only

Former Member
0 Likes
949

CONCATENATE var1 var2 var3 var4 var5 into s_var separated by '_'.

REPLACE ALL OCCURENCES OF '_ ' IN svar BY '_'.

Regards,

Ajay

Read only

Former Member
0 Likes
949

Hello Venkat,

Try to use the below statement after the concatenate.

REPLACE ALL OCCURRENCES OF '_ ' In <your variable> with ''.

Hope it helps.

Thanks,

Jayant

Read only

Former Member
0 Likes
949

Hi Venkata,

I am not sure whether the above posted logic would work for cases where more than 2 consecutive fields are blank. What about when the first field is blank? Maybe you can try with a simple but lengthy if--endif check, like what i have tried below.


DATA:
 matnr TYPE matnr," VALUE '23435',
 plant TYPE plant ,"VALUE 'plant',
 name TYPE name VALUE 'name',
 qmnum TYPE qmnum," VALUE '1234',
 fecod TYPE fecod." VALUE '999'.

IF matnr IS NOT INITIAL AND plant IS NOT INITIAL.
  CONCATENATE matnr plant INTO final SEPARATED BY '_'.
ELSEIF matnr IS NOT INITIAL AND plant IS INITIAL.
  final = matnr.
ELSEIF matnr IS INITIAL AND plant IS NOT  INITIAL.
  final = plant.
ENDIF.

IF final IS NOT INITIAL AND name IS NOT INITIAL.
  CONCATENATE final name INTO final SEPARATED BY '_'.
ELSEIF final IS INITIAL AND name IS NOT INITIAL.
  final = name.
ENDIF.


IF final IS NOT INITIAL AND qmnum IS NOT INITIAL.
  CONCATENATE final qmnum INTO final SEPARATED BY '_'.
ELSEIF final IS INITIAL AND qmnum IS NOT INITIAL.
  final = qmnum.
ENDIF.

IF final IS NOT INITIAL AND fecod IS NOT INITIAL.
  CONCATENATE final fecod INTO final SEPARATED BY '_'.
ELSEIF final IS INITIAL AND fecod IS NOT INITIAL.
  final = fecod.
ENDIF.

WRITE final.

There should be other ways also. Anyway I guess this works too.

Cheers,

Vishnu

Read only

Former Member
0 Likes
949

Hi,

Try like this:

data: v_final type string.

parameters:

matnr TYPE matnr default '23435',

plant TYPE plant default 'plant',

name TYPE name default 'name',

qmnum TYPE qmnum default '1234',

fecod TYPE fecod default '999'.

if matnr is not initial.

if plant is not initial.

if not name is initial.

if not qmnum is initial.

if fecod is not initial.

concatenate matnr plant name qmnum fecod into v_final separated by '_'.

else.

concatenate matnr plant name qmnum into v_final separated by '_'.

endif.

else.

concatenate matnr plant name fecod into v_final separated by '_'.

endif.

else.

concatenate matnr plant qmnum fecod into v_final separated by '_'.

endif.

else.

concatenate matnr name qmnum fecod into v_final separated by '_'.

endif.

else.

concatenate plant name qmnum fecod into v_final separated by '_'.

endif.

write v_final.

Regards,

Bhaskar