‎2008 Jun 17 12:24 PM
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
‎2008 Jun 17 12:37 PM
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
‎2008 Jun 17 12:28 PM
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.
‎2008 Jun 17 12:28 PM
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.
‎2008 Jun 17 12:29 PM
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
‎2008 Jun 17 12:31 PM
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.
‎2008 Jun 17 12:31 PM
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.
‎2008 Jun 17 12:37 PM
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