12-22-2008 11:35 AM
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
12-22-2008 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
12-22-2008 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
12-22-2008 11:56 AM
Thanz Byju 4 ur fast reply...
I will check it and confirm surely .........
Regards,
Murugesh R
12-23-2008 6:57 AM