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

Internal table creation on Dynamic selection

Former Member
0 Likes
3,747

Hello Experts ,

Requirement : I have a multiple value selection Drop down which gives me an option to select "table names"

based on the selected table name i need to get the data from those tables into itab and then into a file.

Now we know the table structure & i have to do "select * " on the tables selected.

i want to create dynamically internal tables for every table selected in the drop down

Better ideas are always welcome

Im using ABAP Release 4.7

Thanks

Regards Renu

1 ACCEPTED SOLUTION
Read only

Former Member
1,392

Hi

This code should work on your release:

PARAMETERS: P_TABLE(30).

DATA: MY_TABLE TYPE REF TO DATA.
FIELD-SYMBOLS: <WA> TYPE ANY.

START-OF-SELECTION.

   CREATE DATA MY_TABLE TYPE (P_TABLE).
   ASSIGN MY_TABLE->* TO <WA>.
   
   SELECT * FROM (P_TABLE) INTO <WA>.
" Here move <WA> to file
   ENDSELECT.

Max

11 REPLIES 11
Read only

Former Member
0 Likes
1,392

This message was moderated.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,392

Im using ABAP Release 4.7

Check if the statement is supported in 4.7:

CREATE DATA dref TYPE STANDARD TABLE OF (P_TABLE).

If yes, then your work is cut short

BR,

Suhas

Read only

Former Member
1,393

Hi

This code should work on your release:

PARAMETERS: P_TABLE(30).

DATA: MY_TABLE TYPE REF TO DATA.
FIELD-SYMBOLS: <WA> TYPE ANY.

START-OF-SELECTION.

   CREATE DATA MY_TABLE TYPE (P_TABLE).
   ASSIGN MY_TABLE->* TO <WA>.
   
   SELECT * FROM (P_TABLE) INTO <WA>.
" Here move <WA> to file
   ENDSELECT.

Max

Read only

0 Likes
1,392

Thanks Max ,

One issue is i cant create "my_table" of "table type" in 4.7 ..

can u please help me with inputs on how i would be able to put the value from <wa> into a file ..

Thanks

Regards Renu

Read only

0 Likes
1,392

Thanks Max ,

One issue is i cant create "my_table" of "table type" in 4.7 ..

can u please help me with inputs on how i would be able to put the value from <wa> into a file ..

Thanks

Regards Renu

Read only

0 Likes
1,392

Hi

I don't think u need to create a dynamic table, but a work are only, so the comand

CREATE DATA MY_TABLE TYPE (P_TABLE)

should be enough...doesn't work in 4.7?

TYPES: TY_RECORD TYPE STRING.

PARAMETERS: P_TABLE(30).

DATA: WA_DYN TYPE REF TO DATA.
FIELD-SYMBOLS: <WA> TYPE ANY.

DATA: W_RECORD TYPE STRING,
      T_FILE   TYPE TABLE OF TY_RECORD.

START-OF-SELECTION.

  CREATE DATA WA_DYN TYPE (P_TABLE).
  ASSIGN WA_DYN->* TO <WA>.

  SELECT * FROM (P_TABLE) INTO <WA>.
    MOVE <WA> TO W_RECORD.
    APPEND W_RECORD TO T_FILE.
  ENDSELECT.

  IF SY-SUBRC = 0.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
      EXPORTING
        FILENAME = 'C:\test.txt'
      CHANGING
        DATA_TAB = T_FILE.
  ENDIF.

Max

Read only

0 Likes
1,392

Hi Max

Thanks for the inputs from your side .

Im facing a problem of "Data objects in a Unicode program are not convertible."

when im trying to

TYPES: TY_RECORD TYPE STRING.

DATA: W_RECORD TYPE STRING,

T_FILE TYPE TABLE OF TY_RECORD.

SELECT * FRom (WA_RETURN-FIELDVAL) INTO <WA>.

bold MOVE <WA> TO W_RECORD. "Error on this line"

APPEND W_RECORD TO T_FILE.

ENDSELECT.

Can You please help me with this .

Regards

Renu

Read only

0 Likes
1,392

In unicode programs it is no longer possible to just move data back and forth like you are trying to do now. You could consider do use statement ASSIGN COMPONENT x OF STRUCTURE .... and then CONCATENATE all separate fields into the string workarea. BUT the concatenate statement is only valid for character type fields. That's something you have to keep in mind. Otherwise you have to move them to char type field first and then concatenate them.

Your exact requirement eludes me, so not sure why you want to move data to internal table of type string??

Read only

0 Likes
1,392

Hi Renu,

SELECT * FRom (WA_RETURN-FIELDVAL) INTO <WA>.

bold MOVE <WA> TO W_RECORD. "Error on this line"

APPEND W_RECORD TO T_FILE.

ENDSELECT.

For the above problem, you need to change the code as below

SELECT * FRom (WA_RETURN-FIELDVAL) INTO <WA>.

APPEND <wa> TO <itab>.

ENDSELECT.

Internal table also should be dynamic, as workarea structure is dynamic.

You can create dynamic itab by calling the method create_dynamic_table of cl_alv_table_create.

Let us know if you still face any issues.

Regards,

NIsha Vengal.

Read only

Former Member
0 Likes
1,392

Hi renu,

You can do this with the concept Dynamic tables, Dynamic Internal table.

Please check the link below for more information :

This will fix the issue.

Let me know if you require more information on this...

Regards,

Kittu

Read only

agnihotro_sinha2
Active Contributor
0 Likes
1,392

hi,

a F1 help on select will bring you this code:



PARAMETERS: p_cityfr TYPE spfli-cityfrom, 
            p_cityto TYPE spfli-cityto. 

DATA: BEGIN OF wa, 
         fldate TYPE sflight-fldate, 
         carrname TYPE scarr-carrname, 
         connid   TYPE spfli-connid, 
       END OF wa. 

DATA itab LIKE SORTED TABLE OF wa 
               WITH UNIQUE KEY fldate carrname connid. 
DATA: column_syntax TYPE string, 
      dbtab_syntax TYPE string. 

column_syntax = `c~carrname p~connid f~fldate`. 

dbtab_syntax = `( ( scarr AS c ` 
  & ` INNER JOIN spfli AS p ON p~carrid  = c~carrid` 
  & ` AND p~cityfrom = p_cityfr` 
  & ` AND p~cityto   = p_cityto )` 
  & ` INNER JOIN sflight AS f ON f~carrid = p~carrid ` 
  & ` AND f~connid = p~connid )`. 

SELECT (column_syntax) 
       FROM (dbtab_syntax) 
       INTO CORRESPONDING FIELDS OF TABLE itab. 

LOOP AT itab INTO wa. 
  WRITE: / wa-fldate, wa-carrname, wa-connid. 
ENDLOOP. 

i think this will be usefull for your case.

ags.