Application Development 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: 

getting Problem on Table Control INSERT operation

Former Member
0 Kudos

How can i INSERT some no. of rows in a Table Control on a Screen to get the Database Update via ABAP Editor Program.

Please tell me the appropriate logic and the mechanism to extract that Inserted rows to my editor program, by that i can INSERT that data INTO the DATABASE.

thank you.

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sateesh

Perhaps the following coding may be useful for your task:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_CHANGEDOC_PREPARE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_changedoc_prepare.



TYPES: BEGIN OF ty_s_knb1_di.
INCLUDE TYPE knb1  AS header.
TYPES:  chind  TYPE bu_chind.
TYPES: END OF ty_s_knb1_di.
TYPES: ty_t_knb1_di  TYPE STANDARD TABLE OF ty_s_knb1_di
                     WITH DEFAULT KEY.

DATA:
  gs_knb1         TYPE knb1,
  gt_knb1_old     TYPE STANDARD TABLE OF knb1,
  gt_knb1_new     TYPE STANDARD TABLE OF knb1,
*
  gs_knb1_di      TYPE ty_s_knb1_di,
  gt_knb1_old_di  TYPE STANDARD TABLE OF knb1,
  gt_knb1_new_di  TYPE STANDARD TABLE OF knb1.




START-OF-SELECTION.

  SELECT * FROM  knb1 INTO TABLE gt_knb1_old
         WHERE  bukrs  = '1000'.

  gt_knb1_new = gt_knb1_old.  " old = new


* Now modify new table
  READ TABLE gt_knb1_new INTO gs_knb1 INDEX 1.
  DELETE gt_knb1_new INDEX 10.
  gs_knb1-kunnr = '9999999999'.  " new customer number
  INSERT gs_knb1 INTO gt_knb1_new INDEX 35.


  SORT gt_knb1_old BY bukrs kunnr.
  SORT gt_knb1_new BY bukrs kunnr.

  LOOP AT gt_knb1_old INTO gs_knb1_di-header.
    APPEND gs_knb1_di TO gt_knb1_old_di.
  ENDLOOP.
  LOOP AT gt_knb1_new INTO gs_knb1_di-header.
    APPEND gs_knb1_di TO gt_knb1_new_di.
  ENDLOOP.

  CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES'
    EXPORTING
      check_indicator              = 'X'
      tablename                    = 'KNB1'
*   IMPORTING
*     RESULT                       =
    TABLES
      table_new                    = gt_knb1_new_di
      table_old                    = gt_knb1_old_di
    EXCEPTIONS
      nametab_error                = 1
      wrong_structure_length       = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



END-OF-SELECTION.

Regards

Uwe

4 REPLIES 4

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sateesh

Perhaps the following coding may be useful for your task:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_CHANGEDOC_PREPARE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_changedoc_prepare.



TYPES: BEGIN OF ty_s_knb1_di.
INCLUDE TYPE knb1  AS header.
TYPES:  chind  TYPE bu_chind.
TYPES: END OF ty_s_knb1_di.
TYPES: ty_t_knb1_di  TYPE STANDARD TABLE OF ty_s_knb1_di
                     WITH DEFAULT KEY.

DATA:
  gs_knb1         TYPE knb1,
  gt_knb1_old     TYPE STANDARD TABLE OF knb1,
  gt_knb1_new     TYPE STANDARD TABLE OF knb1,
*
  gs_knb1_di      TYPE ty_s_knb1_di,
  gt_knb1_old_di  TYPE STANDARD TABLE OF knb1,
  gt_knb1_new_di  TYPE STANDARD TABLE OF knb1.




START-OF-SELECTION.

  SELECT * FROM  knb1 INTO TABLE gt_knb1_old
         WHERE  bukrs  = '1000'.

  gt_knb1_new = gt_knb1_old.  " old = new


* Now modify new table
  READ TABLE gt_knb1_new INTO gs_knb1 INDEX 1.
  DELETE gt_knb1_new INDEX 10.
  gs_knb1-kunnr = '9999999999'.  " new customer number
  INSERT gs_knb1 INTO gt_knb1_new INDEX 35.


  SORT gt_knb1_old BY bukrs kunnr.
  SORT gt_knb1_new BY bukrs kunnr.

  LOOP AT gt_knb1_old INTO gs_knb1_di-header.
    APPEND gs_knb1_di TO gt_knb1_old_di.
  ENDLOOP.
  LOOP AT gt_knb1_new INTO gs_knb1_di-header.
    APPEND gs_knb1_di TO gt_knb1_new_di.
  ENDLOOP.

  CALL FUNCTION 'CHANGEDOCUMENT_PREPARE_TABLES'
    EXPORTING
      check_indicator              = 'X'
      tablename                    = 'KNB1'
*   IMPORTING
*     RESULT                       =
    TABLES
      table_new                    = gt_knb1_new_di
      table_old                    = gt_knb1_old_di
    EXCEPTIONS
      nametab_error                = 1
      wrong_structure_length       = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



END-OF-SELECTION.

Regards

Uwe

0 Kudos

hello.

thank you very much..!!

i will try wid this.

0 Kudos

Hello Sateesh

The tutorial "ABAP Code Sample for Table Controls" is not really useful in order to find out the changes that have happened in the table control. Simply think about the situation where the user simultaneously changes, inserts and deletes records from the table control. I am sure no user will accept that he or she has to tell the application explicitly what has to be done (by either pushing MODIFY button, INSERT button or DELETE button).

Recently I have published a generic approach for comparing itabs (PBO vs. PAI data) which automatically returns the new (INSERT), the changed (UPDATE) and the deleted records:

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/comparing%2btwo%2binternal%2btables%2b-%2ba%2bgeneric%2bapproach">comparing Two Internal Tables - A Generic Approach</a>

Regards

Uwe