2013 Jul 21 1:00 PM
Hello everybody.
First of all, sorry for my English, I am from Catalonian and I know my english is very poor.
Ok, I am developping in Abap since 6 months, more or less, and know I have a little problem.
I hace defined an internal table where there are 12 fields like these: quantity01, quantity02, ... quantity12. Every field is defined for every month (January, february, ... , december).
My idea is assign the values depending of a date contained in other field of the table (field period).
Is something like this:
LOOP gt_report into gs_report.
IF gs_report-period = '01'.
gs_report-quantity01 = gs_report-quant.
ENDIF.
.......
IF gs_report-period = '02'.
gs_report-quantity02 = gs_report-quant.
ENDIF.
ENDLOOP.
I don't want to work with 12 IF's, because I have to do other operations.
I supose this is very easy for most of you, but I have searched a lot and I didn't find anything. I heart something like fieldsymbols but I don't know if these is really the solution.
Can anyone help me, please?
Thank you in advance.
2013 Jul 21 2:25 PM
Hi Marius Conchillo,
I am not having much expertise in the abap so i think my reply may help you.
I understood that your code should not write more if....endif statements.
Instead of writing multiple if...endif statements, we can assign the values to a data object and write a case statement.
using case..... endcase we can exclude multiple if statements.
I think this helped you.
2013 Jul 21 2:25 PM
Hi Marius Conchillo,
I am not having much expertise in the abap so i think my reply may help you.
I understood that your code should not write more if....endif statements.
Instead of writing multiple if...endif statements, we can assign the values to a data object and write a case statement.
using case..... endcase we can exclude multiple if statements.
I think this helped you.
2013 Jul 21 8:23 PM
Thank you for your answer Harsha.
Ok, I can use case/endcase, but by this way is more or less the same. Finally, I have to write 12 portions of code (1 for every month).
The idea is write only one.
Thank you Harsha.
2013 Jul 22 6:16 AM
Hello Conchilo,
You can try like this.
DATA : V_PERIO(40) TYPE C,
v_fs type any.
LOOP at gt_report into gs_report.
concatenate 'GS_REPORT-QUANTITY' GS_REPORT-PERIOD INTO V_PERIO.
ASSIGN (V_PERIO) TO V_FS.
V_FS = GS_REPORT-QUANTITY.
ENDLOOP.
Regards
Gourav.
2013 Jul 22 6:50 AM
Hi,
This will not work
here is how it should be
You can try like this.
DATA : V_PERIO(40) TYPE C.
FIELD-SYMBOLS <fs> TYPE ANY
LOOP at gt_report into gs_report.
concatenate 'GS_REPORT-QUANTITY' GS_REPORT-PERIOD INTO V_PERIO.
ASSIGN (V_PERIO) TO <FS>.
IF <FS> is assigned.
<FS> = GS_REPORT-QUANTITY.
ENDIF.
ENDLOOP.
Regards
Gourav.
2013 Jul 22 6:54 AM
Hi Yakub,
By mistake I wrote that line.
<fs> type any within data,Yes it will under field-symbol.
GOURAV.
2013 Jul 22 9:55 AM
Thank you everybody for your answers.
Now, it's working fine.
2013 Jul 22 7:13 AM
Hi Marius,
Other similar way to solve the problem is:
DATA: lv_name TYPE string.
FIELD-SYMBOLS: <lv_content> TYPE ANY.
LOOP AT gt_report INTO gs_report.
CONCATENATE 'QUANTITY' gs_report-period INTO lv_name.
ASSIGN COMPONENT lv_name OF STRUCTURE gs_report TO <lv_content>.
IF <lv_content> IS ASSIGNED.
<lv_content> = gs_report-quant.
ENDIF.
CLEAR: lv_name.
UNASSIGN: <lv_content>.
ENDLOOP.
Hope it helps. Cheers!
2013 Jul 22 8:30 AM
Hi Marius,
I hope your post is relevant to the below document, it clearly explain you how to use Field Symbols
http://scn.sap.com/docs/DOC-42525
Regard's,.
Shashi Kanth.