This website is not affiliated with, sponsored by, or approved by SAP AG.

Dynamic move to a dynamic structure- Resolved

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Dynamic move to a dynamic structure- Resolved

Postby Pat89 » Tue Feb 11, 2014 3:28 pm

Hi,

I want do a dynamic move to a dynamic structure.


Code: Select all
    Parameters:  p_table(30) type c,
                        p_key(30) type c.

TYPES : BEGIN OF ty_key_bkpf,
          bukrs TYPE bukrs,
          belnr TYPE belnr_d,
          gjahr TYPE gjahr,
        END OF ty_key_bkpf.

TYPES : BEGIN OF ty_key_ekko,
          ebeln TYPE ebeln,
        END OF ty_key_ekko.

data :   ls_key_bkpf      TYPE  ty_key_bkpf,
            ls_key_ekko      TYPE ty_key_ekko.


Examples of selection screen

Code: Select all
        p_table = BKPF
        p_key   = CA101234567892014

or

Code: Select all
       p_table = EKKO
        p_key   = 4500012345



CODE BEFORE

Code: Select all
if p_table = 'BKPF'.
   move p_key to ls_key_bkpf.
endif.

if p_table = 'EKKO'.
   move p_key to ls_key_ekko.
endif.


CODE AFTER

Code: Select all
data ls_struc(30) type c.

concatenate 'ls_key_'  p_table into ls_struc.

move p_key to (ls_struc)
"I know this code doest'n works what i need to do ?????

----------------------------------------------------------------------------------------------------------------------

I do that for do a dynamic select into a dynamic structure with a string parameters for the where condition

Code: Select all
DATA: dyn_table TYPE fieldref.
FIELD-SYMBOLS: <f_wa> TYPE any.


CREATE DATA dyn_table TYPE (p_table).
ASSIGN dyn_table->* TO <f_wa>.
SELECT SINGLE *
  INTO <f_wa>
  FROM  (cs_zxxsparams002-dokob)
  where ???????????????????????????????????????????  is my question in CODE AFTER


Thanks,
Last edited by Pat89 on Wed Feb 12, 2014 10:50 am, edited 1 time in total.
Pat89
 
Posts: 9
Joined: Tue Jun 08, 2004 12:27 pm

Re: Dynamic move to a dynamic structure

Postby Gothmog » Wed Feb 12, 2014 4:55 am

First of all, in your CODE AFTER, you need to use a field-symbol for this MOVE to work:
Code: Select all
data ls_struc(30) type c.
field-symbols: <struc> type ANY.

concatenate 'ls_key_'  p_table into ls_struc.
assign (ls_struc) to <struc>.
if sy-subrc = 0.
  move p_key to <struc>.
endif.

But with this, you have to create all the ls_key... structures for the possible tables.
Why not use a dynamic structure (as in your selection) for these?
Code: Select all
DATA: ls_key_struc TYPE REF TO DATA.
FIELD-SYMBOLS: <key_struc> TYPE ANY.

CREATE DATA ls_key_struc TYPE (p_table).
ASSIGN ls_key_struc->* TO <key_struc>.
IF sy-subrc = 0.
  MOVE p_key TO <key_struc>.
ENDIF.


Your dyn_table needs to be TYPE REF TO DATA, by the way.

Finally, you can use CL_ABAP_TYPEDESCR (and its subclass CL_ABAP_STRUCTDESCR) to describe your structure (using method DESCRIBE_BY_NAME, for example) and read its fields (and key fields) with method GET_DDIC_FIELD_LIST.
Or just read table DD03L, but why not learn to play with these real time typing services classes ? ;)

Loop at these key fields and construct your dynamic where condition (using field-symbols, once again, to read the value of the key components of <key-struc>).
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Dynamic move to a dynamic structure

Postby Pat89 » Wed Feb 12, 2014 9:18 am

Hi,

I tried, and dont works ...

With this code :
Code: Select all
   Parameters:  p_table(30) type c,
                        p_key(30) type c.

TYPES : BEGIN OF ty_key_bkpf,
          bukrs TYPE bukrs,
          belnr TYPE belnr_d,
          gjahr TYPE gjahr,
        END OF ty_key_bkpf.

TYPES : BEGIN OF ty_key_ekko,
          ebeln TYPE ebeln,
        END OF ty_key_ekko.

data :   ls_key_bkpf      TYPE  ty_key_bkpf,
            ls_key_ekko      TYPE ty_key_ekko.

-----------------------------------------------------------------------------
Examples Selection screen

p_table = BKPF
p_key = CA101234567892014
or
p_table = EKKO
p_key = 4500012345

Code: Select all
data ls_struc(30) type c.
field-symbols: <struc> type ANY.

concatenate 'ls_key_'  p_table into ls_struc.
assign (ls_struc) to <struc>.
if sy-subrc = 0.
  move p_key to <struc>.
endif.

I have this message 'Conversion of type "C" to type "h" not supported.'

I did that also , i changed my structure for

Code: Select all
TYPES : BEGIN OF ty_key_bkpf,
          bukrs(4)  TYPE c,
          belnr(10) TYPE c,
          gjahr(4)  TYPE c,
        END OF ty_key_bkpf.

TYPES : BEGIN OF ty_key_ekko,
          ebeln(10) TYPE c,
        END OF ty_key_ekko.

I had the same error.



Thanks for your help
Last edited by Gothmog on Wed Feb 12, 2014 10:17 am, edited 1 time in total.
Reason: code tags
Pat89
 
Posts: 9
Joined: Tue Jun 08, 2004 12:27 pm

Re: Dynamic move to a dynamic structure

Postby Gothmog » Wed Feb 12, 2014 10:28 am

It works on my system.
Type 'h' is supposed to be an internal table. Are you sure ls_key_bkpf is defined exactly as shown? No OCCURS n, or such thing?
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Dynamic move to a dynamic structure

Postby Pat89 » Wed Feb 12, 2014 10:49 am

Super, i did a mistake. All works :)

Thanks you for your help
Pat89
 
Posts: 9
Joined: Tue Jun 08, 2004 12:27 pm


Return to ABAP

Who is online

Users browsing this forum: Google [Bot] and 16 guests



cron


loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.