Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
You are here to learn the ABAP field routine to convert 0CALMONTH to ZFISQRT.

 

In this blog we are using Fiscal Variant as V3, means our Fiscal year will start from April to March.

Also ZFISQRT is the custom generated object as per the requirement.

 

We have a 0CALQUARTER value as (20141, 20142, 20143, 20154,20163, etc.) from this calendar

quarter we have to define the ZFISQRT (Fiscal Quarter) then we write that code in field routine.

 

0CALQUARTER -------------> filed routine ------------>  ZFISQRT

 

Step 1 : Map 0CALQUARTER from source to target with ZFISQRT in transformation.

Then, Right Click on ZFISQRT in target of transformation and select the Rule details option.

Rule Details -


 

Step 2 : Select Rule Type as Routine as mentioned in above screen.

Step 3 : Write the below code to convert 0CALMONTH to ZFISQRT in field routine as -

 
DATA: YEAR(4) TYPE N, //Declaring YEAR with length 4 of TYPE N.
QUARTER(1) TYPE N. //Declaring QUARTER with length 1 of TYPE N.

YEAR = SOURCE_FIELDS-CALQUARTER+0(4).

// Here we calculate YEAR from 0CALQUARTER.

QUARTER = SOURCE_FIELDS-CALQUARTER+4(1).

// Here we calculate only QUARTER from 0CALQUARTER.

// Below is the logic to calculate fiscal year quarter from calendar quarter.

IF QUARTER = 1.
RESULT = YEAR - 1.
CONCATENATE RESULT '4' into RESULT.

ELSEIF QUARTER = 2.
RESULT = YEAR.
CONCATENATE RESULT '1' into RESULT.

ELSEIF QUARTER = 3.
RESULT = YEAR.
CONCATENATE RESULT '2' into RESULT.

ELSEIF QUARTER = 4.
RESULT = YEAR.
CONCATENATE RESULT '3' into RESULT.
ENDIF.

 


 























0CALQUARTER (INPUT) ZFISCQRT (OUTPUT)
20142 20141
20143 20142
20144 20143
20141 20144


Step 4 :
Save the routine and transformation. Run your DTP and check the above table from Input data to Output data.

Conclusion : In the above blog post you have learned about the ABAP field routine code to convert 0CALMONTH (Calendar month) to ZFISQRT (Fiscal Quarter). It’s a complete customization to convert Calendar Month to Fiscal Quarter. In next some blogs you will get so many routine code for time characteristics conversion.

 

 
3 Comments
pbaumann
Active Contributor
Hi Saurabh Choudhary!

 

Thank you for your effort writing this blog.

 

Just some hints to help people participating better from what you write.

It would be good to remark somewhere that you are in a SAP BW context with this content. 0CALMONTH is well known within BW community but not so much outside.

Z objects are customer specific. So what you show to us is specific to a customer and not a common logic.

Last but not least to give a context about the logic ist helpful in the blog as it is in the commentary of your code. You are shifting calendar quarter minus 1 quarter for fiscal quarter. This is not the same for every company and therefore no standard logic for someone else. To make that clear giving context about why this is relevant here can be helpful.

Thank you!
Hello Peter,

Thanks for the update.

I have add few lines in blog post that this code is used only for the company which uses Fiscal Variant as V3 and Fiscal Quarter variable is not available in Time characteristics of BW system.

Thank You..!
matt
Active Contributor
0 Kudos
It is better to use CASE, WHEN, ENDCASE than multiple IF, ELSEIF, ENDIF. It's clearer and cleaner code.

As mentioned here https://blogs.sap.com/2021/08/26/how-to-convert-0calmonth2-0calyear-to-0fiscper/comment-page-1/#comm... -> even better to put it into a class method so it can be reused - and unit tests can be written.

 
Labels in this area