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

To select the field dynamically while fetching th e data

kavya_2017
Explorer
0 Likes
897

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

bbalci
Contributor
0 Likes
810

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

Former Member
0 Likes
810

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

Read only

bbalci
Contributor
0 Likes
811

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
810

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

Read only

0 Likes
810

Hi Bulent and Raymond,

Your answer solved my problem,

Thank you

Read only

Former Member
0 Likes
810

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