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

Doubt in code....

Former Member
0 Likes
982

Hi,

I have following doubt. I am using a BAPI to get details regarding particular Object number. The list of object numbers are in internal table it_tab

Loop at it_tab.

Call Function 'ZCUSTOM'

EXPROTING

NUMBER = IT_TAB-NUMBER

TABLES

TAB1 = TAB1[]

TAB2 = TAB2[]

TAB3 = TAB3[].

Now the Data from TAB1 table, TAB2 table and Tab3 table should be written in a flat file1, fil2 and file3.

My doubt, is when the next number is passed to BAPI ZCUSTOM while looping, the data tables for that next number should be written in respective files but on next line (keeping the previous data intact)

So,

Data returned when NUMBER1 :- TAB1 - AAA,11; TAB2 - BBB,12; TAB3 - CCC,13

Data returned when Number2 :- TAB1 - YYY,10; TAB2 - ZZZ,09; TAB3 - TTT,08

Flat file1 Content should be:

AAA,11

YYY,10

-


Flat file2 Content should be:

BBB,12

ZZZ,09

-


Flat file3 Content should be:

CCC,13

TTT,08

How can I achieve this ?

Regards,

Rajesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
707

transfer the contents of internal table inside the loop itself.

else,

move contents of those internal tables to another internal table

Loop at it_tab.

Call Function 'ZCUSTOM'

EXPROTING

NUMBER = IT_TAB-NUMBER

TABLES

TAB1 = TAB1[]

TAB2 = TAB2[]

TAB3 = TAB3[].

move tab1 to tabA.

move tab2 to tabb.

... tab3 to tabc .

append : taba,. tabb, tabc.

endloop.

5 REPLIES 5
Read only

Former Member
0 Likes
707

If you are using OPEN DATASET, use the option FOR APPENDING. See below.

OPEN DATASET p_file FOR APPENDING IN TEXT MODE ENCODING DEFAULT.

If you are using GUI_DOWNLOAD, then set the parameter "append = 'X' ".

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
707

These files, are they on the frontend PC, or the application server file system?

You should probably write all records to internal tables and then write to file form these internal tables when done processing the custom BAPI.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
708

transfer the contents of internal table inside the loop itself.

else,

move contents of those internal tables to another internal table

Loop at it_tab.

Call Function 'ZCUSTOM'

EXPROTING

NUMBER = IT_TAB-NUMBER

TABLES

TAB1 = TAB1[]

TAB2 = TAB2[]

TAB3 = TAB3[].

move tab1 to tabA.

move tab2 to tabb.

... tab3 to tabc .

append : taba,. tabb, tabc.

endloop.

Read only

0 Likes
707

Hi,

The flat files are on presentation server...

Read only

0 Likes
707

Ok, so again, I would build internal tables for you files. Then when done in the LOOP and calling the custom BAPI, simply download the internal tables to the PC once. see the pseudo code below.

Loop at itab.

    call function 'ZCUSTOM'
           ......

    append lines of ttab1 to itab1.
    append lines of ttab2 to itab2.
    append lines of ttab3 to itab3.
    append lines of ttab4 to itab4.

endloop.


call function 'GUI_DOWNLOAD'
            .....
         tables
               data_tab   = itab1.

Regards,

Rich Heilman