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: 

Look up for value in the set

Former Member
0 Kudos

Hello

there is a set for GL accounts

group sign option low high

1 I EQ 11

1 I BT 17 33

2 I EQ 55

2 I EQ 66

2 I BT 77 80

I have to populate each GL account with its group from the set.

GL account group

11 1

78 2

What is the best ABAP approach to do it? shall I create multiple ranges (one range for each group)?

I would like it to be very flexible and independent on the number of groups.

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Check the below code for an approach to your problem. You can enhance the logic by deleting the set from LT_GLSET once we move to next set only if all the GL accounts are retrieved based on set values and if all the GL accounts are in ascending along with the sets.


DATA lr_range TYPE RANGE OF hkont.
DATA ls_range LIKE LINE OF lr_range.

DATA: BEGIN OF ls_glset,
        set   TYPE i,
        range LIKE lr_range,
      END OF ls_glset.

DATA lt_glset LIKE STANDARD TABLE OF ls_glset.

* Sample code the way LT_GLSET is populated for group 1
  CLEAR: ls_glset, ls_glset-range[].
  ls_glset-set = 1.

  CLEAR: ls_range, lr_range[].
  ls_range-sign = 'I'.
  ls_range-option = 'EQ'.
  ls_range-low = '11'.
  APPEND ls_range TO lr_range.
  ls_range-sign = 'I'.
  ls_range-option = 'BT'.
  ls_range-low = '17'.
  ls_range-low = '33'.
  APPEND ls_range TO lr_range.
  ls_glset-range = lr_range.
  APPEND ls_glset TO lt_glset.
....
* Sample code to get the set from GL
  LOOP AT lt_data INTO ls_data.
    LOOP AT lt_glset INTO ls_glset.
      IF ls_data-hkont IN ls_glset-range.
* G/L Set will be in ls_glset-set
        EXIT.
      ENDIF.
    ENDLOOP.

  ENDLOOP.

1 REPLY 1

Former Member
0 Kudos

Check the below code for an approach to your problem. You can enhance the logic by deleting the set from LT_GLSET once we move to next set only if all the GL accounts are retrieved based on set values and if all the GL accounts are in ascending along with the sets.


DATA lr_range TYPE RANGE OF hkont.
DATA ls_range LIKE LINE OF lr_range.

DATA: BEGIN OF ls_glset,
        set   TYPE i,
        range LIKE lr_range,
      END OF ls_glset.

DATA lt_glset LIKE STANDARD TABLE OF ls_glset.

* Sample code the way LT_GLSET is populated for group 1
  CLEAR: ls_glset, ls_glset-range[].
  ls_glset-set = 1.

  CLEAR: ls_range, lr_range[].
  ls_range-sign = 'I'.
  ls_range-option = 'EQ'.
  ls_range-low = '11'.
  APPEND ls_range TO lr_range.
  ls_range-sign = 'I'.
  ls_range-option = 'BT'.
  ls_range-low = '17'.
  ls_range-low = '33'.
  APPEND ls_range TO lr_range.
  ls_glset-range = lr_range.
  APPEND ls_glset TO lt_glset.
....
* Sample code to get the set from GL
  LOOP AT lt_data INTO ls_data.
    LOOP AT lt_glset INTO ls_glset.
      IF ls_data-hkont IN ls_glset-range.
* G/L Set will be in ls_glset-set
        EXIT.
      ENDIF.
    ENDLOOP.

  ENDLOOP.