Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reading file from application server

Former Member
0 Likes
1,200

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

1 ACCEPTED SOLUTION
Read only

former_member556412
Active Participant
0 Likes
776

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

6 REPLIES 6
Read only

Former Member
0 Likes
776

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.

Read only

Former Member
0 Likes
776

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.

Read only

Former Member
0 Likes
776

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

Read only

Former Member
0 Likes
776

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.

Read only

Former Member
0 Likes
776

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.

Read only

former_member556412
Active Participant
0 Likes
777

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