Skip to Content
0
Former Member
May 03, 2007 at 05:02 PM

download the KTOPL field data and GLT0 table data into one Internal table

57 Views

Hi,

I have downloaded GLT0 table fields data to PC file . But i need to download KTOPL(Chart Of Accounts) data also. in GLT0 table there is no KTOPL field.

But in SKA1 table have KTOPL field. Then what is the issue is GLT0 data & KTOPL field data needs to download into one Internal Table.

anybody could you please solve this problem. immediately need to solve this.

Below is the code.

REPORT ZFXXEABL_1 NO STANDARD PAGE HEADING

LINE-SIZE 200.

************************************************************************

  • Tables Declaration

************************************************************************

TABLES : GLT0.

************************************************************************

  • Data Declaration

************************************************************************

DATA : FP(8) TYPE C,

YEAR LIKE GLT0-RYEAR,

PERIOD(3) TYPE C,

DBALANCE LIKE VBAP-NETWR VALUE 0 ,

CBALANCE LIKE VBAP-NETWR VALUE 0.

*Internal table for for final data..

DATA : BEGIN OF REC1 OCCURS 0,

BAL LIKE GLT0-TSLVT value 0,

COAREA LIKE GLT0-RBUSA,

  • CA(4) TYPE C,

KTOPL LIKE ska1-ktopl,

CCODE LIKE GLT0-BUKRS,

CREDIT LIKE VBAP-NETWR,

CURRENCY LIKE GLT0-RTCUR,

CURTYPE(2) TYPE N,

DEBIT LIKE VBAP-NETWR,

YEAR(8) TYPE C,

FY(2) TYPE C,

ACCOUNT LIKE GLT0-RACCT,

VER LIKE GLT0-RVERS,

VTYPE(2) TYPE N,

CLNT LIKE SY-MANDT,

S_SYS(3) TYPE C,

INDICATOR LIKE GLT0-DRCRK,

END OF REC1.

DATA : C(2) TYPE N,

D(2) TYPE N.

DATA REC1_H LIKE REC1.

  • Variable declarations

DATA :

W_FILES(4) TYPE N,

W_DEBIT LIKE GLT0-TSLVT,

W_CREDIT LIKE GLT0-TSLVT,

W_PCFILE LIKE RLGRAP-FILENAME ,

W_UNIXFILE LIKE RLGRAP-FILENAME,

W_PCFILE1 LIKE RLGRAP-FILENAME,

W_UNIXFIL1 LIKE RLGRAP-FILENAME,

W_EXT(3) TYPE C,

W_UEXT(3) TYPE C,

W_PATH LIKE RLGRAP-FILENAME,

W_UPATH LIKE RLGRAP-FILENAME,

W_FIRST(1) TYPE C VALUE 'Y',

W_CFIRST(1) TYPE C VALUE 'Y',

W_PCFIL LIKE RLGRAP-FILENAME.

DATA: "REC LIKE GLT0 OCCURS 0 WITH HEADER LINE,

T_TEMP LIKE GLT0 OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF REC3 OCCURS 0.

INCLUDE STRUCTURE GLT0.

DATA: KTOPL LIKE SKA1-KTOPL,

END OF REC3.

DATA: BEGIN OF T_KTOPL OCCURS 0,

KTOPL LIKE SKA1-KTOPL,

SAKNR LIKE SKA1-SAKNR,

END OF T_KTOPL.

  • Download data.

DATA: BEGIN OF I_REC2 OCCURS 0,

BAL(17), " like GLT0-TSLVT value 0,

COAREA(4), " like glt0-rbusa,

CA(4), " chart of accounts

CCODE(4), " like glt0-bukrs,

CREDIT(17), " like vbap-netwr,

CURRENCY(5), " like glt0-rtcur,

CURTYPE(2), " type n,

DEBIT(17), " like vbap-netwr,

YEAR(8), " type c,

FY(2), " type c, fiscal yr variant

ACCOUNT(10), " like glt0-racct,

VER(3), " like glt0-rvers,

VTYPE(3), " type n,

CLNT(3), "like sy-mandt,

S_SYS(3), "like sy-sysid,

INDICATOR(1), " like glt0-drcrk,

END OF I_REC2.

************************************************************************

  • Selection screen. *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1.

SELECT-OPTIONS : COMPCODE FOR GLT0-BUKRS,

GLACC FOR GLT0-RACCT,

FISYEAR FOR GLT0-RYEAR,

  • no intervals no-extension, "- BG6661-070212

FISCPER FOR GLT0-RPMAX,

  • busarea for glt0-rbusa,

CURRENCY FOR GLT0-RTCUR.

SELECTION-SCREEN END OF BLOCK BL1.

SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME TITLE TEXT-BL2.

PARAMETERS:

P_UNIX AS CHECKBOX, "Check box for Unix Option

P_UNFIL LIKE RLGRAP-FILENAME, " Unix file Dnload file name

  • default '/var/opt/arch/extract/GLT0.ASC', "- BG6661-070212

P_PCFILE AS CHECKBOX, "Check box for Local PC download.

P_PCFIL LIKE RLGRAP-FILENAME " PC file Dnload file name

  • default 'C:\GLT0.ASC'. "- BG6661-070212

DEFAULT 'C:\glt0_gl_balance_all.asc'. "+ BG6661-070212

SELECTION-SCREEN END OF BLOCK BL2.

*eject

************************************************************************

  • Initialization. *

************************************************************************

INITIALIZATION.

  • Try to default download filename

  • p_pcfil = c_pcfile.

  • p_unfil = c_unixfile.

  • if sy-sysid eq c_n01.

  • p_unfil = c_unixfile.

  • endif.

  • if sy-sysid eq c_g21.

  • p_unfil = c_g21_unixfile.

  • endif.

  • if sy-sysid eq c_g9d.

  • p_unfil = c_g9d_unixfile.

  • endif.

  • Default for download filename

*{ Begin of BG6661-070212

CONCATENATE C_UNIXFILE

SY-SYSID C_FSLASH C_CHRON C_FILENAME INTO P_UNFIL.

*} End of BG6661-070212

AT SELECTION-SCREEN OUTPUT.

  • loop at screen.

  • if screen-name = 'P_PCFIL'. "PC FILE

  • screen-input = '0'.

  • modify screen.

  • endif.

  • if screen-name = 'P_UNFIL'. "UN FILE

  • screen-input = '0'.

  • modify screen.

  • endif.

  • endloop.

  • if w_first = 'Y'.

  • perform path_file.

  • w_first = 'N'.

  • endif.

  • if w_cfirst = 'Y'.

  • perform cpath_file.

  • w_cfirst = 'N'.

  • endif.

************************************************************************

  • Start-of-Selection. *

************************************************************************

START-OF-SELECTION.

*COLLECT DATA

PERFORM COLLECT_DATA.

*BUILD FILENAMES

PERFORM BUILD_FILES.

*LOCAL

IF P_PCFILE = C_YES.

PERFORM LOCAL_DOWNLOAD.

ENDIF.

*UNIX

IF P_UNIX = C_YES.

PERFORM UNIX_DOWNLOAD.

ENDIF.

IF P_PCFILE IS INITIAL AND P_UNIX IS INITIAL.

MESSAGE I000(ZL) WITH 'Down load flags both are unchecked'.

ENDIF.

END-OF-SELECTION.

IF P_PCFILE = C_YES.

WRITE :/ 'PC File' , C_UNDER, P_PCFIL.

ENDIF.

&----


*& Form DOWNLOAD

&----


  • Download *

----


FORM DOWNLOAD.

P_PCFIL = W_PATH.

DATA LIN TYPE I.

DESCRIBE TABLE I_REC2 LINES LIN.

WRITE:/ 'No of Records downloaded = ',LIN.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = P_PCFIL

FILETYPE = C_ASC "c_dat "dat

TABLES

DATA_TAB = I_REC2 " t_str

  • fieldnames = t_strhd

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

IF SY-SUBRC EQ 0.

ENDIF.

ENDFORM.

&----


*& Form WRITE_TO_SERVER

&----


  • text *

----


  • --> p1 text

  • <-- p2 text

----


FORM WRITE_TO_SERVER.

DATA : L_MSG(100) TYPE C,

L_LINE(5000) TYPE C.

P_UNFIL = W_UPATH.

DATA LIN TYPE I.

DESCRIBE TABLE I_REC2 LINES LIN.

WRITE:/ 'No of Records downloaded = ',LIN.

OPEN DATASET P_UNFIL FOR OUTPUT IN TEXT MODE. " message l_msg.

IF SY-SUBRC <> 0.

WRITE: / L_MSG.

ENDIF.

  • perform header_text1.

LOOP AT I_REC2.

TRANSFER I_REC2 TO P_UNFIL.

ENDLOOP.

CLOSE DATASET P_UNFIL.

WRITE : / C_TEXT , W_UPATH.

SPLIT W_UNIXFILE AT C_DOT INTO W_UNIXFIL1 W_UEXT.

CLEAR W_UPATH.

IF NOT W_UEXT IS INITIAL.

CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.

ELSE.

W_UEXT = C_ASC. " c_csv.

CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.

ENDIF.

ENDFORM. " WRITE_TO_SERVER

&----


*& Form BUILD_FILES

&----


FORM BUILD_FILES.

IF P_PCFILE = C_YES.

W_PCFILE = P_PCFIL.

***Split path at dot**

SPLIT W_PCFILE AT C_DOT INTO W_PCFILE1 W_EXT.

IF NOT W_EXT IS INITIAL.

CONCATENATE W_PCFILE1 C_DOT W_EXT INTO W_PATH.

ELSE.

W_PATH = W_PCFILE1.

ENDIF.

ENDIF.

IF P_UNIX = C_YES.

W_UNIXFILE = P_UNFIL.

SPLIT W_UNIXFILE AT C_DOT INTO W_UNIXFIL1 W_UEXT.

IF NOT W_UEXT IS INITIAL.

CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.

ELSE.

W_UPATH = W_UNIXFIL1.

ENDIF.

ENDIF.

ENDFORM.

FORM CPATH_FILE.

CLEAR P_PCFIL.

CONCATENATE C_PCFILE

C_COMFILE SY-SYSID C_UNDER SY-DATUM SY-UZEIT

C_DOT C_ASC INTO P_PCFIL.

ENDFORM. " CPATH_FILE

FORM PATH_FILE.

CLEAR P_UNFIL.

  • if sy-sysid eq c_n01.

CONCATENATE C_UNIXFILE

C_COMFILE SY-SYSID C_UNDER SY-DATUM SY-UZEIT

C_DOT C_ASC INTO P_UNFIL.

  • endif.

  • if sy-sysid eq c_g21.

  • concatenate c_g21_unixfile

  • c_comfile sy-sysid c_under sy-datum sy-uzeit

  • c_dot c_asc into p_unfil.

  • endif.

  • if sy-sysid eq c_g9d.

  • concatenate c_g9d_unixfile

  • c_comfile sy-sysid c_under sy-datum sy-uzeit

  • c_dot c_asc into p_unfil.

  • endif.

ENDFORM. " PATH_FILE

&----


  • Local_Download *

  • Local *

----


FORM LOCAL_DOWNLOAD.

  • perform header_text.

LOOP AT REC1.

REC1-CLNT = SY-MANDT.

REC1-S_SYS = SY-SYSID.

MOVE: REC1-BAL TO I_REC2-BAL,

REC1-COAREA TO I_REC2-COAREA,

  • REC1-CA TO I_REC2-CA,

REC1-KTOPL TO I_REC2-CA,

REC1-CCODE TO I_REC2-CCODE,

REC1-CREDIT TO I_REC2-CREDIT,

REC1-CURRENCY TO I_REC2-CURRENCY,

REC1-CURTYPE TO I_REC2-CURTYPE,

REC1-DEBIT TO I_REC2-DEBIT,

REC1-YEAR TO I_REC2-YEAR,

REC1-FY TO I_REC2-FY,

REC1-ACCOUNT TO I_REC2-ACCOUNT,

REC1-VER TO I_REC2-VER,

REC1-VTYPE TO I_REC2-VTYPE,

REC1-CLNT TO I_REC2-CLNT,

REC1-S_SYS TO I_REC2-S_SYS,

REC1-INDICATOR TO I_REC2-INDICATOR.

APPEND I_REC2.

CLEAR I_REC2.

ENDLOOP.

IF NOT I_REC2[] IS INITIAL.

PERFORM DOWNLOAD .

CLEAR I_REC2.

REFRESH I_REC2.

ELSE.

WRITE : / ' no record exist due to unavailability of data'.

ENDIF.

ENDFORM. " LOCAL_DOWNLOAD

&----


*& Form UNIX_DOWNLOAD

&----


FORM UNIX_DOWNLOAD.

LOOP AT REC1.

REC1-CLNT = SY-MANDT.

REC1-S_SYS = SY-SYSID.

MOVE: REC1-BAL TO I_REC2-BAL,

REC1-COAREA TO I_REC2-COAREA,

  • REC1-CA TO I_REC2-CA,

REC1-KTOPL TO I_REC2-CA,

REC1-CCODE TO I_REC2-CCODE,

REC1-CREDIT TO I_REC2-CREDIT,

REC1-CURRENCY TO I_REC2-CURRENCY,

REC1-CURTYPE TO I_REC2-CURTYPE,

REC1-DEBIT TO I_REC2-DEBIT,

REC1-YEAR TO I_REC2-YEAR,

REC1-FY TO I_REC2-FY,

REC1-ACCOUNT TO I_REC2-ACCOUNT,

REC1-VER TO I_REC2-VER,

REC1-VTYPE TO I_REC2-VTYPE,

SY-MANDT TO I_REC2-CLNT,

SY-SYSID TO I_REC2-S_SYS,

REC1-INDICATOR TO I_REC2-INDICATOR.

APPEND I_REC2.

CLEAR I_REC2.

ENDLOOP.

IF NOT I_REC2[] IS INITIAL.

PERFORM WRITE_TO_SERVER.

CLEAR I_REC2.

REFRESH I_REC2.

ELSE.

WRITE : / ' no record exist due to unavailability of data'.

ENDIF.

ENDFORM. " UNIX_DOWNLOAD

&----


*& Form HEADER_TEXT

&----


  • text *

----


  • --> p1 text

  • <-- p2 text

----


*form header_text.

  • concatenate c_bal c_ba c_ca c_cc c_credit c_currency c_curtype

  • c_debit c_fisyear c_fisvar c_acct c_ver c_vtype c_indicator

  • into t_strhd

  • separated by c_comma.

  • append t_strhd.

*endform. " HEADER_TEXT

&----


*& Form HEADER_TEXT1

&----


  • text *

----


*form header_text1.

  • concatenate c_bal c_ba c_ca c_cc c_credit c_currency c_curtype

  • c_debit c_fisyear c_fisvar c_acct c_ver c_vtype c_indicator

  • into t_strhd1

  • separated by c_comma.

  • append t_strhd1.

  • transfer t_strhd1 to p_unfil.

*endform. " HEADER_TEXT1

&----


*& Form COLLECT_DATA

&----


  • Collect Data *

----


FORM COLLECT_DATA.

SELECT * FROM GLT0 INTO TABLE REC3

WHERE BUKRS IN COMPCODE

AND RYEAR IN FISYEAR

AND RPMAX IN FISCPER

AND RACCT IN GLACC

AND RTCUR IN CURRENCY.

SELECT KTOPL FROM SKA1

INTO TABLE T_KTOPL

FOR ALL ENTRIES IN REC3

WHERE SAKNR = REC3-RACCT.

LOOP AT REC3 .

  • select *

  • from glt0

  • into table t_temp

  • where rldnr = rec-rldnr

  • and rrcty = rec-rrcty

  • and rvers = rec-rvers

  • and bukrs = rec-bukrs

  • and ryear = rec-ryear

  • and racct = rec-racct

  • and rbusa = rec-rbusa

  • and rtcur <> 'ZAR'

  • and rpmax = rec-rpmax.

  • if sy-subrc = 0.

  • rec1-bal = '0.00'.

  • else.

  • rec1-bal = rec-hslvt.

  • endif.

*READ TABLE T_KTOPL WITH KEY SAKNR = REC-RACCT BINARY SEARCH.

MOVE T_KTOPL-KTOPL TO REC3-KTOPL.

CLEAR: CBALANCE, DBALANCE.

REC1-BAL = REC3-HSLVT.

IF REC3-DRCRK = 'S'.

IF REC3-HSLVT NE C_ZERO.

  • YEAR = REC-RYEAR.

  • PERIOD = '000'.

  • CONCATENATE PERIOD C_DOT YEAR INTO FP.

  • REC1-INDICATOR = REC-DRCRK.

  • REC1-DEBIT = C_ZERO.

  • REC1-CREDIT = C_ZERO.

  • REC1-CCODE = REC-BUKRS.

  • REC1-YEAR = FP.

  • REC1-CURRENCY = REC-RTCUR.

  • REC1-ACCOUNT = REC-RACCT.

  • rec1-bal = rec-hslvt.

  • dbalance = rec1-bal.

  • REC1-CURTYPE = C_CTYPE.

  • REC1-FY = C_FY.

  • REC1-COAREA = REC-RBUSA.

  • REC1-VER = REC-RVERS.

  • REC1-VTYPE = C_CTYPE.

  • REC1-CA = C_CHART.

  • APPEND REC1.

  • C = 0.

    PERFORM D.

    ENDIF.

    IF REC3-HSL01 NE C_ZERO.

    YEAR = REC3-RYEAR.

    PERIOD = '001'.

    CONCATENATE PERIOD C_DOT YEAR INTO FP.

    REC1-INDICATOR = REC3-DRCRK.

    REC1-DEBIT = REC3-HSL01 .

    REC1-CCODE = REC3-BUKRS.

    REC1-YEAR = FP.

    REC1-CURRENCY = REC3-RTCUR.

    REC1-ACCOUNT = REC3-RACCT.

    • rec1-bal = REC3-hsl01 + dbalance.

    • dbalance = rec1-bal.

    REC1-CURTYPE = C_CTYPE.

    REC1-FY = C_FY.

    REC1-COAREA = REC3-RBUSA.

    REC1-VER = REC3-RVERS.

    REC1-VTYPE = C_CTYPE.

    • REC1-CA = C_CHART.

    REC1-KTOPL = REC3-KTOPL.

    APPEND REC1.

    C = 1.

    PERFORM D.

    ENDIF.

    IF REC3-HSL02 NE C_ZERO.

    REC1-DEBIT = REC3-HSL02.

    YEAR = REC3-RYEAR.

    PERIOD = '002'.

    CONCATENATE PERIOD C_DOT YEAR INTO FP.

    REC1-INDICATOR = REC3-DRCRK.

    REC1-DEBIT = REC3-HSL02.

    REC1-CCODE = REC3-BUKRS.

    REC1-YEAR = FP.

    REC1-CURRENCY = REC3-RTCUR.

    REC1-ACCOUNT = REC3-RACCT.

    • rec1-bal = REC3-hsl02 + dbalance.

    • dbalance = rec1-bal.

    REC1-CURTYPE = C_CTYPE.

    REC1-FY = C_FY.

    REC1-COAREA = REC3-RBUSA.

    REC1-VER = REC3-RVERS.

    REC1-VTYPE = C_CTYPE.

    • REC1-CA = C_CHART. "-BF7957-070503

    REC1-KTOPL = REC3-KTOPL. "+BF7957-070503

    APPEND REC1.

    C = 2.

    PERFORM D.

    ENDIF.

    IF REC3-HSL03 NE C_ZERO.

    YEAR = REC3-RYEAR.

    PERIOD = '003'.

    CONCATENATE PERIOD C_DOT YEAR INTO FP.

    REC1-INDICATOR = REC3-DRCRK.

    REC1-DEBIT = REC3-HSL03.

    REC1-CCODE = REC3-BUKRS.

    REC1-YEAR = FP.

    REC1-CURRENCY = REC3-RTCUR.

    REC1-ACCOUNT = REC3-RACCT.

    • rec1-bal = REC3-hsl03 + dbalance .

    • dbalance = rec1-bal.

    REC1-CURTYPE = C_CTYPE.

    REC1-FY = C_FY.

    REC1-COAREA = REC3-RBUSA.

    REC1-VER = REC3-RVERS.

    REC1-VTYPE = C_CTYPE.

    • REC1-CA = C_CHART. "-BF7957-070503

    REC1-KTOPL = REC3-KTOPL. "+BF7957-070503

    APPEND REC1.

    C = 3.

    PERFORM D.

    ENDIF.

    IF REC3-HSL04 NE C_ZERO.

    REC1-DEBIT = REC3-HSL04.

    YEAR = REC3-RYEAR.

    PERIOD = '004'.

    CONCATENATE PERIOD C_DOT YEAR INTO FP.

    REC1-INDICATOR = REC3-DRCRK.

    REC1-DEBIT = REC3-HSL04.

    REC1-CCODE = REC3-BUKRS.

    REC1-YEAR = FP.

    REC1-CURRENCY = REC3-RTCUR.

    REC1-ACCOUNT = REC3-RACCT.

    • rec1-bal = REC3-hsl04 + dbalance .

    REC1-CURTYPE = C_CTYPE.

    REC1-FY = C_FY.

    REC1-COAREA = REC3-RBUSA.

    REC1-VER = REC3-RVERS.

    REC1-VTYPE = C_CTYPE.

    • REC1-CA = C_CHART. "-BF7957-070503

    REC1-KTOPL = REC3-KTOPL. "+BF7957-070503

    APPEND REC1.

    • dbalance = rec1-bal.

    C = 4.

    PERFORM D.

    ENDIF.

    Thanks and Regards,

    Ram