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

Reading dynamic table column based on user selection

Former Member
0 Likes
449

Hi there,

I am having a problem of reading and manipulating the data stored in a standard SAP table. The following example simulates the table and what i am trying to do:

Table: Storing sales data for sales person

SALES_PERSON REGION YEAR MTH_S1 MTH_S2 MTH_S3 MTH_S4...

Richard S NORTH 2007 100 200 300 400

John K SOUTH 2007 50 100 100 20

Brad P NORTH 2007 300 100 100 50

User have have the following selection option:

1. Month.

The program will calculate the sales based on the individual month selected

Example, if user select Month = 3, then program take only MTH_S3 column value

So total sales = 300100100=500

2. Month range

The program will calculate the sales based on the month range selected

Example, if user select Month 2 to 4, then program take MTH 2 to MTH_S4 columns value

So total sales = 400 (for MTH_S2) + 500 (for MTH_S3) + 470 (for MTH_S4) = 1370

How should i write the logic or code for this requirement?

Hope someone can help.

Thanks,

Pang HK

3 REPLIES 3
Read only

Former Member
0 Likes
426

plz specify the table u r using i mean the standard sap table

Read only

0 Likes
426

Hi there,

I am using the FMBDT table

Read only

Former Member
0 Likes
426

Try something like this

TABLES:

t247.

SELECT-OPTIONS:

s_month FOR t247-mnr NO-EXTENSION.

DATA:

BEGIN OF fs_data,

person(30),

area(10),

year(4),

mon1 TYPE kbetr,

mon2 TYPE kbetr,

mon3 TYPE kbetr,

mon4 TYPE kbetr,

mon5 TYPE kbetr,

END OF fs_data,

t_data LIKE STANDARD TABLE OF fs_data,

w_no_months TYPE i,

w_kbetr TYPE kbetr,

w_total TYPE kbetr.

LOOP AT t_data INTO fs_data.

CLEAR w_kbetr.

DO 5 TIMES VARYING w_kbetr FROM fs_data-mon1

NEXT fs_data-mon2.

IF sy-index IN s_month.

w_total = w_total + w_kbetr.

ENDIF.

ENDDO.

ENDLOOP.

change the value 5, according to the no.of months in ur internal table