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

Reading file from application server

Hi experts,

I have a file in the application server which has first f15 rows as header and the rest as body.

I want to take the header in a separate internal table and the body in another.

Is this possible using dataset commands.If not how do we do this.

Ankit

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Jun 17, 2008 at 11:37 AM

    Hi try this out

    data: t_header like <desiredstructure> occcurs 0 with headerline

    data: t_lineitem .............................................

    data: t_headerspecial like .........................like above

    *-declare structure with acutal fields on the file

    data: begin of t_header_fulltable..

    <required structure>

    end of t_header_full table.

    *--similarly create for item & header special

    • Variables

    DATA: w_tab TYPE x VALUE '09',

    *--load the file into internal table t_file using GUI_UPLOAD or open data set if the file

    *--is in Appserver

    LOOP AT t_file.

    • The incoming file is tab-delimited. Break them into individual columns

    • Header record

    IF t_file+22(1) = 'H' "or whatever.

    SPLIT t_file AT w_tab INTO

    w_rctyp

    t_header_fulltable-batch_date

    t_header_fulltable-batch_id

    t_header_fulltable-batch_total.

    *-Now you have all fields into t_header_fulltable structure

    *-here move only required field to your t_header table.

    move-corresponding t_header_fulltable to t_header

    append t_header.

    clear t_header.

    • ITem record

    ELSEIF t_file+22(1) = 'I'.

    SPLIT t_file AT w_tab INTO

    t_item_fulltable-w_rctyp

    t_item_fulltable-acct_doc

    t_item_fulltable-w_posting_type

    t_item_fulltable-card_type

    t_item_fulltable-currency

    t_item_fulltable-w_amount

    do the same thing as header move the required info to your internal table

    DO THE SAME FOR HEADER SPECIAL TOO

    endloop. " input file

    Regards,

    Bhanu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:28 AM

    hi,

    Use this:

    DO.

    READ DATASET DG_UNIX INTO DS_STR.

    IF SY-SUBRC NE 0.

    EXIT.

    ELSE.

    IF SY-INDEX < 16.

    APPEND DS_STR TO DT_head.

    CLEAR DS_STR.

    else.

    APPEND DS_STR TO DT_body.

    CLEAR DS_STR.

    ENDIF.

    ENDIF.

    ENDDO.

    Thanks,

    Keerthi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:28 AM

    Hi,

    First u read all the records into an internal table and later you move the first 15 records to header int table and the remaining records to item int table.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:29 AM

    Hi,

    Check the below code..

    Open dataset <DNAME>.....

    Do.

    Read dataset <DNAME> .......

    IF sy-index LE 15.

    Append to your header table.

    ELSE.

    Append to your item table.

    ENDIF.

    Rgds,

    Bujji

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:31 AM

    Hi,

    First u read all the records into one final internal table.

    Then depending on the fields read the header data in to it_head

    and then the remaining item data into it_item.

    -Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:31 AM

    you need to have an indicator saying that the line is header or item.

    based on that indicator fill you internal tables or

    do.

    read data set.

    if sy-subrc ne 0.

    exit.

    endif.

    if sy-index LE 15.

    fill header data.

    append header table.

    else.

    fill item data.

    append item table.

    endif.

    enddo.

    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.