quarta-feira, 24 de junho de 2009

ABAP - Todas variáveis de sistema

Segue uma lista com todas as variáveis de sistema:

  • SY-ABCDE - Constant: Alphabet (A,B,C,...)
  • SY-APPLI - SAP applications
  • SY-BATCH - Background active (X)
  • SY-BATZD - Background SUBMIT: Daily
  • SY-BATZM - Background SUBMIT: Monthly
  • SY-BATZO - Background SUBMIT: Once
  • SY-BATZS - Background SUBMIT: Immediately
  • SY-BATZW - Background SUBMIT: Weekly
  • SY-BINPT - Batch input active (X)
  • SY-BREP4 - Background SUBMIT: Root name of request report
  • SY-BSPLD - Background SUBMIT: List output to spool
  • SY-CALLD - CALL mode active (X)
  • SY-CALLR - Print: ID for print dialog function
  • SY-CCURS - Rate specification/result field (CURRENCY CONVERT)
  • SY-CCURT - Table rate from currency conversion
  • SY-CDATE - Date of rate from currency conversion
  • SY-COLNO - Current column during list creation
  • SY-CPAGE - Current page number
  • SY-CPROG - Runtime: Main program
  • SY-CTABL - Exchange rate table from currency conversion
  • SY-CTYPE - Exchange rate type 'M','B','G' from CURRENCY CONVERSION
  • SY-CUCOL - Cursor position (column)
  • SY-CUROW - Cursor position (line)
  • SY-DATAR - Flag: Data received
  • SY-DATLO - Local date for user
  • SY-DATUM - System: Date
  • SY-DATUT - Global date related to UTC (GMT)
  • SY-DAYST - Summertime active ? ('daylight saving time')
  • SY-DBCNT - Number of elements in edited dataset with DB operations
  • SY-DBNAM - Logical database for ABAP/4 program
  • SY-DBSYS - System: Database system
  • SY-DCSYS - System: Dialog system
  • SY-DSNAM - Runtime: Name of dataset for spool output
  • SY-DYNGR - Screen group of current screen
  • SY-DYNNR - Number of current screen
  • SY-FDAYW - Factory calendar weekday
  • SY-FDPOS - Location of a string
  • SY-FMKEY - Current function code menu
  • SY-HOST  - Host
  • SY-INDEX - Number of loop passes
  • SY-LANGU - SAP logon language key
  • SY-LDBPG - Program: ABAP/4 database program for SY-DBNAM
  • SY-LILLI - Number of current list line
  • SY-LINCT - Number of list lines
  • SY-LINNO - Current line for list creation
  • SY-LINSZ - Line size of list
  • SY-LISEL - Interact.: Selected line
  • SY-LISTI - Number of current list line
  • SY-LOCDB - Local database exists
  • SY-LOCOP - Local database operation
  • SY-LOOPC - Number of LOOP lines at screen step loop
  • SY-LSIND - Number of secondary list
  • SY-LSTAT - Interact.: Status information for each list level
  • SY-MACDB - Program: Name of file for matchcode access
  • SY-MACOL - Number of columns from SET MARGIN
  • SY-MANDT - Client number from SAP logon
  • SY-MARKY - Current line character for MARK
  • SY-MAROW - No. of lines from SET MARGIN statement
  • SY-MODNO - Number of alternative modi
  • SY-MSGID - Message ID
  • SY-MSGLI - Interact.: Message line (line 23)
  • SY-MSGNO - Message number
  • SY-MSGTY - Message type (E,I.W,...)
  • SY-MSGV1 - Message variable
  • SY-MSGV2 - Message variable
  • SY-MSGV3 - Message variable
  • SY-MSGV4 - Message variable
  • SY-OPSYS - System: Operating system
  • SY-PAART - Print: Format
  • SY-PAGCT - Page size of list from REPORT statement
  • SY-PAGNO - Runtime: Current page in list
  • SY-PDEST - Print: Output device
  • SY-PEXPI - Print: Spool retention period
  • SY-PFKEY - Runtime: Current F key status
  • SY-PLIST - Print: Name of spool request (list name)
  • SY-PRABT - Print: Department on cover sheet
  • SY-PRBIG - Print: Selection cover sheet
  • SY-PRCOP - Print: Number of copies
  • SY-PRDSN - Print: Name of spool dataset
  • SY-PREFX - ABAP/4 prefix for background jobs
  • SY-PRIMM - Print: Print immediately
  • SY-PRNEW - Print: New spool request (list)
  • SY-PRREC - Print: Recipient
  • SY-PRREL - Print: Delete after printing
  • SY-PRTXT - Print: Text for cover sheet
  • SY-REPID - Program: Name of ABAP/4 program
  • SY-RTITL - Print: Report title of program to be printed
  • SY-SAPRL - System: SAP Release
  • SY-SCOLS - Columns on screen
  • SY-SLSET - Name of selection set
  • SY-SPONO - Runtime: Spool number for list output
  • SY-SPONR - Runtime: Spool number from TRANSFER statement
  • SY-SROWS - Lines on screen
  • SY-STACO - Interact.: List displayed from column
  • SY-STARO - Interact.: Page displayed from line
  • SY-STEPL - Number of LOOP line at screen step
  • SY-SUBRC - Return value after specific ABAP/4 statements
  • SY-SUBTY - ABAP/4: Call type for SUBMIT
  • SY-SYSID - System: SAP System ID
  • SY-TABIX - Runtime: Current line of an internal table
  • SY-TCODE - Session: Current transaction code
  • SY-TFDSN - Runtime: Dataset for data extracts
  • SY-TFILL - Current number of entries in internal table
  • SY-TIMLO - Local time for user
  • SY-TIMUT - Global time related to UTC (GMT)
  • SY-TITLE - Title of ABAP/4 program
  • SY-TLENG - Line width of an internal table
  • SY-TMAXL - Maximum number of entries in internal table (?)
  • SY-TNAME - Name of internal table after an access (?)
  • SY-TOCCU - OCCURS parameter with internal tables
  • SY-TPAGI - Flag indicating roll-out of internal table to paging area (?)
  • SY-TSTLO - Timestamp (date and time) for user
  • SY-TSTUT - Timestamp (date and time) related to UTC (GMT)
  • SY-TTABC - Number of line last read in an internal table (?)
  • SY-TTABI - Offset of internal table in roll area (?)
  • SY-TVAR0 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR1 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR2 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR3 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR4 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR5 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR6 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR7 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR8 - Runtime: Text variable for ABAP/4 text elements
  • SY-TVAR9 - Runtime: Text variable for ABAP/4 text elements
  • SY-TZONE - Time difference from 'Greenwich Mean Time' (UTC) in seconds
  • SY-UCOMM - Interact.: Command field function entry
  • SY-ULINE - Constant: Underline (---------...)
  • SY-UNAME - Session: SAP user from SAP logon
  • SY-UZEIT - System: Time
  • SY-VLINE - Constant: Vertical bar
  • SY-WAERS - T001: Company code currency after reading B segment
  • SY-WILLI - Number of current window line
  • SY-WINCO - Cursor position in window (column)
  • SY-WINDI - Index of current window line
  • SY-WINRO - Cursor position in window (line)
  • SY-WINSL - Interact.: Selected window line
  • SY-WINX1 - Window coordinate (column left)
  • SY-WINX2 - Window coordinate (column right)
  • SY-WINY1 - Window coordinate (line left)
  • SY-WINY2 - Window coordinate (line right)
  • SY-WTITL - Standard page header indicator
  • SY-XCODE - Extended command field
  • SY-ZONLO - Time zone of user

quarta-feira, 13 de maio de 2009

Funções úteis do SAP

Segue uma lista de algumas funções que podem se tornar úteis no dia a dia.

Formatar números:

a) Retirar zeros a esquerda do número:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        input  = t_saida-zf_transp
      IMPORTING
        output = t_saida-zf_transp.

t_saida-zf_transp = Tipo C 

b) Incluir zeros a esquerda do número:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = t_saida-zf_transp
      IMPORTING
        output = t_saida-zf_transp.
t_saida-zf_transp = Tipo C

FORMATAÇÃO DE DATAS

*  Função que converte um campo CHAR para DATE

CALL FUNCTION 'CONVERT_DATE_INPUT'
               EXPORTING
                    INPUT  = FIELD_NAME
               IMPORTING
                    OUTPUT = *AFRUD-BUDAT
               EXCEPTIONS
                    OTHERS = 1.

FIELD_NAME(30) TYPE C .
AFRUD-BUDATE TYPE SY-DATUM.

*  Função que formata um campo DATE para CHAR

CALL FUNCTION 'SLS_MISC_CONVERT_TO_DATE'
      EXPORTING
        p_date                        = v_data_aux
        p_date_format                 = 'DD.MM.YYYY'
      IMPORTING
        p_date_string                 = t_transp_interno-datalan
      EXCEPTIONS
        error_selecting_user_defaults = 1
        OTHERS                        = 2.

v_data_aux type sy-datum.
t_transp_interno-datalan(10) type c.

Formato do campo char de 10 de saida
'DD.MM.YYYY'
'MM/DD/YYYY'
'MM-DD-YYYY'
'YYYY.MM.DD'
'YYYY/MM/DD'
'YYYY-MM-DD'

* Retorna o numero de dias do mês

    CALL FUNCTION 'RTP_US_API_MAX_DAYS_IN_MONTH'
      EXPORTING
        i_date_month = v_mes
        i_date_year  = v_ano
      IMPORTING
        e_max_days   = v_dia.

Exibindo janela pop-up

CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
            titlebar              = text-p01 "Titulo da janela
            text_question         = text-p02 "Pergunta que será exibida
            text_button_1         = text-p03 "Texto do botão 1
            icon_button_1         = text-p04 "Nome do icone do botão 1
            text_button_2         = text-p05 "Texto do botão 2
            icon_button_2         = text-p04 "Nome do icone botão 2
            default_button        = '2' 
            display_cancel_button = 'X' "Habilitar botão cancelar
     popup_type            = text-p07 "Nome do icone que irá aparecer na                 *                                            "janela do pop-up
          IMPORTING
            answer                = vc_resposta "Codigo de retorno que a função *  *                                               "irá receber dependendo do lugar *                                               "onde usuário clicou ( CHAR DE 1)
          EXCEPTIONS
            text_not_found        = 1
            OTHERS                = 2.

Criando planilha do EXCEL

CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
      EXPORTING
        file_name                 = p_file
      TABLES
        data_tab                  = t_planilha
      EXCEPTIONS
        file_not_exist            = 1
        filename_expected         = 2
        communication_error       = 3
        ole_object_method_error   = 4
        ole_object_property_error = 5
        invalid_pivot_fields      = 6
        download_problem          = 7
        OTHERS                    = 8.

Onde os parâmetros exportados são do tipo:

DATA: p_file   LIKE rlgrap-filename.

Baixando planilha do EXCEL

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 100
      i_end_row               = 15000
    TABLES
      intern                  = t_intern
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

  IF sy-subrc <> 0.
  ENDIF.

Onde os parâmetros exportados são do tipo:

DATA: p_file   LIKE rlgrap-filename,
      t_intern LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE,

Envio de Email:

Function SO_DOCUMENT_SEND_API1

Chama qualquer transação, independente se tem autorização

TRANSACTION_CALL_VIA_RFC

Converter texto do formato ISO para UTF-8.

WWW_URLENCODE



terça-feira, 5 de maio de 2009

Transporte de tabelas via SE16N

Nosso amigo Aparecido Borges, consultor SAP/SD enviou uma dica excelente para um grupo de email ensinando a transportar tabelas via SE16N.

Normalmente, não se transfere de um Client para Outro, algumas tabelas.
Principalmente as tabelas de dados mestres. Com as dicas em no link abaixo, da SE16N é possível transportar uma tabela  Z ou  qualquer outra tabela do SAP.

Link:
Espero que aproveitem.

Abraços

sexta-feira, 16 de janeiro de 2009

Pesquisa salarial - Estatística

Conversando com meu amigo Renato no msn, o mesmo me passou um link bacana para podermos ter uma média de salarios do mundo SAP.
Segue a dica do link:
http://www.trackjobs.com.br/estatisticas.asp

Inté

terça-feira, 6 de janeiro de 2009

Gerar Tabela Interna Automaticamente

Este codigo abaixo tem por finalidade gerar tabelas internas automaticamente.
Não cheguei a testar, mas é bem provável que funcione:

*&---------------------------------------------------------------------*
*& Report ZGERA_TABELA_INTERNA *
*& Versões testadas: 4.6 e 4.7! *
*&---------------------------------------------------------------------*
REPORT zcompontes_dinamicos.

*&---------------------------------------------------------------------*
*ANTES DE EXECUTAR O PROGRAMA SIGA OS PASSOS ABAIXO:
*1- Copiar o status gui STANDARD_FULLSCREEN do grupo de funções
*SLVC_FULLSCREEN com o nome de ZAIRES
*2-Colocar os nomes dos campos da tela de seleção e mensagens!
*P_BW ?...
*P_NOME Nome da tabela interna
*P_NP ?...
*P_TABINT Nome da tabela
*P01 Via notepad! 12 50
*P02 Via browser (explorer)! 12 50
*P03 Modo de criação: 16 20
*T01 Componentes 11 50
*T02 Gambiarra plus! 15 50
*3-Colocar um botão no status-gui com o nome AIRES1
*Ativar tudo e executar!

*Para usar é simples, execute o programa passando o nome da tabela da
*qual se quer a tabela interna, o nome da tabela interna e a opção de
*visualização (pelo notepad ou browser).
*Será gerado um ALV com os campos da tabela da tela de seleção,
*selecione as linhas que irão para a tabela interna e clique no botão
*que foi habilitado no status-gui, será dado a opção de três tipo de
*geração do fonte da tabela interna, uma opção simples, outra com a
*descrição dos campos e outra com a descriçaõ dos campos, tamanho e
*tipo do campo.
*A tabela interna será gerada e exibida via notepad ou browser, se
*der algum erro verifique o código fonte!
*Esse fonte foi testado e funcionou nas versões 4.6C e 4.7!

*&---------------------------------------------------------------------*

*BEFORE EXECUTING THE PROGRAM IT FOLLOWS THE STEPS BELOW:
*1- To copy status-GUI STANDARD_FULLSCREEN of the group of functions
*SLVC_FULLSCREEN with the ZAIRES name
*2-To place the names of the fields of the selection screen
*and messages!
*P_BW ?...
*P_NOME Name of internal table
*P_NP ?...
*P_TABINT Nome of table
*P01 By notepad! 12 50
*P02 By browser (explorer)! 12 50
*P03 Way of creation: 16 20
*T01 Components 11 50
*T02 Gambiarra plus! 15 50
*3-To place a button in the status-GUI with name AIRES1
*To activate everything and to execute!

*To use it is simple, it executes the program passing the array name
*of which if it wants the internal table, the internal array name and
*the option of visualization (for notepad or to browser) .
*Será gerado um ALV com os campos da tabela da tela de seleção,
*selecione as linhas que irão para a tabela interna e clique no botão
*que foi habilitado no status-gui, será dado a opção de três tipo de
*geração do fonte da tabela interna, uma opção simples, outra com a
*descrição dos campos e outra com a descriçaõ dos campos, tamanho e
*tipo do campo.
*The internal table will be generated and shown way notepad or to
*browser, if to give some error verifies the code source!
*This source was tested and functioned in the versions 4.6C e 4.7!

*Any thing is alone to cry out in the mail andremd@gmail.com


*&---------------------------------------------------------------------*
*Tabelas
*&---------------------------------------------------------------------*
TABLES: dd04t, "DD-R/3: textos elementos dados
dd03l, "Campos tabela
dd02l, "Tabelas SAP
dd02t, "DD-R/3: textos de tabelas SAP
dd07t. "DD: textos p/valores fixos dom.(depend.idioma)

*&---------------------------------------------------------------------*
* TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS: slis, "Tipos globais para ALV
sydes.

*&---------------------------------------------------------------------*
* Tabelas Internas
*&---------------------------------------------------------------------*
DATA: BEGIN OF ti_tab OCCURS 0,
tabname LIKE dd03l-tabname,
fieldname LIKE dd03l-fieldname,
keyflag LIKE dd03l-keyflag,
rollname LIKE dd03l-rollname,
position LIKE dd03l-position,
inttype LIKE dd03l-inttype,
intlen LIKE dd03l-intlen,
scrtext_s LIKE dd04t-scrtext_s,
scrtext_m LIKE dd04t-scrtext_m,
scrtext_l LIKE dd04t-scrtext_l,
tabclass LIKE dd02l-tabclass,
nome LIKE dd02t-ddtext,
ddtext LIKE dd07t-ddtext,
mark,
ordem(3) TYPE n.
DATA: END OF ti_tab.

DATA: BEGIN OF ti_tab2 OCCURS 0.
INCLUDE STRUCTURE ti_tab.
DATA: alter(3),
campnou(16).
DATA: END OF ti_tab2.

DATA: BEGIN OF ti_down OCCURS 0,
linha(72).
DATA: END OF ti_down.

*ALV
DATA:
v_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
ti_listhead TYPE slis_t_listheader,
ti_listhead1 TYPE slis_listheader,
ti_list_header TYPE slis_t_listheader,
ti_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
ti_sort TYPE slis_sortinfo_alv OCCURS 0 WITH HEADER LINE,
wc_repid LIKE sy-repid,
wc_layout TYPE slis_layout_alv,
gt_events TYPE slis_t_event,
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
gt_list_top_of_page TYPE slis_t_listheader.

*&---------------------------------------------------------------------*
*Variáveis
*&---------------------------------------------------------------------*
DATA: v_info1(50),
v_data(10),
v_hora(10),
v_erro(50),
v_linha(10),
v_flinha(34),
v_cabec(30),
v_nome(60),
v_caminho LIKE rlgrap-filename,
v_url(250) TYPE c,
v_resp,
v_fun(2) TYPE c,
v_cont(3) TYPE n,
v_cont2(3) TYPE n,
v_cont3(3) TYPE n,
v_ult LIKE sy-tabix, "No. linhas da tabela
v_linhas(10) TYPE n. "No. linhas da tabela

*&---------------------------------------------------------------------*
*Constants
*&---------------------------------------------------------------------*
CONSTANTS: c_h VALUE 'H',
c_rele(50) VALUE 'Gerador de componentes dinâmicos!',
c_exec(15) VALUE 'Executado por:',
c_dpt(15) VALUE 'Data e hora:',
c_ntab(23) VALUE 'Nome da tabela:',
c_ttab(23) VALUE 'Tipo de tabela:',
c_linc(23) VALUE 'Qtd campos:',
c_data(5) VALUE 'DATA:',
c_tipo(5) VALUE 'Tipo:',
c_tipo2(14) VALUE 'Tipo do campo:',
c_comp(8) VALUE '#Compr.:',
c_comp2(17) VALUE '#Compr. do campo:',
c_desc(8) VALUE '#Descr.:',
c_like(4) VALUE 'LIKE',
c_begin(10) VALUE 'BEGIN OF',
c_end(8) VALUE 'END OF',
c_ponto VALUE '.',
c_velha VALUE '#',
c_aster VALUE '*',
c_aspas VALUE '"',
c_traco VALUE '-',
c_virgula VALUE ',',
c_3velha(3) VALUE '###',
c_mentor(72) VALUE
'*†By Gambi Plus®† - Sugestões enviar à andremd@gmail.com!!!',
c_occurs(10) VALUE 'OCCURS 0,',
c_x VALUE 'X',
c_s VALUE 'S'.

*&---------------------------------------------------------------------*
*Tela de seleção
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-t02.
*Nome da tabela
PARAMETERS: p_tabint LIKE dd02l-tabname OBLIGATORY.
*Noma da tabela interna
PARAMETERS: p_nome(30) OBLIGATORY.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN COMMENT 1(20) text-p03.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_np RADIOBUTTON GROUP visi DEFAULT 'X' .
SELECTION-SCREEN COMMENT 6(60) text-p01 FOR FIELD p_np.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_bw RADIOBUTTON GROUP visi.
SELECTION-SCREEN COMMENT 6(60) text-p02 FOR FIELD p_bw.
SELECTION-SCREEN END OF LINE.

*SELECTION-SCREEN SKIP.
*SELECTION-SCREEN SKIP.
*SELECTION-SCREEN PUSHBUTTON 10(25) text-p04
* USER-COMMAND US01.
*SELECTION-SCREEN COMMENT 1(50) text-p05.
SELECTION-SCREEN END OF BLOCK a1.

*&---------------------------------------------------------------------*
*Initialization
*&---------------------------------------------------------------------*
INITIALIZATION.

*&---------------------------------------------------------------------*
*Start-of-selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Aguarde... Programa em processamento.'.

*Seleção da tabela!!!
SELECT a~tabname a~fieldname a~keyflag
a~rollname a~position a~inttype
a~intlen b~scrtext_s b~scrtext_m
b~scrtext_l c~tabclass n~ddtext
e~ddtext
INTO TABLE ti_tab
FROM dd03l AS a
INNER JOIN dd04t AS b
ON a~rollname = b~rollname
INNER JOIN dd02l AS c
ON a~tabname = c~tabname
INNER JOIN dd02t AS n
ON c~tabname = n~tabname
INNER JOIN dd07l AS d
ON c~tabclass = d~domvalue_l
INNER JOIN dd07t AS e
ON d~domvalue_l = e~domvalue_l
AND d~as4local = e~as4local
AND d~valpos = e~valpos
WHERE e~ddlanguage = sy-langu
AND b~ddlanguage = sy-langu
AND n~ddlanguage = sy-langu
AND a~tabname = p_tabint
AND d~domname = 'TABCLASS'
AND a~fieldname <> 'MANDT'.

IF NOT sy-subrc IS INITIAL.
*Se a budega num tá traduzida tem que refazer o select em inglês
*Se nem em inglês puxar todos os dados se vire e faça na mão a parada!!
SELECT a~tabname a~fieldname a~keyflag
a~rollname a~position a~inttype
a~intlen b~scrtext_s b~scrtext_m
b~scrtext_l c~tabclass n~ddtext
e~ddtext
INTO TABLE ti_tab
FROM dd03l AS a
INNER JOIN dd04t AS b
ON a~rollname = b~rollname
INNER JOIN dd02l AS c
ON a~tabname = c~tabname
INNER JOIN dd02t AS n
ON c~tabname = n~tabname
INNER JOIN dd07l AS d
ON c~tabclass = d~domvalue_l
INNER JOIN dd07t AS e
ON d~domvalue_l = e~domvalue_l
AND d~as4local = e~as4local
AND d~valpos = e~valpos
WHERE e~ddlanguage = 'EN'
AND b~ddlanguage = 'EN'
AND n~ddlanguage = 'EN'
AND a~tabname = p_tabint
AND d~domname = 'TABCLASS'
AND a~fieldname <> 'MANDT'.
ENDIF.

SORT ti_tab BY position.
DELETE ADJACENT DUPLICATES FROM ti_tab COMPARING position.

IF ti_tab[] IS INITIAL.
MESSAGE i011(pc) WITH 'Nenhum dado encontrado!'.
STOP.
ENDIF.

DESCRIBE TABLE ti_tab LINES v_linhas.

PERFORM monta_fieldcat USING :
'FIELDNAME' 'TI_TAB' 'DD03L' 'FIELDNAME'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ',
'KEYFLAG' 'TI_TAB' 'DD03L' 'KEYFLAG'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ',
'ROLLNAME' 'TI_TAB' 'DD03L' 'ROLLNAME'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ',
'POSITION' 'TI_TAB' 'DD03L' 'POSITION'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ',
'SCRTEXT_L' 'TI_TAB' 'DD04T' 'SCRTEXT_L'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '.
* 'ORDEM' 'TI_TAB' ' ' ' '
* 'Ordenação' ' ' ' ' ' ' ' ' ' ' ' ' 'X' ' '.

PERFORM eventtab_build USING gt_events[].
PERFORM comment_build USING gt_list_top_of_page[].
PERFORM zf_executar_alv.

*&---------------------------------------------------------------------*
*& FORM MONTA_FIELDCAT
*&---------------------------------------------------------------------*
FORM monta_fieldcat USING
x_field x_tab x_ref x_fil x_text
x_sum x_type x_just x_qfield x_checkbox
x_no_out x_edit x_hotspot.

v_fieldcat-fieldname = x_field.
v_fieldcat-tabname = x_tab.
v_fieldcat-ref_tabname = x_ref.
v_fieldcat-ref_fieldname = x_fil.
v_fieldcat-reptext_ddic = x_text.
v_fieldcat-do_sum = x_sum.
v_fieldcat-inttype = x_type.
v_fieldcat-just = x_just.
v_fieldcat-qfieldname = x_qfield.
v_fieldcat-checkbox = x_checkbox.
v_fieldcat-no_out = x_no_out.
v_fieldcat-edit = x_edit.
v_fieldcat-hotspot = x_hotspot.

APPEND v_fieldcat.
CLEAR v_fieldcat.

ENDFORM. " MONTA_FIELDCAT
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* -->P_GT_EVENTS[] text
*----------------------------------------------------------------------*
FORM eventtab_build USING rt_events TYPE slis_t_event.

DATA: ls_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = rt_events.
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.

ENDFORM. " EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* -->P_GT_LIST_TOP_OF_PAGE[] text
*----------------------------------------------------------------------*
FORM comment_build USING lt_top_of_page TYPE slis_t_listheader..

DATA: ls_line TYPE slis_listheader.

CLEAR: ls_line.

ls_line-typ = c_h.
ls_line-info = c_rele.
APPEND ls_line TO lt_top_of_page.
CLEAR ls_line.

READ TABLE ti_tab INDEX 1.

*-- Nome
ls_line-typ = c_s.
ls_line-key = c_ntab.
IF ti_tab-nome <> space.
CONCATENATE p_tabint ' - ' ti_tab-nome INTO v_info1.
ELSE.
WRITE p_tabint TO v_info1.
ENDIF.
WRITE v_info1 TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
CLEAR: ls_line, v_info1.

*-- Tipo
ls_line-typ = c_s.
ls_line-key = c_ttab.
IF ti_tab-ddtext <> space.
WRITE ti_tab-ddtext TO v_info1.
ELSE.
WRITE 'Indefinida' TO v_info1.
ENDIF.
WRITE v_info1 TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
CLEAR: ls_line, v_info1.

*-- Campos
ls_line-typ = c_s.
ls_line-key = c_linc.
WRITE v_linhas TO v_info1.
PACK v_info1 TO v_info1.
WRITE v_info1 TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
CLEAR: ls_line, v_info1.

*Usuário
ls_line-typ = c_s.
ls_line-key = c_exec.
WRITE sy-uname TO v_info1.
WRITE v_info1 TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
CLEAR: ls_line, v_info1.

*-- Data e Hora
ls_line-typ = c_s.
ls_line-key = c_dpt.
WRITE sy-datum TO v_data.
WRITE sy-uzeit TO v_hora.
CONCATENATE v_data '-' v_hora 'hs' INTO v_info1 SEPARATED BY space.
WRITE v_info1 TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
CLEAR: ls_line, v_info1.

ENDFORM. " COMMENT_BUILD
*&---------------------------------------------------------------------*
*& FORM TOP_OF_PAGE *
*&---------------------------------------------------------------------*
FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO' "ENJOYSAP_LOGO
it_list_commentary = gt_list_top_of_page.

ENDFORM. " top_of_page
*&---------------------------------------------------------------------
*
*& Form F_STATUS - GUI ALV
*&---------------------------------------------------------------------
*
FORM f_status USING rt_extab TYPE slis_t_extab. "#EC CALLED

SET PF-STATUS 'ZAIRES'.

ENDFORM. "f_status
*&---------------------------------------------------------------------*
*& Form zf_executar_alv_infor
*&---------------------------------------------------------------------*
FORM zf_executar_alv.

* Preenchendo algumas opções de impressão (Não é obrigatório)
wc_layout-expand_all = 'X'. "Abrir subitens
wc_layout-colwidth_optimize = 'X'. "Largura melhor possível coluna
* wc_layout-edit = 'X'. "Não Permitir a edição
wc_layout-zebra = 'X'. "Listagem aparece zebrada.
wc_repid = sy-repid.

wc_layout-box_tabname = 'TI_TAB'.
wc_layout-box_fieldname = 'MARK'.
wc_layout-box_rollname = space.
wc_layout-key_hotspot = c_x.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = wc_repid
i_background_id = 'ALV_BACKGROUND'
* i_callback_top_of_page = 'F_TOP_OF_PAGE'
i_callback_user_command = 'F_USER_COMMAND3'
i_callback_pf_status_set = 'F_STATUS'
it_fieldcat = v_fieldcat[]
is_layout = wc_layout
it_sort = ti_sort[]
i_default = 'X'
i_save = 'A'
it_events = gt_events[]
TABLES
t_outtab = ti_tab
EXCEPTIONS
program_error = 1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE i011(pc) WITH 'Erro ao gerar relatório ALV'.
STOP.
ENDIF.

ENDFORM. " zf_executar_alv_infor
*&--------------------------------------------------------------------*
*& Form F_USER_COMMAND_ANUAL
*&--------------------------------------------------------------------*
FORM f_user_command3 USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.

CLEAR v_cont.
LOOP AT ti_tab WHERE mark = 'X'.
v_cont = v_cont + 1.
ENDLOOP.

IF v_cont = 0.
MESSAGE e011(pc) WITH 'Selecione as linhas para a tabela interna!'.
ELSEIF v_cont = 1.

CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
defaultoption = 'Y'
textline1 = 'Sua tabela terá apenas 1 campo!'
textline2 = 'Deseja realmente gerá-la?!'
titel = 'Geração de compontes'
start_column = 25
start_row = 6
cancel_display = 'X'
IMPORTING
answer = v_resp.

IF v_resp = 'J'.
MESSAGE i011(pc) WITH 'Santa preguiça viu!'.
ELSE.
MESSAGE e011(pc) WITH 'Selecione a(s) outra(s) linha(s)!'.
ENDIF.

ENDIF.

CASE ucomm.

WHEN 'AIRES1'.

CLEAR v_fun.
CALL FUNCTION 'K_KKB_POPUP_RADIO3'
EXPORTING
i_title = 'Tipo de tabela interna'
i_text1 = 'A mais simples!'
i_text2 = 'Meia boca...'
i_text3 = 'Tipo perfeccionista!!!'
i_default = '1'
IMPORTING
i_result = v_fun
EXCEPTIONS
cancel = 1
OTHERS = 2.

IF sy-subrc IS INITIAL AND v_fun <> space.

LOOP AT ti_tab WHERE mark = 'X'.
MOVE-CORRESPONDING ti_tab TO ti_tab2.
APPEND ti_tab2.
CLEAR ti_tab2.
ENDLOOP.

IF ti_tab2[] IS INITIAL.
MESSAGE e011(pc) WITH 'Execute o programa novamente!'.
ENDIF.

LOOP AT ti_tab2.
CLEAR v_cont2.
LOOP AT ti_tab2 WHERE fieldname+0(10) = ti_tab2-fieldname+0(10).
v_cont2 = v_cont2 + 1.

IF v_cont2 >= 2.
CONCATENATE ti_tab2-fieldname+0(5) v_cont2 INTO ti_tab2-fieldname.
MODIFY ti_tab2.
ENDIF.

ENDLOOP.
ENDLOOP.

CASE v_fun.

*######################################################################*
*#########################Opção 1######################################*
*######################################################################*
WHEN 1.

*Declaração
CONCATENATE c_data
c_velha
c_begin
c_velha
p_nome
c_velha
c_occurs
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

DESCRIBE TABLE ti_tab2 LINES v_ult.

*Linhas
LOOP AT ti_tab2.
CLEAR v_linha.
IF sy-tabix = v_ult.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_ponto
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ELSE.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_virgula
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ENDIF.

ENDLOOP.

*Declaração final
CONCATENATE c_data
c_velha
c_end
c_velha
p_nome
c_ponto
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

*Propaganda!
WRITE c_mentor TO ti_down-linha.
APPEND ti_down.
CLEAR ti_down.

*######################################################################*
*#########################Opção 2######################################*
*######################################################################*
WHEN 2.

CLEAR v_nome.
READ TABLE ti_tab2 INDEX 1.
IF sy-subrc IS INITIAL.
v_nome = ti_tab2-nome.
ENDIF.

IF v_nome <> space.
CONCATENATE c_aster
v_nome
INTO ti_down-linha.
APPEND ti_down.
CLEAR ti_down.
ENDIF.

*Declaração
CONCATENATE c_data
c_velha
c_begin
c_velha
p_nome
c_velha
c_occurs
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

DESCRIBE TABLE ti_tab2 LINES v_ult.

*Linhas
LOOP AT ti_tab2.

CLEAR v_linha.
IF sy-tabix = v_ult.
CLEAR: v_linha, v_flinha.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_ponto
INTO v_flinha.
TRANSLATE v_flinha USING ' #'.

IF ti_tab2-scrtext_m = space.
CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ELSE.
CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
c_velha
c_aspas
ti_tab2-scrtext_m+0(17)
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ENDIF.
ELSE.
CLEAR: v_linha, v_flinha.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_virgula
INTO v_flinha.
TRANSLATE v_flinha USING ' #'.

IF ti_tab2-scrtext_m = space.
CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ELSE.
CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
c_velha
c_aspas
ti_tab2-scrtext_m+0(17)
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

ENDIF.
ENDIF.

ENDLOOP.

*Declaração final
CONCATENATE c_data
c_velha
c_end
c_velha
p_nome
c_ponto
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

*Propaganda!
WRITE c_mentor TO ti_down-linha.
APPEND ti_down.
CLEAR ti_down.

*######################################################################*
*#########################Opção 3######################################*
*######################################################################*
WHEN 3.

CLEAR v_nome.
READ TABLE ti_tab2 INDEX 1.
IF sy-subrc IS INITIAL.
v_nome = ti_tab2-nome.
ENDIF.

IF v_nome <> space.
CONCATENATE c_aster
v_nome
INTO ti_down-linha.
APPEND ti_down.
CLEAR ti_down.
ENDIF.

*Declaração
CONCATENATE c_data
c_velha
c_begin
c_velha
p_nome
c_velha
c_occurs
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

DESCRIBE TABLE ti_tab2 LINES v_ult.

*Linhas
LOOP AT ti_tab2.
CLEAR v_linha.
IF sy-tabix = v_ult.
CLEAR: v_linha, v_flinha.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_ponto
INTO v_flinha.
TRANSLATE v_flinha USING ' #'.

CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
IF ti_tab2-scrtext_l = space.
CONCATENATE c_aster
c_tipo2
ti_tab2-inttype
c_comp2
ti_tab2-intlen
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ELSE.
CONCATENATE c_aster
c_tipo
ti_tab2-inttype
c_comp
ti_tab2-intlen
c_desc
ti_tab2-scrtext_l
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ENDIF.
ELSE.
CLEAR: v_linha, v_flinha.
v_linha = ti_tab2-fieldname+0(10).
TRANSLATE v_linha USING ' #'.

CONCATENATE ti_tab2-tabname
c_traco
ti_tab2-fieldname
c_virgula
INTO v_flinha.
TRANSLATE v_flinha USING ' #'.

CONCATENATE c_3velha
v_linha
c_velha
c_like
c_velha
v_flinha
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

IF ti_tab2-scrtext_l = space.
CONCATENATE c_aster
c_tipo2
ti_tab2-inttype
c_comp2
ti_tab2-intlen
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ELSE.
CONCATENATE c_aster
c_tipo
ti_tab2-inttype
c_comp
ti_tab2-intlen
c_desc
ti_tab2-scrtext_l
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.
ENDIF.
ENDIF.
ENDLOOP.

*Declaração final
CONCATENATE c_data
c_velha
c_end
c_velha
p_nome
c_ponto
INTO ti_down-linha.
TRANSLATE ti_down-linha USING '# '.
APPEND ti_down.
CLEAR ti_down.

*Propaganda!
WRITE c_mentor TO ti_down-linha.
APPEND ti_down.
CLEAR ti_down.

ENDCASE.

IF NOT ti_down[] IS INITIAL.

CONCATENATE 'C:\'
p_tabint
sy-datum
sy-uzeit
'.txt'
INTO v_caminho.

CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = v_caminho
filetype = 'ASC'
TABLES
data_tab = ti_down
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
gui_refuse_filetransfer = 8
OTHERS = 9.

IF sy-subrc <> 0.
MESSAGE e011(pc) WITH
'Erro ao gerar a tabela interna! Debugue'.
ENDIF.

COMMIT WORK.
v_url = v_caminho.
FREE ti_down.

IF p_bw = 'X' .

CALL FUNCTION 'CALL_BROWSER'
EXPORTING
url = v_url
new_window = c_x
EXCEPTIONS
frontend_not_supported = 1
frontend_error = 2
prog_not_found = 3
no_batch = 4
unspecified_error = 5
OTHERS = 6.

IF sy-subrc <> 0.
MESSAGE e011(pc) WITH
'Seu browser está bixado! Formate o pc!!!'.
ENDIF.

ELSE.

CALL FUNCTION 'WS_EXECUTE'
EXPORTING
commandline = v_url
program = 'notepad'
EXCEPTIONS
frontend_error = 1
no_batch = 2
prog_not_found = 3
illegal_option = 4
gui_refuse_execute = 5
OTHERS = 6.

IF sy-subrc <> 0.
MESSAGE e011(pc) WITH
'Aff! Seu bloco de notas está bixado! Formate o pc!'.
ELSE.

WAIT UP TO 5 SECONDS.
CALL FUNCTION 'WS_FILE_DELETE'
EXPORTING
file = v_caminho.
ENDIF.
ENDIF.
ENDIF.
ENDIF.

WHEN OTHERS.
ENDCASE.

LEAVE TO SCREEN 0.

ENDFORM. "F_USER_COMMAND_MENSAL

ALV por Função - Editar cor de uma linha

Darei inicio ao blog explicando o ABAP(Advanced Business Application Programming).
Abap nada mais é do que uma linguagem de programação proprietária da SAP.
É a principal linguagem utilizada no SAP/R3.
Para mais informações é só consultar os sites:
Wikipedia
Desciclopedia

Neste blog irei colocar algumas dicas interessantes que encontrei na linguagem para consultas posteriores.

Dando inicio, um código de um ALV por função onde é alterado a cor de uma linha somente da sua exibição:


REPORT z_alv_cell_color.
*---------------------------------------------------------------------*
* Example of ALV with Cell color *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.

TYPE-POOLS: slis. " ALV Global types

SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY. "#EC *
SELECTION-SCREEN END OF LINE.

TYPES :
BEGIN OF ty_data,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
END OF ty_data,

* Data displayed
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
tabcolor TYPE lvc_t_scol, " Cell Color
END OF ty_vbak.

DATA:
gt_data TYPE TABLE OF ty_data,
* Data displayed
gt_vbak TYPE TABLE OF ty_vbak.

*---------------------------------------------------------------------*
INITIALIZATION.

v_1 = 'Maximum of records to read'. "#EC NOTEXT

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

PERFORM f_read_data.

PERFORM f_fill_color.

PERFORM f_display_data.

*---------------------------------------------------------------------*
* Form f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM vbak UP TO p_max ROWS.

ENDFORM. " F_READ_DATA
*--------------------------------------------------------------------*
* Form f_fill_color
*--------------------------------------------------------------------*
FORM f_fill_color.

DATA :
ls_data TYPE ty_data,
ls_vbak TYPE ty_vbak.

LOOP AT gt_data INTO ls_data.

CLEAR ls_vbak.
MOVE-CORRESPONDING ls_data TO ls_vbak.

PERFORM f_modify_color USING 'NETWR' CHANGING ls_vbak.
PERFORM f_modify_color USING 'VBELN' CHANGING ls_vbak.

* Fill gt_vbak
APPEND ls_vbak TO gt_vbak.

ENDLOOP.

ENDFORM. " F_FILL_COLOR
*---------------------------------------------------------------------*
* Form F_modify_color
*---------------------------------------------------------------------*
FORM f_modify_color USING u_fieldname TYPE lvc_fname
CHANGING us_vbak TYPE ty_vbak.

DATA :
l_rnd_value TYPE integer2,
ls_tabcolor TYPE lvc_s_scol.

* Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.

CLEAR ls_tabcolor.
ls_tabcolor-fname = u_fieldname.

CASE l_rnd_value.
WHEN 0.
ls_tabcolor-color-col = 1. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 1.
ls_tabcolor-color-col = 3. " Yellow.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 2.
ls_tabcolor-color-col = 5. " Green.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 3.
ls_tabcolor-color-col = 6. " Red.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
ENDCASE.

INSERT ls_tabcolor INTO TABLE us_vbak-tabcolor.

ENDFORM. " F_MODIFY_COLOR
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.

DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.

* Fill Layout
ls_layout-coltab_fieldname = 'TABCOLOR'.

* Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.

ENDFORM. " F_DISPLAY_DATA
***************** END OF PROGRAM Z_ALV_CELL_COLOR *********************