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

is it possible to use insert command within the form routine

suneel_uggina
Participant
0 Likes
819

Hi gurus,

              I am getting sy-subrc eq 4 when i execute the following code.

FORM itable_ztab .

   INSERT zdsl FROM TABLE it_zdsl.      '" I set the break point at this line."

 

   IF sy-subrc EQ 0.

     LOOP AT it_zdsl INTO wa_zdsl.

       WRITE:/1 wa_zdsl-mandt,

               10 wa_zdsl-werks,

               30 wa_zdsl-pallet_id,

               45  wa_zdsl-matnr,

               60 wa_zdsl-erfmg,

               75 wa_zdsl-uom,

               90 wa_zdsl-lgort,

               105 wa_zdsl-lot,

               125 wa_zdsl-prod_date,

               140 wa_zdsl-ebeln,

               155 wa_zdsl-erdat,

               170 wa_zdsl-erzet,

               185 wa_zdsl-ernam,

               190  wa_zdsl-aedat,

               210 wa_zdsl-username,

                230 wa_zdsl-floc.

       CLEAR wa_zdsl.

     ENDLOOP.

   ENDIF.

ENDFORM.      

Should I use the insert command within the form routine.If it's not causing the runtime error  what is the main reason behind this.

1 ACCEPTED SOLUTION
Read only

GirieshM
Active Contributor
0 Likes
790

Hi Suneel,

The insert command works with in the form..endform. I hope that Zdsl is an customer transparent table and it_zdsl is your internal table. Please check whether the Primary keys are same for more than one records which also leads to an issue. Also check the Internal table has records.

Hope it might help you. Revert back if you need any information further.

With Regards,

Giriesh M

4 REPLIES 4
Read only

FredericGirod
Active Contributor
0 Likes
790

Hi,

maybe you have declare two times your internal table. Inside the FORM the internal table is empty. Outside is not empty and the values you would like to insert is already existing so you have a sy-subrc = 4.

regards

Fred

Read only

0 Likes
790

Hi Fred,

          How can I overcome this problem. the full code is

REPORT z_upload.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS     : aps_ztab RADIOBUTTON GROUP abc.

PARAMETERS     : prs_ztab RADIOBUTTON GROUP abc  MODIF ID fda.

SELECTION-SCREEN : END OF BLOCK b1.

TABLES:zdsl.

*TYPES: BEGIN OF ty_zdsl,

* mandt TYPE mandt,

*       werks TYPE zdsl-werks,

*       pallet_id TYPE zdsl-pallet_id,

*         matnr TYPE zdsl-matnr,

*       erfmg(13) type c,

*       uom TYPE zdsl-uom ,

*       lgort TYPE zdsl-lgort,

*       lot TYPE zdsl-lot,

*       prod_date TYPE zdsl-prod_date,

*       ebeln TYPE zdsl-ebeln,

*       erdat TYPE zdsl-erdat,

*       erzet TYPE zdsl-erzet,

*       ernam TYPE zdsl-ernam,

*       aedat TYPE zdsl-aedat,

*       username TYPE zdsl-username,

*       floc TYPE c,

*  END OF ty_zdsl.

DATA:it_zdsl TYPE TABLE OF zdsl,

         wa_zdsl TYPE zdsl.

*data: me_zdsl type table of zdsl,

*      wa2 type zdsl.

DATA:p_file TYPE rlgrap-filename,

      s_file TYPE rlgrap-filename,

      t_file TYPE string,

      s_test TYPE char25.

IF aps_ztab  = 'X'.

   PERFORM apserv_itab.

   PERFORM itable_ztab.

ENDIF.

IF prs_ztab = 'X'.

   PERFORM pserver_itab.      " file uploaded from presentation server to internal table"

   PERFORM itable_ztab.       " updating standard table  by using internal table"

ENDIF.

*&---------------------------------------------------------------------*

*&      Form  PSERVER_ITAB

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM pserver_itab .

   s_file = 'C:\Users\Owner\Documents\suneel.txt'.

   t_file = s_file.

   CALL FUNCTION 'GUI_UPLOAD'

     EXPORTING

       filename                      = t_file

      filetype                      = 'DAT'

      has_field_separator           = 'X'

*     HEADER_LENGTH                 = 0

*     READ_BY_LINE                  = 'X'

*     DAT_MODE                      = ' '

*     CODEPAGE                      = ' '

*     IGNORE_CERR                   = ABAP_TRUE

*     REPLACEMENT                   = '#'

*     CHECK_BOM                     = ' '

*     VIRUS_SCAN_PROFILE            =

*     NO_AUTH_CHECK                 = ' '

*     ISDOWNLOAD                    = ' '

*   IMPORTING

*     FILELENGTH                    =

*     HEADER                        =

     TABLES

       data_tab                      = it_zdsl

*   CHANGING

*     ISSCANPERFORMED               = ' '

    EXCEPTIONS

      file_open_error               = 1

      file_read_error               = 2

      no_batch                      = 3

      gui_refuse_filetransfer       = 4

      invalid_type                  = 5

      no_authority                  = 6

      unknown_error                 = 7

      bad_data_format               = 8

      header_not_allowed            = 9

      separator_not_allowed         = 10

      header_too_long               = 11

      unknown_dp_error              = 12

      access_denied                 = 13

      dp_out_of_memory              = 14

      disk_full                     = 15

      dp_timeout                    = 16

      OTHERS                        = 17

             .

   IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   ENDIF.

ENDFORM.                    " PSERVER_ITAB

*&---------------------------------------------------------------------*

*&      Form  APSERV_ITAB

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM apserv_itab .

   DATA:l_data TYPE string.

   p_file = '\\dj6ci00v\migration\migration\CNVManual\suneel.txt'.

   OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

   IF sy-subrc NE 0.

     MESSAGE 'UNABLE TO OPEN THE FILE' TYPE 'I'.

   ENDIF.

   DO.

     READ DATASET p_file INTO l_data.

     IF sy-subrc = 0.

       SPLIT l_data AT cl_abap_char_utilities=>horizontal_tab  INTO wa_zdsl-mandt

                               wa_zdsl-werks

                               wa_zdsl-pallet_id

                               wa_zdsl-matnr

                               s_test

                               wa_zdsl-uom

                               wa_zdsl-lgort

                               wa_zdsl-lot

                               wa_zdsl-prod_date

                               wa_zdsl-ebeln

                               wa_zdsl-erdat

                               wa_zdsl-erzet

                               wa_zdsl-ernam

                               wa_zdsl-aedat

                               wa_zdsl-username

                               wa_zdsl-floc.

       wa_zdsl-erfmg = s_test.

       APPEND wa_zdsl TO it_zdsl.

       CLEAR wa_zdsl.

     ELSE.

       EXIT.

     ENDIF.

   ENDDO.

ENDFORM.                    " APSERV_ITAB

*&---------------------------------------------------------------------*

*&      Form  ITABLE_ZTAB

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM itable_ztab .

   INSERT zdsl FROM TABLE it_zdsl.

   IF sy-subrc EQ 0.

     LOOP AT it_zdsl INTO wa_zdsl.

       WRITE:/1 wa_zdsl-mandt,

               10 wa_zdsl-werks,

               30 wa_zdsl-pallet_id,

               45  wa_zdsl-matnr,

               60 wa_zdsl-erfmg,

               75 wa_zdsl-uom,

               90 wa_zdsl-lgort,

               105 wa_zdsl-lot,

               125 wa_zdsl-prod_date,

               140 wa_zdsl-ebeln,

               155 wa_zdsl-erdat,

               170 wa_zdsl-erzet,

               185 wa_zdsl-ernam,

               190  wa_zdsl-aedat,

               210 wa_zdsl-username,

                230 wa_zdsl-floc.

       CLEAR wa_zdsl.

     ENDLOOP.

   ENDIf.

   endform.                  " ITABLE_ZTAB



it's urgent.please suggest me to resolve this error.


regards,

suneel.



Read only

0 Likes
790

HI Suneel,

Use the insert statement in the loop .

LOOP AT it_zdsl INTO wa_zdsl.

insert wa_zdsl into table zdsl .

if sy-subrc eq 0.

       WRITE:/1 wa_zdsl-mandt,

               10 wa_zdsl-werks,

               30 wa_zdsl-pallet_id,

               45  wa_zdsl-matnr,

               60 wa_zdsl-erfmg,

               75 wa_zdsl-uom,

               90 wa_zdsl-lgort,

               105 wa_zdsl-lot,

               125 wa_zdsl-prod_date,

               140 wa_zdsl-ebeln,

               155 wa_zdsl-erdat,

               170 wa_zdsl-erzet,

               185 wa_zdsl-ernam,

               190  wa_zdsl-aedat,

               210 wa_zdsl-username,

                230 wa_zdsl-floc.

       CLEAR wa_zdsl.

endif.

     ENDLOOP.

Read only

GirieshM
Active Contributor
0 Likes
791

Hi Suneel,

The insert command works with in the form..endform. I hope that Zdsl is an customer transparent table and it_zdsl is your internal table. Please check whether the Primary keys are same for more than one records which also leads to an issue. Also check the Internal table has records.

Hope it might help you. Revert back if you need any information further.

With Regards,

Giriesh M