Application Development 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: 

Subroutine in sapscript for net due date

former_member220430
Active Participant
0 Kudos

Hi,

This is the first time I am creating a subroutine for sapscript and I could not get it to work. I need to calculate the net due date using the baseline date plus cash discount days. But the form is just printing out 0000000. I am just trying to extract one due date here but I will have to get it for all line items then sort descending to get the latest one. Can anyone help me to see the gap why this is not working?

In the sapscript I have the following:

DEFINE &BASEDATE& = &REGUP-ZFBDT&

DEFINE &PAYTERMS& = &REGUP-ZBD1T&

PERFORM NET_DUE_DATE IN PROGRAM Z_SAPSCRIPT_FUNCTIONS

USING &BASEDATE&

USING &PAYTERMS&

CHANGING &DUEDATE&

ENDPERFORM

In program Z_SAPSCRIPT_FUNCTIONS

Thanks in advance!

Cholen

1 ACCEPTED SOLUTION

satyabrata_sahoo3
Contributor
0 Kudos

I hope you have defined DUEDATE earlier.


DEFINE &DUEDATE& = &REGUP-ZFBDT&



Debug the NET_DUE_DATE IN PROGRAM Z_SAPSCRIPT_FUNCTIONS.


Check import values and result of the export values.




19 REPLIES 19

Former Member
0 Kudos

Hi

this is your code (you've attached):


form net_due_date tables in_tab structure itcsy

                         out_tab structure itcsy.

data: lv_basedate like sy-datum,

      lv_payterms type i,

      lv_duedate like sy-datum.

read table in_tab with key name = 'BASEDATE'.

move in_tab-value to lv_basedate.

read table in_tab with key name = 'PAYTERMS'.

move in_tab-value to lv_payterms.

lv_duedate = lv_basedate + lv_payterms.

read table out_tab with key name = 'DUEDATE'.

out_tab-value = lv_duedate.

modify out_tab index sy-tabix.

endform.

Now you should consider the routine get a value in output format, so probably these lines


read table in_tab with key name = 'BASEDATE'.

move in_tab-value to lv_basedate.

doesn't work well as in IN_TAB-VALUE there's a data in format DD.MM.YYYY and not YYYYMMDD

so I believe you need to transform all values from sapscript in the internal format

Max

0 Kudos

I used the FM RP_CALC_DATE_IN_INTERVAL. Still same result though.

0 Kudos

Set a break point in your routine and check in which format the variables are transfered

Max

0 Kudos

The basedate gets the correct information in date mm.dd.yyyy format. But the problem is that the payterms is not getting any value.

Private_Member_7726
Active Contributor
0 Kudos

Hi,

I apologize for not actually answering the question... but why would you even consider doing something like that (due date calculation - clearly a business logic) via "Sapscript formroutine", in a form...?

Suppose I could format a disc in "Sapscript formroutine" - would it be good idea to do so? Or to post open item using Sapscript? Same with due date calculations - only less obvious perhaps. If the application has not prepared and stored the due dates, prepare them and the rest of data before calling form and pass (or "pass" in the case of abomination known as Sapscript) it to the form? So the form can do what its meant to do - format and output data according to layout.

I obviously don't know what "driver" program and what form it is, but is there really no suitable place to latch on to the thing with custom logic (via implicit enhancement if need be), where all the necessary data can be prepared..? And then the thing even behaves weirdly... why even try to use it then?

cheers

Jānis

0 Kudos

Hi Jänis, thanks for your comments. I am new to doing these stuff and I thought this would be the simplest way to get the task done. The print program is standard from SAP, the sapscript is something I created copying from a standard. The program is run in F110 assigning a variant where the sapscript I'm working on is specified. Not sure how/where I can create a custom logic since we don't want to modify the print program. That's why I am trying to create something separately to call in the sapscript.

0 Kudos

Hi

You are printing the automatic payment so as Janis says the due date should be calculated by standard process:

that doesn't mean the date is stored in the system (it depends on customizing) as it can be caluclated at runtime.

Usually the fm used to calculate the due date is NET_DUE_DATE_GET, probably if REGUP-ZBD1T is initial it could mean the due date is calculated, if it's so the result is in REGUP-ZFBDT.

Try to check it

Max

0 Kudos

I have also seen that the values being passed from the form to the subroutine is different. How is that possible? For example, I added a DEFINE &LV_LAUFD& = &REHUG-LAUFD&. Then in the subroutine form I have lv_laufd type sy-datum. When I run the debug, I see that the date is cutoff. For example, 09.12.2014 becomes 09.12.20.

0 Kudos

Its because  REGUP-ZFBDT is 8 character long. But your date must be in 10 character.

satyabrata_sahoo3
Contributor
0 Kudos

I hope you have defined DUEDATE earlier.


DEFINE &DUEDATE& = &REGUP-ZFBDT&



Debug the NET_DUE_DATE IN PROGRAM Z_SAPSCRIPT_FUNCTIONS.


Check import values and result of the export values.




0 Kudos

I now see the inconsistencies between the import and export values. Would you have any suggestion how to address this?

0 Kudos

Hi

You don't have to see the value in LV_LAUFD, but the value in IN_TAB-VALUE

Here you should see the value in output format, if LV_LAUFD cuts the value it means its lenght is too small

Max

0 Kudos

I think  am getting the values correctly. But when I select from regup using all the values, I do not get a hit. But when I go to SE16 and search the table with exactly the same values from debugging, I have records. Does it matter that some variables are null?

0 Kudos

Check if you need conversion exits to convert the variables to SAP internal format before doing the SELECT. Also check your SELECT statement if you have AND or OR? Please show us how your SELECT statement look like..

Cheers,

Raju.

0 Kudos

How do I check if I need conversion exits before doing the select?

My select statement is:

select * from regup into table ls_regup

where laufd = lv_laufd and laufi = lv_laufi

and xvorl = lv_xvorl and zbukr = lv_zbukr

and lifnr = lv_lifnr and kunnr = lv_kunnr

and empfg = lv_empfg.

I defined ls_regup as standard table of regup.

0 Kudos

Hi Cholen,

I believe your lv_laufd is a 10 character field in format MM/DD/YYY or DD/MM/YYYY. You should move that data to a 8 character variable (say lv_date) in YYYYDDMM format.

Please try this conversion

    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

      EXPORTING

        date_external            = lv_laufd

      IMPORTING

        date_internal            = lv_date

      EXCEPTIONS

        date_external_is_invalid = 1

        OTHERS                   = 2.

Check in debug, you should get lv_date in YYYYMMDD. Now use lv_date in your WHERE clause.

If you still do not get data after lv_date eq YYYYMMDD, check your LIFNR and KUNNR. They should be 10 charaters with leading zeroes if not 10 .

If needed use the conversion for lv_lifnr and lv_kunnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        date_external            = lv_lifnr

      IMPORTING

        date_internal            = lv_lifnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        date_external            =  lv_kunnr

      IMPORTING

        date_internal            =  lv_kunnr.

Cheers,

Raju.

0 Kudos

Hi Raju!

I am really getting close! I did the conversion for all variables, however for VBLNR, it does not work. It gives leading zeroes but the value starts with a 'P' before the zeroes and the numeric value. I tried to remove that from the where clause and my select finally got something. However the output on the form is in the internal format. I suppose I should use CONVERT_DATE_TO_EXTERNAL which I tried doing after out_tab-value = lv_netduedate which is the variable I am passing to the form. 


Raju Shrestha wrote:

Hi Cholen,

I believe your lv_laufd is a 10 character field in format MM/DD/YYY or DD/MM/YYYY. You should move that data to a 8 character variable (say lv_date) in YYYYDDMM format.

Please try this conversion

    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

      EXPORTING

        date_external            = lv_laufd

      IMPORTING

        date_internal            = lv_date

      EXCEPTIONS

        date_external_is_invalid = 1

        OTHERS                   = 2.

Check in debug, you should get lv_date in YYYYMMDD. Now use lv_date in your WHERE clause.

If you still do not get data after lv_date eq YYYYMMDD, check your LIFNR and KUNNR. They should be 10 charaters with leading zeroes if not 10 .

If needed use the conversion for lv_lifnr and lv_kunnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        date_external            = lv_lifnr

      IMPORTING

        date_internal            = lv_lifnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        date_external            =  lv_kunnr

      IMPORTING

        date_internal            =  lv_kunnr.

Cheers,

Raju.

0 Kudos

Hi Cholen,

If your requirement is just to convert the date to external format.

WRITE lv_netduedate USING EDIT MASK '__/__/____  TO lv_out_date.

lv_out_date should be 10 character.

Pass this lv_out_date to FORM.

Hope this helps.

Cheers!!

Raju.

former_member220430
Active Participant
0 Kudos

Thanks everyone for all the inputs. I think this should be good except that I still could not include VBLNR in my where clause. Hopefully, the keys are enough even without this field. Thanks once again.