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

save multiple entries in table control

former_member670450
Participant
0 Likes
19,070

Hi, i am able to create and save an entry for table control and to its ztable. Currently im trying to do save multiple entry to table control and into ztable.I am able to enter multiple entries for a new record but only one record (first record) can be saved upon pressing save button.

Am I handling table control logic correctly?

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.

        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO ACCEPTING DUPLICATE KEYS.

In screen code

PROCESS AFTER INPUT.

 LOOP AT GT_ZEKPO.
 MODULE MODIFY.
 MODULE INSERT.
 ENDLOOP.

 MODULE USER_COMMAND_9002.

Table control logic:

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.

        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO ACCEPTING DUPLICATE KEYS.



*&---------------------------------------------------------------------*
*& Module MODIFY INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE MODIFY INPUT.
 READ TABLE GT_ZEKPO INTO GWA_ZEKPO INDEX TC_ZEKPO-CURRENT_LINE.

 IF MARK IS NOT INITIAL.
 GWA_ZEKPO-ZMARK = 'X'.
 MODIFY GT_ZEKPO FROM ZEKPO_03 INDEX TC_ZEKPO-CURRENT_LINE.

 ENDIF.
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module INSERT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE INSERT INPUT.

 IF SY-SUBRC NE 0.
 APPEND GWA_ZEKPO TO GT_ZEKPO .
 ENDIF.

ENDMODULE.
27 REPLIES 27
Read only

venkateswaran_k
Active Contributor
18,216

Dear A.S.

You make sure the ebelp is also populated in the internal table as below

       LOOP AT GT_ZEKPO INTO GWA_ZEKPO.
          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          GWA_ZEKPO-EBELP = SY-TABIX.  <==== add this line 
          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.

        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO ACCEPTING DUPLICATE KEYS.

Regards,

Venkat

Read only

0 Likes
18,216

during debug, all values are passed into internal table no problem, problem originated from sy-subrc return 4.

Theres "duplicate error entries" error when i removed "accepting duplicate keys" for the insert, is it due to key field (ebeln) being the same for zekpo?

I tried other ways, for example, insert into zekpo_03 values gwa_zekpo / INSERT ZEKPO_03 FROM gwa_zekpo, lets say 2 rows created, it only displays the 2nd row in table control.

Delete adjacent duplicate zekpo_03 comparing ebeln is also not applicable as it deletes an entry.

Which left sy-dbcnt (insert multiple records) for insert statement, im not sure how to use it or is there a way to make rest of the rows editable like alv ?

Read only

0 Likes
18,216

arnold92 The "key" of a database table is in fact a primary key, means there must be uniqueness of values. In your case, the primary key should be made of both EBELN and EBELP.

INSERT only inserts lines. ACCEPTING DUPLICATE KEYS doesn't mean that you can insert duplicate keys, but that INSERT won't produce a runtime error in case of duplicate keys, but in any case duplicate lines are not written. If you want to insert if it doesn't exist, or update if it exists, use MODIFY.

And of course, read the ABAP documentation so that you learn quicker.

Read only

0 Likes
18,216

Applied modify zekpo_03 FROM TABLE gt_zekpo instead of INSERT ZEKPO_03 FROMTABLE GT_ZEKPO ACCEPTING DUPLICATEKEYS.

logically it should save 2 records if 2 records saved, however only second record is saved (when 2 records are created), even through sy-subrc is returning 0.

I have also included this in the loop at gt_zekpo in PAI DynPro

IF sy-subrc IS NOT INITIAL.
APPEND GWA_ZEKPO TO GT_ZEKPO .
ENDIF.

Read only

0 Likes
18,216

Dear A.S.

Hope you added the EBELN and EBELP in the inernal table as they are the keys to that table.

       LOOP AT GT_ZEKPO INTO GWA_ZEKPO.
          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.                 <==== add this line ********************
          GWA_ZEKPO-EBELP = SY-TABIX.                        <==== add this line ********************
          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.

        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO ACCEPTING DUPLICATE KEYS.

Regards,

Venkat

Read only

0 Likes
18,216

Hi Venkat,

Thank you for your reply, yes i have added those 2 lines, those two key fields.

Issue is originated from PAI screenshot (debug3.png) where it returns sy-subrc = 4. I have added the following with intention to make sy-subrc = 0:

  if gv_create = 'X'.      <<<<<<<<<< added this
  GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.          <<<<< added this
  gwa_zekpo-ebelp = sy-tabix.  <<<<<<<<<<<<< added this
  IF sy-subrc is NOT INITIAL.
    APPEND GWA_ZEKPO TO GT_ZEKPO .
  ENDIF.
  endif.                       <<<<<<<<<< added this

User command

    IF GV_CREATE EQ 'X'.      <<<<< based on user command here

        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN         .

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKKO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKKO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELP
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELP.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-MATNR
          IMPORTING
            OUTPUT = GWA_ZEKPO-MATNR.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          gwa_zekpo-ebelp = sy-tabix.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.
         modify zekpo_03 FROM TABLE gt_zekpo.

        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.
        ENDIF.
      ENDIF.
Read only

0 Likes
18,216

Hi A.S.

The module insert in PAI is not required. (comment it out)

You should put these statements at SAVE user command . Your insert process will start when you press SAVE button. (as below)

       LOOP AT GT_ZEKPO INTO GWA_ZEKPO.
          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          GWA_ZEKPO-EBELP = SY-TABIX.  <==== add this line 
          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.

        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO.
Read only

0 Likes
18,216

I have tried to remove PAI insert, it doesnt make sense to loop and append to the same internal table which is gt_zekpo.

However, when i removed the PAI Insert, i wasnt able to save the zekpo entry into db table.

I have followed your code

 
Read only

0 Likes
18,216
*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTO01
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
  SET PF-STATUS 'ZSTATUS'.
  SET TITLEBAR 'ZTITLE'.
ENDMODULE.


*&---------------------------------------------------------------------*
*& Module FETCH_DATA OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE FETCH_DATA OUTPUT.
  SELECT EBELN LIFNR EKORG EKGRP BUKRS WAERS ZTERM ZDESC FROM ZEKKO_03
INTO CORRESPONDING FIELDS OF TABLE GT_ZEKKO
WHERE EBELN = GWA_ZEKKO-EBELN.

  SELECT SINGLE EBELN LIFNR EKORG EKGRP BUKRS WAERS ZTERM ZDESC FROM ZEKKO_03
    INTO CORRESPONDING FIELDS OF GWA_ZEKKO
    WHERE EBELN = GWA_ZEKKO-EBELN.

  READ TABLE GT_ZEKKO INTO GWA_ZEKKO INDEX SY-TABIX.

  SELECT EBELP MATNR WERKS LGORT MENGE MEINS
    INTO CORRESPONDING FIELDS OF TABLE GT_ZEKPO FROM ZEKPO_03
     WHERE EBELN = GWA_ZEKKO-EBELN.

  DESCRIBE TABLE gt_zekpo LINES tc_zekpo-lines.

ENDMODULE.

*&---------------------------------------------------------------------*
*& Module OPERATIONS OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE OPERATIONS OUTPUT.

  CASE OK_CODE.

    WHEN 'EDIT'.

      GV_EDIT = 'X'.
      GV_CREATE = ' '.
      LOOP AT SCREEN.

        """header
        IF SCREEN-NAME = 'GWA_ZEKKO-EBELN'.
          SCREEN-INPUT = 1.

          MODIFY SCREEN.
        ENDIF.


        IF SCREEN-NAME = 'GWA_ZEKKO-EKGRP'.
          SCREEN-INPUT = 1.

          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-EKORG'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-BUKRS'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-LIFNR'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-WAERS'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-ZTERM'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-ZDESC'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.


      ENDLOOP.

      LOOP AT SCREEN.
        """line item
        IF ( SCREEN-GROUP1 = 'GRP' ).
          SCREEN-INPUT = 1.

        ENDIF.
        MODIFY SCREEN.

      ENDLOOP.



    WHEN 'CREATE'.

      GV_CREATE = 'X'.
      GV_EDIT = ' '.
      LOOP AT SCREEN.

        """header
        IF SCREEN-NAME = 'GWA_ZEKKO-EKGRP'.
          SCREEN-INPUT = 1.

          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-EKORG'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-BUKRS'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-LIFNR'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-WAERS'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-ZTERM'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.

        IF SCREEN-NAME = 'GWA_ZEKKO-ZDESC'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        ENDIF.


      ENDLOOP.

      LOOP AT SCREEN.
        """line item
        IF ( SCREEN-GROUP1 = 'GRP' ).
          SCREEN-INPUT = 1.

        ENDIF.
        MODIFY SCREEN.

      ENDLOOP.

  ENDCASE.


ENDMODULE.


*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9002 OUTPUT.
  SET PF-STATUS 'ZSTATUS'.
  SET TITLEBAR 'ZTITLE1'.

ENDMODULE.



*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTI01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9002 INPUT.
  SET PF-STATUS 'ZSTATUS' .
  SET TITLEBAR 'ZTITLE1'.


  CASE OK_CODE.
    WHEN 'BACK' OR 'CANCEL'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.

    WHEN 'DEL'.
      GET CURSOR LINE GV_TABIX.
      F1 = 1.
      PERFORM FETCH_DATA.
      IF F1 = 1.
          DELETE ZEKKO_03 FROM TABLE GT_ZEKKO.
          DELETE FROM ZEKPO_03 WHERE EBELN = GWA_ZEKKO-EBELN.
          DESCRIBE TABLE GT_ZEKPO LINES TC_ZEKPO-LINES.
          COMMIT WORK.
      ENDIF.

    WHEN 'SVE'.

      IF GV_EDIT EQ 'X' .

        UPDATE ZEKKO_03 SET
       EKGRP = GWA_ZEKKO-EKGRP
       EKORG = GWA_ZEKKO-EKORG
       BUKRS = GWA_ZEKKO-BUKRS
       LIFNR = GWA_ZEKKO-LIFNR
       WAERS = GWA_ZEKKO-WAERS
       ZTERM = GWA_ZEKKO-ZTERM
       ZDESC = GWA_ZEKKO-ZDESC
       WHERE EBELN = GWA_ZEKKO-EBELN.


        UPDATE ZEKPO_03 SET
       EBELP = GWA_ZEKPO-EBELP
       MATNR = GWA_ZEKPO-MATNR
       WERKS = GWA_ZEKPO-WERKS
       LGORT = GWA_ZEKPO-LGORT
       MENGE = GWA_ZEKPO-MENGE
       MEINS = GWA_ZEKPO-MEINS
       WHERE EBELN = GWA_ZEKKO-EBELN.
        COMMIT WORK.

      ENDIF.

    WHEN 'INS' .

      IF GV_CREATE EQ 'X'.

        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN          .
*
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKKO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKKO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELP
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELP.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-MATNR
          IMPORTING
            OUTPUT = GWA_ZEKPO-MATNR.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          gwa_zekpo-ebelp = sy-tabix.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.

         insert zekpo_03 FROM TABLE gt_zekpo.

        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.
        ENDIF.
      ENDIF.


  ENDCASE.

ENDMODULE.




*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.
  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
    WHEN 'DELETE' OR 'DISPLAY'.
      IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        PERFORM FETCH_DATA.
        CALL SCREEN 9002.
      ENDIF.

    WHEN 'EDIT'  .
      IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        CALL SCREEN 9002.
      ENDIF.

    WHEN 'CREATE'.
      CALL SCREEN 9002.



  ENDCASE.

ENDMODULE.

*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FETCH_DATA .

  IF F1 NE 1.

    SELECT EBELN LIFNR EKORG EKGRP BUKRS WAERS ZTERM ZDESC FROM ZEKKO_03
      INTO CORRESPONDING FIELDS OF TABLE GT_ZEKKO
      WHERE EBELN = GWA_ZEKKO-EBELN.

    SELECT SINGLE EBELN LIFNR EKORG EKGRP BUKRS WAERS ZTERM ZDESC FROM ZEKKO_03
      INTO CORRESPONDING FIELDS OF GWA_ZEKKO
      WHERE EBELN = GWA_ZEKKO-EBELN.

    READ TABLE GT_ZEKKO INTO GWA_ZEKKO INDEX SY-TABIX.

    SELECT EBELP MATNR WERKS LGORT MENGE MEINS
      INTO CORRESPONDING FIELDS OF TABLE GT_ZEKPO FROM ZEKPO_03
       WHERE EBELN = GWA_ZEKKO-EBELN.

  ENDIF.

ENDFORM.


*&---------------------------------------------------------------------*
*&      Module  MODIFY  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE MODIFY INPUT.

    MODIFY GT_ZEKPO FROM ZEKPO_03 INDEX TC_ZEKPO-CURRENT_LINE.
ENDMODULE.


*&---------------------------------------------------------------------*
*& Module PASS_DATA OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE PASS_DATA OUTPUT.

  READ TABLE gt_zekpo INDEX tc_zekpo-current_line.

ENDMODULE.
Read only

Abinathsiva
Active Contributor
0 Likes
18,216

Hi A S,

Please do some basic search before posting questions to Community and complete this tutorial link https://developers.sap.com/tutorials/community-qa.html Thanks..

Read only

venkateswaran_k
Active Contributor
0 Likes
18,216

Hi A.S.

I believe you created the table control using the wizard with Insert & delete button .

So you no need to write separately to insert data into internal table from table control, This will be already there. As and when you press Ins and added entry - this will be available in the internal table.

So you just need to call your insert statement upon pressing the save button

Read only

0 Likes
18,216

Hi sir, correct me if im wrong, do you mean call insert from PF status save button instead of SVE button? I do not get what you meant

Because im doing Save edit (SVE) and Save Insert (INS) buttons.

Even though i added the insert zekpo_03 FROM TABLE gt_zekpo.in SVE it still doesnt make any difference and not logical to do that since its edit

Do you mean this way, put the insert in the loop? I tried this it is still not saving any entry in table control when upon pressing "save insert"

    WHEN 'INS' .

            IF GV_CREATE EQ 'X'.

        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN        .
*
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKKO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKKO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELP
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELP.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-MATNR
          IMPORTING
            OUTPUT = GWA_ZEKPO-MATNR.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          gwa_zekpo-ebelp = sy-tabix.

        insert gwa_zekpo into gt_zekpo. <<<<<<<<<<<<<<<<<<<<<
          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.


        
        modify zekpo_03 FROM gt_zekpo. <<<<<<<<<<<<<

        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.
        ENDIF.
      ENDIF.


  ENDCASE.<br>
Read only

0 Likes
18,216

Ok, based on your screen, I understand,

  • you press Save_insert - for new record
  • you press Save_edit for modifying the queried records
  • you press + button for add new lines...

As per your sequence, you add lines and Press Save_insert - correct?

Please put break point in WHEN 'INS'... and see where it goes wrong.

Regards,

Venkat

Read only

0 Likes
18,216

Hi sir, first and second statements are correct, no need extra button +, just enter multiple records and press save insert should save those records

  • you press Save_insert - for new record <<<< correct
  • you press Save_edit for modifying the queried records << correct

Here is the result i put breakpoint at 'INS', with append statement in PAI.

  MODULE FETCH_DATA.
  LOOP AT GT_ZEKPO INTO GWA_ZEKPO WITH CONTROL TC_ZEKPO CURSOR
TC_ZEKPO-CURRENT_LINE.
*    MODULE pass_data.
  ENDLOOP.

  MODULE OPERATIONS.

PROCESS AFTER INPUT.
  LOOP AT GT_ZEKPO.
    MODULE MODIFY.
    MODULE APPND.
  ENDLOOP.

  MODULE USER_COMMAND_9002.


*&---------------------------------------------------------------------*
*&      Module  APPND  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE APPND INPUT.

if sy-subrc NE 0.
    append gwa_zekpo to GT_ZEKPO .
endif.

ENDMODULE.<br>

For above debug, internal table values has both 2 records. However, when it runs the fetch_data PBO, then only 1 record is shown

Read only

0 Likes
18,216

Continued from above.

Read only

0 Likes
18,216

Here is the result i put breakpoint at 'INS', without append statement in PAI. Basically it does not run the loop, therefore no value being passed into internal table, and sy-subrc returns 4

Result: Table control is not saved and empty, only header data is saved into tb tbl.

Read only

0 Likes
18,216

Hi A.S.

The issue is now narrow down..

You need to have that + button to create new record. In the table control though you entered it is not actually stored in the Table control record. You need to Press + button to create new line. ( you can see in any standard screens). However, if you do not have the + button - what you can initialize at PBO as below

MODULE STATUS_9001 OUTPUT.
  SET PF-STATUS 'ZSTATUS'.
  SET TITLEBAR 'ZTITLE'.
  PERFORM INIT_TABLE.
ENDMODULE.<br>

In that perform do as below

(It will create 3 blank lines)

form init_table.

if GT_ZEKPO[] IS INITIAL. 
   CLEAR GWA_ZEKPO.
   APPEND GWA_ZKPO INTO GT_ZEKPO.

   CLEAR GWA_ZEKPO.
   APPEND GWA_ZKPO INTO GT_ZEKPO.

   CLEAR GWA_ZEKPO.
   APPEND GWA_ZKPO INTO GT_ZEKPO.
ENDIF.
endform.

** however, Please note that you need the + button if you need more lines.

Please do this code and you will understand where you are missing.

Regards,

Venkat

Read only

0 Likes
18,216

Thanks for your response, sorry i dont get why PERFORM INIT_TABLE in MODULE STATUS_9001 OUTPUT instead of MODULE STATUS_9002 OUTPUT

The issue is exactly the same, when commented out the MODULE APPND INPUT and followed the code you specified above (the following perform statement is in 9002 output), it is showing the following

The following is how i did the '+' in this case function code is 'ADD' (btn added from pf status).

MODULE OPERATIONS OUTPUT.

  CASE OK_CODE.
     WHEN 'ADD'.

      LOOP AT SCREEN.
        """line item
        IF ( SCREEN-GROUP1 = 'GRP' ).
          SCREEN-INPUT = 1.

        ENDIF.
        MODIFY SCREEN.

      ENDLOOP.

  ENDCASE.


  WHEN 'INS' .

       IF GV_CREATE EQ 'X'.

        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN   .
*
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKKO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKKO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELN
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELN.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-EBELP
          IMPORTING
            OUTPUT = GWA_ZEKPO-EBELP.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = GWA_ZEKPO-MATNR
          IMPORTING
            OUTPUT = GWA_ZEKPO-MATNR.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
          gwa_zekpo-ebelp = sy-tabix.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.


        modify zekpo_03 FROM TABLE gt_zekpo.


        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.
        ENDIF.

      ENDIF.


    WHEN 'ADD'.      <<<<<<<<<<<<<

     if GT_ZEKPO[] IS INITIAL.
        CLEAR GWA_ZEKPO.
        GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
        gwa_zekpo-ebelp = sy-tabix.
        APPEND GWA_ZEKPO TO GT_ZEKPO.



Read only

0 Likes
18,216

Okay, If you have Add button then no need of that .. I was under impression that you did not have the add button.

So, only thing you make sure that, when you press INSERT_SAVE button, make sure all key fields are populated properly.

You start by Press ADD button , enter details and

afer pressing insert_add, show the debug screen of the internal table.

Read only

0 Likes
18,215

Screen before pressing the add button

Read only

0 Likes
18,215

Screen after pressing add button.

Read only

venkateswaran_k
Active Contributor
0 Likes
18,215

Okay,

Step 1. in WHEN ADD - remove the if gt_zekpo[] is initial.

And show me debug screens of

1. After pressing the SAVE_INSERT

Read only

0 Likes
18,215

Debugger placed on 'INS' and pressed save insert button, I have removed the gt_zekpo is initial, in my case

    WHEN 'ADD'.

        CLEAR GWA_ZEKPO.
        GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
        gwa_zekpo-ebelp = sy-tabix.
        APPEND GWA_ZEKPO TO GT_ZEKPO.

        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.
        ENDIF.

Read only

0 Likes
18,215

I have also tried this method, meaning that i have to create yet another ZEKPO , say ZEKPO2 table and use move-corresponding zekpo (which is the one im using currently, this would need to declare as structure) to zekpo2 (new table as work area) but problem is my table control fields im using gwa_zekpo-<fieldname>

https://answers.sap.com/questions/11054860/how-to-update-the-multiple-line-items-which-in-tab.html

I will follow your method for now

Read only

0 Likes
18,214

This is what i tried, I uncommented the MODULE APPND INPUT. Upon pressing save insert, it will only save one entry.

After saving, then i tried press 'ADD' hopefully to append, im not able to append to second row. Upon saving (press save insert), it overwrites the entry i saved previously with the newly updated entry.

    WHEN 'ADD'.


        CLEAR GWA_ZEKPO.
        GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
        gwa_zekpo-ebelp = sy-tabix.

        APPEND gwa_zekpo to gt_zekpo.

       UPDATE ZEKPO_03 SET
       EBELP = GWA_ZEKPO-EBELP
       MATNR = GWA_ZEKPO-MATNR
       WERKS = GWA_ZEKPO-WERKS
       LGORT = GWA_ZEKPO-LGORT
       MENGE = GWA_ZEKPO-MENGE
       MEINS = GWA_ZEKPO-MEINS
       WHERE EBELN = GWA_ZEKPO-EBELN.

        IF sy-subrc = 0.
          COMMIT WORK.
          MESSAGE 'Entry created' TYPE 'S'.

Read only

0 Likes
18,214

Dear A.S.

Sorry for the delay in response.

I think you did not create the table control using Wizard..

Actually, if you create the table control using wizard, it will automatically creates the Add/delete buttons and it will creates automatic codes..

The way you written now is made the things more complex ..

Please create the table control using table control wizard..

Then you use only save button to save records into table.

Regards,

Venkat

Read only

0 Likes
18,214

Hi

Is your issue get resolved?

Regards,

Venkat