cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP help

former_member532796
Participant
0 Kudos

Hello everyone,

I have a scenario where abap is required to calculate values based on the Value type of a source field. here is the scenario and would be helpful if get any sample code to achieve the desired output.

Source:

Doc#     ValueType     valuechar

1234     101                   12/13

1234     102                    12/14

1234     103                     12/17

1234      105                     12/20

Output:

Doc#     Valuchar-when 101;      value char-when102     value-char when 103

1234     12/13                              12/14                         12/17

Valuechar-when 101,103,103 are 3 char fields for which the values to populate. this is something like converting row level data to column. the other values 105 etc should be avoided.help is appreciated.

Regards,

Mady

Accepted Solutions (1)

Accepted Solutions (1)

anshu_lilhori
Active Contributor
0 Kudos

Hi,

Create three infoobjects of data type similar to value char.

Map value type and value char to these three infoobjects.

Write a field level routine:

IF source_fields-value type EQ '101'.

Result = Source_fields-value char .

Similarly write for other chars by changing the value type.

Note:Please write the infoobject tech.name accordingly to avoid syntax error.

In case you do not need other value type data then you can delete the same by writing the start routine.

Delete source_package where value type NE '101'

Hope this gives an idea.

Regards,

AL

former_member532796
Participant
0 Kudos

Thank you Anshu for the repsonse.

Actually in our output dso we do not have the value type IO, as we need to avoid unwanted data. The DSO has only doc# and valuechar (3IO's), so when writing that code the value is not being populated. I am not sure if this is because of the value type is not in the dso.

former_member184884
Active Participant
0 Kudos

Hey anshu has suggested you in very clear manner you need to create 3 separate IO for concern DSO which is acting as target, in the piece of code he took value_type IO for checking the record values since you told for 101, 102 & 103 data needs to populated for 3 different IO in the target so value_type is must and i can say it is the main decision maker in populating data.

Hope you understood, still if you've concerns and you need full code for your requirement do revert us we'll assist you in other way

Regards,

Harish

former_member532796
Participant
0 Kudos

Harish,


In the target DSO we have only Doc# & 3 IO's (101, 102, 103). The value type is not included in the target as the data volume is huge and also for some reporting scenarios, we need one record per Doc# in the DSO. So the value type is not maintained in the DSO but I did tried to map the Value type, Doc# & Val char to the target IO to get the require output. This is not working for some reason.

Here is what my transformations look like.

Source                                   Target

Doc# (Directly Mapped to)          Doc#

ValType                                    valchar (Mapped from Doc#, ValType, ValChar & wrote a field routine)

ValChar                   

Routine:

If Source_fields-valtype eq '101'

result = source_fields-val_char.

The above statement is not working for mapped IO. This may be achieved using a expert routine but any sample code would be helpful.

Thx,

Maddy

Former Member
0 Kudos

Hi,

you have to write start routine as following

SORT SOURCE_PACKAGE BY DOC # VALUE TYPE.

Keep an internal table [it_output adn work area wa_output] as similar to target structure [assuming your target would be DSO]

CLEAR L_OLDOCNUM.

LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.

IF l_olddocnum IS NOT INITIAL AND l_olddocnum NE <source_fields>-docnum.

APPEND wa_output INTO it_output.

CLEAR: wa_output, l_olddocnum.

ENDIF.

CASE value_type.

WHEN  = '101'.

WA_OUTPUT-VALUE_TYPE WHEN 101 = <SOURCE_FIELDS>-VALUECHAR.

WHEN =  '102'.

WA_OUTPUT-VALUETYPE WHEN102 = <SOURCE_FIELDS>-VALUECHAR

etc..till required chars, and then delete other values by following statement

WHEN OTHERS

DELETE SOURCE_PACKAGE.

CONTINUE.

ENDCASE.

wa_output-DOCNUM = <SOURCE_FIELDS>-DOCNUM.

....any other fields to mapped directly...ensure it has information in all records

l_olddocnum = <source_fields>-docnum.

ENDLOOP.

"""For last record,

IF l_olddocnum IS NOT INITIAL.

APPEND WA_OUTPUT INTO it_output.

CLEAR wa_output.

*** Now two have options to populate th it_output back to SOURCE_PACKAGE.

either you have global routines with global internal table which will be visible in end routine and then you can map it_output to result_package

or add info source between source and target and add three info objects in info source itself and then write this code in start routine from info source to your target DSO..

If you have any issues, let us know your full techncial details like info objects names and soruce and target type, structure....we can help you on coding part..

former_member532796
Participant
0 Kudos

Thank you Arun.

Source is datasource and target is a DSO.

CLEAR L_OLDOCNUM: this statement is at the begining, how do we fill the value & define this? Also how are we handling the multiple value types for single doc#.

I tried to use source package & field routine but its having issue in populating all the values, it is populating only the last record value i.e. if we have 4 records for one doc# then the 4th record valu type is being fileld using the code.

Could you explain the code in detail? I have field Doc# Value Type Val Char as source fields & Doc# 101ValChar 102 ValChar 103 Valchar as IOs in  my DSO.

Thank you,

Maddy

Former Member
0 Kudos
Former Member
0 Kudos

I had attached code in my note...let me know if you need further help

former_member532796
Participant
0 Kudos

Thank you Arun. How can we assign the internal table to result_package in end routine?

I am getting that the internal table cant be assigned to result_package. Also I tried to map this at field level but when processing multiple records (3..4doc#'s) the values are populated for one doc# remaining three showing '0's. Please suggest if am doing any wrong here.

Appreciate your help.

Maddy

Former Member
0 Kudos

can you copy paste your code ?

Former Member
0 Kudos

sorry, i don't understand you fully... don't go with field level routine - never works for your scenario..either at start routine, end routine or expert routine.

Expert routine is advised if it's only source for that target and filling of the fields through that code.

Otherwise, you are left with start routine and end routine only; also you have to declare that it_output internal table in global data declaration only - not in start routine or end routine.

Also it_output internal table should match with your DSO structure.

Copy / paste your code for further assistance.

former_member532796
Participant
0 Kudos

Solved. Thank you.

I was unable to assign the internal table to result package but used read statement in end routine at new serial number that worked.

Answers (0)