Application Development 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 a dynamic table with key .

Former Member
0 Kudos

Hi All,

I have created a table maintenance generator for a DB table.

I need to make some customizations to this table maintenance, i.e. I need to make changes to the specific function group . In this function group there is a table EXTRACT, which is a dynamic table. I cannot read or reference to any of its fields directly.

This table has following fields:

KSCHL , KAPPKLKE , ERKRS , ACTION , VORTZEIN etc..

Now I need to read this table with a certain key , i.e for a certain value of KSCHL , KAPPLKE and ERKRS, I have these values of KSCHL , KAPPLKE and ERKRS in some variables.

My ultimate goal is to read table as:

read table extract with key kschl = v_kschl kapplke = v_kapplke erkrs = v_erkrs.

but since extract is a dynamic table I cannot use the statement above. How can I read this table as in the manner depicted by read statement above.

Any help appreciated.

TIA.

6 REPLIES 6

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Harmeet,

Its a bit tricky, but try to debug the code you will find it amusing;-))

EXTRACT has got a field LINE of length 128 characters.

From your post i understand that KSCHL , KAPPKLKE , ERKRS are your key fields of your table and you want to get the values of these fields from EXTRACT.

Try this code:


TYPES: 
BEGIN OF lty_extract,
  MANDT     TYPE MANDT, "--> char3
  KSCHL      TYPE KSCHL,  "-->char4
  KAPPLKE  TYPE KAPPLKE, "-->char2
  ERKRS      TYPE ERKRS, "-->char4
END   OF lty_extract.

DATA: lwa_extract TYPE lty_extract.

LOOP AT extract.
  lwa_extract = extract+0(13). "--> lwa_extract conatins the details
ENDLOOP.

Plz try to debug, things will be more clear.

BR,

Suhas

Former Member
0 Kudos

Check this sample code it can be of some help to you.

tables : mara .
data: it_mara type table of mara.
parameters : p_tabnam type dd02l-tabname ,
             p_matnr type matnr.

 
field-symbols: <fs> like it_mara .
field-symbols: <fs1> type any .

select * from mara 
         into table it_mara.
 
assign  it_mara to <fs> .
Read table <fs>  assigning <fs1>  with key matnr = p_matnr .

write:/ ' Field Symbmbol sucessfully read'.

Reagrds,

Murthy.

Former Member
0 Kudos

Hi Suhas,

I have debugges the code lot many times.

the example that you have gave is to read the values of extract in a loop. That anyways I can do . Merely reading the values of extract can be achieved using loop, assigning etc ...

WHAT I NEED IS : READ RECORDS FROM EXTRACT WITH SOME KEY.

If you check the SAP code, you will find many places where extract is read as:

read table extract with key <vim>.

So basically i need to understand how to prepare this fieldsymbol <vim>.

Edited by: Harmeet Singh on Dec 24, 2008 12:51 PM

Edited by: Harmeet Singh on Dec 24, 2008 12:53 PM

Former Member
0 Kudos

Hi Murthy,

The table that you have used is not a dynamic table. It has a predefined structure. Life is certainly easy with these kind of tables.

What I am looking for is : a way to read a DYNAMIC table, the fields of which are unknown until runtime.

Hope you get my point.

Edited by: Harmeet Singh on Dec 24, 2008 1:23 PM

0 Kudos

ok the basic idea is to create a work area of same table type which we want to read. This method has a limitation of passing all IT table keys so i dont know if it will be usefull to you. documentation is there in f1 help on ECC6.

data : wa_dyn TYPE REF TO DATA.

field-symbols : <wa_withkey> type any,

<dyn_field1> type any,

<wa_1> TYPE ANY.

Create data wa_dyn like line of <it1>. "(<it1> is the table(or dynamic table) name to read in READ stmt)

assign wa_dyn->* to <wa_withkey>.

  • it_cf will be table containing your fields to read table (it1) (in from addition)

LOOP at it_cf assigning <wa_cf>.

assign component <wa_cf>-fieldname OF STRUCTURE <wa_withkey> TO <dyn_field1>.

IF SY-SUBRC = 0.

<dyn_field1> = <wa_cf>-fieldname.

ELSE.

*error message if any

ENDIF.

ENDLOOP. "END IT_J_COND LOOP

READ table <IT_1> ASSIGNING <WA_1> FROM <wa_withkey>. "

Mani

Former Member
0 Kudos

If I understand correctly you are trying to modify the generated function group from table maintenance generator... Any such changes will be wiped of as soon as you generate the table maintenance again... I wonder, if you could accomplish what you wanted to do using Events functionality of table maintenance generator - Environment -> Modification -> Events