Boa tarde pessaol da comunidade, eu estou a escrever essa para explicar como fazer um report usando SALV onde uma das colunas é CHECKBOX usando técnicas de OOABAP e usando cursos para exportar valor para tabela interna.

  • primeiro passo definir os tipos e as tabelas que iremos usar ao longo do programa, iremos criar um TYPES DE CLIENTE COM 3 CAMPOS que terão checkbox em colunas “IGNR” , “ACTUALIZAR” “PRINCIPAL”, tornando que se activem unicamente em cada linha.
*--------------------------------------------------------------------*
*- DIFINIÇÕES GERAIS
*--------------------------------------------------------------------*
TYPES : BEGIN OF ty_clie,
         nicb TYPE zclnt,
         nome TYPE zclien,
         nuit TYPE znuit,
         tipo TYPE ztpcl,
         datn TYPE zbdat,
         nomp TYPE zcliep,
         nomm TYPE zcliem,
         ignr TYPE c,
         cbac TYPE c,
         cbpr TYPE c,
         group TYPE int4,
         t_color TYPE lvc_t_scol.
*         button TYPE c.
TYPES : END OF ty_clie.


DATA: ls_color TYPE lvc_s_colo.    " Colors strucutre

DATA: lo_events TYPE REF TO cl_salv_events_table.

FIELD-SYMBOLS : <fs_clie> TYPE ty_clie.
  • Segungo passo vamos fazer definar as classe que ira tratar da informação
  • GET_DATA

 

2. DEFINIR IMPLEMENTAÇÃO DESSAS CLASSES.

 

CLASS lcl_report IMPLEMENTATION.


METHOD set_pf_status.

    DATA: lo_functions TYPE REF TO cl_salv_functions_list.

    lo_functions = co_alv->get_functions( ).

    alv->set_screen_status(
        pfstatus = 'ZALV_STATUS'
        report = sy-repid ).

*    lo_functions->set_default( abap_true ).

  ENDMETHOD.                    "SET_PF_STATUS


  METHOD get_data.

    IF p_nome = 'X'.
      CALL METHOD me->get_data_by_nome.
    ELSE.
      CALL METHOD me->get_data_by_nuit.
    ENDIF.

    me->agrupar_dados( ).

  ENDMETHOD.                    "get_data


  METHOD generate_output.

    alv->display( ).

  ENDMETHOD.                    "generate_output




  METHOD initialize_alv.

    DATA message TYPE REF TO cx_salv_msg.
    DATA cx_error TYPE  REF TO cx_salv_data_error.


    TRY.
        cl_salv_table=>factory(
        IMPORTING
          r_salv_table = alv
        CHANGING
          t_table      = it_clie ).

        lo_events = alv->get_event( ).

        columns = alv->get_columns( ).

        columns->set_optimize( ).


        CALL METHOD set_pf_status
          CHANGING
            co_alv = alv.


        CALL METHOD set_colors
          CHANGING
            co_alv  = alv
            ct_clie = it_clie.


        CALL METHOD me->hide_alv_column
          EXPORTING
            iv_field = 'MANDT'.


*        CALL METHOD me->hide_alv_column
*          EXPORTING
*            iv_field = 'GROUP'.

        CALL METHOD me->set_column_propirties
          EXPORTING
            iv_field = 'CBAC'
            iv_text  = 'ACTUALIZAR'.

        CALL METHOD me->set_column_propirties
          EXPORTING
            iv_field = 'IGNR'
            iv_text  = 'IGNORAR'.

        CALL METHOD me->set_column_propirties
          EXPORTING
            iv_field = 'CBPR'
            iv_text  = 'PRINCIPAL'.

        CALL METHOD me->create_checkbox
          EXPORTING
            iv_field = 'IGNR'.

        CALL METHOD me->create_checkbox
          EXPORTING
            iv_field = 'CBAC'.

        CALL METHOD me->create_checkbox
          EXPORTING
            iv_field = 'CBPR'.

*        PERFORM enable_layout.

        lo_events = alv->get_event( ).

        CREATE OBJECT lo_event_handler.
        SET HANDLER lo_event_handler->m_link_click FOR lo_events.
        SET HANDLER lo_event_handler->on_button_click FOR lo_events.

        TRY .
*          columns->t_color = lt_S_COLOR.

            columns->set_color_column( 'T_COLOR' ).
          CATCH cx_salv_data_error INTO cx_error.

        ENDTRY.



      CATCH cx_salv_msg INTO message.
        " error handling
    ENDTRY.



 

  • DEFINIR A CLASSE QUE IRA FAZER O HANDLER DOS EVENTOS.
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.
    METHODS : m_link_click FOR EVENT link_click OF cl_salv_events_table
                           IMPORTING row column.

    METHODS : on_button_click FOR EVENT added_function OF cl_salv_events.

  PRIVATE SECTION.

*--------------------------------------------------------------------*
* TYPES DE CHAVES DE REGISTRO
*--------------------------------------------------------------------*
    TYPES : BEGIN OF ty_keys,
          nicp TYPE zclnt,
          nica TYPE zclnt.
    TYPES: END OF ty_keys.

    DATA : it_keys TYPE STANDARD TABLE OF ty_keys.

    DATA : keys_invalid TYPE c LENGTH 1.

    DATA : wa_t_clie TYPE  ty_clie,
     wa_keys TYPE ty_keys.

    METHODS :   validar_keys,
                actualizar_keys,
                actualizar_clie.


ENDCLASS.                    "lcl_event_handler DEFINITION
  • IMPLEMENTAÇÃO DA CLASSE
  METHOD m_link_click.

    READ TABLE it_clie ASSIGNING <fs_clie> INDEX row.

    CASE column.

      WHEN 'IGNR'.
        IF <fs_clie>-ignr EQ 'X'.
          <fs_clie>-ignr = ' '.
        ELSE.
          <fs_clie>-ignr = 'X'.
          <fs_clie>-cbac = ' '.
          <fs_clie>-cbpr = ' '.
        ENDIF.
      WHEN 'CBAC'.
        IF <fs_clie>-cbac EQ 'X'.
          <fs_clie>-cbac = ' '.
        ELSE.
          <fs_clie>-ignr = ' '.
          <fs_clie>-cbac = 'X'.
          <fs_clie>-cbpr = ' '.
        ENDIF.

      WHEN 'CBPR'.
        IF <fs_clie>-cbpr EQ 'X'.
          <fs_clie>-cbpr = ' '.
        ELSE.
          <fs_clie>-ignr = ' '.
          <fs_clie>-cbac = ' '.
          <fs_clie>-cbpr = 'X'.
        ENDIF.

    ENDCASE.

    alv->refresh( ).

  ENDMETHOD.                    "m_link_click


  METHOD on_button_click.

    DATA : ans.

    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        titlebar              = 'Ja analisou todo a lista, submenter a informação'
        text_question         = 'Clicar Cancelar para sair'
        text_button_1         = 'SUBMENTER'
        icon_button_1         = 'ICON_CHECKED'
        text_button_2         = 'CANCELAR SUBMISSÃO'
        icon_button_2         = 'ICON_CANCEL'
        display_cancel_button = ' '
        popup_type            = 'ICON_MESSAGE_ERROR'
      IMPORTING
        answer                = ans.
    IF ans = 2.
*      LEAVE PROGRAM.
      RETURN.
    ENDIF.

    IF ans EQ '1'.

      CALL METHOD me->validar_keys( ).

      CALL METHOD me->actualizar_keys( ).

      CALL METHOD me->actualizar_clie( ).

      MESSAGE s002 WITH 'registos submetido com sucesso'.

    ENDIF.

  ENDMETHOD.                    "ON_BUTTON_CLICK

  METHOD validar_keys.

    CLEAR wa_keys.
    CLEAR me->keys_invalid.


    LOOP AT it_clie INTO wa_clie.

      IF wa_clie-cbac EQ 'X'.

        CLEAR wa_t_clie.

        READ TABLE it_clie INTO wa_t_clie WITH KEY group = wa_clie-group cbpr = 'X'.

        IF sy-subrc EQ 0.
          wa_keys-nicp = wa_t_clie-nicb.
          wa_keys-nica = wa_clie-nicb.

          APPEND wa_keys TO it_keys.

        ELSE.
          MESSAGE i002 WITH 'O ' wa_clie-nicb 'NÃO TEM NENHUM NICB PRINCIPAL SELECIONADO NO GRUPO ' wa_clie-group.

          me->keys_invalid = ' '.

        ENDIF.
      ENDIF.

    ENDLOOP.

  ENDMETHOD.                    "validar_keys

  METHOD actualizar_keys.

    DATA : wa_chaves TYPE ztcrckeys.

    LOOP AT it_keys INTO wa_keys.

      wa_chaves-keys_nicp = wa_keys-nicp.

      wa_chaves-keys_nica = wa_keys-nica.
      wa_chaves-keys_datc = sy-datum.
      wa_chaves-keys_horc = sy-uzeit.
      wa_chaves-keys_user = sy-uname.

      wa_clie_del-nicb = wa_keys-nicp.
      APPEND wa_clie_del TO it_clie_del.

      wa_clie_del-nicb = wa_keys-nica.
      APPEND wa_clie_del TO it_clie_del.

      INSERT ztcrckeys FROM wa_chaves.

      COMMIT WORK.

    ENDLOOP.

  ENDMETHOD.                    "actualizar_keys

  METHOD actualizar_clie.

    DATA : wa_clie_arq TYPE ztcrcclie_arq,
           wa_clie_t TYPE ztcrcclie.

    LOOP AT it_clie INTO wa_clie.

      IF wa_clie-ignr EQ 'X'.
        UPDATE ztcrcclie SET clie_etpn = 'X' WHERE clie_iden = wa_clie-nicb.

        wa_clie_del-nicb = wa_clie-nicb.
        APPEND wa_clie_del TO it_clie_del.

      ELSE.
        READ TABLE it_keys INTO wa_keys WITH KEY nica = wa_clie-nicb.

        IF sy-subrc EQ 0.

          SELECT SINGLE * FROM ztcrcclie INTO CORRESPONDING FIELDS OF wa_clie_t WHERE clie_iden = wa_clie-nicb.

          MOVE-CORRESPONDING : wa_clie_t TO wa_clie_arq.

          wa_clie_arq-clie_unam = sy-uname.
          wa_clie_arq-clie_horm = sy-uzeit.
          wa_clie_arq-clie_datm = sy-datum.

          INSERT ztcrcclie_arq FROM wa_clie_arq.
          DELETE FROM ztcrcclie WHERE clie_iden = wa_clie-nicb.

          UPDATE ztcrcclie SET clie_etpn = 'X' WHERE clie_iden = wa_clie-nicb.
          COMMIT WORK.

        ENDIF.

      ENDIF.

    ENDLOOP.

    LOOP AT it_clie_del INTO wa_clie_del.

      READ TABLE it_clie WITH KEY nicb = wa_clie_del-nicb TRANSPORTING NO FIELDS.

      IF sy-subrc EQ 0.

        DELETE it_clie INDEX sy-tabix.

      ENDIF.

    ENDLOOP.

    alv->refresh( ).


  ENDMETHOD.                    "actualizar_clie

 

START-OF-SELECTION

 

  DATA: lo_report TYPE REF TO lcl_report.

  CREATE OBJECT lo_report.

  lo_report->get_data( ).
  lo_report->initialize_alv( ).


*  SET PF-STATUS '0500'.


  lo_report->generate_output( ).

 

RESULTADO

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply