‎2019 May 21 10:06 AM
Hi,
My requirement is selection screen has a field called PERIOD.
If the user give a value '4' in the period field, then the fields TSL01, TSL02, TSL03, TSL04 from table JVTO1 with details has to be displayed.
Similarly if the user gives '5' in the period field then fields TSL01, TSL02, TSL03, TSL04, TSL05 from table JVTO1 with details has to be displayed and so on.
Could someone suggest something regarding this?
‎2019 May 21 1:17 PM
Easy. The below assumes you read out all the required fields from the table into an internal table. Then you can loop over the data and process ....
Do period times.
data(lv_field_name) = 'TSL' && sy-tabix. "Maybe additional formatting of counter is required
assign component (lv_field_name) of structure X to field-symbol(<fs_field>).
check ( sy-subrc eq 0 ).
*do whatever you want with the field value
enddo.
‎2019 May 21 2:06 PM
‎2019 May 22 2:23 AM
If your requirement is simple, you could try dynamic SQL and inline declaration to achive:
field_list = VALUE #( BASE ( field_list ) FOR i = 1 UNTIL i = input_value ( |TSL0{ i }| ) ).
SELECT (field_list)
FROM JVTO1
WHERE (condition)
INTO TABLE @DATA(itab).
in case it more complex (with extra calculation after SQL or something else), you should select all fields then build a dynamic internal table:
https://wiki.scn.sap.com/wiki/display/Snippets/Example+-+create+a+dynamic+internal+table