2023 Feb 15 1:50 AM
Hi Abap guru,
I need to loop the internal table where the racct in a certain range, but it will take a lot of code if i hard coded every single range. I'm new to abap so i don't know if its possible or not. Here's my code :
DATA: r_range1 TYPE RANGE OF hkont,
wa_range1 LIKE LINE OF r_range1.
LOOP AT it_range INTO wa_range.
PERFORM f_count.
ENDLOOP.
FORM f_count.
LOOP AT it_fazg INTO wa_fazg WHERE racct IN r_range1." before
LOOP AT it_itb1 INTO wa_itb1 WHERE racct IN wa_range-rname. " it gets me an error
"RNAME is not an internal table"
" calculations
ENDLOOP.
ENDFORM.
The it_range only consist of one row of data (rname) like r_range1, r_range2, r_range3.
Please help me solve this problem. Thanks in advance!
2023 Feb 15 9:15 AM
I don't understand what you want to do. The code is misleading, misses variables and cannot compile. Currently it's impossible to answer. What is R_RANGE2, R_RANGE3? What is WA_RANGE? Etc.
Please clarify.
2023 Feb 15 3:45 PM
2023 Feb 16 2:35 AM
Hi Raymond,
I tried
IN ( wa_range-rname )
also
IN <fs_range>-rname
both gaves me an error "rname" is not an internal table.
2023 Feb 16 1:52 AM
Hi Sandra,
I wanted to have a dynamic IN condition for example:
LOOP AT (an internal table) INTO (work area) WHERE (the account number of the data looped) IN (range) --> i wanted this to be dynamic so i don't need to code for different 20+ range
So i came up with looping the internal table that consist of ranges name. For example i have ranges:
DATA : r_range1 TYPE RANGE OF hkont, wa_range1 LIKE LINE OF r_range1,
r_range2 TYPE RANGE OF hkont, wa_range2 LIKE LINE OF r_range2,
r_range3 TYPE RANGE OF hkont, wa_range3 LIKE LINE OF r_range3.
And so on.
I made an internal table :
TYPES : BEGIN OF ty_range,
rname TYPE c,
END OF ty_range.
DATA : it_range TYPE TABLE OF ty_range,
wa_range TYPE ty_range.
For those ranges name so that i can call later on. So i append names of ranges that i have it_range:
APPEND VALUE #( rname = 'r_range1' ) TO it_range.
APPEND VALUE #( rname = 'r_range2' ) TO it_range.
APPEND VALUE #( rname = 'r_range3' ) TO it_range.
So that i can make dynamic IN (range) condition.
The loop before dynamic IN condition:
LOOP AT (internal table) INTO (work area) WHERE (acc number) IN r_range1.
The loop after dynamic IN condition: (i need this to be working)
LOOP AT (internal table) INTO (work area) WHERE (acc number) IN it_range-rname.
Its not working atm, whether i used ( it_range-rname ) or [ it_range-rname ]
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S52 { color: #0000FF; }.L0
2023 Feb 16 7:48 AM
Please edit your question and paste the code. Select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!
Code formatted appears like this:
DATA : r_range1 TYPE RANGE OF hkont, wa_range1 LIKE LINE OF r_range1,
r_range2 TYPE RANGE OF hkont, wa_range2 LIKE LINE OF r_range2,
r_range3 TYPE RANGE OF hkont, wa_range3 LIKE LINE OF r_range3.
And so on.
I made an internal table :
TYPES : BEGIN OF ty_range,
rname TYPE c,
END OF ty_range.
DATA : it_range TYPE TABLE OF ty_range,
wa_range TYPE ty_range.
For those ranges name so that i can call later on. So i append names of ranges that i have it_range:
APPEND VALUE #( rname = 'r_range1' ) TO it_range.
APPEND VALUE #( rname = 'r_range2' ) TO it_range.
APPEND VALUE #( rname = 'r_range3' ) TO it_range.
So that I can make dynamic IN (range) condition.
The loop before dynamic IN condition:
LOOP AT (internal table) INTO (work area) WHERE (acc number) IN r_range1.
The loop after dynamic IN condition: (i need this to be working)
LOOP AT (internal table) INTO (work area) WHERE (acc number) IN it_range-rname.
Its not working atm, whether i used
( it_range-rname )
or
[ it_range-rname ]
2023 Feb 16 8:15 AM
Please ask complete questions.
To clarify your question and to make it simple, you'd better post a minimal reproducible code like this:
DATA : BEGIN OF wa,
acc_number TYPE hkont,
END OF wa,
itab LIKE TABLE OF wa.
DATA : r_range1 TYPE RANGE OF hkont, wa_range1 LIKE LINE OF r_range1,
r_range2 TYPE RANGE OF hkont, wa_range2 LIKE LINE OF r_range2,
r_range3 TYPE RANGE OF hkont, wa_range3 LIKE LINE OF r_range3.
TYPES : BEGIN OF ty_range,
rname TYPE c LENGTH 10,
END OF ty_range.
DATA : it_range TYPE TABLE OF ty_range,
wa_range TYPE ty_range.
itab = VALUE #( ( acc_number = '150' ) ( acc_number = '222' )
( acc_number = '300' ) ( acc_number = '391' ) ).
r_range1 = VALUE #( ( sign = 'I' option = 'CP' low = '1*' ) ).
r_range2 = VALUE #( ( sign = 'I' option = 'CP' low = '3*' ) ).
r_range3 = VALUE #( ( sign = 'E' option = 'CP' low = '*' ) ).
APPEND VALUE #( rname = 'R_RANGE1' ) TO it_range.
APPEND VALUE #( rname = 'R_RANGE2' ) TO it_range.
APPEND VALUE #( rname = 'R_RANGE3' ) TO it_range.
LOOP AT it_range INTO wa_range.
LOOP AT itab INTO wa WHERE (acc number) IN it_range-rname. " SYNTAX ERROR
WRITE / wa-acc_number.
ENDLOOP.
ENDLOOP.
Syntax error at the line LOOP AT itab INTO wa, and you don't know how to solve.
The solution should be more clear if you debug your code.
The answer depends on the ABAP version you are using.
This should always work:
FIELD-SYMBOLS <table> TYPE table.
ASSIGN (wa_range-rname) TO <table>.
LOOP AT itab INTO wa WHERE acc_number IN <table>.
The proposal by Raymond works from an ABAP release > 7.52 (I don't know which one exactly but it's easy to check):
LOOP AT itab INTO wa WHERE acc_number IN (wa_range-rname)
2023 Feb 16 3:32 PM
2023 Feb 17 3:12 AM
Thanks! Next time i will use this as a guide to ask a question.
also i notice the 'or use ASSIGN' and still trying it 🙂