วันศุกร์ที่ 3 กันยายน พ.ศ. 2553

Program ABAP : zbot_exchangerate : post_bapi

<< Start-Of-Selection

*&---------------------------------------------------------------------*
*&      Form  POST_BAPI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form post_bapi .
  data : lv_status type string.
  field-symbols <e> type any.
  data : lv_field type string,
         lv_rate type p decimals 4.
  data : gw_ex type bapi1093_0,
         gw_return type bapiret2,
         gv_rtype type bapi1093_0-rate_type,
         gv_fcurr type bapi1093_0-from_curr,
         gv_tcurr type bapi1093_0-to_currncy,
         lv_first.

  data : lv_index type i.
  new-line.

  if not gi_rate[] is initial.

    loop at gi_rate.
      lv_index = lv_index + 1.
      loop at gi_map where waers = gi_rate-waers.
        clear : gi_result,gw_ex.

        gw_ex-to_currncy = 'THB'.
        gw_ex-from_factor = gi_map-ffact.
        gw_ex-to_factor = gi_map-tfact.
        gw_ex-from_curr = gi_map-waers.

        gw_ex-rate_type = gi_map-kurst.



        if gi_map-datetype = '1'.
          if ( gv_rdate = gv_pdate )
            or ( gv_holiday = 'X').                         "CID2++
            gw_ex-valid_from = p_date.
          else.
            gw_ex-valid_from = gv_rdate.
          endif.
        elseif gi_map-datetype = '2'."AND P_DATE = GV_FDATE.
          gw_ex-valid_from = gv_pdate.
        endif.

        if gi_map-currtype eq 'AVD'.
          lv_rate = ( gi_rate-tt + gi_rate-asr ) / 2.
          gw_ex-exch_rate = lv_rate .
        else.
          concatenate 'GI_RATE-' gi_map-currtype
          into lv_field.
          assign (lv_field) to <e>.
          if sy-subrc eq 0.
            gw_ex-exch_rate = <e>.
          endif.
        endif.
        move-corresponding gw_ex to gi_result.
        gi_result-zindex = lv_index.
        data : lv_ndate type sy-datum,
              lv_m(2type c.
        lv_ndate = gv_ndate.
        if gv_ndate+4(2ne '12'.
          lv_m = gv_ndate+4(2) - 1.
          unpack lv_m to lv_m.
          lv_ndate+4(2) = lv_m.
        else.
          lv_ndate+4(2) = '12'.
        endif.
        if gi_map-datetype  eq '1' or
           ( gi_map-datetype  eq '2' and
            ( p_date = gv_ndate or
              p_date = gv_fdate or
              p_date = lv_ndate ) ) .                      

          if p_test ne 'X'.
            call function 'BAPI_EXCHANGERATE_CREATE'
              exporting
                exch_rate  = gw_ex
                upd_allow  = 'X'
                chg_fixed  = 'X'
                dev_allow  = '000'
              importing
                return     = gw_return
                rate_type  = gv_rtype
                from_curr  = gv_fcurr
                to_currncy = gv_tcurr.

            if sy-subrc eq 0.

              gi_result-status = 'OK'.
              call function 'BAPI_TRANSACTION_COMMIT'
               exporting
                 wait          = 'X'
*             IMPORTING
*               RETURN        =
                        .
            else.
              data : lv_msg type bapiret2-message.
              call function 'BAPI_MESSAGE_GETDETAIL'
                exporting
                  id                = gw_return-id
                  number            = gw_return-number
*               LANGUAGE          = SY-LANGU
                  textformat        = '*'
*               LINKPATTERN       =
                 message_v1        =  gw_return-message_v1
                 message_v2        = gw_return-message_v2
                 message_v3        = gw_return-message_v3
                 message_v4        = gw_return-message_v4
               importing
                 message           = lv_msg
*               RETURN            =
*             TABLES
*               TEXT              =
                        .
              gi_result-status = 'Error'.
              gi_result-msg = lv_msg.

            endif.
          endif.
          append gi_result.
        endif.
      endloop.
    endloop.
  else.
    format color 6.
    if gi_map[] is initial.
      write : / 'No mapping table'.
    else.
      write : / 'File not fonud'.
    endif.
    format color off.
  endif.
endform.                    " POST_BAPI


<< Start-Of-Selection 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น