antelio
6/18/2018 - 8:31 PM

ZPAYMENT_CCARD_CONCILIATION

FORM persist_payment_data TABLES tdata TYPE STANDARD TABLE.

  DATA: line   TYPE string,
        tsplit TYPE TABLE OF string,
        field  TYPE string.

  DATA: payments TYPE TABLE OF zpayment_ccard,
        payment  TYPE zpayment_ccard.

  LOOP AT tdata INTO line.
    CHECK sy-tabix GT 1.

    REFRESH tsplit.
    SPLIT line AT '";"' INTO TABLE tsplit.

    CLEAR field.
    READ TABLE tsplit INTO field INDEX 1.
    CHECK field IS NOT INITIAL.

    CLEAR payment.
    READ TABLE tsplit INTO payment-nsu INDEX 26.
    CHECK payment-nsu IS NOT INITIAL.

    READ TABLE tsplit INTO payment-auth_cod INDEX 46.
    READ TABLE tsplit INTO payment-tid INDEX 21.

    CLEAR field.
    READ TABLE tsplit INTO field INDEX 33.
    REPLACE ALL OCCURRENCES OF ',' IN field WITH ''.
*    REPLACE ALL OCCURRENCES OF ',' IN field WITH '.'.
    payment-amount = field.

    CHECK payment-amount GT 0.

    REPLACE ALL OCCURRENCES OF '*' IN payment-tid WITH ''.

    READ TABLE tsplit INTO field INDEX 27.
    CONCATENATE field+6(4) field+3(2) field(2) INTO payment-sale_date.

    READ TABLE tsplit INTO field INDEX 3.
    CONCATENATE field+6(4) field+3(2) field(2) INTO payment-payment_date.

    payment-company = comp.

    SELECT COUNT(*)
      FROM zpayment_ccard
      WHERE nsu      EQ payment-nsu
        AND auth_cod EQ payment-auth_cod
        AND tid      EQ payment-tid.

    IF sy-dbcnt EQ 0.
      APPEND payment TO payments.
    ENDIF.
  ENDLOOP.

  MODIFY zpayment_ccard FROM TABLE payments.
  COMMIT WORK AND WAIT.
ENDFORM.                    "persist_chargeback_data