Table of Contents:



REPORT ZFASSETWORKFLOW NO STANDARD PAGE HEADING LINE-SIZE 255.

*@----------------------------------------------------------------------
*@ Program id    : ZFASSETWORKFLOW
*@ Program Desc  : This programme uploads depreciation and cost centre
*@                 information into assets already created
*@                 (for BJ Svcs.).
*@                 It is meant to Change asset master records in CC6231
*@                 once IC workflow has been posted,
*@                 For Depr Areas 01, 05, and 50.
*@
*@ Transaction Code - ZFASSETWORKFLOW
*@ Input files   : User specified on network drives mapped to SAP box.
*@ Output files  : BDC session
*@
*@ Tables Updated: Table - none
*@
*@
*@ Author      : Ibrahim Jadalowen     (LABK934730)
*@ Date        : March 28, 2003
*@ Requested by: BJ Services (UK)
*@----------------------------------------------------------------------
*@ Algorithm: The data is read from a tab delimited text file and
*@            loaded through a BDC session as per transaction code
*@            AS02.
*@----------------------------------------------------------------------

INCLUDE zsmaster.

TABLES: anla.

CONSTANTS: c_company(4) VALUE '6231'.

DATA: record(300) TYPE c,
      tab         TYPE x VALUE '09',
      col,
      error(1)    TYPE c VALUE '',
      lin         TYPE i.

* Initial screen info
DATA: sanln2 LIKE anla-anln2 VALUE '0000'.

DATA: BEGIN OF datatab OCCURS 0,
        ccode         LIKE anla-bukrs,
        asst          LIKE anla-anln1,
        description   LIKE anla-txt50,
        costcentre    LIKE anlz-kostl,
        depkey01        LIKE anlb-afasl,
        usefullife01    LIKE anlb-ndjar,
        periods01       LIKE anlb-ndper,
        depstart01(10)  TYPE c,            "anlb-afabg,
        exp_ul01        LIKE anlc-ndabj,
        expiredlife01   LIKE anlc-ndabp,
        depkey05        LIKE anlb-afasl,
        usefullife05    LIKE anlb-ndjar,
        periods05       LIKE anlb-ndper,
        depstart05(10)  TYPE c,            "anlb-afabg,
        exp_ul05        LIKE anlc-ndabj,
        expiredlife05   LIKE anlc-ndabp,
        depkey50        LIKE anlb-afasl,
        usefullife50    LIKE anlb-ndjar,
        periods50       LIKE anlb-ndper,
        depstart50(10)  TYPE c,            "anlb-afabg,
        exp_ul50        LIKE anlc-ndabj,
        expiredlife50   LIKE anlc-ndabp,
END OF datatab.

*/ This is the format of the input file:
TYPES: BEGIN OF intype,
        asst(12)      TYPE c,
        description        LIKE anla-txt50,
        costcentre         LIKE anlz-kostl,
        darea01(3)         TYPE c,
        depkey01           LIKE anlb-afasl,
        usefullife01(3)    TYPE c,
        periods01(3)       TYPE c,
        depstart01(10)     TYPE c,
        exp_ul01(3)        TYPE c,
        expiredlife01(3)   TYPE c,
        darea05(3)         TYPE c,
        depkey05           LIKE anlb-afasl,
        usefullife05(3)    TYPE c,
        periods05(3)       TYPE c,
        depstart05(10)     TYPE c,
        exp_ul05(3)        TYPE c,
        expiredlife05(3)   TYPE c,
        darea50(3)         TYPE c,
        depkey50           LIKE anlb-afasl,
        usefullife50(3)    TYPE c,
        periods50(3)       TYPE c,
        depstart50(10)     TYPE c,
        exp_ul50(3)        TYPE c,
        expiredlife50(3)   TYPE c,
END OF intype.

DATA: rc TYPE intype.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-101.
PARAMETERS: datafile LIKE rlgrap-filename
                     DEFAULT 'Z:\'.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(25) text-002.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
PARAMETERS: session(12) TYPE c.
SELECTION-SCREEN END OF BLOCK blk1.

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
START-OF-SELECTION.

  WRITE: / '*** LOG *** Report -',sy-repid COLOR COL_HEADING.
  WRITE: sy-datum, sy-uzeit.
  SKIP.

  PERFORM load_datatab.
  IF NOT error IS INITIAL.
    EXIT.
  ENDIF.

  IF session IS INITIAL.
    session = sy-repid.
  ENDIF.

  DESCRIBE TABLE datatab LINES lin.
  IF lin > 0.

    PERFORM create_bdc_session.

    SKIP.
    WRITE: / 'Batch session',session,'was created.'.

  ELSE.
    WRITE: / 'No data for processing.  No batch session created.'.
    WRITE: / 'Programme ended.'.
  ENDIF.

*---------------------------------------------------------------------*
*       FORM LOAD_DATATAB                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM load_datatab.

  DATA: len TYPE i,
        diff TYPE i,
        ddate(10).

  OPEN DATASET datafile FOR INPUT IN TEXT MODE.
  IF sy-subrc <> 0.
    len = strlen( datafile ).
    WRITE: / 'Error opening file:' COLOR COL_NEGATIVE INVERSE ON,
             datafile(len) COLOR COL_NEGATIVE INVERSE ON.
    error = 'Y'.
    EXIT.
  ENDIF.
  READ DATASET datafile INTO record.
  IF sy-subrc <> 0.
    WRITE: / 'Data spreadsheet error while reading the first record.'
             COLOR COL_NEGATIVE INVERSE ON.
    error = 'Y'.
    EXIT.
  ENDIF.

  DO.
    CLEAR datatab.

    SPLIT record AT tab INTO
      rc-asst rc-description rc-costcentre
      rc-darea01 rc-depkey01 rc-usefullife01 rc-periods01
      rc-depstart01 rc-exp_ul01 rc-expiredlife01
      rc-darea05 rc-depkey05 rc-usefullife05 rc-periods05
      rc-depstart05 rc-exp_ul05 rc-expiredlife05
      rc-darea50 rc-depkey50 rc-usefullife50 rc-periods50
      rc-depstart50 rc-exp_ul50 rc-expiredlife50.

    IF rc-asst NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' AND
       rc-asst <> ''.

      len = strlen( rc-asst ).
      diff = 12 - len.
      SHIFT rc-asst RIGHT BY diff PLACES.
      DO diff TIMES.
        REPLACE '' WITH '0' INTO rc-asst.
      ENDDO.

      MOVE-CORRESPONDING rc TO datatab.
      MOVE c_company TO datatab-ccode.

**   Convert the input date to the user default date format
      PERFORM convert_user_default_date
              USING rc-depstart01 ddate.
      MOVE ddate TO datatab-depstart01.

      PERFORM convert_user_default_date
              USING rc-depstart05 ddate.
      MOVE ddate TO datatab-depstart05.

      PERFORM convert_user_default_date
              USING rc-depstart50 ddate.
      MOVE ddate TO datatab-depstart50.

*   Check if the Asset Exists in ANLA
      SELECT SINGLE * FROM anla
       WHERE anln1 = datatab-asst
         AND anln2 = sanln2
         AND bukrs = datatab-ccode.

      IF sy-subrc = 0.
        APPEND datatab.
        WRITE: / 'Added: Asset #', datatab-asst,
                 'for Co. Code', datatab-ccode.
      ELSE.
        WRITE: / 'Asset #', datatab-asst,
                 'for Co. Code', datatab-ccode,
                 'does not exist in table ANLA.  Values not accepted.'.
      ENDIF.
    ENDIF.

    CLEAR record.
    READ DATASET datafile INTO record.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

  ENDDO.

ENDFORM.                               " LOAD_DATATAB


*---------------------------------------------------------------------*
*       FORM create_bdc_session                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM create_bdc_session.

  DATA: l_session LIKE apqi-groupid.

  mac_set_status_bar 'Creating BDC Session......'.

  SORT datatab BY asst.

  l_session = session.
  mac_bdc_open_group l_session.

  LOOP AT datatab.

    mac_bdc_refresh_data.
    mac_bdc_screen 'SAPLAIST' '0100'.
    mac_bdc_position 'ANLA-BUKRS' ' '.
    mac_bdc_set_value: 'ANLA-ANLN1' datatab-asst.
    mac_bdc_set_value: 'ANLA-ANLN2' '0'.
    mac_bdc_set_value: 'ANLA-BUKRS' datatab-ccode.
    mac_bdc_ok_code '/00'.

    mac_bdc_screen 'SAPLAIST' '1000'.
    mac_bdc_ok_code '=TAB08'.

    mac_bdc_screen 'SAPLAIST' '1000'.
    mac_bdc_set_value: 'ANLB-AFASL(01)' datatab-depkey01.
    mac_bdc_set_value: 'ANLB-AFABG(01)' datatab-depstart01.
    mac_bdc_set_value: 'ANLB-NDJAR(01)' datatab-usefullife01.
    mac_bdc_set_value: 'ANLB-NDPER(01)' datatab-periods01.
    mac_bdc_set_value: 'ANLC-NDABJ(01)' datatab-exp_ul01.
    mac_bdc_set_value: 'ANLC-NDABP(01)' datatab-expiredlife01.

    mac_bdc_set_value: 'ANLB-AFASL(02)' datatab-depkey05.
    mac_bdc_set_value: 'ANLB-AFABG(02)' datatab-depstart05.
    mac_bdc_set_value: 'ANLB-NDJAR(02)' datatab-usefullife05.
    mac_bdc_set_value: 'ANLB-NDPER(02)' datatab-periods05.
    mac_bdc_set_value: 'ANLC-NDABJ(02)' datatab-exp_ul05.
    mac_bdc_set_value: 'ANLC-NDABP(02)' datatab-expiredlife05.

    mac_bdc_set_value: 'ANLB-AFASL(04)' datatab-depkey50.
    mac_bdc_set_value: 'ANLB-AFABG(04)' datatab-depstart50.
    mac_bdc_set_value: 'ANLB-NDJAR(04)' datatab-usefullife50.
    mac_bdc_set_value: 'ANLB-NDPER(04)' datatab-periods50.
    mac_bdc_set_value: 'ANLC-NDABJ(04)' datatab-exp_ul50.
    mac_bdc_set_value: 'ANLC-NDABP(04)' datatab-expiredlife50.

    mac_bdc_ok_code '=TAB02'.

    mac_bdc_screen 'SAPLAIST' '1000'.
    mac_bdc_set_value: 'ANLZ-KOSTL' datatab-costcentre.
    mac_bdc_ok_code '=BUCH'.

    mac_bdc_screen 'SAPLAIST' '3020'.
    mac_bdc_position '%#AUTOTEXT001' ' '.
    mac_bdc_ok_code  '=YES'.

    mac_bdc_insert 'AS02'.

  ENDLOOP.

  mac_bdc_close_group.

ENDFORM.                  "CREATE_BDC_SESSION

*---------------------------------------------------------------------*
*       FORM convert_user_default_date                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  P_indate                                                      *
*  -->  P_outdate                                                     *
*---------------------------------------------------------------------*
FORM convert_user_default_date USING p_indate p_outdate.
*   Convert the input date to the user default date format

  DATA: day(2),
        month(2),
        year(4),
        tmpdate TYPE date.

  day = p_indate(2).
  month = p_indate+3(2).
  year = p_indate+6(4).
  CONCATENATE year month day INTO tmpdate.
  mac_convert_date_user_default tmpdate p_outdate.

ENDFORM.