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: 

Separating Data

Former Member
0 Kudos

Hi,

I am a new to ABAP. I will really appreciate if someone can help me out.

DATA: A1 like I_ALLOCATION_TAB-OBJEK.

WRITE:/ A1.

Now the value of A1 is 00000000000000079720100000000147

Actually there are three datas in this one value.

Value One: 797

Vlaue Two: 2010

Value Three:147

I want to separate these three data in three different variables.

How do I do it ? Is there some offset concept I have to use ?

If yes then how do we do it ?

Please help me out.

Thanks in advance

Tushar

3 REPLIES 3

Former Member
0 Kudos

If you are biforcating based on the positions, then it is real easy. Define a structure with three fields - assign A1 to that and you can write the structure fields

Data: begin of a2,

v1(18),

v2(04),

v3(10),

end of a2.

a2 = A1.

Write: a2-v1,

a2-v2,

a2-v3.

Got the idea

Regards

ssimsekler
Active Contributor
0 Kudos

Hi Tushar

You can use offset and length options as follows:

DATA lv_str TYPE string .
 
lv_str = 'hello, how are you today' .
write:/ lv_str+7 ,
      / lv_str+7(3) ,
      / lv_str(7) .

The output should be:

how are you today

how

hello,

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Former Member
0 Kudos

Hi Tushar,

There is an offset concpet in ABAP. And Serdar's example explains it. But generally, it is not a very generic approach to follow. The reason is simple that you are hardcoding the length and offset values. When somebody looks at the code, they might not have a clue as to why these offsets are being used with these values.

Now, you have not mentioned what table you are getting the data from. But it appears that this OBJEK is some kind of an Object Key. In most case, according to the context of your application we would know beforehand what are all the values that this Object Key will give us. With this knowledge, it is best to have a field string (as suggested by Pramod) which would tell you what values we have for what fields. Consider the following example -

Let us say I'm fetching data from a database table XYZ, which has this field OBJEK. Now in my contaxt, this OBJEK should give me the values of the customers' sales areas. I would have a field string which would be defined something like this -

data : begin of objek,
         kunnr type kunnr,
         vkorg type vkorg,
         vtweg type vtweg,
         spart type spart,
       end of objek.

My SELECT query would look something like this -

SELECT OBJEK
  INTO OBJEK
  FROM XYZ.
  WRITE : / OBJEK-KUNNR,
            OBJEK-VKORG,
            OBJEK-VTWEG,
            OBJEK-SPART.
ENDSELECT.

Now if you look at OBJEK as a whole, it would smply be a string of 18 characters. The fact that the first 10 characters are actually the customer number, the next 4 are the sales organization, the next tow are the distribution channel and the last two are the division, is not really apparent without the definition of the field string (or a <i>structure</i> as somw would prefer to call it).

Hope I have been able to make some sense.

Regards,

Anand Mandalika.