*&---------------------------------------------------------------------*
*& report zief_get_payment
*& description: call eflow web service to get
*&              payment info and create fi document
*&              currency mapping table      : zws_curr
*&              a/c code determination table: zef_acc_det
*&              log table                   : zefpayreqlog
*& date:     18 jun 2019
*&---------------------------------------------------------------------*
report zief_get_pay_request.

constants: c_wsid(4)            value 'IB02',
           c_blart(2)           value 'Z3',
           c_xblnr              like bkpf-xblnr value 'EFLOW PAYMENT',
           c_hkont              like bseg-hkont value '564000',
           formname_top_of_page type slis_formname value 'TOP_OF_PAGE',
           ws_login(30)         type c value 'App_TW_CMS'.
data: ws_pass(30)  type c,
      ws_appid(30) type c.

tables: bkpf,zefpayreqlog.", zws_master.

parameters: p_chk1 radiobutton group g1 default 'X'.
selection-screen begin of block b1 with frame title text-001.
* parameters: p_new as checkbox default 'X'.
* parameters: p_chk1  as checkbox default ' ',
parameters: p_tok   as checkbox default ' '.
select-options: s_budat for bkpf-budat no-extension.
parameters: p_bukrs type bkpf-bukrs default '1000',
            p_url   type string lower case,
            p_file  type string lower case.
selection-screen end of block b1.
parameters: p_chk2 radiobutton group g1.
selection-screen begin of block b2 with frame title text-002.
select-options: s_budat1 for bkpf-budat no-extension,
                s_zuonr1 for zefpayreqlog-eflow_request_no.
selection-screen end of block b2.

* selection-screen begin of block b2 with frame title text-002.
* parameters: p_old as checkbox default 'X'.
* select-options: s_budat1 for bkpf-budat no-extension.
* selection-screen end of block b2.

* JSON Data
types: begin of js_party,
         name type string,
         role type string,
       end of js_party.

types: begin of js_bank_account,
         bank_code type string,
       end of js_bank_account.

types: begin of js_origin,
         party        type js_party,
         bank_account type js_bank_account,
       end of js_origin.

types: begin of js_recipient,
         party type js_party,
       end of js_recipient.

types: begin of js_paydet,
         accounting_code   type string,
         currency          type string,
         amount            type string,
         cheque_number     type string,
         payment_origin    type js_origin,
         payment_recipient type js_recipient,
       end of js_paydet.

types: begin of js_paydata,
         eflow_request_no       type string,
         gross_amount           type string,
         bank_charge            type string,
         payment_method         type string,
         payment_status         type string,
         payment_effective_date type string,
       end of js_paydata.

types: begin of js_res,
         payment_data   type js_paydata,
         payment_detail type table of js_paydet with non-unique default key,
       end of js_res.

types: begin of js_response,
         status   type string,
         msg_code type string,
         msg_desc type string,
         response type table of js_res with non-unique default key,
       end of js_response.

data: wa_js_response type js_response.

* Working ITAB and WA
data: it_js_res type table of js_res,
      wa_js_res type js_res.

data: "it_js_pay type table of js_paydata,
       wa_js_pay   type js_paydata.

data: it_js_paydet type table of js_paydet with non-unique default key,
      wa_js_paydet type js_paydet.

data: "it_js_origin type table of js_origin,
       wa_js_origin   type js_origin.

data: "it_js_recipient type table of js_recipient,
  wa_js_recipient    type js_recipient,
  wa_js_party        type js_party,
  wa_js_bank_account type js_bank_account.

data: it_gl  type table of zgl_accdoc with header line,
      it_gl1 type table of zgl_accdoc with header line,
      it_log type table of zefpayreqlog with header line,
      wa_log type zefpayreqlog.

*data BEGIN OF it_log occurs 0.
*  DATA: sel.
*  INCLUDE STRUCTURE zefpayreqlog.
*DATA END OF it_log.

data BEGIN OF it_log2 occurs 0.
  DATA: sel.
  INCLUDE STRUCTURE zefpayreqlog.
DATA END OF it_log2.

data: begin of it_skip occurs 0,
        zuonr type bseg-zuonr,
      end of it_skip.

DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group TYPE slis_t_sp_group_alv,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid.

data: begin of it_result occurs 0,
        chkbx        type  icon-id,
        seq(4)       type  c,
        bukrs        type  bkpf-bukrs,
        bldat        type  bkpf-bldat,
        budat        type  bkpf-budat,
        wrbtr        type  bseg-wrbtr,
        waers        type  bkpf-waers,
        zuonr        type  bseg-zuonr,
        xref1        type  bseg-xref1,
        doc_no       type  bkpf-belnr,
        debit        type  bseg-hkont,
        credit       type  bseg-hkont,
        type         type  c,
        message(100) type  c,
      end of it_result.

data: w_line(4096).
data: begin of outline occurs 0,
        text(255),
      end of outline.
data: w_lastdate type datum.
data: w_error.
data: w_datum like sy-datum,
      w_uzeit like sy-uzeit.

initialization.
  select single url lastdate into ( p_url, w_lastdate ) from zws_master where wsid = c_wsid.
  if w_lastdate is initial or w_lastdate >= sy-datum.
    s_budat-low = s_budat-high = sy-datum.
  else.
    s_budat-low = w_lastdate.
    s_budat-high = sy-datum.
  endif.
  s_budat-sign = 'I'.
  s_budat-option = 'BT'.
  append s_budat.
  w_datum = sy-datum.
  w_uzeit = sy-uzeit.

at selection-screen.

  if p_url is initial and p_file is initial AND p_chk1 EQ 'X'.
    message e001(00) with 'Please enter URL or File Name'.
  endif.

at selection-screen on value-request for p_file.
  perform f4_filename.

start-of-selection.
*  case 'X'.
*    when p_new.
  if p_chk1 = 'X'.
    perform get_data.
  elseif p_chk2 = 'X'.
    perform get_log.
  endif.

  if w_error is initial.
    perform process_data.
    perform process_doc.
    perform display_doc.
  endif.
*    when p_old.

*  endcase.

form get_data.
  data: lo_http_client type ref to if_http_client,
        lo_rest_client type ref to cl_rest_http_client,
        lv_response    type string,
        token(50)      type c,
        pass_token     type string.

  data: rawdata type truxs_t_text_data with header line,
        temp    type string.
  data:  lv_json  type string.
  clear: wa_js_response,
         wa_js_pay,
         wa_js_origin,
         it_js_paydet,
         wa_js_paydet.
  refresh it_gl.

  if p_file is not initial.
    call function 'GUI_UPLOAD'
      exporting
        filename                = p_file
        filetype                = 'ASC'
        codepage                = '8300'
        "CODEPAGE  = '8300'
      tables
        data_tab                = rawdata
      exceptions
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        others                  = 17.

    loop at rawdata.
      temp = rawdata.
      condense temp.
      concatenate lv_response temp into lv_response.
    endloop.

*    /ui2/cl_json=>deserialize( exporting json = lv_response changing data = wa_js_response  ).
  else.
    concatenate p_url '?paymentStartDate=' s_budat-low
                      '&paymentEndDate='   s_budat-high into p_url.
*    write: / 'Calling EFlow Web Service.'.

    cl_http_client=>create_by_url(
       exporting
         url = p_url
       importing
         client = lo_http_client
       exceptions
         argument_not_found = 1
         plugin_not_active = 2
         internal_error = 3
         others = 4 ).

    if sy-subrc <> 0.
      return.
    endif.

    create object lo_rest_client
      exporting
        io_http_client = lo_http_client.

    lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_0 ).

    if p_tok eq 'X'.
      select single password appid
        into ( ws_pass, ws_appid )
        from zws_token where login = ws_login.
      call function 'Z_BAPI_GET_TOKEN'
        exporting
          login         = ws_login
          password      = ws_pass
          applicationid = ws_appid
        importing
          token         = token.
      "Need to save at somewhere for further use?
    else.
      token = 'SAP'.
    endif.
    if token is not initial.
      pass_token = token.
    else.
      pass_token = 'SAP'.
    endif.
*  * passing the token value in header
    call method lo_http_client->request->set_header_field
      exporting
        name  = 'Token'
        value = pass_token.

**   passing the content-type value in header which is a mandatory field
*    call method lo_http_client->request->set_header_field
*      exporting
*        name  = 'Content-Type'
*        value = 'application/json;charset=utf-8'.

*   lo_http_client->request->set_method( 'GET' ).
*   lo_http_client->request->set_content_type( 'application/json' ).
*   lo_http_client->propertytype_logon_popup = if_http_client=>co_disabled.

    lo_http_client->send(
                     exceptions
                     http_communication_failure = 1
                     http_invalid_state = 2 ).

*   Receiving the response
    lo_http_client->receive(
                    exceptions
                    http_communication_failure = 1
                    http_invalid_state = 2
                    http_processing_failed = 3 ).
    if sy-subrc eq 0.
    else.
      case sy-subrc.
        when 1.
          write: / 'Error: ', 'http_communiation_failure'.
        when 2.
          write: / 'Error: ', 'http_invalid_state'.
        when 3.
          write: / 'Error: ', 'http_processing_failed'.
      endcase.
    endif.
    lv_response = lo_http_client->response->get_cdata( ).
  endif.
  /ui2/cl_json=>deserialize( exporting json = lv_response changing data = wa_js_response  ).

  if not p_file is initial.
    write: / 'Test File: ', p_file.
  else.
    write: / 'URL: ', p_url.
  endif.
  if wa_js_response-status = '200' .
    it_js_res = wa_js_response-response.
    write : / 'Status: 200(OK).'.
    w_line = lv_response.

    loop at it_js_res into wa_js_res.
      wa_js_pay = wa_js_res-payment_data.
      select single eflow_request_no into temp from zefpayreqlog
      where eflow_request_no = wa_js_pay-eflow_request_no
        and payment_effective_date = wa_js_pay-payment_effective_date
        and status = '02'.   " ALready Processed
      check sy-subrc ne 0.

      move-corresponding wa_js_pay to it_log.
      it_log-bukrs = p_bukrs.
      it_log-datum = sy-datum.
      it_log-uzeit = sy-uzeit.
      it_log-status = '01'.
      it_js_paydet = wa_js_res-payment_detail.

      it_log-payment_detail = /ui2/cl_json=>serialize( it_js_paydet ).
      append it_log.
    endloop.
    modify zefpayreqlog from table it_log.
    move wa_js_response-response to it_js_res.
  elseif wa_js_response-status = '0'.
    w_error = 'X'.
    write : / 'Status: ', wa_js_response-status, '(No Record)'.
  else.
    w_error = 'X'.
    write : / 'Status: ', wa_js_response-status, '(Error).'.
    write : / 'Message Code: ', wa_js_response-msg_code.
    write : / 'Message Desc: ', wa_js_response-msg_desc.
  endif.

endform.

form get_log.
  data: paydet_json    type string.
  select *
    from zefpayreqlog
    appending corresponding fields of table it_log2
   where eflow_request_no in s_zuonr1
     and payment_effective_date in s_budat1
     and ( status = '01' or status = '99' ).
*    DATA: temp(10) TYPE n.
*    DO 10 TIMES.
*      temp = temp + 1.
*      it_log-EFLOW_REQUEST_NO = temp.
*      APPEND it_log.
*    ENDDO.

  if lines( it_log2 ) eq 0.
    w_error = 'X'.
    write: / 'No Record Found.'.
  else.
    perform display_alv_list.

    loop at it_log.
      move-corresponding it_log to wa_js_pay.
      wa_js_res-payment_data = wa_js_pay.
      paydet_json = it_log-payment_detail.
      /ui2/cl_json=>deserialize( exporting json = paydet_json changing data = it_js_paydet ).
      wa_js_res-payment_detail = it_js_paydet.
      append wa_js_res to it_js_res.
    endloop.
  endif.
endform.

form process_data.
  data: gv_item  type i,
        dr_acc   type bseg-hkont,
        cr_acc   type bseg-hkont,
        hktid    type t012a-hktid,
        hbkid    type t012a-hbkid,
        wa_line1 type zgl_accdoc,
        wa_line2 type zgl_accdoc,
        wa_line3 type zgl_accdoc,
        wa_line4 type zgl_accdoc,
        w_zuonr  like bseg-zuonr.
  data: it_tran type table of zbk_acc_det with header line.

  data: temp        type string,
        local_waers type bkpf-waers,
        temp2       type string,
        net_total   type bseg-wrbtr.
  data: year(4)  type c,
        month(2) type c,
        day(2)   type c.

  if w_error = ''.

    loop at it_js_res into wa_js_res.   " Process each record
      clear: w_error, wa_line1.
      wa_js_pay = wa_js_res-payment_data.
      w_zuonr = wa_js_pay-eflow_request_no.
      select single eflow_request_no
        into temp
        from zefpayreqlog
      where eflow_request_no = w_zuonr
        and status = '02'.
      if sy-subrc eq 0. " Already Processed
        it_skip-zuonr = temp.
        append it_skip.
        continue.   " Skip
      endif.
* write record to log
*      write: / 'Record no.:  ', sy-tabix.
* process payment data

*      write: /5 'Payment Data: ',
*               wa_js_pay-eflow_request_no, wa_js_pay-gross_amount,
*               wa_js_pay-bank_charge, wa_js_pay-payment_method,
*               wa_js_pay-payment_status, wa_js_pay-payment_effective_date.
* process payment detail
      refresh it_js_paydet.
      it_js_paydet = wa_js_res-payment_detail.
*      loop at it_js_paydet into wa_js_paydet.
*        write: /5 'Payment Detail: ',
*            wa_js_paydet-accounting_code, wa_js_paydet-currency,
*            wa_js_paydet-amount, wa_js_paydet-cheque_number,
*            wa_js_paydet-payment_origin-party-name,
*            wa_js_paydet-payment_origin-party-role,
*            wa_js_paydet-payment_origin-bank_account-bank_code,
*            wa_js_paydet-payment_recipient-party-name,
*            wa_js_paydet-payment_recipient-party-role.
*      endloop.

      add 1 to gv_item.
      wa_line1-index = gv_item.
      wa_line1-zuonr = wa_js_pay-eflow_request_no.

* Header
      wa_line1-blart = c_blart.  " EFlow Document Type
      wa_line1-xblnr = c_xblnr.
      wa_line1-bukrs = p_bukrs. " Company Code
      wa_line1-bldat = sy-datum.
      wa_line1-budat = wa_js_pay-payment_effective_date.

      clear: wa_js_paydet, wa_js_recipient, wa_js_party.
      read table it_js_paydet index 1 into wa_js_paydet.  " 1st Entry
      wa_js_recipient = wa_js_paydet-payment_recipient.
      wa_js_party = wa_js_recipient-party.
      wa_line1-bktxt = wa_js_party-role.

      select single sap_curr into wa_line1-waers from zws_curr
         where ef_curr = wa_js_paydet-currency.   " Currency
      if wa_line1-waers is initial.
        if wa_js_paydet-currency = 'NT$'.
          wa_line1-waers = 'TWD'.
        else.
*          write: /5 'Currency not found in ZWS_CURR: ', wa_js_paydet-currency.
          concatenate 'No matching currency in ZWS_CURR: ' wa_js_paydet-currency
          into wa_line1-message separated by space.
          wa_line1-type = 'E'.
          w_error = 'X'.
        endif.
      endif.

* Line 1: Credit Entry
      wa_line1-bschl = '50'.
      wa_line1-wrbtr = wa_js_pay-gross_amount.

      wa_line1-valut = wa_js_pay-payment_effective_date.
      wa_line1-xref1 = wa_js_pay-payment_method.

      wa_js_origin = wa_js_paydet-payment_origin.
      wa_js_party = wa_js_origin-party.
      wa_line1-xref2 = wa_js_party-name.

      wa_js_bank_account = wa_js_origin-bank_account.
      select single clearing from zef_acc_det into
        wa_line1-hkont where bankcode = wa_js_bank_account-bank_code
                         and payment_method = wa_js_pay-payment_method.
      if wa_line1-hkont is initial.
*        write: /5 'A/C not found: ', wa_js_bank_account-bank_code, wa_js_pay-payment_method.
        concatenate 'No matching A/C in ZEFLOW_ACCT_DET:'
        wa_js_bank_account-bank_code
        wa_js_pay-payment_method
        into wa_line1-message separated by space.
        wa_line1-type = 'E'.
        w_error = 'X'.
      else.
        append wa_line1 to it_gl.
      endif.

*   Line Item 2: For Bank Charge, only if bank charge > 0
      clear wa_line2.
      if wa_js_pay-bank_charge > 0.
        move-corresponding wa_line1 to wa_line2.
        wa_line2-bschl = '40'.
        wa_line2-hkont = c_hkont.
        wa_line2-wrbtr = wa_js_pay-bank_charge.
        clear wa_line2-valut.
        append wa_line2 to it_gl.
      endif.

*   Line Item3 to ItemN: Debit Entry
      net_total = 0.
      loop at it_js_paydet into wa_js_paydet.
        net_total = net_total + wa_js_paydet-amount.
      endloop.

      loop at it_js_paydet into wa_js_paydet.
        clear wa_line3.
        move-corresponding wa_line1 to wa_line3.
        wa_line3-bschl = '40'.
        wa_line3-hkont = wa_js_paydet-accounting_code.
        wa_line3-wrbtr = ( wa_js_pay-gross_amount - wa_js_pay-bank_charge )
                         * ( wa_js_paydet-amount / net_total ).
        wa_line3-sgtxt = wa_js_paydet-currency && wa_js_paydet-amount.
        append wa_line3 to it_gl.
      endloop.


* write all records to log
*      move-corresponding wa_line1 to wa_log.
*      wa_log-seq = wa_line1-index.
*      append wa_log to it_log.
* write correct records to it_gl
      if w_error is initial.  " Only create FI Document if no error
        append lines of it_gl to it_gl1.
        clear: it_gl[].
      else.
        update zefpayreqlog set status = '99'
                                message = wa_line1-message
                     where eflow_request_no = wa_line1-zuonr
                  and payment_effective_date = wa_line1-budat.
      endif.
* write records to it_result
      move-corresponding wa_line1 to it_result.
      it_result-debit = wa_line1-hkont .
      it_result-seq   = wa_line1-index.
      append it_result.
*      endif.
    endloop.
  endif.
endform.

form process_doc.
  data: curr_index(4)  type c,
        bapi_result(4) type c.

  if it_gl1[] is not initial.
    skip.
*    write: / 'Create FI Document....'.
    call function 'Z_BAPI_POST_DOC'
      exporting
        park_flag   = ''
        print_flag  = 'X'
        alv         = 'X'
        test_run    = ''
      tables
        acc_doc     = it_gl1
      exceptions
        check_fail  = 1
        create_fail = 2.

    bapi_result = sy-subrc. "Read table in below loop for it_result may replace sy-subrc.
    clear curr_index.
    loop at it_gl1.
      if curr_index <> it_gl1-index. "skip duplicate line.for D / C balance record in it_gl.
        curr_index = it_gl1-index.
        read table it_result with key seq = it_gl1-index.
        it_result-doc_no  = it_gl1-doc_no.
        it_result-type    = it_gl1-type.
        it_result-message = it_gl1-message.
        modify it_result index sy-tabix.
      endif.
    endloop.
    clear curr_index.

    update zws_master set lastdate = s_budat-high where wsid = c_wsid.
  else.
    bapi_result = -1.
  endif.

  "LOG
  loop at it_gl1."result tab and record tab is create in same time. tabix<->record will be match.
*    on change of it_canc-index.
    loop at it_log where eflow_request_no = it_gl1-zuonr.
      if it_gl1-type = ''.
        it_log-status = '02'.
      elseif it_gl1-type = 'E'.
        it_log-status = '99'.
        it_log-message = it_gl1-message.
      endif.
      modify it_log.
    endloop.
    modify zefpayreqlog from table it_log.
  endloop.
endform.

form display_doc .
*  if w_error is initial.
  data: w_text(10).
  data: w_skip    type i, w_success type i, w_error type i.
  clear: w_skip, w_success, w_error.
  describe table it_skip lines w_skip.
  loop at it_result.
    if it_result-type = 'E'.
      w_error = w_error + 1.
    else.
      w_success = w_success + 1.
    endif.
  endloop.

  skip.
* write: / 'Detail Log:'.
  loop at it_skip.
    write: / 'Skipped' under text-003,
             it_skip-zuonr under text-005.
  endloop.

  loop at it_result where type = 'E'.
    write: / 'Error' under text-003,
              it_result-zuonr   under text-005,
              40 it_result-budat,
              it_result-doc_no under text-006,
              it_result-message under text-007.
  endloop.

  loop at it_result where type <> 'E'.
    write: / 'Success' under text-003,
                  it_result-zuonr   under text-005,
                  40 it_result-budat,
                  it_result-doc_no under text-006,
                  it_result-message under text-007.
  endloop.
  skip.
  write: / 'Record count: ',
             /5 'Skipped: ', w_skip,
             /5 'Posted:  ', w_success,
             /5 'Error    ', w_error.


*  endif.
endform.

form conversion_exit changing k_varbl.
  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = k_varbl
    importing
      output = k_varbl.
endform.                    "CONVERSION_EXITs

form f4_filename.

  data: l_desktop   type string,
        l_i_files   type filetable,
        l_wa_files  type file_table,
        l_rcode     type int4,
        l_file_type type string.

  l_file_type = 'CSV|*.csv|TXT|*.txt|Excel File|*.xls;*.xlsx|All Types|*.*'.

  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      window_title            = 'Select file'
      default_extension       = l_file_type
      file_filter             = l_file_type
    changing
      file_table              = l_i_files
      rc                      = l_rcode
    exceptions
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      others                  = 5.
  if sy-subrc <> 0.
    message e000(00) with 'Error while opening file'.
  endif.

  check l_i_files is not initial.

  read table l_i_files index 1 into l_wa_files.
  if sy-subrc = 0.
    p_file = l_wa_files-filename.
  else.
    message e000(00) with 'Error while opening file'.
  endif.
endform.

FORM display_alv_list.
  gd_repid = sy-repid.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = gd_repid
      i_callback_user_command = 'USER_COMMAND'
      i_callback_pf_status_set = 'SET_PF_STATUS'   "see FORM
      is_layout               = gd_layout
      it_fieldcat             = fieldcatalog[]
      i_save                  = 'X'
    TABLES
      t_outtab                = it_log2
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " DISPLAY_ALV_REPORT
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZGUI_STATUS'.
                  "Copy of 'STANDARD' pf_status from fgroup SALV
ENDFORM.

FORM build_fieldcatalog.
  fieldcatalog-fieldname   = 'EFLOW_REQUEST_NO'.
  fieldcatalog-seltext_m   = 'EFlow Request No'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PAYMENT_EFFECTIVE_DATE'.
  fieldcatalog-seltext_m   = 'Payment Effective Date'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'GROSS_AMOUNT'.
  fieldcatalog-seltext_m   = 'Gross Amount'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'BANK_CHARGE'.
  fieldcatalog-seltext_m   = 'Bank Charge'.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PAYMENT_METHOD'.
  fieldcatalog-seltext_m   = 'Payment Method'.
  fieldcatalog-col_pos     = 4.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PAYMENT_STATUS'.
  fieldcatalog-seltext_m   = 'Payment Status'.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'DATUM'.
  fieldcatalog-seltext_m   = 'Update Date'.
  fieldcatalog-col_pos     = 6.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'UZEIT'.
  fieldcatalog-seltext_m   = 'Update Time'.
  fieldcatalog-col_pos     = 7.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG

FORM build_layout.
  gd_layout-box_fieldname     = 'SEL'.
  "set field name to store row selection
  gd_layout-edit              = 'X'. "makes whole ALV table editable
  gd_layout-zebra             = 'X'.
ENDFORM.                    " BUILD_LAYOUT

FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.
* Check function code
  CASE r_ucomm.
    WHEN 'EXEC'.  "user presses SAVE
      LOOP AT it_log2.
        IF it_log2-sel EQ 'X'.
            MOVE-CORRESPONDING it_log2 TO it_log.
            APPEND it_log.
*       Process records that have been selected
        ENDIF.
      ENDLOOP.
      "rs_selfield-refresh = 'X'.
      rs_selfield-exit = 'X'.
      SET PF-STATUS space.

      LEAVE SCREEN.
*      SUPPRESS DIALOG.
*      LEAVE TO LIST-PROCESSING.
  ENDCASE.
ENDFORM.                    "user_command

top-of-page.

  write: /1  'Status'(003),
           15 'Payout Sequence'(005),
           40 'Effective Date'(008),
           58 'Document No.'(006),
           73 'Message'(007).
  uline.

  • LinkedIn Social Icon
  • Facebook Social Icon
  • Pinterest Social Icon
  • wordpress

HK Office

502 Office Plus@Sheung Wan,

93-103 Wing Lok Street

Sheung Wan, Hong Kong

Taiwan Office

Room 1, 12/F,  

No. 169, Sec 4 ZhongXiao East Road,

Da'an District, Taipei District 10690

Taiwan

Contact Us

info@avant.com.hk

Tel: +852 35902943