Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Untyped field symbols and table assignments

Hello folks,

I have a case where I want to move away from TABLES defenition for assigning untyped fields symbols. Let me give you all more details.

Here is my program which fetches a single record from condition tables and assigns it to a field symbol,

  • Local variables

DATA: V_TABNAM LIKE DFIES-TABNAME,

V_FIELDNAME(60) TYPE C,

V_TABREC(250) TYPE C.

  • Field symbols

  • FIELD-SYMBOLS: <CONDTAB>,

<KUNNRFLD>.

  • Find customer number in condition tables

LOOP AT RT_KOTABNR INTO S_KOTABNR.

CONCATENATE S_KOTABNR-KVEWE S_KOTABNR-KOTABNR INTO V_TABNAM.

*selcetion from condition tables

SELECT SINGLE *

INTO V_TABREC

FROM (V_TABNAM)

WHERE KNUMH = S_KOTABNR-KNUMH

AND DATAB <= SY-DATUM

AND DATBI >= SY-DATUM.

  • Condition record found

IF SY-SUBRC = 0.

ASSIGN (V_TABNAM) TO <CONDTAB>.

<CONDTAB> = V_TABREC.

  • Attempt load from sold-to

CONCATENATE V_TABNAM C_SOLD_TO_FLD INTO V_FIELDNAME

SEPARATED BY '-'.

ASSIGN (V_FIELDNAME) TO <KUNNRFLD>.

  • Sold-to assignment

IF SY-SUBRC = 0.

S_KUNNR-KUNNR = <KUNNRFLD>.

APPEND S_KUNNR TO RT_KUNNR.

The string V_TABREC assigns a record to <CONDTAB> with structure of table V_TABNAM.

The structures of the tables have been defined in the top include ,

  • Tables

TABLES: A968,

A969,

A971,

A972,

A974,

A976,

A977,

A978.

But as an addition few more A* tables were added and the program failed to assign V_TABNAM & V_TABREC to <CONDTAB> as the new tables are not declared in the top include.

I want the program to work for new tables without declaring them(adding to TABLES) in the top include. I tried defining the field symbol <CONDTAB> as ANY TABLE, but it throwed a syntax error as the type of V_TABREC and <CONDTAB> are incompatible.

Please help me to find a way to make the program to work for any tables without declaring them in TOP include.

Tags:
Former Member
Former Member replied

Hi,

Try this..replace the following code

Local variables 
DATA: V_TABNAM LIKE DFIES-TABNAME,
V_FIELDNAME(60) TYPE C,
V_TABREC(250) TYPE C.


Field symbols 
FIELD-SYMBOLS: <CONDTAB>, 
<KUNNRFLD>.


Find customer number in condition tables 
LOOP AT RT_KOTABNR INTO S_KOTABNR.
CONCATENATE S_KOTABNR-KVEWE S_KOTABNR-KOTABNR INTO V_TABNAM.

*selcetion from condition tables 
SELECT SINGLE *
INTO V_TABREC
FROM (V_TABNAM)
WHERE KNUMH = S_KOTABNR-KNUMH
AND DATAB <= SY-DATUM
AND DATBI >= SY-DATUM.


Condition record found 
IF SY-SUBRC = 0.
ASSIGN (V_TABNAM) TO <CONDTAB>.
<CONDTAB> = V_TABREC.

Attempt load from sold-to 
CONCATENATE V_TABNAM C_SOLD_TO_FLD INTO V_FIELDNAME
SEPARATED BY '-'.
ASSIGN (V_FIELDNAME) TO <KUNNRFLD>.

With this code..

DATA: t_data TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY.
DATA: v_tabname TYPE tabname.

LOOP AT RT_KOTABNR INTO S_KOTABNR.

  CONCATENATE S_KOTABNR-KVEWE S_KOTABNR-KOTABNR INTO V_TABNAM.


  CREATE DATA t_data TYPE (v_tabnam).

  ASSIGN t_data->* TO <fs>.

  CHECK sy-subrc = 0.

*selcetion from condition tables 
  SELECT SINGLE *
  INTO <fs>
  FROM (V_TABNAM)
  WHERE KNUMH = S_KOTABNR-KNUMH
  AND DATAB <= SY-DATUM
  AND DATBI >= SY-DATUM.


*Condition record found 
   IF SY-SUBRC = 0.

    ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <FS> TO <KUNNRFLD>.

Sold-to assignment 
  IF SY-SUBRC = 0.
    S_KUNNR-KUNNR = <KUNNRFLD>.
    APPEND S_KUNNR TO RT_KUNNR.

  ENDIF.

   ENDIF.
ENDLOOP.

Thanks

Naren

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question