Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
kallolathome
Active Participant
188,532

Introduction


In certain cases, you need to create and populate range tables in ABAP for different purposes. So, in this blog post, I have explained 3 easy ways to populate range tables.

Solution


The ways are the following.

  1. Using LET with VALUE. Please check the below section for quick reference.
    TYPES lr_bukrs_type TYPE RANGE OF bukrs.
    DATA : lr_bukrs_01 TYPE lr_bukrs_type, "Table 1
    lr_bukrs_02 TYPE lr_bukrs_type. "Table 2

    * Using only LET with VALUE
    *--------------------------------------------------------------------*
    lr_bukrs_01 = VALUE lr_bukrs_type(
    LET s = 'I'
    o = 'EQ'
    IN sign = s
    option = o
    ( low = '0100' )
    ( low = '0200' )
    ( low = '0300' )
    ( low = '0400' )
    ( low = '0500' )
    ( low = '0600' )
    ( low = '0700' )
    ).


  2. Using MACRO: This is the simplest way. Please check the below section for quick reference.
    TYPES lr_bukrs_type TYPE RANGE OF bukrs.
    DATA : lr_bukrs_01 TYPE lr_bukrs_type, "Table 1
    lr_bukrs_02 TYPE lr_bukrs_type. "Table 2

    * Using MACRO
    *--------------------------------------------------------------------*
    DEFINE range_bukrs.
    lr_bukrs_01 = VALUE lr_bukrs_type(
    BASE lr_bukrs_01 (
    sign = 'I'
    option = 'EQ'
    low = &1
    )
    ).
    END-OF-DEFINITION.

    *--------------------------------------------------------------------*
    range_bukrs: '0100', '0200', '0300', '0400', '0500', '0600', '0700'.
    *--------------------------------------------------------------------*​


  3. Using FOR LOOP: By this procedure, one can populate the range table w.r.t another table. Please check the below section for quick reference.
    TYPES lr_bukrs_type TYPE RANGE OF bukrs.
    DATA : lr_bukrs_01 TYPE lr_bukrs_type, "Table 1
    lr_bukrs_02 TYPE lr_bukrs_type. "Table 2

    * Using MACRO
    DEFINE range_bukrs.
    lr_bukrs_01 = VALUE lr_bukrs_type(
    BASE lr_bukrs_01 (
    sign = 'I'
    option = 'EQ'
    low = &1
    )
    ).
    END-OF-DEFINITION.

    range_bukrs: '0100', '0200', '0300', '0400', '0500', '0600', '0700'.

    * Combining LET with FOR LOOP
    *--------------------------------------------------------------------*
    lr_bukrs_02 = VALUE #( FOR ls_bukrs IN lr_bukrs_01
    * ( sign = 'I' "Alternatively
    * option = 'EQ' "Alternatively
    LET s = 'I'
    o = 'EQ'
    IN sign = s
    option = o
    ( low = ls_bukrs-low )
    ).



That’s it. 🙂
22 Comments
Labels in this area