Abap Logic: Field symbol to use in abap for excel

Most of the time if creating a report with alv. When user need us to make a excel report we would create a whole damn list of field or re-write the field back to the codes (REDUNDANT~!)

This snippet could save your time and energy to code the excel or open dataset part.


DATA :  BEGIN OF itab_output OCCURS 0,
         sno(10TYPE c,
         pernr LIKE pernr-pernr,
         ename LIKE pernr-ename,
         werks LIKE p0001-werks,
         name1 LIKE t500p-name1,

         molga LIKE t001p-molga,
        END OF itab_output.



FIELD-SYMBOLS<field>  TYPE ANY,
DATAalv_fcatlog TYPE  slis_t_fieldcat_alv,
      fcatlog_hdr LIKE LINE OF alv_fcatlog,

      l_line TYPE sy-tfill,
      l_field     TYPE string,
      l_file      TYPE rlgrap-filename
      l_tab       TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.

  LOOP AT itab_output.
    CLEAR l_line.

    LOOP AT alv_fcatlog INTO fcatlog_hdr.
      CONCATENATE 'ITAB_OUTPUT-' fcatlog_hdr-fieldname
        INTO l_field.
      ASSIGN (l_fieldTO <field>.

      IF sy-tabix 1.
        MOVE <field> to l_line.
      ELSE.
        CONCATENATE l_line <field> INTO l_line SEPARATED BY l_tab.
      ENDIF.
    ENDLOOP.

    TRANSFER l_line TO l_file.
  ENDLOOP.
0 comments:

Post a Comment

message

Labels

NuffNang

Search google

Blog Archive

My Blog List

Twitter

Message

Followers