‎2013 Oct 07 1:13 PM
Hi All,
I have been developing a dialog program in which i used table control manually (WITHOUT WIZARD). now the table control first column is MATERIAL CODE and is a mandatory field,here i have to do two things.
1. I need to throw an error message when the material code already entered.i.e for eg. if the user enters this material code FDH01106DSAAAB0006 again, then i need to throw error message immediately .
2.After removing the material code, since it is a mandatory field, the screen is not getting enabled and it is giving message "Fill in all required entry fields".
here i need to enable the screen.
Please guide me in resolving these issues.
Thanks in Advance.................!
‎2013 Oct 07 1:43 PM
Hi Mallikarjun,
Considering your first qn;
1. I need to throw an error message when the material code already entered.i.e for eg. if the user enters this material code FDH01106DSAAAB0006 again, then i need to throw error message immediately .
You can do this in many ways; One way of doing this is, in PAI write a module just below the Table control Loop....Endloop, and sort the itab based on MATNR and delete adjacent duplicates, IF sy-subrc EQ o throw the error message and set the cursor on the field (MATNR).
And to your second qn;
2.After removing the material code, since it is a mandatory field, the screen is not getting enabled and it is giving message "Fill in all required entry fields".
here i need to enable the screen.
Remove the Required option from the Screen Painter (Layout) and control the same programmatically using the SCREEN structure.
Hope this will help you
Thanks & Regards
Manu S
‎2013 Oct 07 8:13 PM
Hi Manu,
First of all thanks for your reply. I tried your solution but it is not resolved yet...if have any piece of code for this....plz let me know.
Thanks
G M Reddy
‎2013 Oct 08 6:44 AM
Hi Mallikarjun,
In your PAI, after the Table control Loop....Endloop, write a module as MODULE duplicate_entry (Save this module in PAI), inside the Module write the below code.
SORT itab STABLE BY matnr.
DELETE ADJUCENT DUPLICATES FROM itab COMPARING matnr.
IF sy-subrc EQ 0.
SET CURSOR FIELD 'itab-matnr'.
MESSAGE eXXX.
ENDIF.
OR
As the fellow SCN-mates replied you can use READ TABLE inside the table control Loop....Endloop and throw the error message.
For your second problem after removing the 'Required' option from the Screen Painter, just write, READ TABLE itab
INTO wa_itab
WITH KEY matnr = ' '.
IF Sy-subrc EQ 0.
Throw error message.
ENDIF.
Use this code inside your Loop....Endloop. just below your duplicate 'finding' READ TABLE statement, as the others suggesting.
If you are using the MODULE duplicate_entry then just write the below code,
DELETE itab WHERE matnr EQ ' '.
IF sy-subrc EQ 0.
SET CURSOR FIELD 'itab-matnr'.
MESSAGE eXXX.
ENDIF.
Hope this will solve your issue
Thanks & Regards
Manu S
‎2013 Oct 08 4:53 AM
Hi,
Validate the field material no using chain endchain instead of making it as mandatory.
For eg.
CHAIN.
Field materialno.
module validate on chain input. ------>validate only if the material no is not initial.
ENDCHAIN.
For checking the duplicate entries use READ TABLE statement. Before appending the values to the internal table just check whether the same material no exist in the internal table.Use the read statement in the module validate.
For eg.
READ TABLE <itab> WITH KEY materialno = <field> TRANSPORTING NO FIELDS.
IF sy-subrc eq 0.
"Error msg
ENDIF.
‎2013 Oct 08 4:53 AM
Hi,
In the PAI when values are entered and enter button is pressed you need to check whether there are dupliacte entry in the internal table of the corresponding table control. For that you ca use the "READ" statement.
For Example.
READ
TABLE itab WITH TABLE KEY col1 = 'material code you just entered'.
if sy-subrc = 0.
"value is already there donot modify the internal table.
else.
"modify the internal table.
Refer the link below to make the screen proper automatically after getting the error message
http://scn.sap.com/community/abap/blog/2013/07/31/handy-sap-function-module-to-automate-pai-events
‎2013 Oct 08 5:04 AM
Hi,
To check for duplicate entries use READ statement.
For your second problem, Use CHAIN-ENDCHAIN, or validate it manually with the help TYPE 'E' message inside the step loop of table control.
Regards,
Riju Thomas.
‎2013 Oct 08 5:09 AM
Hi ,
keep all your code same , at PAI add chain ..... end chain
http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbaa4735c111d1829f0000e829fbfe/content.htm (details about chain ..end chain ) .
Chain .
fields : fieldname1,fieldname2 .
module check_duplicate on request .
http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbabbd35c111d1829f0000e829fbfe/content.htm (about
conditional module calls (on request) )
endchain .
module check_duplicate .
Check whether material number already exists in your table control internal table .
if exists throw an error message (meassage of type e ) .
end module .
With Regards ,
Juneed K Manha
‎2013 Oct 08 5:36 AM
Hii Malikarjun,
For duplicate entry prevention use
module insert row user_command 9000 INPUT.
module insert row.
perform duplicate material no check_entry.
rest of ur insertion of row code..
end module.
form duplicate material no check_entry.
SORT itab by matnr ascending.
READ TABLE itab WITH KEY matnr BINARY SEARCH TRANSPORTING matnr.
IF sy-subrc eq 0.
Message 'Same records exist' type 'E' WITH matnr.
ENDIF.
endform.
For screen enabled,
don't make any field mandatory in layout, validate the filed in the program like below,
module user command_9000 INPUT.
Loop at itab.
chain.
FIELD: <filed1>,
<field2>,
<field3>.
MODULE validate_filed ON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
MODULE validate_field.
if matnr is initial.
SET CURSOR FIELD 'matnr'.
MESSAGE 'Enter the material number' TYPE 'E' LINE sy-stepl.
endif.
if <filedname> is initial.
SET CURSOR FILED '<filedname>' LINE sy-stepl.
MESSAGE " type 'E'.
endif.
like ths proceed.
ENDMODULE.
if any filed is initial during insertion of data in TC
the error message will be raised and the field will be editable agian that's the benefit of chain and endchain
Hope this will help u to resolve ur issue.
regards
Syed
‎2013 Oct 08 7:03 AM
Hi
one option is the chain end chain method. when u press an enter wirte the approiate code in the pai for the chekcking for duplicate values or just see whether the material number can be generated automatically. if possile make material no as a non editable field and process. and make sure the moment you press save or enter only the material number has to be generated.
With regards
Suneesh
‎2013 Oct 10 6:53 AM
Hi,
In the PAI Event,
LOOP itab.
CHAIN
FIELD field1
field2
.
.
.
MODULE validate_input.
ENDLOOP.
******************************************************
MODULE validate_input.
MODIFY itab FROM wa INDEX table_con-current_line.
IF sy-subrc <> 0.
READ TABLE itab INTO wa_tmp WITH KEY field1 = wa-field1.
IF sy-subrc NE 0.
APPEND wa TO itab.
ELSE.
CLEAR wa_tmp.
MESSAGE 'Duplicate Entries' TYPE 'E'.
ENDIF.
ENDIF.
ENDMODULE.
Regards,
Shahanaz.
‎2013 Oct 10 8:45 AM
thanks...but my problem is not resolved for the duplicate entries.
‎2013 Oct 10 8:46 AM
i tried as per all your suggestions but still not resolved my issue for the duplicate entries..
‎2013 Oct 10 9:12 AM
Hello mallikarjun,
In short, you have to write a form in which you are USING the material field and CHANGING a flag as the boolean value.
In form, you will check for each record if there are other records like it, doing a loop from the beginning to the end of table control. If there is a record, you raise the flag with +1.
At the end, you should have flag = 1. If flag > 1 then you have more than 1 record with the same key field.
Please ask if I wasn't clear.
Paul.
‎2013 Dec 15 2:35 PM