Fill range table from itab using LET

32,524

Solution 1

You can declare macro utilizing your declared structures like this:

DEFINE range.
 lr_vkorg = VALUE lr_range_t( BASE lr_vkorg ( sign = 'I' option = 'EQ' low = &1 ) ).
END-OF-DEFINITION.

And then fill your ranges with this one-liner:

range: '1100', '1200', '1300', '1400', '1500', '1600'.

If we speak about filling range from itab, use this statement:

lr_vkorg = VALUE #( FOR ls_vkorg IN gt_vkorg
                  ( sign = 'I'
                    option = 'EQ'
                    low = ls_vkorg-vkorg )
                  ).

Solution 2

lr_vkorg = VALUE # ( sign   = 'I'  option = 'EQ' ( low = '1100' ) ( low = '1200' )
             ( low = '1300' ) ( low = '1400' )   ( low = '1500' ) ). 
Share:
32,524

Related videos on Youtube

Cold_Class
Author by

Cold_Class

Things I worked with: Interactive PDF Forms / SAP Adobe Forms (JavaScript for Acrobat) SAP R/3 7.4 (ABAP development) PHP (TYPO3 v.4-8 / WordPress CMS) JavaScript (ES5/ES6, jQuery, AngularJS, React) Node.js GatsbyJS CSS (Less, SCSS, Bootstrap 3 + 4) HTML5 ROS - Robot Operating System (C++, Python) App development with Flutter (Dart) I'm very eager to learn more things related to new technology! I love robots and automation! :D As a hobby I love doing music related stuff (composing, producing, etc.)!

Updated on December 26, 2020

Comments

  • Cold_Class
    Cold_Class over 3 years

    I found this code for filling a range table (source is already offline):

    DATA   lr_vkorg   TYPE RANGE OF vkorg.
    TYPES: lr_range_t TYPE RANGE OF vkorg.
    
    lr_vkorg = VALUE lr_range_t(
              LET s = 'I'
                  o = 'EQ'
              IN sign   = s
                 option = o
                 ( low = '1100' )
                 ( low = '1200' )
                 ( low = '1300' )
                 ( low = '1400' )
                 ( low = '1500' )
    ).
    

    But instead of doing something like this:

    ( low = '1' )
    ( low = '2' )
    ...
    

    I want to fill it with the values of an internal table ['1', '2', ...].
    Does anyone have an idea how to do this?

    Update: This is how I did it based on the answer:

    DATA:
      lt_itab       TYPE TABLE OF string,
      lt_range_itab TYPE RANGE OF string
      .
    
    APPEND '1'  TO lt_itab.
    APPEND '2'  TO lt_itab.
    APPEND '3'  TO lt_itab.
    APPEND '4'  TO lt_itab.
    
    lt_range_itab = VALUE #(
      FOR <ls_itab> IN lt_itab
      ( sign = 'I'
        option = 'EQ'
        low = <ls_itab> )
    ).
    
    • dotchuZ
      dotchuZ over 5 years
      a range always consists of low high, a sign and a operator ... I think ranges will not solve whatever you are trying to do.
    • Cold_Class
      Cold_Class over 5 years
      @zYrEx I'm trying to fill a range table from an internal table with as less code as possible
    • dotchuZ
      dotchuZ over 5 years
      ah okay. that was not clear from my perspective. is "['1', '2', ...]" a structure? just looks like an array or how is your internal table structured?
    • Sandra Rossi
      Sandra Rossi over 5 years
      Not your question but the code you have found contains useless statements ; removing LET ... IN is a valid syntax : lr_vkorg = VALUE lr_range_t( sign = 'I' option = 'EQ' ( low = '1100' ) ( low = '1200' ) ... ).
  • Cold_Class
    Cold_Class over 5 years
    But when I use itab, I don't need the top ( sign = 'I' option = 'EQ' low = &1 ) anymore, right? Can I instead just do DATA lr_vkorg TYPE RANGE OF vkorg.?
  • Suncatcher
    Suncatcher over 5 years
    Can I instead just do DATA lr_vkorg TYPE RANGE OF vkorg? No, you cannot. Macro and itab are two separate cases, macro fills only from literals. And in both cases you need declarations.