Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Selecting required fields from a table

Former Member
0 Likes
1,117

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?

3 REPLIES 3
Read only

StevenDeSaeger
Contributor
0 Likes
874

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.
Read only

RaymondGiuseppi
Active Contributor
0 Likes
874

Either create a dynamic table or use ALV and adapt field catalog ( no_out = abap_true ) or cl_salv_column->set_visible( value = abap_false )

Read only

DoanManhQuynh
Active Contributor
0 Likes
874

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