2009 Jan 30 4:30 AM
Hi experts,
I have implemented a BADI in FTR_CREATE tcode(contract creation). The BADI is triggered in save event. Here is the scenario:
Inside the standard program, one standard subroutine (PERFORM generate_number) is called that generates the contract number. After that, my BADI will be triggered to check some validation. Then when the BADI validation fails, user will remain in the contract creation screen to correct the inputted data. Upon the second time the user clicks the save button, the BADI is not triggered anymore because inside the subroutine (PERFORM generate_number) it is checking if the field NUMBER (which contains the contract number) is not blank:
IF number <> space.
exit
ENDIF.
But the field number is not blank anymore because at the first time the user clicked the save button the contract number is generated.
My problem is how can I refresh the number field when validtion fails so that whenever the user clicked the save button the BADI will always be triggered.
Edited by: Marc Ng on Jan 30, 2009 5:30 AM
2009 Jan 30 4:58 AM
Hi Marc,
The value of any field/structure/table of a standard program can be changed using Field symbols.
First assign the particular field/structure of the standard program to a field symbol using ASSIGN statement. Then check if any value has been assigned using statement
CHECK <fs-data> IS ASSIGNED.
Then manipulate/change the value of the field symbol as you like. This will change the value of the field/structure in the standard program.
But one important point to note is that using the above method only values of those variables can be assigned to field symbols which are defined in the global data declaration of the standard program.
Suppose the program is "SAPMXXXX" and the field is "FIELD1".
Your piece of code would be
FIELD-SYMBOLS: <fs_field1> TYPE ANY.
ASSIGN ('(SAPMXXXX)FIELD1) TO <fs_field1>.
CHECK <fs_field1> IS ASSIGNED.
<fs_field1> = ' '.
But for the above mentioned piece of code to run successfully the field "FIELD1" should be defined in the global data of program "SAPMXXXX".
Hope this helps.
Regards,
Abhisek.
2009 Jan 30 4:58 AM
Hi Marc,
The value of any field/structure/table of a standard program can be changed using Field symbols.
First assign the particular field/structure of the standard program to a field symbol using ASSIGN statement. Then check if any value has been assigned using statement
CHECK <fs-data> IS ASSIGNED.
Then manipulate/change the value of the field symbol as you like. This will change the value of the field/structure in the standard program.
But one important point to note is that using the above method only values of those variables can be assigned to field symbols which are defined in the global data declaration of the standard program.
Suppose the program is "SAPMXXXX" and the field is "FIELD1".
Your piece of code would be
FIELD-SYMBOLS: <fs_field1> TYPE ANY.
ASSIGN ('(SAPMXXXX)FIELD1) TO <fs_field1>.
CHECK <fs_field1> IS ASSIGNED.
<fs_field1> = ' '.
But for the above mentioned piece of code to run successfully the field "FIELD1" should be defined in the global data of program "SAPMXXXX".
Hope this helps.
Regards,
Abhisek.
2009 Jan 30 5:52 AM
Thanks Abhisek, but this statement <fs_field1> = ' '. is resulting to a short dump even if the field symbol is already assigned.
here is my code:
constant: gc_rfha(2) TYPE c VALUE '(SAPLFTR_CTY_OTC)TVB_HEADER-RFHA'.
ASSIGN gc_rfha TO <fs_rfha>.
<fs_rfha> = ' '.
2009 Jan 30 6:04 AM
Hi Marc,
May be the field symbol has not been assigned. That is why it is giving a dump.
Use the statement
CHECK <fs_field1> IS ASSIGNED.
after assign. This will prevent further processing in case nothing has been assigned to the field symbol. If assignment of field symbol fails and any operation on the field symbol is performed the system will generate a dump.
Also if you want to change the value of a variable then assign it to field symbols. If you want to change the value of a field in a table/structure then assign the table/structure to the field symbol and then change the value of the required field.
Use the following piece of code.
FIELD-SYMBOLS: <fs_tvb_header> TYPE ANY.
ASSIGN '(SAPLFTR_CTY_OTC)TVB_HEADER' TO <fs_tvb_header>.
CHECK <fs_tvb_header> IS ASSIGNED.
CLEAR <fs_tvb_header>-rfha.
This should not give a dump.
Also I could not find any program with the name "SAPLFTR_CTY_OTC" in my system.
Hope this helps.
Regards,
Abhisek.
2009 Jan 30 7:24 AM
Hi Abhisek,
In my code:
CONSTANTS gc_rfha(32) TYPE c VALUE '(SAPLFTR_CTY_OTC)VTB_HEADER-RFHA'.
FIELD-SYMBOLS: <fs_rfha> TYPE ANY.
ASSIGN gc_rfha TO <fs_rfha>.
Found the problem, in debug mode:
(SAPLFTR_CTY_OTC)VTB_HEADER-RFHA = 599 (contract number).
but in the statement ASSIGN gc_rfha TO <fs_rfha>, the value of <fs_rfha> is (SAPLFTR_CTY_OTC)VTB_HEADER-RFHA not 599.
2009 Jan 30 7:32 AM
Hi Marc,
The value is different after assign basically means that the value has been changed by standard SAP before calling the BADI method.
But still this should not have resulted in short dump.
Anyways, is your requiremetn solved?
Regards,
Abhisek.
2009 Jan 30 7:47 AM
Still having the short dump, the field symbol is having the hard coded value of (SAPLFTR_CTY_OTC)VTB_HEADER instead of the contract number.
<fs_rfha> = ' ' is still resulting in short dump.
2009 Jan 30 8:42 AM
Hi Marc,
It was a typo on my part. I missed out one "( )". Sorry.
Instead of '(SAPLFTR_CTY_OTC)TVB_HEADER' use ('(SAPLFTR_CTY_OTC)TVB_HEADER').
Try this
FIELD-SYMBOLS: <fs_tvb_header> TYPE ANY.
ASSIGN ('(SAPLFTR_CTY_OTC)TVB_HEADER') TO <fs_tvb_header>.
CHECK <fs_tvb_header> IS ASSIGNED.
CLEAR <fs_tvb_header>-rfha.
or
CONSTANTS gc_rfha(32) TYPE c VALUE ('(SAPLFTR_CTY_OTC)VTB_HEADER-RFHA').
FIELD-SYMBOLS: <fs_rfha> TYPE ANY.
ASSIGN gc_rfha TO <fs_rfha>.
Now it will not contain any hard coded value. Instead it will contain the value of the field itsef.
Hope it helps.
Regards,
Abhisek.
2009 Jan 30 9:36 AM
Many thanks Abhisek! Your solution solved the problem.