Skip to Content
0
Former Member
Oct 19, 2006 at 01:18 PM

Write to file from report runing in background job-problem

66 Views

Hi everybody

i'm having a problem when writing data from internal table to a txt file on the application server and the abap report is running in background.

At first i thought the function module 'SAP_CONVERT_TO_TEX_FORMAT' that converts an internal table to text, was causing problems so i commented it out and wrote my own code for transformation of internal table to text, but i'm still having the same problem - sometimes the data is written to file on the application server and sometimes not (even the file is not created, although open dataset and close dataset commands perform with no errors).

I looked in the help pages if maybe TRANSFER command requires any parameters for background execution, but i did not find anything.

Any suggestions?

And the code:

//**************************************************/

OPEN DATASET fname FOR APPENDING IN TEXT MODE ENCODING UTF-8.

case sy-subrc.

when 0.

write: /'File ', fname, 'successfully opened!'.

when 8.

write: /'Could not open file ', fname.

exit.

endcase.

CONCATENATE p_laufi+2(4) p_laufi(2) '01' INTO datum.

CALL FUNCTION 'DATE_GET_MONTH_LASTDAY'

EXPORTING

I_DATE = datum

IMPORTING

E_DATE = conv_datum.

*/ ce potrebujemo starejse terjatve potem odstejem 180 dni

IF p_old = 'X'.

conv_datum = conv_datum - 180.

ENDIF.

*/ end of init

SELECT gpart vkont bldat faedn opbel xblnr betrw mahns

INTO CORRESPONDING FIELDS OF podatki

FROM dfkkopbw

WHERE

laufd = p_laufd AND

laufi = p_laufi AND

bldat <= conv_datum

ORDER BY gpart.

IF first = 'X'.

old_gpart = podatki-gpart.

CLEAR first.

ENDIF.

SELECT SINGLE vkbez INTO podatki-vkbez

FROM fkkvk

WHERE

vkont = podatki-vkont.

SELECT SINGLE taxnum INTO podatki-taxnum

FROM dfkkbptaxnum

WHERE

partner = podatki-gpart.

IF old_gpart <> podatki-gpart.

PERFORM write_data.

REFRESH it_podatki.

old_gpart = podatki-gpart.

ENDIF.

APPEND podatki TO it_podatki.

ENDSELECT.

PERFORM write_data.

*/ close the file

CLOSE DATASET fname.

IF sy-subrc = 0.

WRITE: /'File ', fname, 'closed!'.

ENDIF.

&----


*& Form write_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_data .

DATA:

add.

REFRESH write_podatki.

SORT it_podatki BY opbel.

LOOP AT it_podatki INTO wa_podatki.

AT END OF opbel.

SUM.

MOVE-CORRESPONDING wa_podatki TO wa_write_podatki.

add = 'X'.

ENDAT.

IF add = 'X'.

MOVE wa_podatki-xblnr TO wa_write_podatki-xblnr.

MOVE wa_podatki-mahns TO wa_write_podatki-mahns.

APPEND wa_write_podatki TO write_podatki.

CLEAR add.

ENDIF.

ENDLOOP.

  • CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

  • EXPORTING

  • I_FIELD_SEPERATOR = ';'

  • I_LINE_HEADER =

  • I_FILENAME = fname

  • I_APPL_KEEP = ' '

  • TABLES

  • I_TAB_SAP_DATA = write_podatki

  • CHANGING

  • I_TAB_CONVERTED_DATA = i_text

  • EXCEPTIONS

  • CONVERSION_FAILED = 1

  • OTHERS = 2

  • .

  • IF SY-SUBRC <> 0.

  • case sy-subrc.

  • when 1.

  • write: /'Conversion failed'.

  • when 2.

  • write: /'Unknown error'.

  • endcase.

  • ENDIF.

  • *

    • IF sy-subrc NE 0.

    • MESSAGE i000(38) WITH text-e01 fname.

    • EXIT.

    • ENDIF.

    *

    • LOOP AT i_text INTO wa_text.

    *

    • TRANSFER wa_text TO fname.

    • ENDLOOP.

    *

    LOOP AT write_podatki INTO wa_write_podatki.

    MOVE wa_write_podatki-betrw TO c_betrw.

    CONDENSE c_betrw NO-GAPS.

    IF p_odpos = 'X'.

    CONCATENATE

    wa_write_podatki-gpart wa_write_podatki-vkont

    wa_write_podatki-vkbez wa_write_podatki-taxnum

    wa_write_podatki-bldat wa_write_podatki-faedn

    wa_write_podatki-opbel wa_write_podatki-xblnr

    c_betrw

    INTO wa_text SEPARATED BY ';'.

    ELSE.

    CONCATENATE

    wa_write_podatki-gpart wa_write_podatki-vkont

    wa_write_podatki-vkbez wa_write_podatki-taxnum

    wa_write_podatki-bldat wa_write_podatki-faedn

    wa_write_podatki-opbel wa_write_podatki-xblnr

    c_betrw wa_write_podatki-mahns

    INTO wa_text SEPARATED BY ';'.

    ENDIF.

    TRANSFER wa_text TO fname.

    ENDLOOP.

    ENDFORM. " write_data