2010 Sep 17 3:37 PM
I have an itab and a variable as below.
DATA: Begin of ITAB_HDR OCCURS 0,
DOCNUM(10),
END OF ITAB_HDR.
DATA: VAR(10).
concatenate 'ITAB_' 'HDR' into VAR.
ITAB_HDR = 'ABC'
append ITAB_HDR.
I want to read the internal table ITAB_HDR from the variable as follows:-
read table VAR with key DOCNUM = 'ABC'.
VAR as you can see has the name of the internal table....why is it not working and how can i make it work???
Edited by: Rob Burbank on Sep 17, 2010 10:40 AM
2010 Sep 17 4:38 PM
Wont it be easier to achieve this with pointers?
2010 Sep 17 4:10 PM
According to the syntax error, this is something that is just not possible.
But what exactly is it you are trying to do here? What do you want to achieve?
2010 Sep 17 4:22 PM
I want to generate an internal table name at runtime and read from it. The internal table is not dynamic and its already been defined. Only the name of the internal table is dynamic (that is the name is generated at runtime)
I cant believe no one has ever asked this question
2010 Sep 17 4:38 PM
2010 Sep 17 4:41 PM
2010 Sep 17 5:04 PM
The name of the internal table is generated, you say. Now, at what point (where) do you have access to this internal table (dynamic name, but structure is static). Is it an import parameter into your method, or function module? Do you have extract of the coding perhaps, something that can help.
2010 Sep 17 5:16 PM
**************ITABS**************************
Data: Begn of ITAB_HDR
.......
........
End of ITAB_HDR.
Data: Begn of ITAB_TAX
.......
........
End of ITAB_TAX.
***************************************************
perform build_itab using
'HDR'.
perform build_itab using
'TAX'.
The parameter 'HDR' and "TAX" are passed via subroutines as shown above. The internal ITAB_HDR and ITAB_TAX are globally defined hence accessable from the subroutines.
The name of the ITAB's are generated within the subroutines to either ITAB_HDR and ITAB_TAX in a variable.
Hope it clarifies the situation further...Appreciate your help!!!
2010 Sep 17 5:30 PM
And how exactly does the subroutine look like? I mean, how is this variable declared in the subroutine?
something like this:
FORM buil_itab using value(table).
ENDFORM.
2010 Sep 17 5:45 PM
Not sure if you are bound to the syntax you have given, but here is an example of how it could work, without knowing the exact conditions (restrictions) you have to work under.
TYPES: BEGIN OF ty_header,
field1(20).
TYPES: END OF ty_header.
TYPES: BEGIN OF ty_tax,
field2(10).
TYPES: END OF ty_tax.
DATA:
itab_header TYPE TABLE OF ty_header,
itab_tax TYPE TABLE OF ty_tax.
START-OF-SELECTION.
PERFORM build_itab USING itab_header.
PERFORM build_itab USING itab_tax.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form build_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->VALUE(TABLE) text
*----------------------------------------------------------------------*
FORM build_itab USING table TYPE ANY TABLE.
FIELD-SYMBOLS:
<line> TYPE ANY.
LOOP AT table ASSIGNING <line>.
* DO SOME CODING HERE.
ENDLOOP.
ENDFORM. "build_itab
2010 Sep 17 5:46 PM
Yes it looks like as below where ITAB_TYP contains string either "HDR" or "TAX" that was passed while calling the subroutine.
FORM BUILD_ITAB USING
VALUE(ITAB_TYP).
ENDFORM.
2010 Sep 17 5:55 PM
Thanks. Now if there were any changes to be made to the table in the loop (within the sub routine) how can those reflect in the original internal tables for header and tax?
2010 Sep 18 12:57 AM
Thanks alot for your help Micky. Based on your code I used the logic of passing the table as parameter to the subroutine and it did the trick, I was wanting to apply!!!!
Very grateful for your direction and full points given!!!! Wish could give you more!!
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |