Application Development 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: 

Standard Report - Send it to application server

Former Member
0 Kudos

Hello All,

I have a standard SAP report that needs to be sent to the application server.

Ex. After running the report , it needs to be converted to .txt format and then sent to the application server. Can this process by automated or done in the background ?

option : create a zreport and add code for throwing it on the application server.

Question : Can it be done automatically or in the background using tcodes CG3Z and thus avoiding any development work. I mean after running the report save it locally in text format and then downloading on to application server using CG3Z.

( saving locally and then uploading it to app sever needs to be done in background)

The idea is to automate this process and set this as a background job and also avoid any development work.

Please suggest !

1 ACCEPTED SOLUTION

Former Member
0 Kudos

to automate this process ,best way is to create a Z rport and there u can submit this sap standard report and get its output into an Internal table and then u can write this internal table to application server via following demo code -

this is code for both (download /upload),u can not use CG3y and CG3z as u want to do it as a background job ..

&----


*& Report ZGILL_AS *

*& *

&----


*& *

*& *

&----


REPORT ZGILL_AS message-id rp .

tables: pa0001,pa0002.

select-options s_pernr for pa0001-pernr no intervals MODIF ID XYZ.

parameters: p_dwnld AS CHECKBOX ,

p_upld AS CHECKBOX DEFAULT 'X'.

parameters: P_DSNI(75) TYPE C MODIF ID ABG DEFAULT

'/usr/local/sapdata/amit.dat' LOWER CASE.

data: begin of itab occurs 0,

pernr(8),

sp1(1) value ',',

werks(4),

sp2(1) value ',',

persg(1),

sp3(1) value ',',

persk(2),

end of itab.

data: s_eof(3).

start-of-selection.

if p_upld = 'X'.

OPEN DATASET P_DSNI FOR OUTPUT IN LEGACY TEXT MODE.

PERFORM FETCH_DATA.

STOP.

elseif p_dwnld = 'X'.

OPEN DATASET P_DSNI FOR INPUT IN LEGACY TEXT MODE.

IF SY-SUBRC NE 0.

MESSAGE E016 WITH

'Error opening seq. file, RC:' SY-SUBRC.

EXIT.

ENDIF.

CLEAR S_EOF.

DO.

PERFORM FETCH_file.

IF S_EOF EQ 'YES'. stop. ENDIF.

ENDDO.

endif.

END-OF-SELECTION.

if itab[] is not initial.

perform print_file1 tables itab.

else.

write:/ 'No records exists'.

endif.

&----


*& Form FETCH_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_DATA .

SELECT * FROM PA0001 WHERE PERNR IN S_PERNR.

MOVE-CORRESPONDING PA0001 TO ITAB.

TRANSFER ITAB TO P_DSNI.

APPEND ITAB.

ENDSELECT.

CLOSE DATASET P_DSNI.

ENDFORM. " FETCH_DATA

&----


*& Form FETCH_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_file .

READ DATASET P_DSNI INTO itab.

append itab.

clear itab.

IF SY-SUBRC NE 0.

S_EOF = 'YES'. EXIT.

ENDIF.

ENDFORM. " FETCH_file

&----


*& Form print_file1

&----


  • text

----


  • -->P_ITAB text

----


FORM print_file1 tables P_ITAB structure itab .

write:/2 'EmpNo',

14 'Personnel Area',

34 'Emp Group',

47 'Emp SubGroup'.

skip 1.

loop at p_itab.

write:2 p_itab-pernr,

14 p_itab-werks,

34 p_itab-persg,

47 p_itab-persk.

skip 1.

endloop.

ENDFORM. " print_file1

1 REPLY 1

Former Member
0 Kudos

to automate this process ,best way is to create a Z rport and there u can submit this sap standard report and get its output into an Internal table and then u can write this internal table to application server via following demo code -

this is code for both (download /upload),u can not use CG3y and CG3z as u want to do it as a background job ..

&----


*& Report ZGILL_AS *

*& *

&----


*& *

*& *

&----


REPORT ZGILL_AS message-id rp .

tables: pa0001,pa0002.

select-options s_pernr for pa0001-pernr no intervals MODIF ID XYZ.

parameters: p_dwnld AS CHECKBOX ,

p_upld AS CHECKBOX DEFAULT 'X'.

parameters: P_DSNI(75) TYPE C MODIF ID ABG DEFAULT

'/usr/local/sapdata/amit.dat' LOWER CASE.

data: begin of itab occurs 0,

pernr(8),

sp1(1) value ',',

werks(4),

sp2(1) value ',',

persg(1),

sp3(1) value ',',

persk(2),

end of itab.

data: s_eof(3).

start-of-selection.

if p_upld = 'X'.

OPEN DATASET P_DSNI FOR OUTPUT IN LEGACY TEXT MODE.

PERFORM FETCH_DATA.

STOP.

elseif p_dwnld = 'X'.

OPEN DATASET P_DSNI FOR INPUT IN LEGACY TEXT MODE.

IF SY-SUBRC NE 0.

MESSAGE E016 WITH

'Error opening seq. file, RC:' SY-SUBRC.

EXIT.

ENDIF.

CLEAR S_EOF.

DO.

PERFORM FETCH_file.

IF S_EOF EQ 'YES'. stop. ENDIF.

ENDDO.

endif.

END-OF-SELECTION.

if itab[] is not initial.

perform print_file1 tables itab.

else.

write:/ 'No records exists'.

endif.

&----


*& Form FETCH_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_DATA .

SELECT * FROM PA0001 WHERE PERNR IN S_PERNR.

MOVE-CORRESPONDING PA0001 TO ITAB.

TRANSFER ITAB TO P_DSNI.

APPEND ITAB.

ENDSELECT.

CLOSE DATASET P_DSNI.

ENDFORM. " FETCH_DATA

&----


*& Form FETCH_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_file .

READ DATASET P_DSNI INTO itab.

append itab.

clear itab.

IF SY-SUBRC NE 0.

S_EOF = 'YES'. EXIT.

ENDIF.

ENDFORM. " FETCH_file

&----


*& Form print_file1

&----


  • text

----


  • -->P_ITAB text

----


FORM print_file1 tables P_ITAB structure itab .

write:/2 'EmpNo',

14 'Personnel Area',

34 'Emp Group',

47 'Emp SubGroup'.

skip 1.

loop at p_itab.

write:2 p_itab-pernr,

14 p_itab-werks,

34 p_itab-persg,

47 p_itab-persk.

skip 1.

endloop.

ENDFORM. " print_file1