06-18-2008 8:58 PM
Good day, everyone!
I am working on a program in which there are many different amount fields in which an amount may be assigned. For reusability purposes, I was wondering if it would be possible to write a routine that identifies the target amount field, stores it in a variable that is passed back to the calling program, and then assigns a value to it. There may be different structures having the same field name; what I'm trying to do is avoid having to code a huge IF or CASE statement for each structure. For example:
Structures S1, S2, and S3 have some fields identically named. Call one of them F1.
What I'd like to do is call a routine that identifies "F1" as my target field to populate. Then, upon return, I can assign it to the desired structure. Kinda like this:
S1-fieldname = 24.17. (but fieldname isn't a true field in the structure -- it would hold the value of the true field, "F1").
I realize this might not even be possible, but given how talented the folks are on this forum, I thought I should at least pose the question.
As always, points given for all helpful answers, and thank you!!
Dave
06-18-2008 9:31 PM
Hi,
The value in the variable w_column_name should be in capital letters...which means the field name in the variable should be in capital letters..
Thanks
Naren
06-18-2008 9:04 PM
You can do that by the use of Field-Symbols.
http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3923358411d1829f0000e829fbfe/content.htm
check the link to get the details of how to use a field symbol and try to implement it in your solution
06-18-2008 9:21 PM
Ok. I gave that a shot, but what happens is that my ASSIGN COMPONENT statement doesn't work. It gets a sy-subrc of 4, and <column> remains unassigned. The program then abends on the line to assign <a1>-trbtr's value to the field because of <column> being unassigned.
DATA:
w_setname TYPE setleaf-setname,
w_column_name(20) TYPE c.
ASSIGN COMPONENT w_column_name OF STRUCTURE wa_expense_ng_report
TO <column>.
<column> = <a1>-trbtr.
Any thoughts on what I might be doing wrong?
06-18-2008 9:32 PM
Possible reasons
1. w_column_name may not be available in structure wa_expense_ng_report
2. w_column_name not in CAPS
3. field-symbol declaration is wrong
a®
06-18-2008 9:31 PM
Hi,
The value in the variable w_column_name should be in capital letters...which means the field name in the variable should be in capital letters..
Thanks
Naren
06-18-2008 9:46 PM
Thank you so much to ALL OF YOU! My problem was that the field name wasn't capitalized! Once I fixed it, it worked like a charm.
Points awarded to all of you as well!
Dave