cancel
Showing results for 
Search instead for 
Did you mean: 

Deriving Calmonth from Fisacal period and Fiscal variant-Code not working

vyellamelli
Participant
0 Kudos

Hi Experts,

I have ABAP code in Field routine of transformation for deriving calmonth from Fiscal perios and Fiscal year variant .If I try to debug in DTP it is not going to debug mode.The code is as below.I dont know where it is going wrong .It is not fetching any values for Cal month from fiscal period and Fiscal variant.the code is as below

IF SOURCE_FIELDS-fiscvarnt = 'V3'.

CASE SOURCE_FIELDS-fiscper+4(3).

WHEN '001' OR '002' OR '003' OR '004' OR '005' OR '006' OR '007'

OR '008' OR '009'

.

zcalyear = SOURCE_FIELDS-fiscper+0(4).

zmonth = SOURCE_FIELDS-fiscper+5(2) + 3.

CONCATENATE zcalyear zmonth INTO zcalmonth.

RESULT = zcalmonth.

WHEN '010'.

zcalyear = SOURCE_FIELDS-fiscper+0(4) + 1.

zmonth = '01'.

CONCATENATE zcalyear zmonth INTO zcalmonth.

RESULT = zcalmonth.

WHEN '011'.

zcalyear = SOURCE_FIELDS-fiscper+0(4) + 1.

zmonth = '02'.

CONCATENATE zcalyear zmonth INTO zcalmonth.

RESULT = zcalmonth.

WHEN '012'.

zcalyear = SOURCE_FIELDS-fiscper+0(4) + 1.

zmonth = '03'.

CONCATENATE zcalyear zmonth INTO zcalmonth.

RESULT = zcalmonth.

ENDCASE.

ENDIF.

Please suggest where it is going worng.Is there any better way to write the code using any FM

Regards

Prasad

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can access debugging by going to SM50, when load is running. Go to SM50 and mark the run --> go to 'program/session' > 'program'> 'debugging'.

Br,

Sonni

vyellamelli
Participant
0 Kudos

Hi Sonni

Thanks for the reply.Please suggest is there any refining is required in code

Regards

Prasad

former_member186445
Active Contributor
0 Kudos

you can use a formula to do this

CALMONTH_FISCPER Calculate Fiscal Period from Calender Month (YYYYMM -Y YYYYPPP)

Answers (3)

Answers (3)

Former Member
0 Kudos

Prasad,

Unless you are using a routine for some other purpose, you could use a formula instead. I am not a 100% sure but i am assuming might help in performance.

Create an input mapping from you fiscal year period field to the field you want to populated with calendar year. Go to rule details and choose to use a formula. Enter formula as -

MONTH_YEAR ( FISCPER_CALMONTH( Fiscal Period, Fiscal Variant, Fiscal Year))

where FISCPER_CALMONTH will return the year and month of the fiscal period and MONTH_YEAR will return the year.

Also with routine and formulas, there is an easier way to test rather than running the DTP in debug mode.

Once you have created your field routine or formula and saved it and ready to hit the transfer value button, there is an option on the same window to test routine / formula (next to the transfer values button). Click on it and you can enter whatever value you want and see the output of your routine / formula.

Hope this helps.

Former Member
0 Kudos

Hi,

You can use this simple code.

IF SOURCE_FIELDS-fiscvarnt = 'V3'.

zmonth = SOURCE_FIELDS-fiscper+5(2).

IF ZMONTH LE 9.

ZYEAR = SOURCE_FIELDS-fiscper+0(4).

zmonth = zmonth + 3.

ELSE.

ZYEAR = SOURCE_FIELDS-fiscper+0(4) + 1.

zmonth = zmonth - 9.

ENDIF.

CONCATENATE zcalyear zmonth INTO zcalmonth.

RESULT = zcalmonth.

ENDIF.

Thanks & Regards

Kiran

vyellamelli
Participant
0 Kudos

Hi Kiran And M

Both formual & The code given by you also not working can you suggest any other code using FM.Please get me this if possible.

Regards

Venkatesh

Edited by: PRASAD on Mar 30, 2010 5:33 PM

former_member185181
Active Contributor
0 Kudos

use function module FIRST_DAY_IN_PERIOD_GET. You pass the fiscal year, the fiscal period and the fiscal year variant to it and it delivers the first calender day of that period. Take that calender day and use the first four characters as the year and characters five and six for the month. characters one to six will be the calmonth.

former_member186445
Active Contributor
0 Kudos

if the formula is not working, i suppose you don't put the correct parameters. Can you please post the formula you are using (with the source fields)

M.

former_member181964
Active Contributor
0 Kudos

Hi,

See the below code in revers way.

It will get disply First Fy Year into the text variable ZT_FTMNTH1 based on User input Month for the variable ZS_MONTH

WHEN 'ZT_FTMNTH1'.

    IF i_step = 2.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZS_MONTH'.
        IF sy-subrc = 0.

          CLEAR: l_s_range.

          zcmnth = loc_var_range-low.

          CALL FUNCTION 'FISCPER_FROM_CALMONTH_CALC'
            EXPORTING
              iv_calmonth       = zcmnth
              iv_periv          = 'V3'
           IMPORTING
*             EV_FISCPER3       =
*             EV_FISCYEAR       =
              ev_fiscper        = zfyprd.

          CALL FUNCTION 'UMC_FISCPER_TO_CALMONTH'
            EXPORTING
              i_periv     =  'V3'
              i_fiscper   =  zfyprd
*              i_calmonth_ichanm   =
            IMPORTING
              es_calmonth = zumc_ys_dimvals.
*              exceptions
*              invalid     = 1
*              OTHERS      = 2.
*          IF sy-subrc <> 0.
*             * message id sy-msgid type sy-msgty number sy-msgno
*             * with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*          ENDIF.

          l_s_range-low+0(4)  = zumc_ys_dimvals-bw_val_nam+0(4).
          l_s_range-low+4(1)  = '.'.
*          l_s_range-low+5(2)  = ZUMC_YS_DIMVALS-BW_VAL_NAM+4(2).
          l_s_range-low+5(2)  = '03'.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.

        ENDIF.
      ENDLOOP.
    ENDIF.

Use UMC_FISCPER_TO_CALMONTH FM and try.

See Customer Exit Blogs and Artcles.

https://wiki.sdn.sap.com/wiki/display/profile/Surendra+Reddy

Thanks

Reddy

vyellamelli
Participant
0 Kudos

Hi Surendra,

Thanks a lot.....!!! for your reply.But my code is in transformation -field routine not in eixt variable.If you can suggest me any function module which converts fiscal period to calmonth using fiscal variant it would be of great help.Or please suggest any changes required for my exisintg code written laready.

regards

Prasad

former_member186445
Active Contributor
0 Kudos

is there any particular reason why you don't want to use the formula? it does what's supposed to do...no additional coding required...standard transformation...

M.

vyellamelli
Participant
0 Kudos

Dear M,

If I got Formula it is giving

FISCPER_CALMONTH( , , , ) what to give in between these commas,

Please let me know and is it it dynamic or hard code ..????? will it take changing periods automoatically

Prasad

Edited by: PRASAD on Mar 30, 2010 8:54 AM

former_member186445
Active Contributor
0 Kudos

To derive period from calendar month:

CALMONTH_FISCPER( 'calendar month field' , 'fiscal variant field', 0 )

To derive calender month from period:

FISCPER_CALMONTH( FISCPER, FISCVAR, FISCYEAR, 0 ).

M.