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

dynamic field symbol declaration

marcelo_dudzin2
Explorer
0 Likes
3,407

Currently there is a badi that contains instructions to manipulate data from an HRFORM named zhr_payslip_xxx.

The code is as follows:

FIELD-SYMBOLS: <im_data>  TYPE /1pyxxfo/zhr_payslip_xxx.

  DATA: l_lines             TYPE i,

        ls_deductions_y4    LIKE LINE OF <im_data>-star_deductions_y4,

        ls_payments_z9      LIKE LINE OF <im_data>-star_payments_z9,

        wc_notices          LIKE LINE OF <im_data>-star_notices,

        wc_inperiod         LIKE LINE OF <im_data>-dim_forperiod,

        l_begdate           TYPE d,

        l_enddate           TYPE d.

* Assign the infostar!

  ASSIGN ch_data->* TO <im_data> CASTING.

*Reject if no data!

  DESCRIBE TABLE <im_data>-dim_inperiod_id LINES l_lines.

  IF l_lines = 0.

    RAISE reject.

  ELSE.

* Save current period info

    READ TABLE <im_data>-dim_forperiod INDEX 1 INTO wc_inperiod.

    l_begdate = wc_inperiod-key-begin_date.

    l_enddate = wc_inperiod-key-end_date.

  ENDIF.

I need to re use the same code but with a different HRFORM named zhr_payslip_yyy.

Are any of you aware on how can it be possible to declare/assign a different type to <im_data>?

Something like a

if XXX =‘1’.

FIELD-SYMBOLS: <im_data>  TYPE /1pyxxfo/zhr_payslip_xxx.

Else

FIELD-SYMBOLS: <im_data>  TYPE /1pyxxfo/zhr_payslip_yyy.

Endif.

Could anybody please point me on the correct direction on how to achieve this ?

1 ACCEPTED SOLUTION
Read only

naveen_inuganti2
Active Contributor
0 Likes
2,050

Use type ANY.

FIELD-SYMBOLS: <im_data>  TYPE ANY.

Regards,

Naveen

Use type ANY.

FIELD-SYMBOLS: <im_data>  TYPE ANY.

Regards,

Naveen

3 REPLIES 3
Read only

naveen_inuganti2
Active Contributor
0 Likes
2,051

Use type ANY.

FIELD-SYMBOLS: <im_data>  TYPE ANY.

Regards,

Naveen

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,050

Do it all dynamic as Naveen said (and you'll also need to use additionally other field symbols and statements like ASSIGN COMPONENT 'DIM_INPERIOD_ID' OF STRUCTURE <im_data> TO <dim_inperiod_id>), but if you have only one other HR form, then maybe it will be more readable to define a separate field symbol:

FIELD-SYMBOLS: <im_data_xxx>  TYPE /1pyxxfo/zhr_payslip_xxx.

FIELD-SYMBOLS: <im_data_yyy>  TYPE /1pyxxfo/zhr_payslip_yyy.

if XXX =‘1’.

ASSIGN ch_data->* TO <im_data_xxx> CASTING..

" only work with <im_data_xxx>

Else.

ASSIGN ch_data->* TO <im_data_yyy> CASTING..

" only work with <im_data_yyy>

Endif.

Read only

marcelo_dudzin2
Explorer
0 Likes
2,050

Thank you both.

I have done already something similar to  Sandra's code, but I am not entirely happy about it.

I want to use the same Field-symbol name but different type.

I will see if  I can learn to do it with the assign component code...

Thank you