Application Development 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: 

Dynamic Concat

Former Member
0 Kudos

Hi all

i need to concat the field in the table? Below is my code

My ZSTUDGARY table contain admino, fname, lname field.

How to convert:

CONCATENATE <b>it_vbak-admino it_vbak-fname it_vbak-lname</b> into val

SEPARATED BY space.

to

CONCATENATE <b>it_vbak-field1 it_vbak-field2 it_vbak-field3</b> into val

SEPARATED BY space.

REPORT ZGARY_CONCAT1.

DATA: val type string.

PARAMETERS:field1(30).

PARAMETERS:field2(30).

PARAMETERS:field3(30).

TABLES: ZSTUDGARY.

DATA: it_vbak TYPE TABLE OF ZSTUDGARY WITH HEADER LINE,

wa_fld(72) TYPE C,

it_fldtab LIKE TABLE OF wa_fld.

if field1 <> ''.

append field1 to it_fldtab.

endif.

if field2 <> ''.

append field2 to it_fldtab.

endif.

if field3 <> ''.

append field3 to it_fldtab.

endif.

SELECT (it_fldtab)

INTO CORRESPONDING FIELDS OF TABLE it_vbak

FROM ZSTUDGARY.

IF SY-SUBRC = 0.

LOOP AT it_vbak.

CONCATENATE <b>it_vbak-admino it_vbak-fname it_vbak-lname</b> into val

SEPARATED BY space.

write:/ val.

ENDLOOP.

ENDIF.

4 REPLIES 4

former_member200338
Active Contributor
0 Kudos

Hi,

Try this.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

langu = sy-langu

tabname = 'ZSTUDGARY'

TABLES

nametab = i_nametab.

LOOP AT i_nametab INTO w_nametab .

concatenate val w_nametab-fieldname into val separated by space.

endloop.

Try to restrict the field based on conditions.

Reward point if usefull

Regards,

Niyaz

0 Kudos

Can you help me to put inside my code. The code can gt from the previous post

. Advance thank!

former_member200338
Active Contributor
0 Kudos

REPORT ZGARY_CONCAT1.

DATA: val type string.

PARAMETERS:field1(30).

PARAMETERS:field2(30).

PARAMETERS:field3(30).

TABLES: ZSTUDGARY.

DATA: it_vbak TYPE TABLE OF ZSTUDGARY WITH HEADER LINE,

wa_fld(72) TYPE C,

it_fldtab LIKE TABLE OF wa_fld.

DATA : i_nametab TYPE TABLE OF dntab, " <b>NEW CODE</b>

w_nametab TYPE dntab. <b>" NEW CODE</b>

if field1 <> ''.

append field1 to it_fldtab.

endif.

if field2 <> ''.

append field2 to it_fldtab.

endif.

if field3 <> ''.

append field3 to it_fldtab.

endif.

SELECT (it_fldtab)

INTO CORRESPONDING FIELDS OF TABLE it_vbak

FROM ZSTUDGARY.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

langu = sy-langu

tabname = 'ZSTUDGARY'

TABLES

nametab = i_nametab.

IF SY-SUBRC = 0.

LOOP AT i_nametab INTO w_nametab .

concatenate val w_nametab-fieldname into val separated by space.

endloop.

Write: val.

write:/ sy-uline.

LOOP AT it_vbak.

clear val.

CONCATENATE it_vbak-admino it_vbak-fname it_vbak-lname into val

SEPARATED BY space.

write:/ val.

ENDLOOP.

ENDIF.

The output will be like this

admino fname lname

-


10 xxx yyy

Regards,

Niyaz

Please award points for all usefull answers...

0 Kudos

sorry think u gt me wrong

i want to display the concat record out base on the seq order of the parameter value

field1 -


lname

field2----


admino

field3----


fname

if the user specify the above

after the concat

the result gt is : <b>gary 1234 yip</b>

This is the result i want

but now the result i gt is: <b>123 yip gary</b>

This follow the table seq after the concat which i dont want.

Below is my code. Thks advance for amending the code

REPORT ZGARY_CONCAT1.

DATA: val type string.

PARAMETERS:field1(30).

PARAMETERS:field2(30).

PARAMETERS:field3(30).

TABLES: ZSTUDGARY.

DATA: it_vbak TYPE TABLE OF ZSTUDGARY WITH HEADER LINE,

wa_fld(72) TYPE C,

it_fldtab LIKE TABLE OF wa_fld.

if field1 <> ''.

append field1 to it_fldtab.

endif.

if field2 <> ''.

append field2 to it_fldtab.

endif.

if field3 <> ''.

append field3 to it_fldtab.

endif.

SELECT (it_fldtab)

INTO CORRESPONDING FIELDS OF TABLE it_vbak

FROM ZSTUDGARY.

IF SY-SUBRC = 0.

LOOP AT it_vbak.

<b>CONCATENATE it_vbak-admino it_vbak-fname it_vbak-lname into val

SEPARATED BY space.</b>

write:/ val.

ENDLOOP.

ENDIF.