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: 

offsets into hex string

Former Member
0 Kudos

Currently I am trying to concatenate multiple hex values from a tvarv into a single string. To do this I am trying to dynamically tell the code to write the values in specific positions but when I try to do this the compiler throws a warning that this is obsolete functionality and the debugger is showing value l_low(l_displace) below becomes l_low0. How do I pass a dynamic value to the offset?

DATA: l_low_temp(2000) type x,

l_low(2000) type x,

l_hex_tvarv(8) type x,

l_displace type i.

DATA: BEGIN OF lt_tvarv OCCURS 0,

low LIKE tvarv-low,

END OF lt_tvarv.

CLEAR: lt_tvarv, l_low_temp, l_low.

REFRESH: lt_tvarv.

SELECT low

INTO TABLE lt_tvarv

FROM tvarv

WHERE name = 'Z_EXCLUDE_HEX'.

DESCRIBE TABLE lt_tvarv LINES sy-tabix.

IF sy-tabix > 0.

LOOP AT lt_tvarv.

l_displace = ( sy-tabix - 1 ) * 4.

l_hex_tvarv = lt_tvarv-low(4).

IF sy-tabix = 1.

l_low = l_hex_tvarv.

ELSE.

l_low+(l_displace) = l_hex_tvarv.

ENDIF.

ENDLOOP.

ENDIF.

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Instead of

DESCRIBE TABLE lt_tvarv LINES sy-tabix.

IF sy-tabix > 0.

LOOP AT lt_tvarv.

l_displace = ( sy-tabix - 1 ) * 4.

l_hex_tvarv = lt_tvarv-low(4).

IF sy-tabix = 1.

l_low = l_hex_tvarv.

ELSE.

l_low+(l_displace) = l_hex_tvarv.

ENDIF.

ENDLOOP.

ENDIF.

...try this:


if lt_tvarv[ ] is not initial.
loop at lt_tvarv.
l_displace = (sy-tabix - 1)*4.     
"first loop = 0, second = 4, thrird = 8 and so on

l_low+l_displace(4) = lt_tvarv-low+l_displace(4).     
"first loop l_low+0(4) = lt_trvav-low+0(4).   "zero here is allowed
"second     l_low+4(4) = lt_trvav-low+4(4).
"third      l_low+8(4) = lt_trvav-low+8(4).
...
endloop.
endif.

2 REPLIES 2

MarcinPciak
Active Contributor
0 Kudos

Instead of

DESCRIBE TABLE lt_tvarv LINES sy-tabix.

IF sy-tabix > 0.

LOOP AT lt_tvarv.

l_displace = ( sy-tabix - 1 ) * 4.

l_hex_tvarv = lt_tvarv-low(4).

IF sy-tabix = 1.

l_low = l_hex_tvarv.

ELSE.

l_low+(l_displace) = l_hex_tvarv.

ENDIF.

ENDLOOP.

ENDIF.

...try this:


if lt_tvarv[ ] is not initial.
loop at lt_tvarv.
l_displace = (sy-tabix - 1)*4.     
"first loop = 0, second = 4, thrird = 8 and so on

l_low+l_displace(4) = lt_tvarv-low+l_displace(4).     
"first loop l_low+0(4) = lt_trvav-low+0(4).   "zero here is allowed
"second     l_low+4(4) = lt_trvav-low+4(4).
"third      l_low+8(4) = lt_trvav-low+8(4).
...
endloop.
endif.

Former Member
0 Kudos

Was able to get it to work this way...

SELECT low

INTO TABLE lt_tvarv

FROM tvarv

WHERE name = 'Z_EXCLUDE_HEX'.

DESCRIBE TABLE lt_tvarv LINES sy-tabix.

IF sy-tabix > 0.

LOOP AT lt_tvarv.

  • Note: number of characters will be 8 even through number of bytes

  • to shift will be 4. Confirmed this via debugging.

l_displace = ( sy-tabix - 1 ) * 4. "shifting number of bytes

l_hex_tvarv = lt_tvarv-low(8). " characters to add.

  • First record

IF sy-tabix = 1.

l_low = l_hex_tvarv.

ELSE. " additional records

l_low+l_displace = l_hex_tvarv.

ENDIF.

ENDLOOP.