Friday, August 29, 2014

LED es mi nuevo Hello World - Tiempo de ABAP

Ha pasado mucho tiempo desde que hice algo de desarrollo con ABAP...así que solo por los buenos tiempos decidí construir una aplicación de números LED en ABAP también... -;)

Estaré un poco oxidado...pero pienso que todavía me acuerdo de todos los trucos -:P

Este va para todos mi amigos que desarrollan en ABAP...tengo muchos -:)

ZLED
REPORT  zled.

TYPES: BEGIN OF ty_lines,
       line(1) TYPE c,
       index(1) TYPE c,
       map TYPE string,
       END OF ty_lines.

DATA: s_number TYPE string,
      counter TYPE i,
      num_counter TYPE i,
      line1 TYPE string,
      line2 TYPE string,
      line3 TYPE string.

DATA: t_lines TYPE STANDARD TABLE OF ty_lines.
FIELD-SYMBOLS: <fs_lines> LIKE LINE OF t_lines.

SELECTION-SCREEN BEGIN OF BLOCK params.
PARAMETERS: p_number TYPE i.
SELECTION-SCREEN END OF BLOCK params.

START-OF-SELECTION.
  PERFORM load_data.
  num_counter = 0.
  s_number = p_number.
  counter = strlen( s_number ) - 1.
  DO counter TIMES.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 1
             index = s_number+num_counter(1).
    CONCATENATE line1 <fs_lines>-map INTO line1 SEPARATED BY space.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 2
             index = s_number+num_counter(1).
    CONCATENATE line2 <fs_lines>-map INTO line2 SEPARATED BY space.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 3
             index = s_number+num_counter(1).
    CONCATENATE line3 <fs_lines>-map INTO line3 SEPARATED BY space.
    num_counter = num_counter + 1.
  ENDDO.
  REPLACE ALL OCCURRENCES OF '%' IN line1 WITH ` ` IN CHARACTER MODE.
  REPLACE ALL OCCURRENCES OF '%' IN line2 WITH ` ` IN CHARACTER MODE.
  REPLACE ALL OCCURRENCES OF '%' IN line3 WITH ` ` IN CHARACTER MODE.
  WRITE:/ line1.
  WRITE:/ line2.
  WRITE:/ line3.

*&---------------------------------------------------------------------*
*&      Form  LOAD_DATA
*&---------------------------------------------------------------------*
FORM load_data.

  PERFORM add_lines USING '1' '0' '%_%%'.
  PERFORM add_lines USING '2' '0' '| |%'.
  PERFORM add_lines USING '3' '0' '|_|%'.
  PERFORM add_lines USING '1' '1' '%%'.
  PERFORM add_lines USING '2' '1' '|%'.
  PERFORM add_lines USING '3' '1' '|%'.
  PERFORM add_lines USING '1' '2' '%_%%'.
  PERFORM add_lines USING '2' '2' ' _|%'.
  PERFORM add_lines USING '3' '2' '|_%%'.
  PERFORM add_lines USING '1' '3' '_%%'.
  PERFORM add_lines USING '2' '3' '_|%'.
  PERFORM add_lines USING '3' '3' '_|%'.
  PERFORM add_lines USING '1' '4' '%%%%'.
  PERFORM add_lines USING '2' '4' '|_|%'.
  PERFORM add_lines USING '3' '4' '  |%'.
  PERFORM add_lines USING '1' '5' '%_%%'.
  PERFORM add_lines USING '2' '5' '|_ %'.
  PERFORM add_lines USING '3' '5' ' _|%'.
  PERFORM add_lines USING '1' '6' '%_%%'.
  PERFORM add_lines USING '2' '6' '|_%%'.
  PERFORM add_lines USING '3' '6' '|_|%'.
  PERFORM add_lines USING '1' '7' '_%%'.
  PERFORM add_lines USING '2' '7' '%|%'.
  PERFORM add_lines USING '3' '7' '%|%'.
  PERFORM add_lines USING '1' '8' '%_%%'.
  PERFORM add_lines USING '2' '8' '|_|%'.
  PERFORM add_lines USING '3' '8' '|_|%'.
  PERFORM add_lines USING '1' '9' '%_%%'.
  PERFORM add_lines USING '2' '9' '|_|%'.
  PERFORM add_lines USING '3' '9' ' _|%'.

ENDFORM.                    " LOAD_DATA

*&---------------------------------------------------------------------*
*&      Form  add_lines
*&---------------------------------------------------------------------*
FORM add_lines USING p_line p_index p_map.
  APPEND INITIAL LINE TO t_lines ASSIGNING <fs_lines>.
  <fs_lines>-line = p_line.
  <fs_lines>-index = p_index.
  <fs_lines>-map = p_map.
ENDFORM.                    "add_lines

Fotos o nunca pasó -:)





Saludos,

Blag.
Development Culture.

No comments: