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

what's wrong in this program, I want to insert a row using this program

sanjeev_mishra_15aug
Active Participant
0 Likes
2,629

TABLES: zemployee, sscrfields.

TYPES: BEGIN OF t_zemployee,

        empid TYPE zemployee-empid,

        empname TYPE zemployee-empname,

        dob TYPE zemployee-dob,

        dept TYPE zemployee-dept,

        END OF t_zemployee.

DATA: it_zemployee TYPE STANDARD TABLE OF t_zemployee WITH HEADER LINE,

       wa_zemployee TYPE t_zemployee .                       " OCCURS 0.

*DATA: gd_ucomm TYPE sy-ucomm.

LOAD-OF-PROGRAM.

   SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE t1.

   SELECTION-SCREEN SKIP.

   PARAMETERS: empid1 TYPE zemployee-empid,

               empname1 TYPE zemployee-empname,

               dob1 TYPE zemployee-dob,

               dept1 TYPE zemployee-dept.

   SELECTION-SCREEN BEGIN OF LINE.

   SELECTION-SCREEN PUSHBUTTON (10) w_button USER-COMMAND but1.

   SELECTION-SCREEN END OF LINE.

   SELECTION-SCREEN END OF BLOCK block1.

INITIALIZATION.

   t1 = 'ENTER THE VALID DATA'.

*  w_button = 'SAVE'.

   MOVE 'SAVE' TO W_BUTTON.

AT SELECTION-SCREEN.

*  AT SELECTION-SCREEN OUTPUT.

   IF empid1 IS INITIAL OR empname1 IS INITIAL OR dob1 IS INITIAL OR dept1 IS INITIAL.

     MESSAGE: 'PLEASE FILL ALL THE DATA PROPERLY' TYPE 'I'.

   ELSE.

     wa_zemployee-empid = empid1.

     wa_zemployee-empname = empname1.

     wa_zemployee-dob = dob1.

     wa_zemployee-dept = dept1.

     APPEND wa_zemployee TO it_zemployee.

   ENDIF.

  IF sscrfields-ucomm = 'BUT1'.

     sy-ucomm = 'BUT1'.

  ENDIF.

   IF sy-ucomm = 'BUT1'.

     LOOP AT it_zemployee INTO wa_zemployee.

       INSERT zemployee FROM wa_zemployee.

       IF sy-subrc = 0.

         MESSAGE 'DATABASE SUCCESSFULLY RECORDED' TYPE 'S'.

       ELSEIF sy-subrc = 4.

         MESSAGE 'EMPLOYEE ID ALREADY EXISTS' TYPE 'E'.

         CLEAR: empid1, empname1, dob1, dept1.

       ENDIF.

*CLEAR: WA_ZEMPLOYEE, IT_ZEMPLOYEE.

     ENDLOOP.

   ENDIF.

1 ACCEPTED SOLUTION
Read only

PeterJonker
Active Contributor
0 Likes
2,598

You had the answer already: Do not put the update in AT SELECTION SCREEN event.

If you want a screen with a button SAVE and want to update the table when the user clicks this button go for module pool program.

Hi

Which is the problem

15 REPLIES 15
Read only

Former Member
0 Likes
2,598

Hi

Which is the problem

Read only

PeterJonker
Active Contributor
0 Likes
2,598

What is the message you get ?

Why are you placing the values in a table first then loop around this table to update your db table if the table always only has one entry ?

Why are you updating a database table in the event AT SELECTION SCREEN ?

I would do the update in the event START-OF-SELECTION or END-OF-SELECTION but not in AT SELECTION SCREEN.

Read only

0 Likes
2,598

I get the error message as wa_zemployee in not long enough..

Read only

Former Member
0 Likes
2,598

AT SELECTION-SCREEN describes the event when you display your selection screen.

I guess you want to update your table when you click on execution, so you should replace at selection screen by end-of-selection

Read only

0 Likes
2,598

Following your case I find the value of sy-ucomm is omitted as soon as i press at 'save' button...

So I added it in at-selection-screen event only.

Read only

0 Likes
2,598

Hi

You have written this definition;

wa_zemployee TYPE t_zemployee


but the type T_ZEMPLOYEE is not like the table ZEMPLOYEE:



TYPES: BEGIN OF t_zemployee,

        empid TYPE zemployee-empid,

        empname TYPE zemployee-empname,

        dob TYPE zemployee-dob,

        dept TYPE zemployee-dept,

        END OF t_zemployee.

so probably some fields of ZEMPLOYEE are missing, you should use this declaration:

DATA WA_ZEMPLOYEE TYPE ZEMPLOYEE

Max



Read only

0 Likes
2,598

all the fields of the tables are included in the declaration of t_zemployee.

and wa_zemployee is the work area i have declared here.

Read only

0 Likes
2,598

If you don't tell us what exactly you need we can't find it by ourselves.

A common selection screen program will use the execute button and won't need any PAI management.

If you really need such a thing: sy ucomm management etc..., you'll need to create a dynpro and manage your PBO and PAI

Read only

0 Likes
2,598

I mean if you need to insert your row when clicking on execute button you can replace your at selection screen block by :

END-OF-SELECTION.

   IF empid1 IS INITIAL OR empname1 IS INITIAL OR dob1 IS INITIAL OR dept1 IS INITIAL.

     MESSAGE: 'PLEASE FILL ALL THE DATA PROPERLY' TYPE 'I'.

   ELSE.

     wa_zemployee-empid = empid1.

     wa_zemployee-empname = empname1.

     wa_zemployee-dob = dob1.

     wa_zemployee-dept = dept1.

     INSERT zemployee FROM wa_zemployee.

       IF sy-subrc = 0.

         MESSAGE 'DATABASE SUCCESSFULLY RECORDED' TYPE 'S'.

       ELSEIF sy-subrc = 4.

         MESSAGE 'EMPLOYEE ID ALREADY EXISTS' TYPE 'E'.

         CLEAR: empid1, empname1, dob1, dept1.

       ENDIF.

   ENDIF.


Read only

renatobertizini
Explorer
0 Likes
2,598

Probably zemployee is different from wa_zemployee.

Use type zemployee for declare wa_zemployee.

Read only

Former Member
0 Likes
2,598

Hi Sanjeev,

What you are trying to insert? Define the repective field in workarea if you are using loop.Simply you cant pass a workarea to Ztable.

LOOP AT it_zemployee INTO wa_zemployee.

       INSERT zemployee FROM wa_zemployee.

or

Try the following INSERTzemployee FROM TABLE it_zemployee.

  WRITE :/ 'NO OF RECORDS INSERTED SUCCESSFULLY', SY-DBCNT.

Regards,

Kannan

Read only

Former Member
0 Likes
2,598

Hi Sanjeev,

Please avoid "Please reply soon" statements in this forum.

Regards,

Kannan

Read only

0 Likes
2,598

Thanks for reminding him.  I removed those references.

Read only

PeterJonker
Active Contributor
0 Likes
2,599

You had the answer already: Do not put the update in AT SELECTION SCREEN event.

If you want a screen with a button SAVE and want to update the table when the user clicks this button go for module pool program.

Read only

Former Member
0 Likes
2,598

Hi

Perhaps you've included all fields of your table ZEMPLOYEE.....I don't think:


TYPES: BEGIN OF t_zemployee,

                  empid     TYPE zemployee-empid,

                 empname TYPE zemployee-empname,

                 dob          TYPE zemployee-dob,

                 dept         TYPE zemployee-dept,

              END OF t_zemployee.

I can't know how ZEMPLOYEE is defined in the dictionary, but probably a field is missing in your declaration: the client (MANDT)

Max