2006 Dec 06 12:36 AM
Hi,
I am writing a BDC for transaction code GS01. I did a recording from SM35 and there is a section of code that I am not sure how would I approach it:
perform bdc_field using 'RGSBL-FROM(01)'
record-FROM_01_008.
perform bdc_field using 'RGSBL-FROM(02)'
record-FROM_02_009.
perform bdc_field using 'RGSBL-FROM(03)'
record-FROM_03_010.
perform bdc_field using 'RGSBL-FROM(04)'
record-FROM_04_011.
FROM varies in number and I think I can't really hardcode this in the program. How would I handle this for varying number of records to be added to the FROM column without the (nn)?
Thanks,
Will
2006 Dec 06 12:41 AM
Hi Will,
Can you post the recordign script from SXDB and highlight where this peice of code is appearing? may be seeign that I will be able to help you.
Alternatively you can pre-determine the number of entries and fill in these numbers with help of a loop.
Regards,
Guru
2006 Dec 06 12:41 AM
Hi Will,
Can you post the recordign script from SXDB and highlight where this peice of code is appearing? may be seeign that I will be able to help you.
Alternatively you can pre-determine the number of entries and fill in these numbers with help of a loop.
Regards,
Guru
2006 Dec 06 12:46 AM
Hi Guruprasad ,
Thanks for your help . Here is the complete code that I did a recording from SM35:
report ZTEST
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
If it is nessesary to change the data section use the rules:
1.) Each definition of a field exists of two lines
2.) The first line shows exactly the comment
'* data element: ' followed with the data element
which describes the field.
If you don't have a data element use the
comment without a data element name
3.) The second line shows the fieldname of the
structure, the fieldname must consist of
a fieldname and optional the character '_' and
three numbers and the field length in brackets
4.) Each field must be type C.
*
Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
data element: SETNAMENEW
SHORTNAME_001(024),
data element: SETTABLE
UTAB_002(030),
data element: SETTYPEB
SETTYPEB_003(001),
data element: SETFLD
FIELD_004(030),
data element: SETTEXT
TITLE_005(040),
data element: SETUNIQSAV
UNIQUE_S_006(001),
data element: SETTEXT
TITLE_007(040),
data element: SETVALMIN
FROM_01_008(024),
data element: SETVALMIN
FROM_02_009(024),
data element: SETVALMIN
FROM_03_010(024),
data element: SETVALMIN
FROM_04_011(024),
end of record.
End generated data section ***
start-of-selection.
perform open_dataset using dataset.
perform open_group.
do.
read dataset dataset into record.
if sy-subrc <> 0. exit. endif.
perform bdc_dynpro using 'SAPMGSBM' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RGSBM-UTAB'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RGSBM-SHORTNAME'
record-SHORTNAME_001.
perform bdc_field using 'RGSBM-UTAB'
record-UTAB_002.
perform bdc_field using 'RGSBM-SETTYPEB'
record-SETTYPEB_003.
perform bdc_dynpro using 'SAPMGSBM' '0190'.
perform bdc_field using 'BDC_CURSOR'
'RGSBS-FIELD'.
perform bdc_field using 'BDC_OKCODE'
'=GOON'.
perform bdc_field using 'RGSBS-FIELD'
record-FIELD_004.
perform bdc_dynpro using 'SAPMGSBM' '0110'.
perform bdc_field using 'BDC_CURSOR'
'RGSBS-TITLE'.
perform bdc_field using 'BDC_OKCODE'
'=SETV'.
perform bdc_field using 'RGSBS-TITLE'
record-TITLE_005.
perform bdc_field using 'RGSBM-UNIQUE_S'
record-UNIQUE_S_006.
perform bdc_dynpro using 'SAPMGSBM' '0115'.
perform bdc_field using 'BDC_CURSOR'
'RGSBL-FROM(04)'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'RGSBS-TITLE'
record-TITLE_007.
perform bdc_field using 'RGSBL-FROM(01)'
record-FROM_01_008.
perform bdc_field using 'RGSBL-FROM(02)'
record-FROM_02_009.
perform bdc_field using 'RGSBL-FROM(03)'
record-FROM_03_010.
perform bdc_field using 'RGSBL-FROM(04)'
record-FROM_04_011.
perform bdc_dynpro using 'SAPMGSBM' '0100'.
perform bdc_field using 'BDC_OKCODE'
'/EBACK'.
perform bdc_field using 'BDC_CURSOR'
'RGSBM-SHORTNAME'.
perform bdc_transaction using 'GS01'.
enddo.
perform close_group.
perform close_dataset using dataset.
I was recording for only several records but I will be reading from a table to ge the value to update the FROM column, and the number of rows vary for each set.
Thanks again!
Will
2006 Dec 06 1:00 AM
Hi Will,
If I understood the problem correctly, you are facing problem with the number of columns as that is dynamic in the flat file. You can solve this with two options:
1. If you have the ability to get the flat file changed:
Then structure the flat file so that it will have have one record in a row with the last field as "FROM". So in case of multiple values for from you shoudl have multiple rows in the flat file.In the code you sent you will have 4 records for this transaction in yoru flat file. Then you can loop in the internal table and fill the corresponding column at runtime. You can diffrentiate between transactions usign the syntax "On change of" in the internal table.
2. If you cannot change the flat file then:
Declare your record with the maximum number of fields you are expecting. In this case you will have only one record with multiple "FROM" values. Then you need to read each of these fields until you find a blank field.
Hope this helps. Feel free to ask me if you didnt understand the logic.
Regards,
Guru
2006 Dec 06 1:24 AM
Hi Guruprasad,
Thanks for the explanation. I am actually will be reading from a table. I am not sure how I would write the code for the following.
perform bdc_field using 'RGSBL-FROM(01)'
record-FROM_01_008.
perform bdc_field using 'RGSBL-FROM(02)'
record-FROM_02_009.
perform bdc_field using 'RGSBL-FROM(03)'
record-FROM_03_010.
perform bdc_field using 'RGSBL-FROM(04)'
record-FROM_04_011.
That is I can't hard code the (01) (02) (03) (04) because it could be up to (20) or (30) or (17) rows when I read the table. I think I am suppose to have only 1 of these statemetns:
perform bdc_field using 'RGSBL-FROM(01)'
record-FROM_01_008.
My missing link is how would I write this code to loop through the FROM without specifying the row number (01) (02) etc. because it varies each time I save to end creating a set. I am writing a BDC for transaction code GS01 and on the second screen it allows me to enter line item rows for a set.
Would you have sample code for htis scenario?
Thanks,
Will
2006 Dec 06 1:33 AM
Hi Will,
Currently I dont have access to a SAP system.
Yes you are right in the sense that you will have to use the statement only once.
I would suggest try this.
1. Declare a numeric variable say N.
2. set the screen size using sysntax set-screen.
3. Then you can use
loop at record.
.
.
N = 0..
do.
N = N+4
perform bdc_field using 'RGSBL-FROM(N-3)'
record-FROM_01_008.
perform bdc_field using 'RGSBL-FROM(N-2)'
record-FROM_02_009.
perform bdc_field using 'RGSBL-FROM(N-1)'
record-FROM_03_010.
perform bdc_field using 'RGSBL-FROM(N)'
record-FROM_04_011.
if 'RGSBL-FROM(N)' eq null.
exit.
enddo.
end loop.
This should solve the problem.
Guru
2006 Dec 06 1:38 AM