Application Development 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: 

To select the field dynamically while fetching th e data

kavya_2017
Explorer
0 Kudos

Hi Experts,

We have fields like TKG001, TKG002, TKG003 etc in COST table...

My requirement is that we want the value present in the field TKG0** where ** is the month of system data.

Do we have any method to extract the field dynamically from the table.

Please suggest me how can i achieve the requirement.

Thank you,

Regards,

Kavya

1 ACCEPTED SOLUTION

bbalci
Contributor
0 Kudos

Hello

You can use dynamic field specification

Check this :

REPORT x.

DATA :

      BEGIN OF lw_field,
        field(20),
      END OF lw_field,
      lt_field LIKE STANDARD TABLE OF lw_field.

START-OF-SELECTION.

  lw_field-field = 'BUKRS'.
  APPEND lw_field TO lt_field.

  lw_field-field = 'GJAHR'.
  APPEND lw_field TO lt_field.


  SELECT (lt_field)   "<-- Internal table contains your dynamically specified in parenthesis 
  FROM bkpf
  INTO TABLE itab.

  BREAK-POINT.

5 REPLIES 5

Former Member
0 Kudos

Dear Kavya,

Could you please elaborate your query ? If you want to extract data through any programme you can always define some variable according to the no. of a particular month.

Anyway, please elaborate on your requirement.

Regards

bbalci
Contributor
0 Kudos

Hello

You can use dynamic field specification

Check this :

REPORT x.

DATA :

      BEGIN OF lw_field,
        field(20),
      END OF lw_field,
      lt_field LIKE STANDARD TABLE OF lw_field.

START-OF-SELECTION.

  lw_field-field = 'BUKRS'.
  APPEND lw_field TO lt_field.

  lw_field-field = 'GJAHR'.
  APPEND lw_field TO lt_field.


  SELECT (lt_field)   "<-- Internal table contains your dynamically specified in parenthesis 
  FROM bkpf
  INTO TABLE itab.

  BREAK-POINT.

raymond_giuseppi
Active Contributor
0 Kudos

Yes [SELECT|http://help.sap.com/abapdocu_70/en/ABAPSELECT.htm] statement allow a dynamic [SELECT - columns|http://help.sap.com/abapdocu_70/en/ABAPSELECT_CLAUSE_COLS.htm#&ABAP_ALTERNATIVE_3@3@] syntax - Check the sample at the bottom of the last link.

Regards,

Raymond

0 Kudos

Hi Bulent and Raymond,

Your answer solved my problem,

Thank you

Former Member
0 Kudos

A simpler way would be to select the twelve fields and then decide which one to use while processing the internal table.