W Pub: ABAP Rut PRINTTAB

  1. report Print_Tab.
  2.  
  3. * Ini : Print_Tab v0.1 --------------- 14.09.2004
  4. define print_tab_create.
  5.   data: pt_edx(30) occurs 0 with header line,
  6.         pt_esi(30),
  7.         pt_eax type i,
  8.         pt_edi(6) type n,
  9.         pt_ebx type i,
  10.         begin of pt_tab occurs 0,
  11.            tab      like dd03l-tabname,
  12.            fie      like dd03l-fieldname,
  13.            lon      like dd01l-leng,
  14.         end of pt_tab.
  15.   field-symbols <pt_fs>.
  16. end-of-definition.
  17.  
  18. define print_tab_show.
  19.   split &4 at ',' into table pt_edx.
  20.   pt_eax = 01.
  21.   if not  &1 is initial.
  22.     skip. write: / &3, '->', &2. skip.
  23.   endif.
  24.   import pt_tab from memory id 'pt_esi'.
  25.   loop at pt_edx.
  26.     read table pt_tab with key tab = &2 fie = pt_edx.
  27.     if sy-subrc ne 0.
  28.       select single d~leng into pt_tab-lon from dd03l as k
  29.                    inner join dd01l as d
  30.                    on d~domname      = k~domname
  31.                    where k~tabname   = &2 and
  32.                          k~fieldname = pt_edx.
  33.       pt_tab-tab = &2.
  34.       pt_tab-fie = pt_edx.
  35.       append pt_tab.
  36.     endif.
  37.     pt_edi = pt_tab-lon.
  38.     if pt_eax = 1. write / ''. endif.
  39.     if pt_edi > 30. pt_edi = 30. endif.
  40.     pt_ebx = strlen( pt_edx ).
  41.     if pt_ebx > pt_edi. pt_edi = pt_ebx. endif.
  42.     if not &1 is initial.
  43.       write: at pt_eax pt_edx+0(30).
  44.     else.
  45.       concatenate &3 '-' pt_edx into pt_esi.
  46.       assign (pt_esi) to <pt_fs>.
  47.       pt_esi = <pt_fs>.
  48.       shift pt_esi left deleting leading ' '.
  49.       pt_ebx = pt_edi - strlen( pt_esi ).
  50. * Por si quieres desplazar a la derecha
  51.       if  pt_ebx > 0. shift pt_esi right by pt_ebx places. endif.
  52.       write: at pt_eax pt_esi+0(30).
  53.     endif.
  54.     pt_eax = pt_eax + 2 + pt_edi .
  55.   endloop.
  56.   export pt_tab to memory id 'pt_esi'.
  57.   check not &1 is initial.
  58.   uline at /001(pt_eax).
  59. end-of-definition.
  60. * Fin : Print_Tab v0.1 --------------- 14.09.2004
  61.  
  62.  
  63. *--- Slo para el ejemplo
  64.  
  65. tables: tcurt, tcurr.
  66.  
  67. data: begin of itabb occurs 0,
  68.    spras like tcurt-spras,
  69.    waers like tcurt-waers,
  70.    ltext like tcurt-ltext,
  71.    ktext like tcurt-ktext,
  72.    ukurs like tcurr-ukurs,
  73. end of itabb.
  74.  
  75. end-of-selection.
  76.   select * from tcurt where spras = sy-langu.
  77.     move-corresponding tcurt to itabb.
  78.     select ukurs into itabb-ukurs from tcurr where
  79.                   kurst = 'EURO' and
  80.                   fcurr = tcurt-waers.
  81.       append itabb.
  82.     endselect.
  83.   endselect.
  84.   print_tab_create.
  85.   loop at itabb.
  86.     at first.
  87.        print_tab_show 'X' 'TCURT' 'ITABB' 'WAERS,KTEXT,LTEXT,SPRAS'.
  88.     endat.
  89.     print_tab_show ' ' 'TCURT' 'ITABB' 'WAERS,KTEXT,LTEXT,SPRAS'.
  90.   endloop.