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: 

Adding new record in a database table from table control

manish_malakar0316
Active Participant
0 Kudos

Hello experts,

Now the issue I have is a very common issue and I have seen several threads pertaining to it. However, I am unable to get the desired result in spite of following the resolutions of such threads. I am unable to figure out where I am wrong so it would be of immense help if someone can help me out with it.

The main requirement is to edit and add new records in a custom database table via a table control with wizard in module pool. Below are the relevant screenshots.

I have created the ztable as shown:

Then I created a module pool . Below are the variables I declared at the TOP include.

For editing existing records, the flow logic is below:

The code in MODULE TC1_USER_COMMAND is:

The above code is working fine.

Now for adding new records, my code is incorrect somewhere. Below are the screenshots of the flow logic and code:

Below is the code:

On executing my program, when I click on "NEW" :

When I add new records in the table control and press "SAVE", there is no data which is saved in the table and hence no new records are getting updated in my ztable.

On debugging it, IT_MASTER2 doesnt have any records. As a result, ITMASTER isnt getting populated and the records are not getting modified in the ztable. How do I rectify this?

Regards.

Manish.

1 ACCEPTED SOLUTION

former_member202818
Active Contributor
0 Kudos

hi manish,

What is there inside module tc1_modify?

it should be...

modify itab from wa index tbc-current_line.

if sy-subrc <> 0.

append wa to itab.

endif.

regards

15 REPLIES 15

former_member188724
Contributor
0 Kudos

Hi,

Where is it_master2.

I don't see any code for the same except in SAVE.Only it_master has code.Is the code for it_master2 written somewhere.

Please check and populate records to master2 if not.

Hope this helps.

Regards,

K.S


0 Kudos

Hi,

Sorry, my mistake. The code I wrote is below. It is not IT_MASTER but IT_MASTER2.

The change is below:

Regards.

Manish

0 Kudos

Hi,

Your module tc1_modify should look like below.

MODIFY it_master2 FROM wa_master2 INDEX tc2-current_line.

Pls check after changing the code in debug whether it_master2 is filled.

Hope this helps.

Regards,

K.S

former_member202818
Active Contributor
0 Kudos

hi manish,

What is there inside module tc1_modify?

it should be...

modify itab from wa index tbc-current_line.

if sy-subrc <> 0.

append wa to itab.

endif.

regards

0 Kudos

Hi,

Inside Module TC1_modify, the following code is there:

MODULE TC1_MODIFY INPUT.


   MODIFY IT_MASTER2

     FROM WA_MASTER2

     INDEX TC1-CURRENT_LINE.

ENDMODULE.


Regards.


Manish

0 Kudos

Modify like this... this will solve your issue..

   MODIFY IT_MASTER2

     FROM WA_MASTER2

     INDEX TC1-CURRENT_LINE.

if sy-subrc <> 0.

append WA_MASTER2 to IT_MASTER2.

endif.

0 Kudos

Hi Sreekanth,

Yes, it solves the issue. Thanks a lot. But just 1 thing. After I click on the "SAVE" button, the data does get added in the ztable, but the new records from the table control get disappeared. Wat do I do to prevent that?

After adding the records, on clicking "SAVE":

    

Regards.

Manish

0 Kudos

Probably you are refreshing internal table IT_MASTER2 some where after saving.

Create a watch point for IT_MASTER2 and find out..

0 Kudos

Hi,

Am not refreshing IT_MASTER2 after saving..so why is it getting refreshed? By the way, why is sy-subrc = 4 after the MODIFY statement? Could you plz explain?

Regards.

Manish.

0 Kudos

what are you doing inside module tc1_change_tc_attribute?

Now case of sy-subrc = 4. Means modification failed.

Here you are trying to modifying internal table using index tc1-current_line...

If there is no record in the internal table with the specified index modification will get failed.

0 Kudos

It may help u

0 Kudos

Hi,

Thanks a lot...you have been of immense help.   It was getting refreshed in tc1_change_tc_attribute. I rectified it.

Regards.

Manish

0 Kudos

Former Member
0 Kudos

Hi,

In PBO you are mentioning IT_MASTER and in PAI you are mentioning IT_MASTER2. Pls check.

0 Kudos

  MODULE TC1_MODIFY ON REQUEST.



in the above module.

IF <INTERNAL TABLE IS EMPTY >


MODULE TC1_MODIFY.

APPEND  <WA> TO <INTERNAL TABLE>.

ENDMODULE.


OTHERWISE FOLLOW SREEKANTH