2005 Sep 06 7:40 PM
In selection screen, skunag(vbrk-kunag) and swerks(vbrp-werks) fields are there.these two fileds are obligatory.
If skunag field values start with 'P'.I have to remove the initial 'P' in that values,because I have to validate that field with ztable-kunag.
i have written folllowing way.but no result.
AT SELECTION-SCREEN ON SKUNAG.
PERFORM check_skunag.
form check_skunag.
data: p_kunag(10) type c.
if not skunag is initial.
p_kunag = skunag+4(4).
move p_kunag to skunag.
endif.
endform.
one more thing this skunag filed is also using in another form for database selection.In this form i want to use the above skunag field, after validation....
form gatherdata.
SELECT vbeln kunag zuonr vkorg waerk fkart FROM vbrk INTO CORRESPONDING FIELDS OF TABLE itab
WHERE vbeln IN svbeln
AND kunag IN <b>skunag</b>.
endform.
how can i write the above scenario...
thanks in advance,
fractal
2005 Sep 06 7:52 PM
Hi Fractal;
Try using a separate range for the value when you want the "P" removed. Example:
ranges: ra_kunag for vbrk-kunag.
ra_kunag[] = skunag[].
loop at ra_kunag.
shift ra_kunag-low left deleting leading 'P'.
shift ra_kunag-high left deleting leading 'P'.
modify ra_kunag.
endloop.
Now you have two ranges, one has the leading 'P' (skunag), and the other (ra_kunag) does not. You can use the range in your select statement if you want, and still have the original values in the select-option.
Cheers,
John
Message was edited by: John Carlson
2005 Sep 06 7:51 PM
2005 Sep 06 7:52 PM
Hi Fractal;
Try using a separate range for the value when you want the "P" removed. Example:
ranges: ra_kunag for vbrk-kunag.
ra_kunag[] = skunag[].
loop at ra_kunag.
shift ra_kunag-low left deleting leading 'P'.
shift ra_kunag-high left deleting leading 'P'.
modify ra_kunag.
endloop.
Now you have two ranges, one has the leading 'P' (skunag), and the other (ra_kunag) does not. You can use the range in your select statement if you want, and still have the original values in the select-option.
Cheers,
John
Message was edited by: John Carlson
2005 Sep 06 8:11 PM
hi srinivas,
skunag is in select-option.I changed like you said.
If i enters multiple values in skunag if the values are not matches with zplants table,then i have to add
zplants-vplant field to skunag.what statements should i write?
data: p_kunag(10) type c.
LOOP AT skunag.
CHECK skunag-low+0(1) = 'P'.
p_kunag = skunag-low+1. "(remove the first P).
SELECT * FROM zplants
WHERE werks = p_kunag
and reswk in swerks.
IF sy-subrc <> 0.
DELETE skunag.
ELSE.
MOVE p_kunag to skunag-low.
MODIFY skunag.
ENDIF.
endselect.
endloop.
Thanks,
fractal
2005 Sep 06 8:36 PM
Hi Fractal;
Try taking it out of the AT SELECTION-SCREEN event and placing it after the START-OF-SELECTION event, which you may want to use to distnguish your processing blocks from each other. It may be get over-written after the event you are currently using.
Cheers,
John
2005 Sep 06 8:51 PM
I am sorry I didn't fully understand your statement
<i>"If i enters multiple values in skunag if the values are not matches with zplants table,then i have to add
zplants-vplant field to skunag"</i>
If the entered skunag does <b>not</b> match with the zplants table, then you don't have the value for zplants-vplant. So how and what value do you get and move for zplants-vplant? Something is missing here.
Also, if zplants-vplant is plant, why do you want to add it to the skunag(which is customer, I guess) select option, not swerks(which is plant, I guess) select option.
Please clarify.
Srinivas
2005 Sep 06 9:22 PM
you are correct skunag is customer.i will get one plant name with skunag values(after deleting initial value 'p').
I have to validate the values which we are entering in selection screen with zplants table.zplants table has 2 plant fields(werks,reswk).
SELECT * FROM zplants
WHERE werks = p_kunag
and reswk in swerks.
1.If the entered plants matches with zplants table, i have to substitute swerks field with zplants-vplant field.
2.If multiple vlaues are entered in skunag field, after deleting initial 'p'in those values, i have to compare with zplants table(just like the above(select * from zplants....)),If it is not matches I have to add zplants-vplant field to skunag and i have to keep with original swerks field(value from selection screen) for further selection in the program.
thanks,
fractal
2005 Sep 06 9:34 PM
In point 2, as I said before, if it does not match, that means you did not get any record from zplants, then zplants-vplant will be blank right? So how can you move it to skunag.
Let us take an example.
Let us say the user entered the following values in skunag.
P10001
P10002
P10003
and the following values for swerks.
6000
6001
6002
Now here is our code.
Let us say that the select statment failed for the value of P10002. That means no records from zplants were selected, which means that the field zplants-vplant is blank. What is it that you want to do in this case?
Regards,
Srinivas
2005 Sep 06 10:09 PM
hi srinivas,
Zplants table has 3 fields(reswk,werks,vplant).vplant has always one default valueY278.I have to compare selection screen values with reswk and werks fields.
In the example, if those values(P10001 P10002 P10003) are not matches with zplants-werks field, then I have to add zplants-vplant (Y278) field to skunag.now skunag contains one value(Y278).then the program will continue with that value .
Now the values are .
For skunag
Y278
And for swerks
6000
6001
6002
how can write the above statements..
thanks,
fractal
2005 Sep 06 10:42 PM
Maybe this is what you want.
LOOP AT skunag.
*-- only if the first character is P
CHECK skunag-low+0(1) = 'P'.
p_kunag = skunag-low+1(remove the first P)
*-- check against the Z table with p_kunag
SELECT KUNAG FROM ztable WHERE kunag = p_kunag.
IF sy-subrc <> 0.
*-- invalid KUNAG
DELETE skunag.
ELSE.
*-- If you want to move the value without P back into
* your skunag then do the following
MOVE p_kunag to skunag-low.
MODIFY skunag.
ENDIF.
ENDLOOP.
IF skunag[] IS INITIAL.
*-- none of the values entered are valid, then add the
* default to this select option
CLEAR skunag.
skunag-low = 'Y278'.
skunag-sign = 'I'.
skunag-option = 'EQ'.
APPEND skunag.
ENDIF.
2005 Sep 07 2:43 PM
Hi srinivas,
everything is ok...except these 2 points.
1.Can i write like this,Instead of... skunag-low = 'Y278'. I want to write... skunag-low = zplants-vplant.
2.I want to do one more validation here(swerks field from selection screen).In the select statement, If any records found, I have to substitute zplants-vplant field for swerks.how can i write this statement...
SELECT * FROM ztable WHERE kunag = p_kunag
<b>and swerks in reswk</b>.
IF sy-subrc <> 0.
*-- invalid KUNAG
DELETE skunag.
ELSE.
*-- If you want to move the value without P back into
your skunag then do the following
MOVE p_kunag to skunag-low.
MODIFY skunag.
ENDIF.
endselect.
ENDLOOP.
Thanks,
fractal
Message was edited by: fractal ger
2005 Sep 07 10:45 PM
Hi Fractel,
1. No, I don't think you can write like that. You are coming to this stage only when you didn't find a record in "zplants". If that is true, then how can there be a value in the field zplants-vplant?
2. I don't know what you want to do here. Yes, I forgot adding the <b>and swerks in reswk</b> addition in the "where" clause. But, you want to update swerks or skunag? Your statement "If any records found, I have to substitute zplants-vplant field for swerks", is not clear. We are looping through the <b>skunag</b> select-option here, so we can update the skunag with the value of zplants-vplant. How will you identify which record of swerks you want to update, if that is what you want to do?
Please give me an example and let me know how you want to see the result.
Thanks,
Srinivas
2005 Sep 09 2:14 AM
Hi Srinivas,
Actually I want to update skunag and swerks fields.With your previous answers in this post, I am updating SKUNAG field.
Now I want to update swerks field, how can i do? I want to update with zplants-vplant field.Here is the specs for my report.
"If any selection fields(both the plants swerks and skunag(without 'P')) are matches with Zplants table,Substitute VPLANT for supplying plant(swerks). IF multiple skunag are entered and not all are matching with zplants table,
just add VPLANT field, don't remove the original swerks from the selection."
Shall write like this for swerks validation?
LOOP AT swerks.
*-- check against the Z table with p_kunag
SELECT werks FROM ztable WHERE werks = swerks.
IF sy-subrc <> 0.
DELETE swerks.
ELSE.
...........(What should i write here)
ENDIF.
ENDLOOP.
Thanks,
Fractal.
2005 Sep 09 3:09 AM
Is this what you want?
LOOP AT swerks.
*-- check against the Z table with p_kunag
SELECT werks FROM ztable WHERE werks = swerks.
IF sy-subrc <> 0.
DELETE swerks.
ELSE.
SWERKS-LOW = Z_PLANTS-VPLANT.
SWERKS-SIGN = 'I'.
SWERKS-OPTION = 'EQ'.
CLEAR SWERKS-HIGH.
APPEND SWERKS.
ENDIF.
ENDLOOP.
2005 Sep 06 8:01 PM
Hello Fractal,
Select options are not fields but actual internal table called range tables. There are four fields in this table (check it out in the debugger and also read the "Help" on keyword "Range", it makes things a lot easier). The four fields are sign, option, high, and low. Basically, these fields control all the various options you can choose w/a select-option.
To solve this issue, you will need to loop at the table skunag and modify the high and low values to omit the "P".
So the code should look something like this:
form check_skunag.
if not skunag is initial.
loop at skunag.
if skunag-low(1) = 'P'.
skunag-low = skunag-low+1(4).
modify skunag transporting skunag-low.
endif.
if skunag-high(1) = 'P'.
skunag-high = skunag-high+1(4).
modify skunag transporting skunag-high.
endif.
endloop.
endif.
endform.
If the above logic gets used, your other select should be fine.
2005 Sep 06 8:08 PM
Looks like skunag is a select-option. In that case, it will be very difficult to validate it because if the user enters a range like P00001 to P99999, how are you going to validate this against the Z table.
First you will have to restrict the user from using ranges. That you can do by defining your skunag with no-intervals. Then you will be able to validate that easily as user can only enter single values, no ranges.
You need to have your validation in AT SELECTION-SCREEN ON <b>skunag-low</b>.
In your FORM check_skunag, you need to change the code as follows
data: p_kunag(10) type c.
LOOP AT skunag.
*-- only if the first character is P
CHECK skunag-low+0(1) = 'P'.
p_kunag = skunag-low+1(remove the first P)
*-- check against the Z table with p_kunag
SELECT KUNAG FROM ztable WHERE kunag = p_kunag.
IF sy-subrc <> 0.
*-- invalid KUNAG
DELETE skunag.
ELSE.
*-- If you want to move the value without P back into
* your skunag then do the following
MOVE p_kunag to skunag-low.
MODIFY skunag.
ENDIF.
ENDLOOP.
2005 Sep 09 11:00 AM
Hi,
Try with this
SELECT-OPTIONS: SKUNAG for vbrk-kunag, " your field
DKUNAG for vbrk-kunag NO-DISPLAY.
before you processing the selet
DKUNG[] = SKUNG[].
LOOP AT DKUNG.
IF NOT DKUNG-LOW IS INITIAL.
DKUNG-LOW = skunag+4(4).
ENDIF.
IF NOT DKUNG-HIGH IS INITIAL.
DKUNG-HIGH = skunag+4(4).
ENDIF.
MODIFY DKUNG.
ENDLOOP
so now you have two select options as per your requirement
you can use both at different requirements.
Instead of the dummy select option you can use ranges also.
Cheers,
Sasi