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: 

BDC 1st screen to 2nd screen then back to 1st screen...

Wil_Wilstroth
Active Participant
0 Kudos

.:: <b>i have included my sourcecode for you guys to help me</b> ::.

Hi all gurus,

i just did bdc on kp06, the bdc works well. Here is the scenario that prompted me to ask you all.

I have a data file (in .txt format) and is use by BDC session to insert into kp06.

In this data file, i have the following:

-


cost center | cost element | Plan 1 | plan 2 ...

-


00000001 1012222 12 23

-


00000001 1012223 23 34

-


00000002 1012222 15 23

-


00000002 1012223 16 24

Now, i am able to bdc cost center 00000001 <b>but</b> i am not able to bdc the next cost center 00000002.

Each time i run the bdc session.. it will always finish saving cost center 00000001 but not 00000002...

Some of the steps i tried:

1. I have tried putting a loop in my bdc coding but it wouldn't work.

2. I tried recording the sequence but still only the cost center 00000001 is saved not the next cost center

3. When i create the BDC session and process it in sm35, in kp06, it will always successfully save the cost center 00000001 but the it will just stop there and say, "No data/batch input for scree XXXXX nnnn..."

Does anyone of you know what i should do? Why i can save the first batch of 00000001 but not the second batch of 00000002? Strange...

Please help.

Thanks

William Wilstroth

Message was edited by: william wilstroth

William Wilstroth
10 REPLIES 10

former_member188685
Active Contributor
0 Kudos

can you give the code,....

so that we can see what is the problem

vijay

0 Kudos

Hi Vijay and others,

Vijay, here is the coding... please take a look at it...

REPORT zfic_plan_upload LINE-SIZE 147

LINE-COUNT 255

MESSAGE-ID 00

NO STANDARD PAGE HEADING.

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

  • --- TYPESa

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

TYPES : BEGIN OF tp_data,

costcenter(11),

costelment(11),

plan01(8),

plan02(8),

plan03(8),

plan04(8),

plan05(8),

plan06(8),

plan07(8),

plan08(8),

plan09(8),

plan10(8),

plan11(8),

plan12(8),

END OF tp_data.

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

  • --- INTERNAL TABLES *

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

  • Data Declaration to hold data from EXCEL format

DATA : t_fromexcel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

  • Data Declaration to hold data arrange from EXCEL

DATA : t_data TYPE tp_data OCCURS 0 WITH HEADER LINE.

  • Data Declaration to hold data for report header

DATA : BEGIN OF id,

system LIKE sy-sysid,

dash VALUE '-',

client LIKE sy-mandt,

END OF id.

  • Data Declaration to hold data for BDC - Direct Input and Session

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

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

  • --- VARIABLES *

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

  • Data Declaration to hold data count

DATA : t_datacount TYPE i.

  • Data Declaration for report header layout

DATA : title1_length TYPE p,

title1_pos TYPE p,

title1(30),

date_pos TYPE p,

time_pos TYPE p,

page_pos TYPE p.

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

  • --- SELECTION SCREENS *

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

SELECTION-SCREEN BEGIN OF BLOCK program WITH FRAME TITLE s_fileup.

PARAMETERS : p_upload LIKE rlgrap-filename OBLIGATORY,

p_plansv(3) TYPE c DEFAULT '0',

p_pfiscl(4) TYPE c,

p_dirupd AS CHECKBOX,

p_bdcses AS CHECKBOX DEFAULT 'X',

p_detlis AS CHECKBOX DEFAULT 'X',

p_bdcsna(12).

SELECTION-SCREEN END OF BLOCK program.

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

  • --- INITIALIZATION *

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

INITIALIZATION.

s_fileup = 'Cost Center Upload:'.

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

  • --- AT SELECTION SCREENS *

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_upload.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_path = 'C:\WINDOWS\DESKTOP\'

mask = ',All files,..'

IMPORTING

filename = p_upload

EXCEPTIONS

OTHERS = 01.

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

  • --- TOP-OF-PAGE *

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

TOP-OF-PAGE.

MOVE: sy-sysid TO id-system,

'-' TO id-dash,

sy-mandt TO id-client.

CONDENSE id NO-GAPS.

title1_pos = ( sy-linsz - title1_length ) / 2.

time_pos = page_pos = date_pos = sy-linsz - 15.

WRITE: /1 id.

POSITION date_pos. WRITE: sy-datum.

title1_length = STRLEN( sy-title ).

title1_pos = ( sy-linsz - title1_length ) / 2.

WRITE:/ sy-uname.

POSITION title1_pos. WRITE sy-title.

POSITION time_pos. WRITE: sy-uzeit, ' '.

WRITE:/ sy-repid.

POSITION page_pos. WRITE : 'Page:', sy-pagno.

ULINE.

FORMAT RESET.

WRITE: / 'Fiscal Year: ', p_pfiscl.

ULINE.

WRITE : / 'Cost Ctr ',

'Cost Elmnt ',

'Per. 01 ',

'Per. 02 ',

'Per. 03 ',

'Per. 04 ',

'Per. 05 ',

'Per. 06 ',

'Per. 07 ',

'Per. 08 ',

'Per. 09 ',

'Per. 10 ',

'Per. 11 ',

'Per. 12 '.

ULINE.

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

  • --- START-OF-SELECTION *

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

START-OF-SELECTION.

PERFORM zsr_get_data_from_excel.

DESCRIBE TABLE t_fromexcel LINES t_datacount.

IF t_datacount NE 0. "If there is data from EXCEL file

PERFORM zsr_realign_data_from_excel.

PERFORM zsr_build_the_bdc_structure.

  • IF p_dirupd = 'X'. "If it is direct update

  • PERFORM zsr_direct_update.

  • ENDIF.

*

  • IF p_bdcses = 'X'. "If it is bdc session

  • PERFORM zsr_bdc_session.

  • ENDIF.

IF p_detlis = 'X'. "If required to display data

PERFORM zsr_display_list.

ENDIF.

ELSE.

MESSAGE ID 'ZI' TYPE 'E' NUMBER '000' WITH 'File upload failure!'.

ENDIF.

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

  • --- END-OF-SELECTION *

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

END-OF-SELECTION.

&----


*& Form ZSR_GET_DATA_FROM_EXCEL

&----


  • Get Data from an EXCEL file

----


FORM zsr_get_data_from_excel.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_upload

i_begin_col = '1'

i_begin_row = '2'

i_end_col = '14'

i_end_row = '9'

TABLES

intern = t_fromexcel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2.

IF sy-subrc NE 0.

MESSAGE ID 'ZI' TYPE 'E' NUMBER '000' WITH 'File upload failure!'.

ENDIF.

ENDFORM. "ZSR_GET_DATA_FROM_EXCEL

&----


*& Form zsr_realign_data_from_excel

&----


  • Realign Data into readable format coz file extract from

  • EXCEL has other data append to it. Therefore, these data

  • need to filter and realign to its readable form for

  • processing.

----


FORM zsr_realign_data_from_excel.

DATA: l_current TYPE i.

l_current = t_fromexcel-row.

CLEAR t_data. REFRESH t_data.

LOOP AT t_fromexcel.

  • Reset values for next row

IF t_fromexcel-row NE l_current.

APPEND t_data. CLEAR t_data.

l_current = t_fromexcel-row.

ENDIF.

CASE t_fromexcel-col.

WHEN '1'.

t_data-costcenter = t_fromexcel-value.

WHEN '2'.

t_data-costelment = t_fromexcel-value.

WHEN '3'.

t_data-plan01 = t_fromexcel-value.

WHEN '4'.

t_data-plan02 = t_fromexcel-value.

WHEN '5'.

t_data-plan03 = t_fromexcel-value.

WHEN '6'.

t_data-plan04 = t_fromexcel-value.

WHEN '7'.

t_data-plan05 = t_fromexcel-value.

WHEN '8'.

t_data-plan06 = t_fromexcel-value.

WHEN '9'.

t_data-plan07 = t_fromexcel-value.

WHEN '10'.

t_data-plan08 = t_fromexcel-value.

WHEN '11'.

t_data-plan09 = t_fromexcel-value.

WHEN '12'.

t_data-plan10 = t_fromexcel-value.

WHEN '13'.

t_data-plan11 = t_fromexcel-value.

WHEN '14'.

t_data-plan12 = t_fromexcel-value.

ENDCASE.

ENDLOOP.

APPEND t_data. CLEAR t_data.

PERFORM zsr_fill_data_header.

ENDFORM. "zsr_realign_data_from_excel

&----


*& Form ZSR_FILL_DATA_HEADER

&----


  • - Put a column header to the internal table.

----


FORM zsr_fill_data_header.

LOOP AT t_data.

IF sy-tabix = '1'.

t_data-costcenter = 'Cost Center'.

t_data-costelment = 'Cost Element'.

t_data-plan01 = 'Per. 01'.

t_data-plan02 = 'Per. 02'.

t_data-plan03 = 'Per. 03'.

t_data-plan04 = 'Per. 04'.

t_data-plan05 = 'Per. 05'.

t_data-plan06 = 'Per. 06'.

t_data-plan07 = 'Per. 07'.

t_data-plan08 = 'Per. 08'.

t_data-plan09 = 'Per. 09'.

t_data-plan10 = 'Per. 10'.

t_data-plan11 = 'Per. 11'.

t_data-plan12 = 'Per. 12'.

ENDIF.

MODIFY t_data.

EXIT.

ENDLOOP.

CLEAR t_data.

ENDFORM. "FILL_TEXT_HEADER

&----


*& Form zsr_build_the_bdc_structure

&----


  • Build the BDC structure

----


FORM zsr_build_the_bdc_structure.

DATA : l_index(2) TYPE n,

l_param(15) TYPE c.

DATA : BEGIN OF l_tp_costcenter OCCURS 0,

costcenter LIKE t_data-costcenter,

END OF l_tp_costcenter.

l_index = 1.

LOOP AT t_data.

IF sy-tabix > 1.

l_tp_costcenter-costcenter = t_data-costcenter.

APPEND l_tp_costcenter. CLEAR l_tp_costcenter.

ENDIF.

ENDLOOP.

DELETE ADJACENT DUPLICATES FROM l_tp_costcenter.

*--First Screen for Controlling Area

PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'SVALD-VALUE(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=FURT'.

PERFORM bdc_field USING 'SVALD-VALUE(01)'

'sc01'.

LOOP AT l_tp_costcenter.

IF sy-tabix > 1.

*--Second Screen for data selection

PERFORM bdc_dynpro USING 'SAPLKPP0' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KPP0B-VALUE(08)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=CSUB'.

PERFORM bdc_field USING 'KPP1B-ONLY'

'X'.

PERFORM bdc_field USING 'KPP0B-VALUE(01)'

p_plansv.

PERFORM bdc_field USING 'KPP0B-VALUE(02)'

p_pfiscl.

PERFORM bdc_field USING 'KPP0B-VALUE(04)'

l_tp_costcenter-costcenter.

PERFORM bdc_field USING 'KPP0B-VALUE(07)'

'400000'.

PERFORM bdc_field USING 'KPP0B-VALUE(08)'

'799999'.

PERFORM bdc_dynpro USING 'SAPLKPP2' '0103'.

LOOP AT t_data WHERE costcenter = l_tp_costcenter-costcenter.

*--Third Screen for Entering Plans

CONCATENATE 'Z-BDC15(' l_index ')' INTO l_param.

PERFORM bdc_field USING 'BDC_CURSOR'

l_param.

PERFORM bdc_field USING 'BDC_OKCODE'

'=CBUC'.

CONCATENATE 'Z-BDC02(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-costelment.

CONCATENATE 'Z-BDC04(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan01.

CONCATENATE 'Z-BDC05(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan02.

CONCATENATE 'Z-BDC06(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan03.

CONCATENATE 'Z-BDC07(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan04.

CONCATENATE 'Z-BDC08(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan05.

CONCATENATE 'Z-BDC09(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan06.

CONCATENATE 'Z-BDC10(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan07.

CONCATENATE 'Z-BDC11(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan08.

CONCATENATE 'Z-BDC12(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan09.

CONCATENATE 'Z-BDC13(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan10.

CONCATENATE 'Z-BDC14(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan11.

CONCATENATE 'Z-BDC15(' l_index ')' INTO l_param.

PERFORM bdc_field USING l_param

t_data-plan12.

l_index = l_index + 1.

ENDLOOP.

ENDIF.

IF p_dirupd = 'X'. "If it is direct update

PERFORM zsr_direct_update.

ENDIF.

IF p_bdcses = 'X'. "If it is bdc session

PERFORM zsr_bdc_session.

ENDIF.

l_index = 1.

ENDLOOP.

ENDFORM. "zsr_build_the_bdc_structure

&----


*& Form BDC_DYNPRO

&----


  • Makes an entry into a bdc table specified for a new screen.

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Makes an entry into a bdc table specified for a new field

----


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. " BDC_FIELD

&----


*& Form ZSR_DIRECT_UPDATE

&----


  • Process data using Direct Update

----


FORM zsr_direct_update.

CALL TRANSACTION 'KP06' USING bdcdata MODE 'N' UPDATE 'A'.

ENDFORM. "ZSR_DIRECT_UPDATE

&----


*& Form ZSR_BDC_SESSION

&----


  • Process data using BDC Session

----


FORM zsr_bdc_session.

PERFORM zsr_open_group.

PERFORM zsr_bdc_transaction USING 'KP06'.

PERFORM zsr_close_group.

ENDFORM. "zsr_bdc_session

&----


*& Form zsr_open_group

&----


  • Open Group for BDC Session

----


FORM zsr_open_group.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_bdcsna

user = sy-uname

keep = space.

ENDFORM. "zsr_open_group

&----


*& Form zsr_bdc_transaction

&----


  • Run BDC Session

----


  • -->TCODE Transaction Code

----


FORM zsr_bdc_transaction USING tcode.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = tcode

TABLES

dynprotab = bdcdata.

REFRESH bdcdata.

ENDFORM. "zsr_bdc_transaction

&----


*& Form zsr_close_group

&----


  • Close BDC Session

----


FORM zsr_close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM. "zsr_close_group

&----


*& Form ZSR_DISPLAY_LIST

&----


  • Display the data after data processing

----


FORM zsr_display_list.

CLEAR t_data.

LOOP AT t_data.

IF sy-tabix > 1.

WRITE : / t_data-costcenter,

t_data-costelment,

t_data-plan01,

t_data-plan02,

t_data-plan03,

t_data-plan04,

t_data-plan05,

t_data-plan06,

t_data-plan07,

t_data-plan08,

t_data-plan09,

t_data-plan10,

t_data-plan11,

t_data-plan12.

ENDIF.

ENDLOOP.

ULINE.

ENDFORM. "zsr_display_list

William Wilstroth

0 Kudos

Hi,

place your CLEAR statement inside the loop.

Example:

LOOP AT ITAB.

......

......

.....

APPEND ITAB1.

CLEAR: ITAB, ITAB1.

ENDLOOP.

Thanks.

If this helps you reward with points.

Former Member
0 Kudos

Hi william,

1. just make sure the BDC is such that :

one full transaction

is completed for cost center

00000001

and after that the SCREEN

comes out the whole transaction

to the SAP EASY ACCESS SCREEN.

2. It should not remain in the

same tcode.

I hope it helps.

regards,

amit m.

Former Member
0 Kudos

HI,

Loop will work in this case.

Just assume,

<b>Loop</b> the Internal table, first time it will take the First record(00000001), then perocess the BDC, after SAVE ok code, this cost Center will be saved then <b>ENDLOOP</b>, again it will go to LOOP at statment, then it will take the second record, then process it.. again the 3rd record .. every time the same process...

if this is not workng then you are missing one or more screen fileds or the Screen No's in your Program

Regards

Sudheer

0 Kudos

Before endloop clear ur internal table header.

Just check it out whether the header is clearing or not in the debug mode.

Thanx.

Former Member
0 Kudos

Hi,

just let me know whether u r recording the transaction properly i mean whether u r entering any values for the second cost center if u r entering the values properly r u getting the total details for both the cost centers if u r getting the details of both the cost centers i.e screens then the problem is with ur code go through ur code whether u r looping the data from the internal table propely.check it out and if doen't clears ur doubt then send me the code i'll go through that.

Regards,

suresh

Wil_Wilstroth
Active Participant
0 Kudos

OK guys,

I will try each and everyone solution and suggestion... just give me an hour i come back to you guys...

Thanks appreciate you guys.

William Wilstroth

William Wilstroth

Former Member
0 Kudos

Hi William,

Your first 2 records in the txt file has no problem in updating the database right. i saw your code. I don't thing there is a error in your code. I doubt that

00000001 1012222 12 23<eol>
00000001 1012223 23 34<space><eol>
00000002 1012222 15 23<eol>
00000002 1012223 16 24<eof>

... at the end of 2 line have you left any space. This may make the bdc program not work correctly. Run the program with all the screen visible i.e in mode 'A'.

check it out.

Hope this helps you.

Regards,

Maheswaran.B

0 Kudos

Sorry, it is still not working.

I have change the file to a Excel File (.XLS)

Problem still persist...

Thanks

William Wilstroth