cancel
Showing results for 
Search instead for 
Did you mean: 

Update routine for 0CALWEEK

Former Member
0 Kudos

Hi all.

I am trying to write an update routine for the date characteristic 0CALWEEK. It must be calculated from eather NETDUEDATE or ALLOC_NMBR both from the comm.str. The two dates are in different formats, so will have to be formatted correctly.

I am very new to ABAP so I need a little help here.

This is what I have made:

-


PROGRAM UPDATE_ROUTINE.

$$ begin of global - insert your declaration only below this line -

  • TABLES: ...

<b>DATA: ZDUEDATE TYPE C LENGTH 8,

ZWEEK TYPE C LENGTH 6,

ZEXPDATEY TYPE C LENGTH 4,

ZEXPDATEM TYPE C LENGTH 2,

ZEXPDATED TYPE C LENGTH 2,

ZEXPDATE TYPE C LENGTH 8.</b>

$$ end of global - insert your declaration only before this line -

FORM compute_key_field

TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring

USING COMM_STRUCTURE LIKE /BIC/CS0FI_AR_4

RECORD_NO LIKE SY-TABIX

RECORD_ALL LIKE SY-TABIX

SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS

CHANGING RESULT LIKE /BI0/V0FIAR_C03T-CALWEEK

RETURNCODE LIKE SY-SUBRC

ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update

*

$$ begin of routine - insert your code only below this line -

<b>CLEAR: ZDUEDATE, ZEXPDATEY, ZEXPDATEM, ZEXPDATED, ZEXPDATE.

  • COMM_STRUCTURE-ALLOC_NMBR IS IN FORMAT YYMMDD

IF COMM_STRUCTURE-ALLOC_NMBR NE 0.

ZEXPDATEY = '20' + COMM_STRUCTURE-ALLOC_NMBR(2).

ZEXPDATEM = COMM_STRUCTURE-ALLOC_NMBR+2(2).

ZEXPDATED = COMM_STRUCTURE-ALLOC_NMBR+4(2).

CONCATENATE ZEXPDATEY ZEXPDATEM ZEXPDATED INTO

ZEXPDATE.

  • ZEXPDATE MUST BE CALCULATED TO A WEEK BY FUNCTION 'DATE_GET_WEEK'

RESULT = 0.

ELSE.

ZDUEDATE = COMM_STRUCTURE-NETDUEDATE.

  • ZDUEDATE MUST BE CALCULATED TO A WEEK BY FUNCTION 'DATE_GET_WEEK'

  • TEST DATE_GET_WEEK START

CALL FUNCTION 'DATE_GET_WEEK'

EXPORTING

DATE = ZDUEDATE

IMPORTING

WEEK = ZWEEK

EXCEPTIONS

DATE_INVALID = 1

  • TEST DATE_GET_WEEK END

RESULT = ZWEEK.

ENDIF.</b>$$ end of routine - insert your code only before this line -

*

ENDFORM.

-


If I check the routine I get the following error:

<i>E:The exception "RESULT" must be assigned to a number (literal), but "ZWEEK" is not numeric.</i>

I understand the error but does not know how to correct it. Also I am not quite sure in how to use the function DATE_GET_WEEK.

Please help me out here guys.

BR

Stefan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

There is no diferent formats for dates, there is only one AAAAMMDD.

If you have different formats is because your IO not are dates else character ones.

Date IO can be assigned to temporary IO as 0calweek directly in update rules doing conversion automatically assign netduedate to 0calweek.

in all way:

result = zweek

shoul do the conversion if it can, it is said, there is no character non numeric in zweek

Former Member
0 Kudos

Oscar --> I am using two types of IO's which is why one has to be changed. NETDUEDATE is of the type DATS but ALLOC_NMBR is of the type CHAR.

I can not do the conversion automatically as the week has to come from ALLOC_NMBR if it is not empty or else it has to be converted from NETDUEDATE.

Jerry --> I tried to change ZWEEK and ZDUEDATE to SCAL-WEEK and SCAL-DATE, but I still get the same error.

But after checking the FM it seems like it has to be like this, so thank you.

Arun --> That might be a problem as you mention.

I don't know if this is correct, but what I understand from the line:

CHANGING RESULT LIKE /BI0/V0FIAR_C03T-CALWEEK

is that RESULT has to be the same type as CALWEEK which is NUMC.

Isn't this what the error tells me and how can I solve this?

BR

Stefan

edwin_harpino
Active Contributor
0 Kudos

hi Stefan,

error 'E:The exception "RESULT" must be assigned to a number (literal), but "ZWEEK" is not numeric.... ' is due to there is no . after DATE_INVALID = 1

and as mentioned, import and export parameter should have data type exactly same as in function module (SCAL-DATE and SCAL-WEEK)....

hope this helps.

EXCEPTIONS

DATE_INVALID = 1<b>.</b>

<b>* put '.' (dot)</b>

  • TEST DATE_GET_WEEK END

RESULT = ZWEEK.

ENDIF.$$ end of routine - insert your code only before this line -

*

ENDFORM.

-


Former Member
0 Kudos

Thanks Edwin!

Sometimes focusing so much on a problem makes you blind...

The "<b>.</b>" solved the problem!

RB

Stefan

Answers (3)

Answers (3)

Former Member
0 Kudos

Also, even if you can get it to compile, you will get a runtime error unless you change the type of zduedate as well, to scal-date.

Otherwise, the FM will fail at runtime.


DATA: zduedate  TYPE scal-date,
      zweek     TYPE scal-week,

former_member184494
Active Contributor
0 Kudos

Stefan,

this could also be due to the mismatch in the data types.. check the data types for 0calweek and zweek .. that might be the issue even though both values are the same.

Arun

Former Member
0 Kudos

I cannot recreate your syntax error in a standalone ABAP program, but you might try changing the type of ZWEEK.

I.e.

from

ZWEEK TYPE C LENGTH 6,

to


ZWEEK     TYPE SCAL-WEEK,

or