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

Splitting DEC values

Former Member
0 Likes
350

Hello ,

I have a DEC variable initialised with time in the form hhmmss.

I want to be able to split it every 2 digits .

I dont want to use logic  DEC+2(2)  because it doesnt suit my needs.

Is there any other possiblity for this ??

Thanks and Regards

Shubhendu

1 ACCEPTED SOLUTION
Read only

former_member16322
Participant
0 Likes
323

Could you use MOD and integer division to split?

For example:

DATA:

   g_result TYPE n LENGTH 2

  .

g_result = g_var MOD 100 .

This should return the last 2 digits.

DATA:

  g_result2 TYPE n LENGTH 4

.

g_result2 = g_var MOD 10000 . "Gets last 4 digits

g_result = g_result DIV 100 . " Gets First 2 Digits of Last 4 Digits.

Would this work?

Edit - g_result would need to be declared longer then length 2 for second example. Fixing that.

Edit 2 - Attaching Code example that illustrates.

TYPES:

   BEGIN OF gts_time,

     hour TYPE n LENGTH 2,

     min  TYPE n LENGTH 2,

     sec  TYPE n LENGTH 2,

   END   OF gts_time

   .

DATA:

   gs_time  TYPE gts_time,

   g_time   TYPE DECFLOAT34,

   g_result TYPE n LENGTH 4

   .

START-OF-SELECTION .

   g_time = 123456 .

   g_result = g_time MOD 10000 .

   gs_time-min = g_result DIV 100 .

   gs_time-hour = g_time DIV 10000 .

   gs_time-sec = g_time MOD 100 .

   WRITE:

     gs_time-hour, ':', gs_time-min, ':', gs_time-sec

     .

1 REPLY 1
Read only

former_member16322
Participant
0 Likes
324

Could you use MOD and integer division to split?

For example:

DATA:

   g_result TYPE n LENGTH 2

  .

g_result = g_var MOD 100 .

This should return the last 2 digits.

DATA:

  g_result2 TYPE n LENGTH 4

.

g_result2 = g_var MOD 10000 . "Gets last 4 digits

g_result = g_result DIV 100 . " Gets First 2 Digits of Last 4 Digits.

Would this work?

Edit - g_result would need to be declared longer then length 2 for second example. Fixing that.

Edit 2 - Attaching Code example that illustrates.

TYPES:

   BEGIN OF gts_time,

     hour TYPE n LENGTH 2,

     min  TYPE n LENGTH 2,

     sec  TYPE n LENGTH 2,

   END   OF gts_time

   .

DATA:

   gs_time  TYPE gts_time,

   g_time   TYPE DECFLOAT34,

   g_result TYPE n LENGTH 4

   .

START-OF-SELECTION .

   g_time = 123456 .

   g_result = g_time MOD 10000 .

   gs_time-min = g_result DIV 100 .

   gs_time-hour = g_time DIV 10000 .

   gs_time-sec = g_time MOD 100 .

   WRITE:

     gs_time-hour, ':', gs_time-min, ':', gs_time-sec

     .