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: 

Internal table value access

Former Member
0 Kudos
159

Dear all,

I have a requirement mentioned below.

I have a internal table with columns

ZPER1

ZOPR2

ZOPR3.......TO ZOPR50

I want to concatenate all fields 1 to 50 in string. I want to avoid writting this 50 fields.

Is there any way we can do this?

Regards,

Vinit

1 ACCEPTED SOLUTION

Former Member
0 Kudos
108

Hi,

You can use field symbols, like:

DATA: W_TEXT(1000),
      W_IDX TYPE I,
      W_NN(2) TYPE C.

FIELD-SYMBOLS: <FS> TYPE ANY.

W_IDX = 1.
WHILE W_IDX<51.
   W_NN = W_IDX.
   W_XX = 'ZOPER'.
   ASSIGN (W_XX) TO <FS>.
   CONCATENATE W_TEXT <FS> INTO W_TEXT.
   W_IDX = W_IDX + 1.
ENDWHILE.

Best regards,

Leandro Mengue

9 REPLIES 9

Former Member
0 Kudos
108

Hi,

DATA: BEGIN OF DATA_TAB,
        ZPER1
...
        ZOPR50
      END OF DATA_TAB.

DATA: W_TEXT(1000) TYPE C.

...fill your fields and:

W_TEXT = DATA_TAB.

Best regards,

Leandro Mengue

0 Kudos
108

Hi,

Thanks for u r reply.

The problem is I have other fields in my internal table as well other that 1 to 50 which i do not wish to concatenate.

0 Kudos
108

Hi,

You may use also:

DATA: BEGIN OF DATA_TAB,
        FIELD1
...
        ZOPR1
...
        ZOPR50
      END OF DATA_TAB.
 
DATA: W_TEXT(1000) TYPE C,
      W_POS TYPE I,
      W_TAM TYPE I.
 
...fill your fields and:

DESCRIBE DISTANCE BETWEEN DATA_TAB-FIELD1 AND DATA_TAB-ZOPER1 INTO W_POS IN BYTE MODE.

W_TAM = 50 * 4.   " => adjust 4 to the size of zopr1.
 
W_TEXT = DATA_TAB+W_POS(W_TAM).

Best regards,

Leandro Mengue

0 Kudos
108

Really sorry,

Missed out on one point.

I want to concatenate separated by comma.

0 Kudos
108

Thanks looks like Field symbol shoud work.

0 Kudos
108

Hi,

No problem:

CONCATENATE W_TEXT <FS> ';' INTO W_TEXT.

Best regards,

Leandro Mengue

Former Member
0 Kudos
109

Hi,

You can use field symbols, like:

DATA: W_TEXT(1000),
      W_IDX TYPE I,
      W_NN(2) TYPE C.

FIELD-SYMBOLS: <FS> TYPE ANY.

W_IDX = 1.
WHILE W_IDX<51.
   W_NN = W_IDX.
   W_XX = 'ZOPER'.
   ASSIGN (W_XX) TO <FS>.
   CONCATENATE W_TEXT <FS> INTO W_TEXT.
   W_IDX = W_IDX + 1.
ENDWHILE.

Best regards,

Leandro Mengue

0 Kudos
108

Hi,

What is use of W_NN in your code? How I will change ZOPER1 then 2....to 50?

0 Kudos
108

Hi,

Sorry, change this:

W_XX = 'ZOPER'.

by

CONCATENATE 'ZOPER' W_NN INTO W_XX.

Best regards,

Leandro Mengue