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

Problem while incrementing the index

Former Member
0 Likes
2,213

Hi Friends,

I am working on creating Credit memos and return orders through BDC. For the item level, I am incrementing the index in order to enter the MATNR, POSNR, KWMENG etc. I have seven lines open in my screen. So when I have an order greater than or equal to seven lines, the program is showing an error that that line does not exist in the screen. Please, let me know what is the solution for this.

Thanks,

Raj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,106

Hi, as Srinivas post before that should work, I just edited some lines, I guess was just mistyped.

idx = 01.

LOOP AT itabi WHERE ihrez = itabh-ihrez.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

  • PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.

PERFORM bdc_field USING 'BDC_CURSOR' fnam.

CONCATENATE 'RV45A-MABNR(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-mabnr.

CONCATENATE 'VBAP-ZMENG(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-zmeng.

CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-posnr.

CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam 'Z2'.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=PKO1'.

CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.

PERFORM bdc_field USING 'BDC_CURSOR' fnam.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '=V69A_KOAN'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KWERT(07)'.

PERFORM bdc_field USING 'KOMV-KSCHL(02)' 'ZPR0'.

PERFORM bdc_field USING 'KOMV-KBETR(02)' itabi-kbetr1.

PERFORM bdc_field USING 'KOMV-KSCHL(03)' 'ZPRS'.

PERFORM bdc_field USING 'KOMV-KBETR(03)' itabi-kbetr2.

PERFORM bdc_field USING 'KOMV-KSCHL(04)' 'ZR1'.

PERFORM bdc_field USING 'KOMV-KWERT(04)' itabi-kwert1.

PERFORM bdc_field USING 'KOMV-KSCHL(05)' 'ZLWR'.

PERFORM bdc_field USING 'KOMV-KWERT(05)' itabi-kwert2.

PERFORM bdc_field USING 'KOMV-KSCHL(06)' 'ZLDL'.

PERFORM bdc_field USING 'KOMV-KWERT(06)' itabi-kwert3.

PERFORM bdc_field USING 'KOMV-KSCHL(07)' 'ZLFB'.

PERFORM bdc_field USING 'KOMV-KWERT(07)' itabi-kwert4.

  • perform bdc_field using 'KOMV-KSCHL(08)'

  • 'ZLBD'.

  • perform bdc_field using 'KOMV-KWERT(08)'

  • '0.00'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '=T\13'.

PERFORM bdc_dynpro USING 'SAPMV45A' '4003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/EBACK'.

PERFORM bdc_field USING 'BDC_CURSOR' 'VBAP-ZZRFAR'.

PERFORM bdc_field USING 'VBAP-ZZRWAR' itabi-wcd.

PERFORM bdc_field USING 'VBAP-ZZRFAR' itabi-fcd.

<b>IF idx >= 2.</b>

*-- from third line onwards start doing '+'

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

<b>idx = 1.</b>

ELSE.

*-- this will increment it to 2 and then the IF will takeover

idx = idx + 1.

ENDIF.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE''=SICH'.

Another way to do this is, usually the way I go, is to just execute the next two lines for every incoming line:

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

Hope it Helps.

Regards,

Gilberto Li

20 REPLIES 20
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,106

I believe that when you get to that point, you will need to fire a page down in the OKCODE. I think maybe P+ may work. I have seen many posts that cover this. I usually try to stay away from doing this kind of thing with table controls in BDC, are you sure there is not a BAPI or function module that will work for you?

Regard,

Rich Heilman

Read only

0 Likes
2,106

Rich,

You are right. I was trying the same thing too. I saw a + sign at the bottom of the table control. I am testing through that logic, I hope that works out fine.

Thanks,

Raj

Read only

0 Likes
2,106

Yep, you probably need to keep track of what line number that you are currently on, and when at a certain index 7, 14, 21, 28 etc, hit the page down icon in your BDC. Please make sure to read the post that I have presented above, it talks about screen resolution.

<i>3. Screen Size: Make CTU_PARAMS-DEFSIZ = 'X' in your BDC.</i>

which means that this may act differently depending on what box you run it on.

So when calling the transaction make sure that you check to use the def size.



report zrich_0001 .


data: opt type CTU_PARAMS.
data: bdcdata type table of bdcdata with header line.


<b>opt-defsize = 'X'.</b>

call transaction 'VA02' using bdcdata
                       <b> options from opt.</b>

Regards,

Rich Heilman

Read only

0 Likes
2,106

Typically when you have such a feature(+ button), you can press that after entering every line and by doing that, you will get the new line always in either first or second position in the table control.

1. Enter the first line.

2. Enter the second line.

3. Press '+'.

4. Enter the third record in the second(or first depending on how the '+' reacts) position.

5. Repeat 3 and 4 until all the records are exhausted.

Read only

0 Likes
2,106

Srinivas,

I am giving a new line from the very first line. It is working fine till the seventh line. But after the seventh line, the cursor is coming to the MATNR position and the proghram errors there. I am also attaching my code. If you can correct me from that, it would be helpful.

idx = 01.

LOOP AT ITABI WHERE IHREZ = ITABH-IHREZ.

perform bdc_dynpro using 'SAPMV45A' '4001'.

perform bdc_field using 'BDC_OKCODE'

'=POAN'.

CONCATENATE 'VBAP-ABGRU(' IDX ')' into FNAM.

perform bdc_field using 'BDC_CURSOR'

FNAM.

CONCATENATE 'RV45A-MABNR(' IDX ')' INTO FNAM.

perform bdc_field using fnam

ITABI-MABNR.

CONCATENATE 'VBAP-ZMENG(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

ITABI-ZMENG.

CONCATENATE 'VBAP-POSNR(' IDX ')' INTO FNAM.

perform bdc_field using fnam

ITABI-POSNR.

concatenate 'VBAP-ABGRU(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

'Z2'.

perform bdc_dynpro using 'SAPMV45A' '4001'.

perform bdc_field using 'BDC_OKCODE'

'=PKO1'.

CONCATENATE 'VBAP-POSNR(' IDX ')' into FNAM.

perform bdc_field using 'BDC_CURSOR'

FNAM.

perform bdc_dynpro using 'SAPMV45A' '5003'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'KOMV-KSCHL(01)'.

perform bdc_dynpro using 'SAPMV45A' '5003'.

perform bdc_field using 'BDC_OKCODE'

'=V69A_KOAN'.

perform bdc_field using 'BDC_CURSOR'

'KOMV-KSCHL(01)'.

perform bdc_dynpro using 'SAPMV45A' '5003'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'KOMV-KWERT(07)'.

perform bdc_field using 'KOMV-KSCHL(02)'

'ZPR0'.

perform bdc_field using 'KOMV-KBETR(02)'

ITABI-KBETR1.

perform bdc_field using 'KOMV-KSCHL(03)'

'ZPRS'.

perform bdc_field using 'KOMV-KBETR(03)'

ITABI-KBETR2.

perform bdc_field using 'KOMV-KSCHL(04)'

'ZR1'.

perform bdc_field using 'KOMV-KWERT(04)'

ITABI-KWERT1.

perform bdc_field using 'KOMV-KSCHL(05)'

'ZLWR'.

perform bdc_field using 'KOMV-KWERT(05)'

ITABI-KWERT2.

perform bdc_field using 'KOMV-KSCHL(06)'

'ZLDL'.

perform bdc_field using 'KOMV-KWERT(06)'

ITABI-KWERT3.

perform bdc_field using 'KOMV-KSCHL(07)'

'ZLFB'.

perform bdc_field using 'KOMV-KWERT(07)'

ITABI-KWERT4.

  • perform bdc_field using 'KOMV-KSCHL(08)'

  • 'ZLBD'.

  • perform bdc_field using 'KOMV-KWERT(08)'

  • '0.00'.

perform bdc_dynpro using 'SAPMV45A' '5003'.

perform bdc_field using 'BDC_OKCODE'

'=T\13'.

perform bdc_dynpro using 'SAPMV45A' '4003'.

perform bdc_field using 'BDC_OKCODE'

'/EBACK'.

perform bdc_field using 'BDC_CURSOR'

'VBAP-ZZRFAR'.

perform bdc_field using 'VBAP-ZZRWAR'

ITABI-WCD.

perform bdc_field using 'VBAP-ZZRFAR'

ITABI-FCD.

idx = IDX + 1.

ENDLOOP.

perform bdc_dynpro using 'SAPMV45A' '4001'.

perform bdc_field using 'BDC_OKCODE'

'=SICH'.

Thanks,

Raj

Read only

0 Likes
2,106

What is the okcode for '+' ?

Read only

0 Likes
2,106

it is '=POAN'.

Read only

0 Likes
2,106

When you are creating it online, enter two lines of data and then press this button. See where the new line comes to. Is the second line a new line or is it the first line itself?

Read only

0 Likes
2,106

It is the first line that is new line.I started from the first line because we dont exactly know how many lines are coming in.

Read only

0 Likes
2,106

If it is the 2nd line, something like this should work.


idx = 01.
LOOP AT itabi WHERE ihrez = itabh-ihrez.
  PERFORM bdc_dynpro USING 'SAPMV45A'   '4001'.
<b>*  PERFORM bdc_field  USING 'BDC_OKCODE' '=POAN'.</b>
  CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.
  PERFORM bdc_field  USING 'BDC_CURSOR' fnam.
  CONCATENATE 'RV45A-MABNR(' idx ')' INTO fnam.
  PERFORM bdc_field  USING fnam         itabi-mabnr.
  CONCATENATE 'VBAP-ZMENG(' idx ')' INTO fnam.
  PERFORM bdc_field  USING fnam         itabi-zmeng.
  CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.
  PERFORM bdc_field  USING fnam         itabi-posnr.
  CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.
  PERFORM bdc_field  USING fnam         'Z2'.

  PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
  PERFORM bdc_field USING 'BDC_OKCODE' '=PKO1'.
  CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.
  PERFORM bdc_field USING 'BDC_CURSOR' fnam.

  PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.
  PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
  PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

  PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.
  PERFORM bdc_field USING 'BDC_OKCODE' '=V69A_KOAN'.
  PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

  PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.
  PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
  PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KWERT(07)'.

  PERFORM bdc_field USING 'KOMV-KSCHL(02)' 'ZPR0'.
  PERFORM bdc_field USING 'KOMV-KBETR(02)' itabi-kbetr1.
  PERFORM bdc_field USING 'KOMV-KSCHL(03)' 'ZPRS'.
  PERFORM bdc_field USING 'KOMV-KBETR(03)' itabi-kbetr2.
  PERFORM bdc_field USING 'KOMV-KSCHL(04)' 'ZR1'.
  PERFORM bdc_field USING 'KOMV-KWERT(04)' itabi-kwert1.
  PERFORM bdc_field USING 'KOMV-KSCHL(05)' 'ZLWR'.
  PERFORM bdc_field USING 'KOMV-KWERT(05)' itabi-kwert2.
  PERFORM bdc_field USING 'KOMV-KSCHL(06)' 'ZLDL'.
  PERFORM bdc_field USING 'KOMV-KWERT(06)' itabi-kwert3.
  PERFORM bdc_field USING 'KOMV-KSCHL(07)' 'ZLFB'.
  PERFORM bdc_field USING 'KOMV-KWERT(07)' itabi-kwert4.
* perform bdc_field using 'KOMV-KSCHL(08)'
* 'ZLBD'.
* perform bdc_field using 'KOMV-KWERT(08)'
* '0.00'.

  PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.
  PERFORM bdc_field USING 'BDC_OKCODE'  '=T13'.

  PERFORM bdc_dynpro USING 'SAPMV45A' '4003'.
  PERFORM bdc_field USING 'BDC_OKCODE'  '/EBACK'.
  PERFORM bdc_field USING 'BDC_CURSOR'  'VBAP-ZZRFAR'.
  PERFORM bdc_field USING 'VBAP-ZZRWAR'  itabi-wcd.
  PERFORM bdc_field USING 'VBAP-ZZRFAR'  itabi-fcd.
<b>  IF sy-tabix >= 2.
*-- from third line onwards start doing '+'
    PERFORM bdc_dynpro USING 'SAPMV45A'   '4001'.
    PERFORM bdc_field  USING 'BDC_OKCODE' '=POAN'.
  ELSE.
*-- this will increment it to 2 and then the IF will takeover
    idx = idx + 1.
  ENDIF.</b>
ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE''=SICH'.

Read only

ferry_lianto
Active Contributor
0 Likes
2,106

Hi Raj,

Please try to code BDC_OKCODE = '/00' after looping 7 times. It should open next 7th line items.

Hope this will help.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
2,107

Hi, as Srinivas post before that should work, I just edited some lines, I guess was just mistyped.

idx = 01.

LOOP AT itabi WHERE ihrez = itabh-ihrez.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

  • PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.

PERFORM bdc_field USING 'BDC_CURSOR' fnam.

CONCATENATE 'RV45A-MABNR(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-mabnr.

CONCATENATE 'VBAP-ZMENG(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-zmeng.

CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam itabi-posnr.

CONCATENATE 'VBAP-ABGRU(' idx ')' INTO fnam.

PERFORM bdc_field USING fnam 'Z2'.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=PKO1'.

CONCATENATE 'VBAP-POSNR(' idx ')' INTO fnam.

PERFORM bdc_field USING 'BDC_CURSOR' fnam.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '=V69A_KOAN'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KSCHL(01)'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMV-KWERT(07)'.

PERFORM bdc_field USING 'KOMV-KSCHL(02)' 'ZPR0'.

PERFORM bdc_field USING 'KOMV-KBETR(02)' itabi-kbetr1.

PERFORM bdc_field USING 'KOMV-KSCHL(03)' 'ZPRS'.

PERFORM bdc_field USING 'KOMV-KBETR(03)' itabi-kbetr2.

PERFORM bdc_field USING 'KOMV-KSCHL(04)' 'ZR1'.

PERFORM bdc_field USING 'KOMV-KWERT(04)' itabi-kwert1.

PERFORM bdc_field USING 'KOMV-KSCHL(05)' 'ZLWR'.

PERFORM bdc_field USING 'KOMV-KWERT(05)' itabi-kwert2.

PERFORM bdc_field USING 'KOMV-KSCHL(06)' 'ZLDL'.

PERFORM bdc_field USING 'KOMV-KWERT(06)' itabi-kwert3.

PERFORM bdc_field USING 'KOMV-KSCHL(07)' 'ZLFB'.

PERFORM bdc_field USING 'KOMV-KWERT(07)' itabi-kwert4.

  • perform bdc_field using 'KOMV-KSCHL(08)'

  • 'ZLBD'.

  • perform bdc_field using 'KOMV-KWERT(08)'

  • '0.00'.

PERFORM bdc_dynpro USING 'SAPMV45A' '5003'.

PERFORM bdc_field USING 'BDC_OKCODE' '=T\13'.

PERFORM bdc_dynpro USING 'SAPMV45A' '4003'.

PERFORM bdc_field USING 'BDC_OKCODE' '/EBACK'.

PERFORM bdc_field USING 'BDC_CURSOR' 'VBAP-ZZRFAR'.

PERFORM bdc_field USING 'VBAP-ZZRWAR' itabi-wcd.

PERFORM bdc_field USING 'VBAP-ZZRFAR' itabi-fcd.

<b>IF idx >= 2.</b>

*-- from third line onwards start doing '+'

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

<b>idx = 1.</b>

ELSE.

*-- this will increment it to 2 and then the IF will takeover

idx = idx + 1.

ENDIF.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE''=SICH'.

Another way to do this is, usually the way I go, is to just execute the next two lines for every incoming line:

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=POAN'.

Hope it Helps.

Regards,

Gilberto Li

Read only

0 Likes
2,106

Hi Gilberto,

Your changes will work if by pressing the '+' brings a new line as the first one, but in this case I found that it is bringing the new line in the second position. That is why I left idx without resetting it.

Read only

0 Likes
2,106

Hi,

what about starting from first line.I think this code works from second line.

RAJ

Read only

0 Likes
2,106

When the loop strated, you enter the value in the first line and then the second line. From the third record of the internal table, you will just enter on thw second line only because of the '+'.

Read only

0 Likes
2,106

Hi,

There is a BAPI to create credit memos and orders BAPI_SALESORDER_CREATEFROMDAT2. But as you have already worked on the BDC thing you can go ahead with that.

As far as BDC is concerned, you need not pass POSNR, it will automatically pick the next available number(increment by 10). Moreover, you need not initialize idx to 1 as you need to press '+' for all items >= 2.

For the first line you can just type values without pressing '+', only when it comes to line 2 or more you will use '=POAN'. But I recommend you use BAPI for this.

Thanks

Vamsi

Read only

0 Likes
2,106

Raj,

BDCs are very outdated now. BAPIs are the direction in which you should heading.

When the company with whom you are working goes to upgrade to newer version of SAP, custom BDCs frequently cause headaches as the screens get changed.

You should really re-work your project using BAPIs. Upgrades will be little or NO problem then.

Read only

0 Likes
2,106

Srinivas,

It almost solved my problem. I am now getting all the lines in order. But somehow the item condition values is not being populated. I can see the value when I debug. But when I run it in background the condition values are not coming in.

Raj

Read only

0 Likes
2,106

For the conditions, I think you may not be selecting the correct line item. Again, your BDC logic should be such that you always select the second line item(except for the first record of the internal table) and then go to conditions.

Did you consider the suggestions regarding the use of BAPI instead of BDC?

Read only

0 Likes
2,106

Thanks Srinivas. It solved my problems. I am now able to populate conditions also. I've rewarded you points and also closed the thread.

Once again thanks.

Raj