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

Regarding flat file

Former Member
0 Likes
554

Hi Abapers,

I m working in IDES System and doing XK01 bdc.I m having a problem in preparing my flat file structure in notepad.i m providing my code plzz help me in preparing my flat file.I hav to update the code for table control in bank details .

rest i hav done with.

 report ZREC_XK01 no standard page heading line-size 255.

* Internal table for Loading flat file data

types : begin of ty_data,
         data(300) type c,
         end of ty_data.
DATA : V_DATA TYPE TY_DATA.
data : t_data type table of ty_data.

* Iternal table for loading transactional data

types : begin of ty_header,
        lifnr type rf02k-lifnr,
        bukrs type rf02k-bukrs,
        ekorg type rf02k-ekorg,
        ktokk type rf02k-ktokk,
        anred  type lfa1-anred,
        name1 type  lfa1-name1,
        sortl type  lfa1-sortl,
        land1 type lfa1-land1,
        fdgrv type lfb1-fdgrv,
        akont type lfb1-akont,
        waers type lfm1-waers,
        end of ty_header.
data : v_header type ty_header.
data : t_header type table of ty_header.

* internal table for loading the bank details
types : begin of ty_bank,
        banks type lfbk-banks,
        bankl type lfbk-bankl,
        bankn type lfbk-bankn,
        banka type bnka-banka,
        end of ty_bank.
data : v_bank type ty_bank.
data : t_bank type table of ty_bank.

data : cnt(2) type c,
       flag(50) type c.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = 'c:Test.txt'
   FILETYPE                      = 'dat'
   HAS_FIELD_SEPARATOR           = 'X'
* IMPORTING
  TABLES
    data_tab                      = t_data
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT T_DATA INTO V_DATA.

      IF V_DATA(02) = '10'.

         MOVE V_DATA-DATA+2 TO V_HEADER.

         APPEND V_HEADER TO T_HEADER.

      ELSEIF V_DATA(02) = '20'.

         MOVE V_DATA-DATA+2 TO V_BANK.

         APPEND V_BANK TO T_BANK.

      ENDIF.
      ENDLOOP.

 include bdcrecx1.

start-of-selection.

perform open_group.

LOOP AT T_HEADER INTO V_HEADER.

perform bdc_dynpro      using 'SAPMF02K' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'RF02K-KTOKK'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.


perform bdc_field       using 'RF02K-LIFNR' v_header-lifnr.
perform bdc_field       using 'RF02K-BUKRS'
                              v_header-bukrs.
perform bdc_field       using 'RF02K-EKORG'
                              v_header-ekorg.
perform bdc_field       using 'RF02K-KTOKK'
                              v_header-ktokk.
* screen one complete

perform bdc_dynpro      using 'SAPMF02K' '0110'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFA1-LAND1'.
perform bdc_field       using 'BDC_OKCODE'
                              '=VW'.


perform bdc_field       using 'LFA1-ANRED'
                              v_header-anred.
perform bdc_field       using 'LFA1-NAME1'
                              v_header-name1.
perform bdc_field       using 'LFA1-SORTL'
                              v_header-sortl.
perform bdc_field       using 'LFA1-LAND1'
                              v_header-land1.
perform bdc_dynpro      using 'SAPMF02K' '0120'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFA1-KUNNR'.
perform bdc_field       using 'BDC_OKCODE'
                              '=VW'.

* end of 2nd screen

LOOP AT T_BANK INTO V_BANK.

perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'BANKNAM(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.


perform bdc_field       using 'LFBK-BANKS(01)'
                              v_bank-banks.
perform bdc_field       using 'LFBK-BANKL(01)'
                              v_bank-bankl.
perform bdc_field       using 'LFBK-BANKN(01)'
                              v_bank-bankn.
perform bdc_dynpro      using 'SAPLBANK' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'BNKA-BANKA'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
* begin of pop-up screen in bank table control

perform bdc_field       using 'BNKA-BANKA'
                              v_bank-banka.
perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFBK-KOINH(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'LFBK-BANKS(02)'
                              v_bank-banks.
perform bdc_field       using 'LFBK-BANKL(02)'
                              v_bank-bankl.
perform bdc_field       using 'LFBK-BANKN(02)'
                              v_bank-bankn.
perform bdc_dynpro      using 'SAPLBANK' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'BNKA-BANKA'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'BNKA-BANKA'
                              v_bank-banka.
perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFBK-KOINH(03)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'LFBK-BANKS(03)'
                              v_bank-banks.
perform bdc_field       using 'LFBK-BANKL(03)'
                              v_bank-bankl.
perform bdc_field       using 'LFBK-BANKN(03)'
                              v_bank-bankn.
perform bdc_dynpro      using 'SAPLBANK' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'BNKA-BANKA'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'BNKA-BANKA'
                              v_bank-banka.
perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFBK-BANKN(04)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'LFBK-BANKS(04)'
                              v_bank-banks.
perform bdc_field       using 'LFBK-BANKL(04)'
                              v_bank-bankl.
perform bdc_field       using 'LFBK-BANKN(04)'
                              v_bank-bankn.
perform bdc_dynpro      using 'SAPLBANK' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'BNKA-BANKA'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'BNKA-BANKA'
                              v_bank-banka.
perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFBK-BANKN(05)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'LFBK-BANKS(05)'
                              v_bank-banks.
perform bdc_field       using 'LFBK-BANKL(05)'
                              v_bank-bankl.
perform bdc_field       using 'LFBK-BANKN(05)'
                              v_bank-bankn.
perform bdc_dynpro      using 'SAPLBANK' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'BNKA-BANKA'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_field       using 'BNKA-BANKA'
                              v_bank-banka.
perform bdc_dynpro      using 'SAPMF02K' '0130'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFBK-BANKS(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.

perform bdc_dynpro      using 'SAPMF02K' '0210'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFB1-FDGRV'.
perform bdc_field       using 'BDC_OKCODE'
                              '=UPDA'.
perform bdc_field       using 'LFB1-AKONT'
                              v_header-akont.
perform bdc_field       using 'LFB1-FDGRV'
                              v_header-fdgrv.
perform bdc_dynpro      using 'SAPMF02K' '0310'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFM1-WAERS'.
perform bdc_field       using 'BDC_OKCODE'
                              '=UPDA'.
perform bdc_field       using 'LFM1-WAERS'
                              v_header-waers.
perform bdc_transaction using 'XK01'.

perform close_group.
endloop.
endloop.

Help me frnds.

thanking u all.

regards,

satya

5 REPLIES 5
Read only

Former Member
0 Likes
531

Hi Satya,

I have gone through your code. You are trying to pass the data from notepad into an internal table having a flat line of 300 Chars. Instead of that, I will recommend you to create an internal table with the exact structure you want for final processing. And then prepare the data in excel file first having exactly same columns as of internal table. And copy the data from excel file to notepad. Now execute the program. This works smoothly without any problem.

Find the following piece of code for reference -

-


  • Top Include

-


  • Table from the uploaded file structure

TYPES: BEGIN OF GS_REVISIT,

MATNR TYPE EQUI-MATNR,

SERNR TYPE EQUI-SERNR,

R90REVDAT(30),

R90REVSMR(30),

R120REVDAT(30),

R120REVSMR(30),

END OF GS_REVISIT.

DATA GT_REVISIT TYPE TABLE OF GS_REVISIT.

-


  • Subroutine

-


  • Filename

DATA LV_FILENAME TYPE STRING.

REFRESH GT_REVISIT.

  • Get the filename as per the method requirement

  • Upload the text file tab delimited into table

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD

EXPORTING

FILENAME = LV_FILENAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

CHANGING

DATA_TAB = GT_REVISIT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

NOT_SUPPORTED_BY_GUI = 17

ERROR_NO_GUI = 18

OTHERS = 19.

-


The notepad flat file will have following structure -

HM400 1100 01/01/2004 65 01/03/2004 140

-


Hope this sort out your query.

PS If the answer solves your query, plz close the thread by rewarding each reply.

Regards

Read only

Former Member
0 Likes
531

It should look like

10lifnr bukrs ekorg ktokk ...

20banks1 bankl1 bankn1 banka1

20banks2 bankl2 bankn2 banka2

20banks3 bankl3 bankn3 banka3

10lifnr2 bukrs2 ekorg2 ktokk2 ...

20banks1 bankl1 bankn1 banka1

20banks2 bankl2 bankn2 banka2

20banks3 bankl3 bankn3 banka3

and so on (length of the fields according to fieldspecification,

that means if definition of lifnr is 10 fields but the actual lifnr is only 8 digits,

it looks like 10 12345678bukrs ekorg ).

Don't use field-seperators and remove flag "has field seperators" from GUI_UPLOAD.

The programm is pushing the rows of the flatfile straight into the structure.

Hope that helps.

Timo.

Read only

Former Member
0 Likes
531

Thank you all frnds for replying to my query.

I m giving my flat file structure which i hav created. And Sapna i m getting what u want to say but how to take the data which i have ceated in notepad into the excel sheet.

My sample Flat file :

Test data :-

Test data :-
 

100000000000000176000100010001MR             SHIVA                          SA    iN      31000a1        inr       

200000000000000176in 100001         1234

200000000000000176in 1001           2345

200000000000000176in 0120           1234

200000000000000176in 1003           1234

200000000000000176in 1002           2345

200000000000000176in 123            1234

200000000000000176in 1234           2345

 

Please advice.

thanks& regards

satya

Read only

Former Member
0 Likes
531

Frnds any solutions.

Thanks& regards,

satya

Read only

Former Member
0 Likes
531

Can you please specify what problems your program is encountering while processing your flat file?

Timo.