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

Inserting data in dynamically generated db table thro' dynamically ITAB

Former Member
0 Likes
273

FUNCTION Z_BC_INSERT_DATA.

Hi Friends,

I have created RFC function module for transfering data from one client to another client or from one quality to devlopment as well but now i m getting error in inserting data to target table as both taget table and internal table for holding data are generated dynamically. Can anybody faced such type of problem earliear?

Help me with solution as i m giving my code of function module.

*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(TARGET_TABLE) TYPE  DD03L-TABNAME
*"     VALUE(TARGET_CLIENT) TYPE  SY-MANDT
*"     VALUE(I_TDATA) TYPE  STRING
*"  EXCEPTIONS
*"      AUTHORIZATION_ERROR
*"      INVALID_TABLE
*"      TABLE_NOT_EXIST
*"      INSERT_ERROR
*"----------------------------------------------------------------------
  DATA: DREF TYPE REF TO DATA.
  FIELD-SYMBOLS: <FS> TYPE ANY.
  CREATE DATA DREF TYPE (TARGET_TABLE).
  ASSIGN DREF->* TO <FS>.
  DATA: WA_TADIR TYPE TADIR.

* internal table to hold the data
  DATA: W_TABNAME TYPE W_TABNAME,
        W_DREF TYPE REF TO DATA.

  FIELD-SYMBOLS: <LT_DATA> TYPE ANY TABLE.

  W_TABNAME = TARGET_TABLE.

  CREATE DATA W_DREF TYPE TABLE OF (W_TABNAME).

  ASSIGN W_DREF->* TO <LT_DATA>.

*  verify that the table starts with a 'Z'.
  IF TARGET_TABLE(1) <> 'Z'.
    RAISE INVALID_TABLE.
  ENDIF.
*  verify that the table exists.
  SELECT SINGLE * FROM TADIR INTO WA_TADIR
         WHERE
           PGMID = 'R3TR' AND
           OBJECT = 'TABL' AND
           OBJ_NAME = TARGET_TABLE.
  IF SY-SUBRC <> 0.
    RAISE TABLE_NOT_EXIST.
  ENDIF.
* Insert the data.
  DATA: COUNT_F TYPE I.
** delete target client
  DELETE FROM (TARGET_TABLE) CLIENT SPECIFIED
         WHERE MANDT = TARGET_CLIENT.
  COMMIT WORK.

* Add imported XML data into lt_data internal table
  CALL TRANSFORMATION (`Z_XML_ID`)
       SOURCE XML I_TDATA
         RESULT L_T_DATA = <LT_DATA>.

* Insert records from internal table into target table
  insert (target_table) CLIENT SPECIFIED from TABLE <lt_data>.

  COMMIT WORK.
  IF SY-SUBRC <> 0.
    RAISE INSERT_ERROR.
  ENDIF.
ENDFUNCTION.

1 REPLY 1
Read only

mvoros
Active Contributor
0 Likes
256

Hi,

exactly what error do you get? I don't know your transformation but I can not see any usage of the parameter target_client except in DELETE statement. You should fill this value in all lines in your table <lt_data>.

Cheers