Skip to content

Instantly share code, notes, and snippets.

@larshp
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larshp/505fd0118bf538878227 to your computer and use it in GitHub Desktop.
Save larshp/505fd0118bf538878227 to your computer and use it in GitHub Desktop.
Permutations
METHOD permute.
DATA: lv_length TYPE i,
lv_value TYPE i,
lt_perm LIKE LINE OF et_perm,
lt_new LIKE LINE OF et_perm.
DO iv_count TIMES.
CLEAR lt_perm.
APPEND sy-index TO lt_perm.
APPEND lt_perm TO et_perm.
ENDDO.
DO iv_count - 1 TIMES.
lv_length = sy-index + 1.
LOOP AT et_perm INTO lt_perm.
IF lines( lt_perm ) <> lv_length - 1.
CONTINUE.
ENDIF.
DO iv_count TIMES.
lt_new = lt_perm.
lv_value = sy-index.
READ TABLE lt_new FROM lv_value TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
APPEND lv_value TO lt_new.
APPEND lt_new TO et_perm.
ENDIF.
ENDDO.
ENDLOOP.
ENDDO.
ENDMETHOD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment