Friday, October 13, 2017

[SAP ABAP] Convert ITAB to STRING

 FUNCTION ZFM_MMODS_ITAB_STRING.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  EXPORTING

*"     REFERENCE(E_STRING) TYPE  STRING

*"  TABLES

*"      T_ITAB TYPE  TABLE

*"----------------------------------------------------------------------



  FIELD-SYMBOLS <data>  TYPE ANY.
  DATA : lv_str TYPE string,
         lv_len TYPE i,
         j TYPE i,
         lv_blanks TYPE string.

  CLEAR E_STRING.
  LOOP AT T_ITAB ASSIGNING <data>.
    EXIT.
  ENDLOOP.
  IF sy-subrc EQ 0.

    DESCRIBE FIELD  LENGTH lv_len IN CHARACTER MODE.
    SHIFT lv_blanks RIGHT BY lv_len PLACES.

    LOOP AT T_ITAB ASSIGNING <data>.
      lv_str = <data>.
      j = lv_len - STRLEN( lv_str ).
      IF j EQ 0.
        CONCATENATE E_STRING lv_str INTO E_STRING.
      ELSE.
        CONCATENATE E_STRING lv_str lv_blanks(j) INTO E_STRING.
      ENDIF.
    ENDLOOP.

  ENDIF.


ENDFUNCTION.

No comments:

[SAP ABAP] Convert LIST MEMORY to HTML

FUNCTION  zfmarein_list_to_html . *"---------------------------------------------------------------------- *"*"Local Inte...