Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reading an internal table name from a variable

Former Member
0 Likes
1,975

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,630

Wont it be easier to achieve this with pointers?

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

11 REPLIES 11
Read only

Sm1tje
Active Contributor
0 Likes
1,630

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?

Read only

Former Member
0 Likes
1,630

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

Read only

Former Member
0 Likes
1,631

Wont it be easier to achieve this with pointers?

Read only

0 Likes
1,630

Please can you help with the syntax?

Read only

0 Likes
1,630

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.

Read only

0 Likes
1,630

**************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!!!

Read only

0 Likes
1,630

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.

Read only

0 Likes
1,630

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

Read only

0 Likes
1,630

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.

Read only

0 Likes
1,630

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?

Read only

0 Likes
1,630

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!!