IP41-maintain the date and period in the plan

Source: Internet
Author: User

In the development of custom programs, IP41 programming is involved. When BDC is used for programming, several related problems need to be solved.

1. the scheduled start date is limited to the time type.

2. The cycle must be an integer multiple of the day.

3. If you can run the first ticket on the day of the planned start date, you need to advance the date by one period (the planned start date is filled in on the developed program interface)

For 1, 2, see the following code

*&---------------------------------------------------------------------*
* & Form FRM_CHECK_TIME
*&---------------------------------------------------------------------*
* Check whether the entered time is an integer multiple of the day
*----------------------------------------------------------------------*
* --> P_GS_HEAD_200_ZYKL1 text
* --> P_GS_HEAD_200_ZEIEH text
*----------------------------------------------------------------------*
Form frm_check_time using up_zykl1 like zzpmttzsxm-zykl1
Up_zeieh like zzpmttzsxm-zeieh.

Data: lv_sec_zykl1 like mmpt-zykl1. "cycle in seconds
Data: rest_tag like mmpt-zykl1.

Data: lv_zykl1 like zzpmttzsxm-zykl1.

Lv_zykl1 = up_zykl1.

Perform char_fltp_conversion_pak_f40
Using lv_zykl1 "Period
Lv_sec_zykl1 "returns the number of cycles in seconds.
Up_zeieh. "cycle unit

Perform fltp_char_conversion_pak_f40
Using lv_zykl1
Lv_sec_zykl1
Up_zeieh.

If not (lv_sec_zykl1 is initial ).
Clear rest_tag.
Rest_tag = lv_sec_zykl1 mod 86400. "determine whether the value can be divisible by the number of seconds in a day.
If rest_tag <> 0.
Message e000 (zdev) with 'must be an integer multiple of day '.
Endif.
Endif.

Endform. "FRM_CHECK_TIME

*&---------------------------------------------------------------------*
* & Form CHAR_FLTP_CONVERSION_PAK_F40
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> CHAR_WERT text
* --> FLTP_WERT text
* --> EINHEIT text
*----------------------------------------------------------------------*
Form char_fltp_conversion_pak_f40 using char_wert
Fltp_wert
Einheit.

Data: dec_max like t006-decan value '15 '.
Data: dec_char like t006-decan.

Call function 'Char _ FLTP_CONVERSION_TO_SI'
Exporting
Char_unit = einheit
Char_value = char_wert
Decimals_max = dec_max
Field_name =''
Masc_symbol =''
Importing
Fltp_value_si = fltp_wert
Decimals = dec_char
Exceptions
No_unit_given = 1.

* CASE sy-subrc.
* WHEN '1 '.
* Set cursor field 'rmipm-zeieh '.
* MESSAGE e044 (ir). "nicht mit Masseinheit
* ENDCASE.

If dec_char ne 0.
Message e000 with 'decimal '.
Endif.

Endform. "CHAR_FLTP_CONVERSION_PAK_F40

*&---------------------------------------------------------------------*
* & Form fltp_char_conversion_pak_f40
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> CHAR_WERT text
* --> FLTP_WERT text
* --> EINHEIT text
*----------------------------------------------------------------------*
Form fltp_char_conversion_pak_f40 using char_wert
Fltp_wert
Einheit.
Clear char_wert.

Check not einheit is initial.

Call function 'fltp _ CHAR_CONVERSION_FROM_SI'
Exporting
Char_unit = einheit
Decimals = 0
Exponent = 0
Fltp_value_si = fltp_wert
Indicator_value = 'X'
Masc_symbol =''
Importing
Char_value = char_wert.

Endform. "fltp_char_conversion_pak_f40


For the third point, you need to advance the date by a period. The related computing logic and the BDC program of IP41 are as follows:

Form frm_bdc_ip41 changing cs_template like gs_template
Cp_error type c.

Data:
Rochelle zyklsort out like t006a-mseh3,
Rochelle ndate like sy-datum,
Rochelle warpl like zzpmttemplate-warpl,
Lt_bdcmsg like standard table of bdcmsgcoll with header line.

Data: lv_sec_zykl1 like the mmpt-zykl1,
Lv_days type I,
Lv_days_f (2) type n. "function parameters

Clear cp_error.

"Convert internal table data to output format
Write cs_template-zeieh to l_zykltimed out.

"Calculation start date = next start date-cycle
"First, convert the cycle to the cycle in seconds.
Perform char_fltp_conversion_pak_f40
Using cs_template-zykl1
Lv_sec_zykl1
Cs_template-zeieh.

Lv_days = lv_sec_zykl1/cns_sec_tag. "The previous verification has been an integer multiple.

"Because the number of days of a function is only two digits, the maximum value is 99 days.
"Cycle, need to be reduced multiple times to get the correct date (cannot be converted to month by 30 days)
L_ndate = cs_template-ndate.
Do.

If lv_days> = 99.
Lv_days_f = 99.
Else.
Lv_days_f = lv_days.
Endif.

Call function 'rp _ CALC_DATE_IN_INTERVAL'
Exporting
Date = l_ndate
Days = lv_days_f
Months = 00
Signum = '-'
Years = 00
Importing
Calc_date = l_ndate.

Lv_days = lv_days-99.
If lv_days <= 0.
Exit.
Endif.

Enddo.

Write l_ndate to l_ndate. "conversion format, BDC used

Call function 'conversion _ EXIT_CUNIT_OUTPUT'
Exporting
Input = cs_template-zeieh
Language = '1'
Importing
* LONG_TEXT =
Output = l_zykl1_out
* SHORT_TEXT =
Exceptions
Unit_not_found = 1
Others = 2
.
If sy-subrc <> 0.
* Message id SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3.
Endif.

* 1.0 BDC IP41
Refresh: gt_bdcdata [], lt_bdcmsg [].
Perform frm_fill_bdc using: 'X' SAPLIWP3 ''0100 ',
'''Bdc _ okcode''/00 ',
'''Rmipm-mptyp' 'ps ',

'X' SAPLIWP3 ''123 ',
'''Bdc _ okcode''/00 ',
'''Rmipm-WPTXT 'cs_template-name1,
'''Rmipm-PSTXT 'cs_template-name1,
'''Riwo1-TPLNR 'cs_template-tplnr,
'''Rmipm-iwer' cs_template-werks,
'''Rmipm-WPGRP 'cs_template-jxbm,
'''Rmipm-auart' cs_template-jxlx,
'''Rmipm-gewer' cs_template-jxxz,
'''Rmipm-WERGW 'cs_template-werks,
'''Rmipm-ZYKL1 'cs_template-zykl1,
"Unit conversion
'''Rmipm-zeieh' l_zykltimed out,
"Us_template-zeieh,
'X' SAPLIWP3 ''123 ',
'''Bdc _ okcode'' = T \ 02 ',
'''Rmipm-priok' cs_template-priok, "Priority

'X' SAPLIWP3 ''123 ',
'''Bdc _ okcode'' = TX ',
* '''Bdc _ okcode'' = BU ',
'''Rmipm-abro' cns_ip41_days,
'''Rmipm-hunit' cns_ip41_days_unit,
'''Rmipm-HORIZ ''' 100 ', "100%
'''Rmipm-stadt' l_ndate, "long text

* "To a default value, activate the Text first. Otherwise, the Save Text function cannot be saved later.
'X' saplstxx' '123 ',
'''Rstxt-TXLINE (02 )''.',
'''Bdc _ okcode'' = txba', "back

'X' SAPLIWP3 ''123 ',
'''Bdc _ okcode'' = bus'. "save
"Us_template-ndate.

Call transaction 'ip41' using gt_bdcdata
Mode g_mode
Update's'
Messages into lt_bdcmsg.

"Save the message to be displayed
Append lines of lt_bdcmsg to gt_bdcmsg.

"Determine whether the operation is successful
Clear cp_error.
Loop at lt_bdcmsg where msgtyp = 'E' or msgtyp = 'A '.
Cp_error = 'x '.
Exit.
Endloop.

If cp_error is initial.
Commit work and wait.
Else.
Rollback work.
* MESSAGE e000 (zdev) WITH 'template activation failed ,'
* 'Failed to call TCODE: IP41 to generate the maintenance plan '.
Return.
Endif.

"If the message is successful, find the new number in the message table.
Read table lt_bdcmsg with key msgtyp ='s'
Msgid = 'IP'
Msgnr = '000000 '.
If sy-subrc eq 0.
Call function 'conversion _ EXIT_ALPHA_INPUT'
Exporting
Input = lt_bdcmsg-msgv1
Importing
Output = l_warpl. "maintenance plan
Endif.

* 1.1 todo Save_text write long text
Perform frm_save_ip41_text using cs_template.

Endform. "FRM_BDC_IP41

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.