Skip to Content

Data Insert to Ztable

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 22, 2008 at 11:45 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.