Skip to Content
author's profile photo Former Member
Former Member

How to convert rows of internal table to columns of another internal table?

Hi,

Experts,

test_data.xls:

one two three four five

one two three four

one two three

one two

one

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = 'c:/test_data.xls'

I_BEGIN_COL = '1'

I_BEGIN_ROW = '1'

I_END_COL = '10'

I_END_ROW = '10'

TABLES

INTERN = it_tab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

output:

0001 0001 one

0001 0002 two

0001 0003 three

0001 0004 four

0001 0005 five

0002 0001 one

0002 0002 two

0002 0003 three

0002 0004 four

0003 0001 one

0003 0002 two

0003 0003 three

0004 0001 one

0004 0002 two

0005 0001 one

but i want this format:

one two three four five

one two three four

one two three

one two

one

i don't want this type of output display i want to display in ABAP report as in file format how can i achieve this post some ideas on it.

Thank U,

Shabeer ahmed.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 05:51 AM

    hi

    refer tot this thread

    dynamic-internal-table--column-to-row-conversion

    hope this helps

    regards

    Aakash Banga

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 05:52 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 05:56 AM

    Hi,

    Use the code below after calling the function module,

    data : begin of fs_itab,

    col1 type string,

    col2 type string,

    col3 type string,

    col4 type string,

    col5 type string,

    end of fs_itab.

    data : t_itab like table of fs_itab.

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

    FILENAME = 'c:/test_data.xls'

    I_BEGIN_COL = '1'

    I_BEGIN_ROW = '1'

    I_END_COL = '10'

    I_END_ROW = '10'

    TABLES

    INTERN = it_tab

    EXCEPTIONS

    INCONSISTENT_PARAMETERS = 1

    UPLOAD_OLE = 2

    OTHERS = 3

    .

    loop at it_tab.

    at new row.

    if sy-tabix ne 1.

    append fs_itab to t_itab.

    clear fs_itab.

    endif.

    endat.

    case col.

    when 1.

    fs_itab-col1 = it_tab-value.

    when 2.

    fs_itab-col2 = it_tab-value.

    when 3.

    fs_itab-col3 = it_tab-value.

    when 4.

    fs_itab-col4 = it_tab-value.

    when 5.

    fs_itab-col5 = it_tab-value.

    endcase.

    endloop.

    loop at t_itab into fs_itab.

    write fs_itab.

    endloop.

    this works fine...

    Regards,

    Siddarth

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi ,

      The code below gives you the F4 help to open select the filename at runtime which will take the path by itself and then you can use that path for further processing

      parameters: p_flname type rlgrap-filename.

      data : it_tab type ALSMEX_TABLINE occurs 5.

      data : t_filetab type FILETABLE,

      fs_filetab type FILE_TABLE.

      data w_rc type i.

      at selection-screen on value-requst for p_flname

      CALL METHOD cl_gui_frontend_services=>file_open_dialog

      • EXPORTING

      • window_title =

      • default_extension =

      • default_filename =

      • file_filter =

      • with_encoding =

      • initial_directory =

      • multiselection =

      CHANGING

      file_table = t_filetab

      rc = w_rc

      • user_action =

      • file_encoding =

      EXCEPTIONS

      file_open_dialog_failed = 1

      cntl_error = 2

      error_no_gui = 3

      not_supported_by_gui = 4

      others = 5

      .

      IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      loop at t_filetab into fs_filetab.

      p_flname = fs_filetab.

      endloop.

      start-of-selection.

      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

      EXPORTING

      FILENAME = p_flname

      I_BEGIN_COL = '1'

      I_BEGIN_ROW = '1'

      I_END_COL = '10'

      I_END_ROW = '10'

      TABLES

      INTERN = it_tab

      EXCEPTIONS

      INCONSISTENT_PARAMETERS = 1

      UPLOAD_OLE = 2

      OTHERS = 3

      .

      Regards,

      Siddarth

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 06:01 AM

    Hi,

    Use GUI_UPLOAD FM, it will upload as it in file format

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = 'C:\test.xls'

    FILETYPE = 'ASC'

    TABLES

    DATA_TAB = itab

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    OTHERS = 17.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 06:04 AM

    Hi Shabir,

    Actually this internal table have values like this:

    row no, col no, data

    so you are getting values like this

    1 1 one

    1 2 two

    likewise..

    now you need to get values of this table into your internal table in desired format.

    This code will help..

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

    filename = p_file

    i_begin_col = '1'

    i_begin_row = '2'

    i_end_col = '5'

    i_end_row = '20'

    TABLES

    intern = itab

    EXCEPTIONS

    inconsistent_parameters = 1

    upload_ole = 2

    OTHERS = 3.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    • In itab, you will get values as said above.

    • here t_dummy is your actual internal table in which you want data in required format.

    SORT itab BY row col.

    LOOP AT itab INTO wa.

    CASE wa-col. * eg. col 1 for first time and its values.. this you are getting in a row as in your excel sheet.

    WHEN '1'.

    wa_dummy-a = wa-value.

    WHEN '2'.

    wa_dummy-b = wa-value.

    WHEN '3'.

    wa_dummy-c = wa-value.

    WHEN '4'.

    wa_dummy-d = wa-value.

    WHEN '5'.

    wa_dummy-e = wa-value.

    ENDCASE.

    AT END OF row.

    APPEND wa_dummy TO t_dummy.

    CLEAR wa_dummy.

    ENDAT.

    ENDLOOP.

    Regards,

    Seema

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 06:06 AM

    Hi,

    Could yu please post you code here for bettre understanding,

    I guess the structure of your intrenal table must be different as comapre to data passed from xls sheet.

    Pooja

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 06:43 AM

    Hi,

    this may help......

    present output:

    0001 0001 one

    0001 0002 two

    0001 0003 three

    0001 0004 four

    0001 0005 five

    0002 0001 one

    0002 0002 two

    0002 0003 three

    0002 0004 four

    0003 0001 one

    0003 0002 two

    0003 0003 three

    0004 0001 one

    0004 0002 two

    0005 0001 one

    say above records are in i_tab.

    the same i_tab can be used for output & format while display.

    loop at i_tab.

    write i_tab-col3.

    if i_tab-col3 eq 'one'.

    new-line.

    endif.

    endloop.

    Regards,

    Mdi.Deeba

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 09:49 AM

    Hi,

    Why don't you use gui_upload which will upload in the same format.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 09, 2009 at 10:23 AM

    thank u

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.