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: 

Data Insert to Ztable

0 Kudos

Dear gurus..

I have the problem in uploading the data into Ztable.. Only the first and last records are inserted in ZTABLE.

I put my code here.... Any one guide me ?

Thanks in Advance,

Murugesh R


REPORT  ZTABLE_UPLOAD.

TYPE-POOLS : ABAP.
TABLES : DD02L.

FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
               <DYN_WA>,
               <DYN_FIELD>.

DATA: DY_TABLE TYPE REF TO DATA,
      DY_LINE  TYPE REF TO DATA,
      XFC TYPE LVC_S_FCAT,
      IFC TYPE LVC_T_FCAT.

DATA  LIN TYPE I.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_TABLE LIKE DD02L-TABNAME.
SELECTION-SCREEN END OF BLOCK B1.


START-OF-SELECTION.
  PERFORM GET_STRUCTURE.
  PERFORM CREATE_DYNAMIC_ITAB.
  PERFORM LOAD.
  PERFORM INSERT_INTO_TABLE.

FORM GET_STRUCTURE.
  DATA : IDETAILS TYPE ABAP_COMPDESCR_TAB,
         XDETAILS TYPE ABAP_COMPDESCR.

  DATA : REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR.

* Get the structure of the table.
  REF_TABLE_DES ?=
      CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( P_TABLE ).
  IDETAILS[] = REF_TABLE_DES->COMPONENTS[].

  LOOP AT IDETAILS INTO XDETAILS.
    CLEAR XFC.
    XFC-FIELDNAME = XDETAILS-NAME .
    XFC-DATATYPE = XDETAILS-TYPE_KIND.
    XFC-INTTYPE = XDETAILS-TYPE_KIND.
    XFC-INTLEN = XDETAILS-LENGTH.
    XFC-DECIMALS = XDETAILS-DECIMALS.
    APPEND XFC TO IFC.
  ENDLOOP.
ENDFORM.                    "get_structure

FORM CREATE_DYNAMIC_ITAB.
* Create dynamic internal table and assign to FS
  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
    EXPORTING
      IT_FIELDCATALOG = IFC
    IMPORTING
      EP_TABLE        = DY_TABLE.
  ASSIGN DY_TABLE->* TO <DYN_TABLE>.
* Create dynamic work area and assign to FS
  CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.
  ASSIGN DY_LINE->* TO <DYN_WA>.
ENDFORM.                    "create_dynamic_itab

FORM LOAD.
  CALL FUNCTION 'UPLOAD'
    EXPORTING
      CODEPAGE = ' '
      FILENAME = ' '
      FILETYPE = 'DAT'
    TABLES
      DATA_TAB = <DYN_TABLE>.
ENDFORM.                    "get_data

FORM INSERT_INTO_TABLE .
  LOOP AT <DYN_TABLE> INTO <DYN_WA>.
    INSERT (P_TABLE) FROM <DYN_WA>.
    COMMIT WORK.
  ENDLOOP.
ENDFORM.                    " WRITE_OUT

Code Formatted by: Alvaro Tejada Galindo on Dec 23, 2008 11:33 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Murugesh ,

The best option to do is to put a break point and find out if all the records are being looped at...

Ideally the update will work ,but if the data passed is wrong like passing key fields multiple times ..this will fail the insert statement...(try using "Modify" as an alternative if you have a case to modify existing records also)..check the sy-subrc in the the line after insert in debugg mode to understand the status of the insert command

The debugging will give you the correct answer

FORM INSERT_INTO_TABLE .

LOOP AT <DYN_TABLE> INTO <DYN_WA>.

INSERT (P_TABLE) FROM <DYN_WA>.

check sy-subrc here to understand if update was suucessful

BREAK_POINT.

COMMIT WORK.

ENDLOOP.

ENDFORM. " WRITE_OUT

Hope it helps

Regards

Byju

3 REPLIES 3

Former Member
0 Kudos

Hi Murugesh ,

The best option to do is to put a break point and find out if all the records are being looped at...

Ideally the update will work ,but if the data passed is wrong like passing key fields multiple times ..this will fail the insert statement...(try using "Modify" as an alternative if you have a case to modify existing records also)..check the sy-subrc in the the line after insert in debugg mode to understand the status of the insert command

The debugging will give you the correct answer

FORM INSERT_INTO_TABLE .

LOOP AT <DYN_TABLE> INTO <DYN_WA>.

INSERT (P_TABLE) FROM <DYN_WA>.

check sy-subrc here to understand if update was suucessful

BREAK_POINT.

COMMIT WORK.

ENDLOOP.

ENDFORM. " WRITE_OUT

Hope it helps

Regards

Byju

0 Kudos

Thanz Byju 4 ur fast reply...

I will check it and confirm surely .........

Regards,

Murugesh R

0 Kudos

Thanx..

probelem solved..

Regards,

Murugesh R