2016 Mar 15 4:20 AM
Hi all,
I have a required as follow:
In the screen, there are two fields, one is a char 2 input field(field A), the other is a char 10 date input field(field B).
In PBO, field B would show the date like 2010/09/08 or 08.09.2010, it depends on SU3 setting.
Then I would input a new month value like '11' in field A and then field B would be changed to 2010/11/08 or 08.11.2010.
My question is, how can I know the month position of field B when I wan to change the month value?
I don't know the user's local format so that it could be either format, including but not limit to the two formats I mentioned.
.
2016 Mar 15 8:13 AM
Hi ,
I just created a report program, simulating the scenario.
Please go through this, hope this is helpful.
PARAMETERS : field_a TYPE c LENGTH 2,
field_b TYPE c LENGTH 10.
DATA: lv_date TYPE sydatum.
AT SELECTION-SCREEN.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = field_b
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = lv_date
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF field_a IS NOT INITIAL.
lv_date+4(2) = field_a.
WRITE lv_date TO field_b USING NO EDIT MASK.
ENDIF.
Regards
Pallavi Koora
2016 Mar 15 4:33 AM
Sy-datum is default type for date. The output will based on SU3 setting, but if you will debug, you can see that the value of date is based on YYYMMDD format. So you can do offsetting to get the month value. You can do this:
DATA:
l_data TYPE sy-datum,
l_month TYPE i.
l_data = sy-datum.
l_month = l_data+4(2).
2016 Mar 15 7:28 AM
Actually, the system is not using standard datum format, it uses char 10 format instead for the screen.
But on the logic level, it has a variable which uses datum format, so I tried that.
However, there still leaves the question.
2016 Mar 15 7:42 AM
Hi,
create a dummy field <date1> of type datum. Take the value which is in field B and write that to your dummy field <date1> by masking.
WRITE <field B> to <date1> " DD/MM/YYYY / " DDMMYY / .
These two are the masking provided for date. By this you will get the exact position of month . Change that in <date1> from the input field A and again assign that value to field B for output.
I think that should solve the problem.
2016 Mar 15 7:49 AM
But there could be many formats for displaying.
And I just take these two as example.
2016 Mar 15 7:57 AM
Hi,
yes there can be. As you are displaying in char 10 format.
As I can get from your requirement is that you are giving input in field A and showing the date output in field B by changing the month, right.?
If you are asking about date format then char(10) or datum is widely used. You can also use that.
The way which I have suggested will not effect the display.
You can also do one thing in-spite of creating that dummy field <date1> of type datum, create it char(10). and follow the rest. Put a breakpoint at write statement and check that its working or not. Then u will get the proper position.
Then for changing value of month you can use the offset way.
2016 Mar 15 8:10 AM
Try this. I tried it working
DATA: l_date TYPE sy-datum,
l_test TYPE char10.
PARAMETERS: p_date TYPE char10.
CALL FUNCTION 'CY_CONVERT_DATE'
EXPORTING
date_string_imp = p_date
IMPORTING
date_string_exp = p_date
date_exp = l_date.
WRITE l_date+4(2).
2016 Mar 15 8:15 AM
Yes, this is working.
But if you change the month and in PAI , you want p_date to show the new month.
How you write the logic of that?
2016 Mar 15 8:13 AM
Hi ,
I just created a report program, simulating the scenario.
Please go through this, hope this is helpful.
PARAMETERS : field_a TYPE c LENGTH 2,
field_b TYPE c LENGTH 10.
DATA: lv_date TYPE sydatum.
AT SELECTION-SCREEN.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = field_b
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = lv_date
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF field_a IS NOT INITIAL.
lv_date+4(2) = field_a.
WRITE lv_date TO field_b USING NO EDIT MASK.
ENDIF.
Regards
Pallavi Koora
2016 Mar 15 8:26 AM
Yes, I tried this and it's correct!
In a nut shell:
CHAR 10 -> DATUM
Use a FM
DATUM->CHAR 10
USING NO EDIT MASK key word
Thank you for the help.
2016 Mar 15 8:31 AM
Bad Practice.
Don't use numerical offsets to get different bits of known format strings. Always define a structure, move the string to the structure and then move the structure fields to where you want them. Conversely if you have part of the main string in a sub string, move that substring to the structures relevant field.
Much more readable, easier to understand and maintain.
Rich