Etiquetas

20111220

ABAP: Ejemplo de Batch Input con resumen en ALV

Un ejemplo para hacer copy/paste de un Batch Input con salida en LVC, donde hubo que hacer un split a la tabla ya que la misma función de carga GUI_UPLOAD no estaba separando los valores.

*&---------------------------------------------------------------------*
*& Report  ZFI_BI_CREADEUDOR
*&
*&---------------------------------------------------------------------*
REPORT  zfi_bi_creadeudor
  NO STANDARD PAGE HEADING.

**********************************************************************
*DECLARACION DATOS
**********************************************************************
TYPE-POOLS: slis.
INCLUDE <icon>.

************************************************************************
*INCLUDE BDCRECX1.
************************************************************************
TABLES t100.
DATA ctumode LIKE ctu_params-dismode VALUE 'N'.
DATA ctu VALUE 'X'.
DATA nodata VALUE '/'.
DATA cupdate LIKE ctu_params-updmode VALUE 'L'.

DATA bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
DATA messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

************************************************************************
* DATOS BI y ALV
************************************************************************
TYPES: BEGIN OF st_data,
        kunnr(10),  "deudor
        bukrs(4),   "soc.
        vkorg(4),   "org. ventas
        vtweg(2),   "canal de distribucion
        spart(2),   "sector
        ktokd(4),   "tipo cliente / grupo de cuentas

        name1(35),  "apellidos
        name2(35),  "nombres
        stras(35),  "calle
        ort01(35),  "pobla
        pstlz(10),  "cod postal
        ort02(35),  "distrito
        land1(3),   "pais
        regio(3),   "region
        stcd1(16),  "rut
        brsch(4),   "especialidad / ramo
        lzone(10),  "zona de transporte

        akont(10),  "cuenta asociada (NEW)
        zuawa(3),   "clave clasif. (NEW)
        fdgrv(10),  "gr. gest. tesor (NEW)

        zterm(4),   "condicion de pago
        xzver(1),   "historial de pago (OPCIONAL)
        bzirk(6),   "zona de ventas
        vkbur(4),   "oficina de ventas
        vkgrp(3),   "grupo de vendedores
        kdgrp(2),   "grupo de clientes
        waers(5),   "clave moneda
        konda(2),   "grupo de precios
        kalks(1),   "esquema cliente
        pltyp(2),   "lista de precios
        versg(1),   "grupo estadisticas cliente

        lprio(2),   "prioridad de entrega
        kzazu(1),   "agrupamiento pedidos (OPCIONAL)
        vsbed(2),   "condicion expedicion
        vwerk(4),   "centro suministrador
        antlf(1),   "maximo entregas parciales (OPCIONAL)

        mrnkz(1),   "tratamiento posterior
        bokre(1),   "rapel
        prfre(1),   "determ. precio
*        zterm2(4), "condicion pago <-- (MOVER A MANO)
        ktgrd(2),   "grupo de imputacion

        taxkd(1),   "IVA
       END OF st_data.

DATA: BEGIN OF ti_salida OCCURS 0,
        kunnr TYPE kna1-kunnr,
        bukrs TYPE knb1-bukrs,
        vkorg TYPE rf02d-vkorg,
        vtweg TYPE rf02d-vtweg,
        spart TYPE rf02d-spart,
        ktokd TYPE rf02d-ktokd,

        name1 TYPE kna1-name1,
        name2 TYPE kna1-name2,
        stras TYPE kna1-stras,
        ort01 TYPE kna1-ort01,
        pstlz TYPE kna1-pstlz,
        ort02 TYPE kna1-ort02,
        land1 TYPE kna1-land1,
        regio TYPE kna1-regio,

        stcd1 TYPE kna1-stcd1,
        brsch TYPE kna1-brsch,
        lzone TYPE kna1-lzone,

        akont TYPE knb1-akont,
        zuawa TYPE knb1-zuawa,
        fdgrv TYPE knb1-fdgrv,

        zterm TYPE knb1-zterm,
        xzver TYPE knb1-xzver,
        bzirk TYPE knvv-bzirk,
        vkbur TYPE knvv-vkbur,
        vkgrp TYPE knvv-vkgrp,
        kdgrp TYPE knvv-kdgrp,
        waers TYPE knvv-waers,
        konda TYPE knvv-konda,
        kalks TYPE knvv-kalks,
        pltyp TYPE knvv-pltyp,
        versg TYPE knvv-versg,

        lprio TYPE knvv-lprio,
        kzazu TYPE knvv-kzazu,
        vsbed TYPE knvv-vsbed,
        vwerk TYPE knvv-vwerk,
        antlf TYPE knvv-antlf,

        mrnkz TYPE knvv-mrnkz,
        bokre TYPE knvv-bokre,
        prfre TYPE knvv-prfre,
*        zterm2 TYPE knvv-zterm,
        ktgrd TYPE knvv-ktgrd,

        taxkd TYPE knvi-taxkd,

        icon(4),
        message TYPE string,
      END OF ti_salida.

DATA ti_data TYPE TABLE OF st_data WITH HEADER LINE.
DATA inicio TYPE i.

CONSTANTS c_ok TYPE string VALUE 'OK'.


************************************************************************
* ALV                                                *
************************************************************************
DATA:
      gs_layout TYPE lvc_s_layo,
      gs_fieldcat TYPE lvc_t_fcat,
      g_exit_caused_by_caller,
      gs_exit_caused_by_user TYPE slis_exit_by_user,
      g_repid LIKE sy-repid.
*Variants
DATA: gs_variant LIKE disvariant,
      g_save.
*"Callback
DATA:
    gt_events      TYPE slis_t_event,
    gt_list_top_of_page TYPE slis_t_listheader.


**********************************************************************
*PANTALLA SELECCION y EVENTOS
**********************************************************************
*** Pantalla
* p_file: Archivo
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN BEGIN OF LINE.
* text-c01: ¿Archivo tiene linea de cabecera?
SELECTION-SCREEN COMMENT (34) text-c01 FOR FIELD p_header.
PARAMETERS p_header AS CHECKBOX.
SELECTION-SCREEN END OF LINE.

*** Eventos
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.


**********************************************************************
INITIALIZATION.
************************************************************************

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

  PERFORM upload_data TABLES ti_data
                      USING  p_file.

  LOOP AT ti_data.

    PERFORM graba_registro USING ti_data.
    PERFORM procesar_salida USING ti_data.

  ENDLOOP.

  PERFORM inicializa_alv.

**********************************************************************
END-OF-SELECTION.
**********************************************************************
  PERFORM muestra_alv TABLES ti_salida.

*&---------------------------------------------------------------------*
*&      define  LLENA_CEROS
*&---------------------------------------------------------------------*
  DEFINE llena_ceros.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = &1
      importing
        output = &1.

  END-OF-DEFINITION.

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_DATA
*&---------------------------------------------------------------------*
FORM upload_data  TABLES   p_ti_data STRUCTURE ti_data
                  USING    p_file TYPE rlgrap-filename.

  DATA: ti_str TYPE string OCCURS 0 WITH HEADER LINE,
        file TYPE string.

  MOVE p_file TO file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = file
      has_field_separator     = 'X'
    TABLES
      data_tab                = ti_str
    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
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc <> 0.
    WRITE / sy-subrc.
    EXIT.
  ENDIF.

  IF p_header IS INITIAL.
    inicio = 1.
  ELSE.
    inicio = 2.
  ENDIF.

  LOOP AT ti_str FROM inicio.
    SPLIT ti_str AT ';' INTO
                            p_ti_data-kunnr
                            p_ti_data-bukrs
                            p_ti_data-vkorg
                            p_ti_data-vtweg
                            p_ti_data-spart
                            p_ti_data-ktokd

                            p_ti_data-name1
                            p_ti_data-name2
                            p_ti_data-stras
                            p_ti_data-ort01
                            p_ti_data-pstlz
                            p_ti_data-ort02
                            p_ti_data-land1
                            p_ti_data-regio

                            p_ti_data-stcd1
                            p_ti_data-brsch
                            p_ti_data-lzone

                            p_ti_data-akont
                            p_ti_data-zuawa
                            p_ti_data-fdgrv

                            p_ti_data-zterm
                            p_ti_data-xzver
                            p_ti_data-bzirk
                            p_ti_data-vkbur
                            p_ti_data-vkgrp
                            p_ti_data-kdgrp
                            p_ti_data-waers
                            p_ti_data-konda
                            p_ti_data-kalks
                            p_ti_data-pltyp
                            p_ti_data-versg

                            p_ti_data-lprio
                            p_ti_data-kzazu
                            p_ti_data-vsbed
                            p_ti_data-vwerk
                            p_ti_data-antlf

                            p_ti_data-mrnkz
                            p_ti_data-bokre
                            p_ti_data-prfre
*                            p_ti_data-zterm2
                            p_ti_data-ktgrd

                            p_ti_data-taxkd.

    llena_ceros: p_ti_data-vtweg,
                 p_ti_data-spart,
                 p_ti_data-vkbur,
                 p_ti_data-vkgrp,
                 p_ti_data-zuawa,
                 p_ti_data-konda,
                 p_ti_data-pltyp,
                 p_ti_data-vsbed,
                 p_ti_data-ktgrd.

    APPEND p_ti_data.
  ENDLOOP.


ENDFORM.                    " UPLOAD_DATA

*&---------------------------------------------------------------------*
*&      Form  PROCESAR_SALIDA
*&---------------------------------------------------------------------*
FORM procesar_salida  USING    p_ti_data STRUCTURE ti_data.

  CLEAR ti_salida.

  MOVE-CORRESPONDING p_ti_data TO ti_salida.

  LOOP AT messtab.
    IF messtab-msgid = 'F2' AND messtab-msgnr = '174'.
      WRITE '@08@' TO ti_salida-icon AS ICON. "OK
    ELSE.
      WRITE '@0A@' TO ti_salida-icon AS ICON. "Error
    ENDIF.

    PERFORM procesa_mensaje CHANGING ti_salida-message.

    APPEND ti_salida.
  ENDLOOP.

ENDFORM.                    " PROCESAR_SALIDA

*&---------------------------------------------------------------------*
*&      Form  PROCESA_ERROR
*&---------------------------------------------------------------------*
FORM procesa_mensaje  CHANGING message TYPE string.
  DATA: l_mstring(480).

  LOOP AT messtab.
    SELECT SINGLE * FROM t100 WHERE sprsl = messtab-msgspra
                              AND   arbgb = messtab-msgid
                              AND   msgnr = messtab-msgnr.
    IF sy-subrc = 0.
      l_mstring = t100-text.
      IF l_mstring CS '&1'.
        REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.
      ELSE.
        REPLACE '&' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv4 INTO l_mstring.
      ENDIF.
      CONDENSE l_mstring.
      CONCATENATE message l_mstring(250) INTO message SEPARATED BY space.
    ELSE.
      WRITE: / messtab.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " PROCESA_ERROR

*&---------------------------------------------------------------------*
*&      Form  GRABA_REGISTRO
*&---------------------------------------------------------------------*

FORM graba_registro  USING  ti_data STRUCTURE ti_data.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0100'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'RF02D-KTOKD'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'RF02D-KUNNR'
                                 ti_data-kunnr.
  PERFORM bdc_field       USING 'RF02D-BUKRS'
                                 ti_data-bukrs.
  PERFORM bdc_field       USING 'RF02D-VKORG'
                                 ti_data-vkorg.
  PERFORM bdc_field       USING 'RF02D-VTWEG'
                                 ti_data-vtweg.
  PERFORM bdc_field       USING 'RF02D-SPART'
                                 ti_data-spart.
  PERFORM bdc_field       USING 'RF02D-KTOKD'
                                 ti_data-ktokd.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0110'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNA1-SPRAS'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNA1-NAME1'
                                ti_data-name1.
  PERFORM bdc_field       USING 'KNA1-NAME2'
                                ti_data-name2.
  PERFORM bdc_field       USING 'KNA1-STRAS'
                                ti_data-stras.
  PERFORM bdc_field       USING 'KNA1-ORT01'
                                ti_data-ort01.
  PERFORM bdc_field       USING 'KNA1-PSTLZ'
                                ti_data-pstlz.  "NUEVO
  PERFORM bdc_field       USING 'KNA1-ORT02'
                                ti_data-ort02.
  PERFORM bdc_field       USING 'KNA1-LAND1'
                                ti_data-land1.
  PERFORM bdc_field       USING 'KNA1-REGIO'
                                ti_data-regio.
  PERFORM bdc_field       USING 'KNA1-SPRAS'
                                sy-langu.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0120'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNA1-LZONE'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNA1-STCD1'
                                ti_data-stcd1.     "TODO: Llenar o Solicitar
  PERFORM bdc_field       USING 'KNA1-BRSCH'
                                ti_data-brsch.
  PERFORM bdc_field       USING 'KNA1-LZONE'
                                ti_data-lzone.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0125'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNA1-BRSCH'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNA1-BRSCH'
                                ti_data-brsch.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0360'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVK-NAMEV(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0210'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNB1-AKONT'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNB1-AKONT'
                                ti_data-akont.  "NUEVO
  PERFORM bdc_field       USING 'KNB1-ZUAWA'
                                ti_data-zuawa.  "NUEVO
  PERFORM bdc_field       USING 'KNB1-FDGRV'
                                ti_data-fdgrv.  "NUEVO

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0215'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNB1-XZVER'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNB1-ZTERM'
                                ti_data-zterm.
  PERFORM bdc_field       USING 'KNB1-XZVER'
                                ti_data-xzver.  "NUEVO

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0220'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNB5-MAHNA'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0610'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNBW-WITHT(01)'.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0310'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVV-VERSG'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNVV-BZIRK'
                                ti_data-bzirk.
  PERFORM bdc_field       USING 'KNVV-VKBUR'
                                ti_data-vkbur.
  PERFORM bdc_field       USING 'KNVV-VKGRP'
                                ti_data-vkgrp.
  PERFORM bdc_field       USING 'KNVV-KDGRP'
                                ti_data-kdgrp.
  PERFORM bdc_field       USING 'KNVV-WAERS'
                                ti_data-waers.
  PERFORM bdc_field       USING 'KNVV-KONDA'
                                ti_data-konda.
  PERFORM bdc_field       USING 'KNVV-KALKS'
                                ti_data-kalks.
  PERFORM bdc_field       USING 'KNVV-PLTYP'
                                ti_data-pltyp.
  PERFORM bdc_field       USING 'KNVV-VERSG'
                                ti_data-versg.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0315'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVV-VWERK'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNVV-LPRIO'
                                ti_data-lprio.
  PERFORM bdc_field       USING 'KNVV-KZAZU'
                                ti_data-kzazu.  "NUEVO
  PERFORM bdc_field       USING 'KNVV-VSBED'
                                ti_data-vsbed.
  PERFORM bdc_field       USING 'KNVV-VWERK'
                                ti_data-vwerk.
  PERFORM bdc_field       USING 'KNVV-ANTLF'
                                ti_data-antlf.  "NUEVO

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0320'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVV-KTGRD'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'KNVV-MRNKZ'
                                ti_data-mrnkz.
  PERFORM bdc_field       USING 'KNVV-BOKRE'
                                ti_data-bokre.
  PERFORM bdc_field       USING 'KNVV-PRFRE'
                                ti_data-prfre.
  PERFORM bdc_field       USING 'KNVV-ZTERM'
                                ti_data-zterm.  "podría usarse otra condicion de pago?
  PERFORM bdc_field       USING 'KNVV-KTGRD'
                                ti_data-ktgrd.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '1350'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVI-TAXKD(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
  PERFORM bdc_field       USING 'KNVI-TAXKD(01)'
                                ti_data-taxkd.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '1350'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVI-TAXKD(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0324'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'RF02D-KTONR(05)'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
  PERFORM bdc_field       USING 'KNVP-PARVW(05)'
                                'YM'.
  PERFORM bdc_field       USING 'RF02D-KTONR(05)'
                                ti_data-kunnr.

  PERFORM bdc_dynpro      USING 'SAPMF02D' '0324'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'KNVP-PARVW(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=UPDA'.

  PERFORM bdc_transaction USING 'XD01'.

ENDFORM.                    " GRABA_REGISTRO


*&---------------------------------------------------------------------*
*&      Form  inicializa_alv
*&---------------------------------------------------------------------*
FORM inicializa_alv.
  g_repid = sy-repid.
  PERFORM layout_init USING gs_layout.
* TODO: inicializar fieldcat
  PERFORM fieldcat_init.
  PERFORM eventtab_build USING gt_events[].
  gs_variant-report = g_repid.
  g_save           = 'X'.

ENDFORM.                    "inicializa_alv

*&---------------------------------------------------------------------*
*&      Form  muestra_alv
*&---------------------------------------------------------------------*
FORM muestra_alv TABLES gt_outtab.
  DATA e VALUE 'E'.

  CHECK gs_fieldcat[] IS NOT INITIAL.

* TODO: inicializar cabecera
  PERFORM comment_build USING gt_list_top_of_page[].

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
         i_buffer_active    = 'X'
         i_callback_program = g_repid
*         i_callback_pf_status_set = 'ALV_STATUS'  "insertar PF-STATUS propio
*         i_callback_user_command = 'USER_COMMAND' "controlar acciones sobre registros
*        i_structure_name   = ''
         it_fieldcat_lvc        = gs_fieldcat[]
         is_layout_lvc          = gs_layout
         i_default          = 'A'
         i_save             = g_save
         is_variant         = gs_variant
         it_events          = gt_events[]

    IMPORTING
         e_exit_caused_by_caller = g_exit_caused_by_caller
         es_exit_caused_by_user  = gs_exit_caused_by_user
    TABLES
         t_outtab = gt_outtab
    EXCEPTIONS
         program_error = 1
         OTHERS        = 2.

  IF sy-subrc <> 0.
    CASE 'X'.
      WHEN g_exit_caused_by_caller.
        MESSAGE 'g_exit_caused_by_caller' TYPE e.
      WHEN gs_exit_caused_by_user-back.
        MESSAGE 'gs_exit_caused_by_user-back' TYPE e.
      WHEN gs_exit_caused_by_user-exit.
        MESSAGE 'gs_exit_caused_by_user-exit' TYPE e.
      WHEN gs_exit_caused_by_user-cancel.
        MESSAGE 'gs_exit_caused_by_user-cancel' TYPE e.
      WHEN OTHERS.
        MESSAGE 'N/E Error ALV' TYPE e.
    ENDCASE.
  ENDIF.

ENDFORM.                    "muestra_alv

*&---------------------------------------------------------------------*
*&      Form  layout_init
*&---------------------------------------------------------------------*
FORM layout_init USING rs_layout TYPE lvc_s_layo.
  rs_layout-zebra             = 'X'.
  rs_layout-edit = ' '.
  rs_layout-cwidth_opt = 'X'.
ENDFORM.                    "layout_init

*&---------------------------------------------------------------------*
*&      Form  fieldcat_init
*&---------------------------------------------------------------------*
FORM fieldcat_init.

  DATA: ls_fieldcat TYPE lvc_s_fcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'KUNNR'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'BUKRS'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VKORG'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  DATA ti_data LIKE ti_salida.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VTWEG'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'SPART'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'KTOKD'.
  ls_fieldcat-ref_table = 'RF02D'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'NAME1'.
  ls_fieldcat-ref_table = 'KNA1'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'NAME2'.
  ls_fieldcat-ref_table = 'KNA1'.
  ls_fieldcat-key = 'X'.
  APPEND ls_fieldcat TO gs_fieldcat.


*  CLEAR ls_fieldcat.
*  ls_fieldcat-fieldname = ''.
*  ls_fieldcat-ref_table = ''.
*  ls_fieldcat-key = 'X'.
*  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'ICON'.
  APPEND ls_fieldcat TO gs_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MESSAGE'.
  ls_fieldcat-scrtext_l = text-t10.
  ls_fieldcat-scrtext_m = text-t10.
  ls_fieldcat-scrtext_s = text-t10.
  APPEND ls_fieldcat TO gs_fieldcat.

ENDFORM.                    "fieldcat_init

*&---------------------------------------------------------------------*
*&      Form  comment_build
*&---------------------------------------------------------------------*
FORM comment_build USING lt_top_of_page TYPE slis_t_listheader.
  DATA: ls_line TYPE slis_listheader.
  DATA: texto TYPE string.

* LIST HEADING LINE: TYPE H
  CLEAR ls_line.
  ls_line-typ  = 'H'."Cabecera
* LS_LINE-KEY:  NOT USED FOR THIS TYPE
  ls_line-info = sy-title.
  APPEND ls_line TO lt_top_of_page.

ENDFORM.                    "comment_build

*&---------------------------------------------------------------------*
*&      Form  eventtab_build
*&---------------------------------------------------------------------*
FORM eventtab_build USING rt_events TYPE slis_t_event.
  DATA: g_status_set   TYPE slis_formname VALUE 'PF_STATUS_SET',
        g_user_command TYPE slis_formname VALUE 'USER_COMMAND',
        g_top_of_page  TYPE slis_formname VALUE 'TOP_OF_PAGE',
        g_top_of_list  TYPE slis_formname VALUE 'TOP_OF_LIST',
        g_data_changed TYPE slis_formname VALUE 'DATA_CHANGED',
        g_end_of_list  TYPE slis_formname VALUE 'END_OF_LIST'.

  DATA: ls_event TYPE slis_alv_event.
*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = rt_events.

* top of page
  READ TABLE rt_events WITH KEY name = slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE g_top_of_page TO ls_event-form.
    APPEND ls_event TO rt_events.
  ENDIF.

* data changed: procesar cambios en datos especificos de alv modificable
  ls_event-name = slis_ev_data_changed.
  ls_event-form = g_data_changed.
  APPEND ls_event TO rt_events.


ENDFORM.                    "eventtab_build

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      i_logo             = ''     "<-- inserte logo empresa
      it_list_commentary = gt_list_top_of_page.
ENDFORM.                    "top_of_page


*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PROGRAM    text
*      -->DYNPRO     text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FNAM       text
*      -->FVAL       text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  IF fval <> nodata.
    CLEAR bdcdata.
    bdcdata-fnam = fnam.
    bdcdata-fval = fval.
    APPEND bdcdata.
  ENDIF.
ENDFORM.                    "BDC_FIELD

*&---------------------------------------------------------------------*
*&      Form  BDC_TRANSACTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TCODE      text
*----------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
  DATA: l_mstring(480).
  DATA: l_subrc LIKE sy-subrc.
* batch input session

  REFRESH messtab.
  CALL TRANSACTION tcode USING bdcdata
                   MODE   ctumode
                   UPDATE cupdate
                   MESSAGES INTO messtab.
  l_subrc = sy-subrc.

  REFRESH bdcdata.
ENDFORM.                    "BDC_TRANSACTION

No hay comentarios:

Publicar un comentario en la entrada

Publicar un comentario en la entrada