*&---------------------------------------------------------------------* *& Report ZFI_GET_INV_DUE_DATE *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zfi_get_inv_due_date. * for testing purposes PARAMETERS: p_bukrs TYPE bukrs DEFAULT '1710', p_kunnr TYPE kunnr DEFAULT '17100100', p_belnr TYPE belnr_d DEFAULT '9400000026'. DATA: lv_faedt TYPE faedt_fpos. PERFORM unit_test USING p_bukrs p_kunnr p_belnr. * To call from from SAP Script: */: DEFINE &DUE_DATE& = '00000000' */: PERFORM CALL_FROM_SCRIPT IN PROGRAM ZFI_GET_INV_DUE_DATE */: USING &BSID-BUKRS& */: USING &BSID-KUNNR& */: USING &BSID-BELNR& */: CHANGING &DUE_DATE& */: ENDPERFORM * To display the variable use the standard: * = &DUE_DATE& * unit_test FORM unit_test USING bukrs TYPE bukrs kunnr TYPE f130kont belnr TYPE belnr_d. TYPES: form_params_ty TYPE STANDARD TABLE OF itcsy WITH NON-UNIQUE KEY name. DATA(in_params) = VALUE form_params_ty( ( name = `BSID-BUKRS` value = bukrs ) ( name = `BSID-KUNNR` value = kunnr ) ( name = `BSID-BELNR` value = belnr ) ). DATA(out_params) = VALUE form_params_ty( ( name = `DUE_DATE` value = '00000000' ) ). PERFORM call_from_script TABLES in_params out_params. loop at out_params ASSIGNING FIELD-SYMBOL(<fs>). write:/ <fs>-name, <fs>-value. endloop. "BREAK-POINT. ENDFORM. * this function is called from the script * the data is passed in and out in TABLES * the tables contain two columns: KEY and VALUE FORM call_from_script TABLES in_params STRUCTURE itcsy out_params STRUCTURE itcsy. DATA: bukrs TYPE bukrs, kunnr TYPE f130kont, belnr TYPE belnr_d, faedt TYPE faedt_fpos. DATA: it_postab TYPE STANDARD TABLE OF rfpos, fs_faedt LIKE LINE OF it_postab. " get the values of the keys from the IN table READ TABLE in_params WITH KEY name = 'BSID-BUKRS'. IF sy-subrc EQ 0. bukrs = in_params-value. ENDIF. READ TABLE in_params WITH KEY name = 'BSID-KUNNR'. IF sy-subrc EQ 0. kunnr = in_params-value. UNPACK kunnr TO kunnr. "ADD LEADING ZEROS ACCORGING TO FM REQUREMENTS ENDIF. READ TABLE in_params WITH KEY name = 'BSID-BELNR'. IF sy-subrc EQ 0. belnr = in_params-value. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "REMOVE LEADING ZEROS ACCORDING WHT THE DATA IN THE t_postab EXPORTING input = belnr IMPORTING output = belnr. ENDIF. CALL FUNCTION 'CUSTOMER_OPEN_ITEMS' EXPORTING bukrs = bukrs kunnr = kunnr * KKBER = * STIDA = TABLES t_postab = it_postab * EXCEPTIONS * NO_OPEN_ITEMS = 1 * OTHERS = 2 . IF sy-subrc = 0. READ TABLE it_postab WITH KEY belnr = belnr INTO fs_faedt. IF sy-subrc = 0. faedt = fs_faedt-faedt. ELSE. faedt = '-'. ENDIF. ELSE. faedt = '--'. ENDIF. " export output parameters in the OUT table LOOP AT out_params ASSIGNING FIELD-SYMBOL(<fs>). IF <fs>-name = 'DUE_DATE'. CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING date_internal = faedt IMPORTING date_external = <fs>-value EXCEPTIONS date_internal_is_invalid = 1 OTHERS = 2. IF sy-subrc <> 0. ENDIF. EXIT. ENDIF. ENDLOOP. ENDFORM.