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: 

Binary addition on ABAP

Former Member
0 Kudos

Hi,

I need a way to simulate binary addition on abap: example

000

001

010

011

100

so if i add 1, then the next value is 101. the lenght would also vary from 2 to 8.

ex. 2

00

01

10

11

I would need this for mass uploading the release statuses for PO. i would use this as an internal table to finaly map it on T16FK (Release statuses)

3 REPLIES 3

former_member182010
Active Participant
0 Kudos

Hello c z,

See Code below.

Kind Regards,

Rae Ellen Woytowiez



 REPORT  zbinary_addition.

DATA:  offset TYPE i,
       power TYPE i.

DATA:  inc TYPE i.

DATA:  help_base10 TYPE i,
       answer_binary(8) TYPE n,
       temp_power TYPE i.

DATA:  wa_t16fk TYPE t16fk.

START-OF-SELECTION.

  inc = 1.

  WHILE inc <= 255.
*
* Convert decimal number to binary.
    answer_binary = '000000000'.

    offset = 0.
    power = 7.
    temp_power = 2 ** power.

    help_base10 = inc.
    WHILE help_base10 > 0.
      IF help_base10 >= temp_power.
        answer_binary+offset(1) = '1'.
        help_base10 = help_base10 - temp_power.
      ENDIF.
      IF help_base10 > 0.
        power = power - 1.
        offset = offset + 1.
        temp_power = 2 ** power.
      ENDIF.
    ENDWHILE.


    wa_t16fk-FRGA1 = answer_binary(1).
    wa_t16fk-FRGA2 = answer_binary+1(1).
    wa_t16fk-FRGA3 = answer_binary+2(1).
    wa_t16fk-FRGA4 = answer_binary+3(1).
    wa_t16fk-FRGA5 = answer_binary+4(1).
    wa_t16fk-FRGA6 = answer_binary+5(1).
    wa_t16fk-FRGA7 = answer_binary+6(1).
    wa_t16fk-FRGA8 = answer_binary+7(1).


    inc = inc + 1.
  ENDWHILE.



Edited by: Rae Ellen Woytowiez on Apr 8, 2011 4:53 PM

Edited by: Rae Ellen Woytowiez on Apr 8, 2011 4:55 PM

0 Kudos

amazing! I don't pretend to understand all of this but it is enough for me to have it modified to fit my code. thanks!

Former Member
0 Kudos

thanks!