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

include space between two variables from internal table

Former Member
0 Likes
1,365

Hi Experts,

I have an internal table with 4 fields with values for a b c d , i have to arrange them in the specific order so that i can download all the data in a text file.

the first 3 variables are already arranged , the format is a bc, but the var d should be put in a specific positon after predefined spaces from var c.

Please refer below for the sample of of the output text file. In this example:

a = A20N

b = 7227802

c = 0300207

d = 010109

Space between c & d is determined by a POS variable in internal table

a b c d

A20N 72278020300207 010109

A20A 72278020300207 21

A20N 72278020300207 2511100

A21F 72278020300207 Van Capellen

A21G 72278020300207 Tim

A20E 72278020300207 1

A20T 72278020300207 2

A20T 72278020300207 1

A20E 72278020300207 01

A20E 72278020300207 Vilvoorde

plz help me out as i have to resolve this as soon as possible.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,121

HI,

How to calculate POS ?

Do you want place each row of internal table in to the string ?

Try using Posotion and Offset this might help you ..

7 REPLIES 7
Read only

Former Member
0 Likes
1,122

HI,

How to calculate POS ?

Do you want place each row of internal table in to the string ?

Try using Posotion and Offset this might help you ..

Read only

0 Likes
1,121

I am not calculating POS , that i have in my internal table . for every variable i have the POS.

plz explain me how to use offset and position.

thanks for reply..

Read only

0 Likes
1,121

Hi,

Check this code..

DATA l_string TYPE char100.
DATA : l_data1 TYPE char4 VALUE 'Test'.
DATA : l_data2 TYPE char10 VALUE '10000'.
DATA l_pos TYPE i VALUE 10.

l_string = l_data1.
l_string+l_pos =  l_data2.  " l_pos is the position value from where l_date2 is started.
WRITE l_string.

Output:
Test      10000

Read only

0 Likes
1,121

hi

thanks a lott...it worked ..

Read only

Former Member
0 Likes
1,121

Why dont you create one more internal table that has all the four a b c d ..

Also it has all three combined in one field in the way you want it to be..

ie using the pos condition determine the space and then concatenate in one variable.

does pos define the space between c and d then you can do this way.

concatenate a b c into e separated by space.
len = strlen( e ).  
len = len + pos.   " this will give the exact offset.
lend = strlen( e ).  " this defines lenght of e
e+len(lend) = d.
write: e.

Now the field e contains your thing to be displayed

Regards,

Lalit Mohan Gupta.

Read only

former_member459142
Participant
0 Likes
1,121

hi

use concatenate like this


date: text(50).
loop at itab. 
CONCATENATE  itab-a  itab-b  itab-c  itab-c  INTO text SEPARATED BY SPACE .
write: text. 
endloop.

it will work

your output will be like this

text = A202 0875467 885548 0098765

Appeciate and give mark if it works

Thanks & Regards

Prashant Gupta

Read only

Former Member
0 Likes
1,121

Hi,

Check this sample code using offsets, and modify as per ur requirement.

DATA : L1 TYPE I.

DATA : L2 TYPE I.

DATA : L3 TYPE I.

DATA : BEGIN OF ITAB OCCURS 0,

A(30) TYPE C,

B(30) TYPE C,

C(30) TYPE C,

D(30) TYPE C,

POS(2) TYPE C,

END OF ITAB.

DATA : TEXT(120) TYPE C.

START-OF-SELECTION.

BREAK-POINT.

ITAB-A = 'ABC'.

ITAB-B = 'IND'.

ITAB-C = 'CATOR'.

ITAB-D = 'FINAL'.

ITAB-POS = '3'.

APPEND ITAB.

CLEAR ITAB.

LOOP AT ITAB.

L1 = STRLEN( ITAB-A ).

L2 = STRLEN( ITAB-B ).

L3 = STRLEN( ITAB-C ).

TEXT = ITAB-A.

L1 = L1 + 1.

TEXT+L1 = ITAB-B.

L1 = L1 + L2.

TEXT+L1 = ITAB-C.

L1 = L1 + L3 + ITAB-POS.

TEXT+L1 = ITAB-D.

CLEAR L1.

CLEAR L2.

CLEAR L3.

ENDLOOP.

WRITE : TEXT.

Rgds

siva