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: 

unpack command

Former Member
0 Kudos
5,764

hai guru's....

can u send me some material on unpack command ...and also can send me the definition and where we actulally use it...

Thnaks

PAvan

1 ACCEPTED SOLUTION

Former Member
0 Kudos
696

Syntax

<b>UNPACK source TO destination.</b>

<b>This statement converts the content of the data object source according to a specific rule and assigns the converted content to data object destination. For source, the data type p of length 16 without decimal places is expected. The data type of destination must be character-type and flat.</b>

<b>The conversion is performed according to the following rules:</b>

If the data type of source is not of the type p with length 16 and without decimal places, then the content of source is converted to this data type. Contrary to the rules described in conversion rules for elementary data types, any decimal separator in source is completely ignored.

The digits of the interim result are assigned to data object destination right-aligned and without <b>+/-</b> sign. Any additional places in destination are filled with leading zeros. If the length of destination is not sufficient, the assigned variable is truncated from the left.

DATA: pack  TYPE p LENGTH 8 DECIMALS 3 VALUE '123.456', 
      char1 TYPE c LENGTH 10, 
      char2 TYPE c LENGTH 10. 

MOVE   pack TO char1. 
UNPACK pack TO char2.

<b>output will be :</b>

char1 -> "123.456"

char2 -> "0000123456

reward points if it is usefull ....

Girish

4 REPLIES 4

Former Member
0 Kudos
696

Hi Pavan,

<b> UNPACK</b>

Converts type P variables to type C.

<b>Syntax</b>

UNPACK <f> TO <g>.

Unpacks the packed field <f> and places it in the string <g> with leading zeros. This can be reversed with the PACK statement.(The opposite of PACK).

So what is PACK :

<b>PACK</b>

Converts type C variables into type P.

<b>

Syntax</b>

PACK <f> TO <g>.

Packs the string <f> and places it in the field <g>. This can be reversed with the UNPACK statement.

<b>UNPACK</b>

Unpacks the packed field f and places it in the field g with leading zeros. If g is too short, it is truncated on the left.

Example

DATA: P_FIELD(2) TYPE P VALUE 103,

C_FIELD(4) TYPE C.

UNPACK P_FIELD TO C_FIELD.

WRITE: / C_FIELD.

unpack command is used to remove the sign from a packed variable and appends zeroes in the left.like unpack p1(-2.5) to c1(length 6)..c1 will be 000025.

<b>Reward pts if found usefull :)</b>

Regards

Sathish

Former Member
0 Kudos
697

Syntax

<b>UNPACK source TO destination.</b>

<b>This statement converts the content of the data object source according to a specific rule and assigns the converted content to data object destination. For source, the data type p of length 16 without decimal places is expected. The data type of destination must be character-type and flat.</b>

<b>The conversion is performed according to the following rules:</b>

If the data type of source is not of the type p with length 16 and without decimal places, then the content of source is converted to this data type. Contrary to the rules described in conversion rules for elementary data types, any decimal separator in source is completely ignored.

The digits of the interim result are assigned to data object destination right-aligned and without <b>+/-</b> sign. Any additional places in destination are filled with leading zeros. If the length of destination is not sufficient, the assigned variable is truncated from the left.

DATA: pack  TYPE p LENGTH 8 DECIMALS 3 VALUE '123.456', 
      char1 TYPE c LENGTH 10, 
      char2 TYPE c LENGTH 10. 

MOVE   pack TO char1. 
UNPACK pack TO char2.

<b>output will be :</b>

char1 -> "123.456"

char2 -> "0000123456

reward points if it is usefull ....

Girish

Former Member
0 Kudos
696

Hi Pavan,

Let me share some p[oints with you.

Unpacks the packed field f and places it in the field g with leading zeros. If g is too short, it is truncated on the left.

The following is the example forUNPACK command.

UNPACK report_tab1-vbeln TO report_tab1-vbeln.

Hope this helps you. Reply for queries, shall post the updates.

Regards.

Kumar.

Former Member
0 Kudos
696

Hi Pavan,

Let me share some p[oints with you.

Unpacks the packed field f and places it in the field g with leading zeros. If g is too short, it is truncated on the left.

The following is the example forUNPACK command.

UNPACK report_tab1-vbeln TO report_tab1-vbeln.

Hope this helps you. Reply for queries, shall post the updates.

Regards.

Kumar.