Saturday, November 03, 2007

SAP R/3 : Payroll Detail and Field Symbol

Very similar to a past report which I had done and requires it to display dynamic numbers of column and it occurs to me maybe I should just put a template here and share it with everyone who are using it. The report which I had just completed displayed list of employees with all of their basic pay, allowance, deductions and employer contribution from left to right.

Thus, any employee at one point might not have the same number of wagetypes [allowance/deductions] with hers or his peers. So the list that displaying those wage types will need to be very flexible when its display an employee and spreading their wagetypes to right of the report. Here goes the coding that I used to display it dynamically.

Assumingly your field for wagetypes in a structure looks like below:

DATA : BEGIN OF ta_wage,
pernr like pernr-pernr,
col001(010) type c,
col002(010) type c,
col003(010) type c,
col004(010) type c,
...
col050(010) type c,
DATA : END OF ta_wage.

As you see the above data structure has 50 columns. Each of this columns will hold a number of wagetypes [allowance/deductions] for an employee. So it should be dynamically to recognize a column that is occupied and to append it with the next employee's wagetype. Otherwise, it will use the next column.

Thus the coding to recognize the degree of each column that spread from left to right is as follows.

DATA : tp_ind(003) TYPE n.
CONSTANTS : cn_col(011) TYPE c VALUE 'TA_WAGE-COL'.
FIELD SYMBOLS : TYPE any.

LOOP ta_wagetype.
DO VARYING tp_value FROM ta_wage-col001 NEXT ta_wage-col002.
IF tp_ind = 50.
exit.
ENDIF.

CONCATENATE cn_col tp_ind INTO tp_dyncol.
ASSIGN (tp_dyncol) TO tp_value.

[add your logic here]

ADD 1 TO tp_ind.
ENDDO.
ENDLOOP.

Notice that i had declared an index variable to hold the count of item; a constant to assign to a field symbol to capture the column dynamically; and the field symbol to move contents fluidly (in my terms not SAP official explanation).

After that i perform a DO VARYING in the INTERNAL TABLE ta_wagetype so that for each employee, I can scroll the columns dynamically to the right and get the content. As I go to the right of each column's content I can actually assign a new value, shift left or shift right and determine which is the last column that it last stop.

is sky the limit... do varying and field symbol...