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

Issue with line item (table control)

Former Member
0 Likes
12,146

Hi, im currently stuck at line item insert. Upon saving, it is not saving the line item

Im using following select statement to get line item. No issue when i created header and line item from database table. The issue occured when i tried to do save changes (function code: sve) for the insert. Correct me if theres something wrong with my select statement

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.

    MOVE-CORRESPONDING gwa_zekpo TO zekpo_03.

This is the insert i used. Im trying to look for insert <dbtab> with where clause or with index <table control>-current_line seems like theres no such statement (correct me if they exist).

 WHEN 'SVE'.

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

      IF GV_CREATE EQ 'X'.

        INSERT ZEKKO_03 FROM GWA_ZEKKO .


        READ TABLE gt_zekpo INDEX tc_zekpo-current_line INTO gwa_zekpo.
        insert INTO zekpo_03 VALUES gwa_zekpo .            

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

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.

      ENDIF.

      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.

  ENDCASE.

  CLEAR GT_ZEKKO.
  CLEAR GT_ZEKPO.

ENDMODULE.
1 ACCEPTED SOLUTION
Read only

venkateswaran_k
Active Contributor
0 Likes
12,002

Dear A.S.

Your code seems to be confusing and not in correct sequence.. I believe you are trying to do as below:

When Create, you are creating completely new entries and push it into your z-table

  • Header
  • Detail

Please follow the sequence as mentioned below.

WHEN 'SVE'.
      IF GV_CREATE EQ 'X'.
         "Header insert goes here.................
         "Step 1 - generate the number
          CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN.  

        "step 2- add leading zeros if any
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = GWA_ZEKKO-EBELN
        IMPORTING
          OUTPUT = GWA_ZEKKO-EBELN.

        "step 3 - insert into the table
        INSERT ZEKKO_03 FROM GWA_ZEKKO .

        "Detail table insert goes here..............
         "step 4 update the detail table with generated number
         LOOP AT GT_ZEKPO INTO GWA_ZEKPO
             GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
             MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.
        
        "step 5 - insert into detail table
        INSERT INTO ZEKPO_03 FROM TABLE GT_ZEKPO.
      
      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.
      ENDIF.

Hi, im currently stuck at line item insert. Upon saving, it is not saving the line item

Im using following select statement to get line item. No issue when i created header and line item from database table. The issue occured when i tried to do save changes (function code: sve) for the insert. Correct me if theres something wrong with my select statement

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.

    MOVE-CORRESPONDING gwa_zekpo TO zekpo_03.

This is the insert i used. Im trying to look for insert <dbtab> with where clause or with index <table control>-current_line seems like theres no such statement (correct me if they exist).

 WHEN 'SVE'.

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

      IF GV_CREATE EQ 'X'.

        INSERT ZEKKO_03 FROM GWA_ZEKKO .


        READ TABLE gt_zekpo INDEX tc_zekpo-current_line INTO gwa_zekpo.
        insert INTO zekpo_03 VALUES gwa_zekpo .            

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

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.

      ENDIF.

      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.

  ENDCASE.

  CLEAR GT_ZEKKO.
  CLEAR GT_ZEKPO.

ENDMODULE.
17 REPLIES 17
Read only

venkateswaran_k
Active Contributor
0 Likes
12,002

Dear A.S.

I beleive when you say insert means you are creating new EBELN.

Check this code

WHEN 'SVE'.
      IF GV_CREATE EQ 'X'.
         "Header insert goes here.................
         "Step 1 - generate the number
          CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN.  

        "step 2- add leading zeros if any
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = GWA_ZEKKO-EBELN
        IMPORTING
          OUTPUT = GWA_ZEKKO-EBELN.

        "step 3 - insert into the table
        INSERT ZEKKO_03 FROM GWA_ZEKKO .


        "Detail table insert goes here..............
         "step 4 update the detail table with generated number
         LOOP AT GT_ZEKPO INTO GWA_ZEKPO
             GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
             MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.
        
        "step 5 - insert into detail table
        INSERT INTO ZEKPO_03 FROM TABLE GT_ZEKPO.
      
      ENDIF.


      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.


      ENDIF.


Read only

0 Likes
12,002

Hi Venket, thanks for your reply.

Yes correct, inserting new ebeln, i have tried your method, no value in internal table therefore sy-subrc = 4 when insert into gt_zekpo (shown in debug screenshots)

The reason i put INSERT ZEKKO_03 FROM GWA_ZEKKO before NUMBER_GET_NEXT is to prevent number range skip .
Otherwise, it will skip from 45000000 to 45000002, records from 45000000 is saved to 45000002, goes on and on.

when 'SVE'.
IF GV_CREATE EQ 'X'.

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

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

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

        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.

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.

      ENDIF.



      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.

        modify zekpo_03 FROM gwa_zekpo.     <<< changes made here

        COMMIT WORK.

      ENDIF.

  ENDCASE.

  CLEAR GT_ZEKKO.
  CLEAR GT_ZEKPO.
<br>

Therefore, i made changes in the following, the result is still the same, what im doing below is that i want to retrieve data from zekpo table therefore the select statement and modify with the current line of table control

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

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

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

        LOOP AT GT_ZEKpO INTO GWA_ZEKpO.
                   GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
                   
              SELECT EBELP MATNR WERKS LGORT MENGE MEINS          <<< added this
      INTO CORRESPONDING FIELDS OF TABLE GT_ZEKPO FROM ZEKPO_03
       WHERE EBELN = GWA_ZEKpO-EBELN.         
 
          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX tc_zekpo-current_line.   <<< changed this

        ENDLOOP.

     
        INSERT ZEKPO_03 FROM TABLE GT_ZEKPO.<br>
Read only

Nawanandana
Active Contributor
0 Likes
12,002

Instead of UPDATE ,you try MODIFY command .

Read only

Former Member
0 Likes
12,002

Yes before update i used modify statement

Read only

venkateswaran_k
Active Contributor
0 Likes
12,002

Hi A.S.

I do not understand your requirement, When it is a create - why you are again selecting it from table to populate the internal table? because your GWA_ZEKPO-EBELN will have newly genrated number that may not exits in the table...

As per your screen, You already have entry in the internal table which is entered or populated.

So I believe your code should be like this

Populate the internal tbale with newly generated number and insert into the table as below

       LOOP AT GT_ZEKpO INTO GWA_ZEKpO.
           GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
           MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX sy-tabix.
       ENDLOOP.
       MODIFY ZEKPO_03 FROM TABLE GT_ZEKPO.

Regards,

Venkat

Read only

0 Likes
12,002

Hi Venket, the requirement does not change as long as line item is inserted then its fine, apologies for the confusion.

Yes what you are saying makes sense, shouldnt have another select statement for zekpo.

Sorry, I dont understand the need to use modify in loop and outside loop, possible to explain?

I have debugged and found out the issue is actually jumping of number range (screenshot)

when create entry, i entered 45000163, however when in debug mode, it jumps to the next number 45000164 (when debug pointing to the get next number range FM), therefore the gt_zekpo shown as empty

However, even with number range FM removed, issue still persists

Read only

0 Likes
12,002
arnold92 If the user enters manually the number to create, why do you use a number range? A number range is to store in the database the next number to use. If you use one, the user shouldn't enter the number manually (I simplify the concept).
Read only

0 Likes
12,002

Hi Sandra, this is the requirement for the Create button.

"Leave Purchase Order number blank – automatically get the next purchase order number from ZKKO." (this is screen1). For this part, managed to get the next PO number upon saving, but only displaying header and not line item which im still trying out.

I removed (comment out) the number range generation FM just to test out if line item save is reflected, but save is not reflected into zekpo table

"Except for Purchase Order number, the rest of the fields are allowed to edit" (screen 2)

"Save button – save the new data to table." (screen 2)

I created search help (required) on the 1st screen, both header and line item should have value in order for search help to reflect PO number

Read only

0 Likes
12,002

Sorry but the issue about "save is not reflected into zekpo table" should be solved by you. It's not a matter of being new in ABAP. Now that you have a few weeks experience in ABAP, you should use very correctly the debugger (that's the same concept as debugger in other languages), and you should be able to locate the root cause why it's not transferred. If you have issues, it's probably because there are some concepts you didn't understand well yet, and you should better think to questions about these concepts rather than asking why a value does not go in a column of a database table... I hope you understand that.

Read only

0 Likes
12,002

Im actually doing it this way, does it make sense, the lowercase are the ones i added

1. move data from itab to tbl control

tables: zekko_03, zekpo_03.

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.

  READ TABLE gt_zekpo INTO gwa_zekpo INDEX sy-tabix.
if sy-subrc = 0.
    zekpo_03-ebelp = gt_zekpo-ebelp.
    zekpo_03-matnr = gt_zekpo-matnr.
    zekpo_03-werks = gt_zekpo-werks.
    zekpo_03-lgort = gt_zekpo-lgort.
    zekpo_03-menge = gt_zekpo-menge.
    zekpo_03-meins = gt_zekpo-meins.
endif.

endmodule.

2. move data from table control to itab

    WHEN 'SVE'.

      IF GV_CREATE EQ 'X'.

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

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

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


    gt_zekpo-ebelp = zekpo_03-ebelp.
    gt_zekpo-matnr = zekpo_03-matnr.
    gt_zekpo-werks = zekpo_03-werks.
    gt_zekpo-lgort = zekpo_03-lgort.
    gt_zekpo-menge = zekpo_03-menge.
    gt_zekpo-meins = zekpo_03-meins.
    
    loop at gt_zekpo INTO gwa_zekpo.
      
      GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
    modify gt_zekpo FROM gwa_zekpo index sy-tabix.

    endloop.
    
    modify zekpo_03 FROM TABLE gt_zekpo.    
    
    zekpo_03-ebelp = gwa_zekpo-ebelp.
    zekpo_03-matnr = gwa_zekpo-matnr.
    zekpo_03-werks = gwa_zekpo-werks.
    zekpo_03-lgort = gwa_zekpo-lgort.
    zekpo_03-menge = gwa_zekpo-menge.
    zekpo_03-meins = gwa_zekpo-meins.<br>

3. insert statement. if data not exist in table control, then insert

      IF SY-SUBRC = 0.
        COMMIT WORK.      <<<<< this part is for header (which is showing data)
        MESSAGE 'Entry created' TYPE 'S'.
      ELSEIF sy-subrc ne 0.
         insert zekpo_03.  <<<<< if data not exist in tbl ctrl, insert
        COMMIT WORK.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.
      ENDIF.<br>

Sorry im totally stuck.

Read only

venkateswaran_k
Active Contributor
0 Likes
12,003

Dear A.S.

Your code seems to be confusing and not in correct sequence.. I believe you are trying to do as below:

When Create, you are creating completely new entries and push it into your z-table

  • Header
  • Detail

Please follow the sequence as mentioned below.

WHEN 'SVE'.
      IF GV_CREATE EQ 'X'.
         "Header insert goes here.................
         "Step 1 - generate the number
          CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            NR_RANGE_NR = GV_RANGE
            OBJECT      = 'ZEBELN_03'
          IMPORTING
            NUMBER      = GWA_ZEKKO-EBELN.  

        "step 2- add leading zeros if any
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = GWA_ZEKKO-EBELN
        IMPORTING
          OUTPUT = GWA_ZEKKO-EBELN.

        "step 3 - insert into the table
        INSERT ZEKKO_03 FROM GWA_ZEKKO .

        "Detail table insert goes here..............
         "step 4 update the detail table with generated number
         LOOP AT GT_ZEKPO INTO GWA_ZEKPO
             GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.
             MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.
        ENDLOOP.
        
        "step 5 - insert into detail table
        INSERT INTO ZEKPO_03 FROM TABLE GT_ZEKPO.
      
      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.
      ELSE.
        MESSAGE 'Create entry failed' TYPE 'E'.
      ENDIF.
Read only

0 Likes
12,002

I have followed through your code while adding code. These are what I tried:

Method1: based on this reference. The reason to use this is to move data from internal table to table control, the fieldname gwa_zekpo-EBELP is the table control name

https://answers.sap.com/questions/1747819/how-to-update-a-db-from-a-table-control.html

*&---------------------------------------------------------------------*
*& Module MOVE_DATA_TO_TAB OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE MOVE_DATA_TO_TAB OUTPUT.

READ TABLE gt_zekpo INTO gwa_zekpo INDEX tc_zekpo-current_line.
IF sy-subrc = 0.

  gwa_zekpo-EBELP = gt_zekpo-ebelp.
  gwa_zekpo-matnr = gt_zekpo-matnr.
  gwa_zekpo-werks = gt_zekpo-werks.
  gwa_zekpo-lgort = gt_zekpo-lgort.
  gwa_zekpo-menge = gt_zekpo-MENGE.
  gwa_zekpo-meins = gt_zekpo-meins.

ENDIF.

ENDMODULE.

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

  gt_zekpo-ebelp = gwa_zekpo-ebelp.
  gt_zekpo-matnr = gwa_zekpo-matnr.
  gt_zekpo-werks = gwa_zekpo-werks.
  gt_zekpo-lgort = gwa_zekpo-lgort.
  gt_zekpo-MENGE = gwa_zekpo-menge.
  gt_zekpo-meins = gwa_zekpo-meins.

 modify gt_zekpo INDEX tc_zekpo-current_line.


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.
        COMMIT WORK.
      ENDIF.

    WHEN 'SVE'.

      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.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        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.

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.

      ENDIF.<br>

Method2: The reason i do this is to transfer data from screen code to internal table in module pool

reference: https://answers.sap.com/questions/7606478/table-control-add-new-records.html

*&---------------------------------------------------------------------*
*& 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 'SVE'.

      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.

        INSERT ZEKPO_03 FROM GWA_ZEKPO.

        LOOP AT GT_ZEKKO INTO GWA_ZEKKO.

          GWA_ZEKPO-EBELN = GWA_ZEKKO-EBELN.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX SY-TABIX.

        ENDLOOP.

        INSERT zekpo_03 FROM table gt_zekpo.

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.

      ENDIF.


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

    DESCRIBE TABLE GT_ZEKPO LINES GV_LINES.

  IF GV_LINES = TC_ZEKPO-CURRENT_LINE.
    
    if ok_code = 'SVE'.
      if gv_create eq 'X'.
        
       if tc_zekpo-current_line = gv_lines.
    MODIFY GT_ZEKPO FROM gwa_ZEKPO INDEX TC_ZEKPO-CURRENT_LINE.
        endif.
        
      endif.
    
    endif.
  ENDIF.

ENDMODULE.<br>

Please provide input whether they are suitable or inappropriate to use.

These 2 methods dont work and ive searched through threads to look for appropriate solutions, what other methods can i use

Read only

0 Likes
12,002

Hi sir, thank you, managed to solve it by following your code while adding the following to pass data from tc_zekpo-current_line to the gt_zekpo module pool

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

  DESCRIBE TABLE GT_ZEKPO LINES GV_LINES.

  MODIFY GT_ZEKPO FROM ZEKPO_03 INDEX TC_ZEKPO-CURRENT_LINE.    

ENDMODULE.

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

  GWA_ZEKPO-EBELP = TC_ZEKPO-CURRENT_LINE.

  APPEND GWA_ZEKPO TO GT_ZEKPO .

ENDMODULE.

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

  READ TABLE GT_ZEKPO INDEX TC_ZEKPO-CURRENT_LINE.

ENDMODULE.
Read only

Former Member
0 Likes
12,002

Hi, Im still stuck at inserting new entry for table control, appreciate your input.

Read only

VenkatRamesh_V
Active Contributor
0 Likes
12,002

Try passing all key fields in where for update statement

Read only

Former Member
0 Likes
12,002

Hi Venkatramesh

Do you mean in the following way? By adding update line item (zekpo) into the create.

Some code are added along the way that differ from above but the issue is still the same, table control unable to create entry.

    WHEN 'SVE'.

      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.

        INSERT ZEKKO_03 FROM GWA_ZEKKO.

        LOOP AT GT_ZEKPO INTO GWA_ZEKPO.

          GWA_ZEKPO-EBELN = GWA_ZEKPO-EBELN.

          MODIFY GT_ZEKPO FROM GWA_ZEKPO INDEX sy-tabix.

        ENDLOOP.

       
       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.
       
      insert zekpo_03 FROM TABLE gt_zekpo ACCEPTING DUPLICATE KEYS.
      

      ENDIF.

      IF SY-SUBRC = 0.
        COMMIT WORK.
        MESSAGE 'Entry created' TYPE 'S'.

      ENDIF.

Please correct me if im wrong.

Read only

Former Member
0 Likes
12,002

I have passed the key field as below in the update statement as well, the result is still the same

      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.


          GWA_ZEKPO-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.