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

table update

Former Member
0 Likes
836

Hi experts,

I have to update a custom table using records from flat file and display the number of error as well as success records. Total no.of records updated and no.of error records.

as i am not performing any recording,plz let me know how to achieve this fuctionality.

thnaks in advance

alson

6 REPLIES 6
Read only

Former Member
0 Likes
801

Hi,

Do you need to show the errors in a separate log and sucess record in separate log file?

whats the functionality for finding out the error records? I mean how will you know that some number of records are invalid?

regards,

nazeer

Read only

Former Member
0 Likes
801

Hi Alson,

1. read the flatfile using GUI_UPLOAD into an internal table (ITAB).

2. MODIFY dbtab FROM TABLE itab.

3. Check sy-subrc after modify if its value is 0. successfully added.

else.

error while updating the table.

- Satish

Read only

aris_hidalgo
Contributor
0 Likes
801

Hi What you can do is to create a program and use the function module GUI_UPLOAD to upload your flatfile into an internal table then using that internal table then you can update your custom table. Hope it helps...

P.S. Please award points if it helps...

Read only

Former Member
0 Likes
801

if you have to create a custom program, use the gui_upload method of the cl_gui_frontend_services class to read the file in an internal table, loop on this internal table and validate it (if required) and then from this table, use the insert or update or modify sql command to insert this into the table.

For success and error messages, you need to check the sy-subrc after insert. in case you want a separate message for each record, you might have to write your sql (insert, update or modify) within the loop on the internal table which is not the most efficient way to do it.

regards,

Priyank

Read only

Former Member
0 Likes
801

hi,

first upload data to an internal table using GUI_UPLOAD,

then use update tablename from table itab(internal table).

check for if sy-subrc <> 0.it means updation is not done and The statement UPDATE sets sy-dbcnt to the number of changed lines.using this you can get number of records updated and records which are not updated

Read only

aris_hidalgo
Contributor
0 Likes
801

Hi Alson,

I have searched my ABAP archives to give you an example on how to do your requirement. I did this report a long time ago but I know it will solve your requirement.


REPORT zfr_update_ztf0196 NO STANDARD PAGE HEADING
                      LINE-COUNT 65
                      LINE-SIZE 255
                      MESSAGE-ID zz.

*-----------------------------------------------------------------------
* Tables
*-----------------------------------------------------------------------
TABLES: ztf0196.       "UDT for ZFR_FR_ACCRUAL_UPLOAD Program

DATA: BEGIN OF it_upload OCCURS 0,
        bukrs LIKE ztf0196-bukrs,
        xref1 LIKE ztf0196-xref1,
        zlas  like ztf0196-zlas,
        zname like ztf0196-zname,
      END OF it_upload.

DATA: wa_upload LIKE ztf0196.

DATA: BEGIN OF it_error OCCURS 0.
        INCLUDE STRUCTURE it_upload.
DATA: msg(50) TYPE c,
      END OF it_error.

*-----------------------------------------------------------------------
* Selection Screen
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK box0 WITH FRAME.
PARAMETERS: p_flnme LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK box0.


*-----------------------------------------------------------------------
AT SELECTION-SCREEN.
*-----------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flnme.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            mask             = ',*.*,*.*.'
            mode             = 'O'
            title            = 'File Selection'
       IMPORTING
            filename         = p_flnme
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.

*-----------------------------------------------------------------------
START-OF-SELECTION.
*-----------------------------------------------------------------------
  CLEAR: it_upload.
  REFRESH: it_upload.

  PERFORM upload_data.

  IF NOT it_upload[] IS INITIAL.
    PERFORM update_ztf0196.
  ENDIF.

  IF it_error[] IS INITIAL.
    MESSAGE s000 WITH 'Records successfully updated.'.
  ELSE.
    PERFORM write_error.
  ENDIF.

************************************************************************
*&---------------------------------------------------------------------*
*&      Form  upload_data
*&---------------------------------------------------------------------*
FORM upload_data.
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            filename        = p_flnme
            filetype        = 'DAT'
       TABLES
            data_tab        = it_upload
       EXCEPTIONS
            file_open_error = 1
            OTHERS          = 2.
  CASE sy-subrc.
    WHEN 1.
      MESSAGE i008 WITH 'Error found when opening dataset' p_flnme.
      STOP.
    WHEN 2.
      MESSAGE i008 WITH 'Error during uploading dataset' p_flnme.
      STOP.
  ENDCASE.
ENDFORM.                    " upload_data
*&---------------------------------------------------------------------*
*&      Form  update_ztf0196
*&---------------------------------------------------------------------*
FORM update_ztf0196.
  LOOP AT it_upload.
    MOVE-CORRESPONDING it_upload TO wa_upload.
    INSERT INTO ztf0196 VALUES wa_upload.

    IF sy-subrc EQ 4.
      MOVE-CORRESPONDING it_upload TO it_error.
      it_error-msg = 'Record already exists.'.

      APPEND it_error.
    ELSEIF sy-subrc NE 0.
      MOVE-CORRESPONDING it_upload TO it_error.
      it_error-msg = 'Error when inserting to the database.'.

      APPEND it_error.
    ENDIF.

    CLEAR: it_error, wa_upload.
  ENDLOOP.
ENDFORM.                    " update_ztf0196
*&---------------------------------------------------------------------*
*&      Form  write_error
*&---------------------------------------------------------------------*
FORM write_error.
  WRITE: 'Validation Error'.
  LOOP AT it_error.
    WRITE: / it_error-bukrs,
             it_error-xref1,
             it_error-msg.
  ENDLOOP.
ENDFORM.                    " write_error

Hope it helps...

P.S. Please award points if it helps...