2014 Sep 02 2:42 PM
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.
2014 Sep 02 3:13 PM
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.
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.
2014 Sep 02 2:46 PM
2014 Sep 02 2:47 PM
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.
2014 Sep 02 3:01 PM
I get the error message as wa_zemployee in not long enough..
2014 Sep 02 2:50 PM
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
2014 Sep 02 3:03 PM
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.
2014 Sep 02 3:06 PM
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
2014 Sep 02 3:08 PM
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.
2014 Sep 02 3:17 PM
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
2014 Sep 02 3:34 PM
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.
2014 Sep 02 3:12 PM
Probably zemployee is different from wa_zemployee.
Use type zemployee for declare wa_zemployee.
2014 Sep 02 3:12 PM
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
2014 Sep 02 3:13 PM
Hi Sanjeev,
Please avoid "Please reply soon" statements in this forum.
Regards,
Kannan
2014 Sep 02 3:36 PM
2014 Sep 02 3:13 PM
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.
2014 Sep 02 3:16 PM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |