Prompt Title: ABAP routine

Created 1 year ago
Votes 0
Views 59 times
IT
0

Prompt Detail:

In this ABAP routine, we'll create a function module that accepts a date string in the format DD-MM-YYYY and returns the date in the format YYYYMMDD. This function can be utilized in your BW transformation.

  1. First, create a new function module in SE37 or SE80 transaction.

  2. Define the function module, let's call it Z_CONVERT_DATE_FORMAT.

  3. Add the following code to the function module:

abap
FUNCTION Z_CONVERT_DATE_FORMAT. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IV_DATE_IN) TYPE STRING *" EXPORTING *" VALUE(EV_DATE_OUT) TYPE STRING *"---------------------------------------------------------------------- DATA: lv_day TYPE string, lv_month TYPE string, lv_year TYPE string, lv_date_temp TYPE yyyymmdd. IF iv_date_in CO '1234567890-' AND strlen( iv_date_in ) = 10. lv_day = iv_date_in+0(2). lv_month = iv_date_in+3(2). lv_year = iv_date_in+6(4). CONCATENATE lv_year lv_month lv_day INTO lv_date_temp. ev_date_out = lv_date_temp. ELSE. ev_date_out = ''. ENDIF. ENDFUNCTION.

This function checks if the input date string contains only numbers and dashes and has a length of 10 characters. If the input format is correct, the function extracts the day, month, and year, and concatenates them in the desired format (YYYYMMDD).

  1. Save and activate the function module.

  2. Now, you can use this function module in your BW transformation to convert date fields from DD-MM-YYYY format to YYYYMMDD format.

Example of usage in BW transformation:

abap
DATA: lv_date_in TYPE string, lv_date_out TYPE string. lv_date_in = <source_date_field>. "Replace with the source date field from your transformation CALL FUNCTION 'Z_CONVERT_DATE_FORMAT' IMPORTING iv_date_in = lv_date_in EXPORTING ev_date_out = lv_date_out. <target_date_field> = lv_date_out. "Replace with the target date field in your transformation

Replace <source_date_field> and <target_date_field> with the appropriate field names from your BW transformation.

avatar
VTS
Shared 1 prompt
Created 1 year ago

Leave a Comment